Linear Functions
InterviewTime limit1sMemory limit512 MB
Assign each of the integers 1 to N to one of N linear functions so that the sum of the function values is maximized.
Problem
There are linear functions of the form . The -th function is .
For each function, substitute a different integer from to as its , using each of the integers exactly once. Find the maximum possible sum of the values over all functions.
Specifically, choose a permutation of length that maximizes .
Input
The first line contains the number of linear functions .
From the second line onward, the next lines each contain two integers and , separated by a space, that describe the -th function.
Output
Print the answer to the problem on the first line.