Under construction

Still being built. Things may change

Linear Functions

Interview

Time limit1sMemory limit512 MB

Summary
Assign each of the integers 1 to N to one of N linear functions so that the sum of the function values is maximized.
Level

Easy3 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

There are NN linear functions of the form f(x)=ax+bf(x) = ax + b. The ii-th function is fi(x)=aix+bif_i(x) = a_i x + b_i.

For each function, substitute a different integer from 11 to NN as its xx, using each of the NN integers exactly once. Find the maximum possible sum of the values f(x)f(x) over all functions.

Specifically, choose a permutation x1,x2,…,xNx_1, x_2, \ldots, x_N of length NN that maximizes ∑i=1Naixi+bi\sum_{i=1}^N a_i x_i + b_i.

Input

The first line contains the number of linear functions NN. (1≤N≤100,000)(1 \le N \le 100{,}000)

From the second line onward, the next NN lines each contain two integers aia_i and bib_i, separated by a space, that describe the ii-th function. (0≤ai,bi≤109)(0 \le a_i, b_i \le 10^9)

Output

Print the answer to the problem on the first line.

Examples1

  1. Example 1

    Input
    5
    2 4
    5 1
    3 2
    1 10
    0 0
    
    Expected output
    62