#d2971. 奶牛集会
奶牛集会
Cow Gathering
Problem Source
Original problem: USACO04OPEN MooFest G.
Although an simulation can pass, a divide and conquer or Fenwick tree approach is recommended for the full challenge.
Related (harder) problem where fails: P5094.
Problem Description
John's cows attend the "Moo Moo Gathering" every year. It is a grand event in the cow world, with many activities such as stacking hay, jumping fences, and patting cowboys on the butt.
When they gather, the -th cow stands at coordinate , and no two cows share the same coordinate.
The cows are very loud. When cow and cow communicate, they produce a volume of
where and are the hearing abilities of cow and cow respectively.
Assuming every pair of cows is talking simultaneously, compute the sum of the volumes produced by all cows.
Input Format
The first line contains a single integer , .
Lines through : the -th line contains two integers and ().
Output Format
Output a single integer: the total volume produced by all cows.
Sample Input
4
3 1
2 5
2 6
4 3
Sample Output
57