CF276C Little Girl and Maximum Sum

Description

The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $ n $ elements (the elements of the array are indexed starting from 1); also, there are $ q $ queries, each one is defined by a pair of integers $ l_{i} $ , $ r_{i} $ $ (1

Input Format

The first line contains two space-separated integers $ n $ ( $ 1

Output Format

In a single line print a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.