链接:https://codeforces.com/problemset/problem/1151/D

During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of nn high school students numbered from 11 to nn. Initially, each student ii is on position ii. Each student ii is characterized by two numbers — aiai and bibi. Dissatisfaction of the person ii equals the product of aiai by the number of people standing to the left of his position, add the product bibi by the number of people standing to the right of his position. Formally, the dissatisfaction of the student ii, which is on the position jj, equals ai⋅(j−1)+bi⋅(n−j)ai⋅(j−1)+bi⋅(n−j).

The director entrusted Stas with the task: rearrange the people in the queue so that minimize the total dissatisfaction.

Although Stas is able to solve such problems, this was not given to him. He turned for help to you.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of people in the queue.

Each of the following nn lines contains two integers aiai and bibi (1≤ai,bi≤1081≤ai,bi≤108) — the characteristic of the student ii, initially on the position ii.

Output

Output one integer — minimum total dissatisfaction which can be achieved by rearranging people in the queue.

Examples

input

Copy

3
4 2
2 3
6 1

output

Copy

12

input

Copy

4
2 4
3 3
7 1
2 3

output

Copy

25

input

Copy

10
5 10
12 4
31 45
20 55
30 17
29 30
41 32
7 1
5 5
3 15

output

Copy

1423

Note

In the first example it is optimal to put people in this order: (3,1,23,1,2). The first person is in the position of 22, then his dissatisfaction will be equal to 4⋅1+2⋅1=64⋅1+2⋅1=6. The second person is in the position of 33, his dissatisfaction will be equal to 2⋅2+3⋅0=42⋅2+3⋅0=4. The third person is in the position of 11, his dissatisfaction will be equal to 6⋅0+1⋅2=26⋅0+1⋅2=2. The total dissatisfaction will be 1212.

In the second example, you need to put people in this order: (3,2,4,13,2,4,1). The total dissatisfaction will be 2525.

题解:wa点在for循环i也要用long long,-_-

#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
unsigned long long n,t,r,k,s=0;
struct node{
	long long a;
	long long b;
}x[10000001];
bool cmp(node p,node q)
{
	return p.a-p.b>q.a-q.b;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>x[i].a>>x[i].b;
    }
    sort(x+1,x+1+n,cmp);
    for(long long i=1;i<=n;i++)
    {
    	s+=x[i].a*(i-1)+x[i].b*(n-i);
    }
    cout<<s;
    return 0;
}