#P5094. Cow Carnival Communications

    ID: 18332 Type: Default 1000ms 256MiB

Cow Carnival Communications

Cow Carnival Communications

Every year, John's N cows participate in the grand Cow Carnival, a worldwide celebration where cows from all over engage in fun activities such as haystack stacking, cow-jumping, and even playful pranks. In one of the celebrations, the cows line up and moo, though their shrill moos have damaged their hearing to varying degrees.

You are given the hearing ability of each cow. For cow i, her hearing threshold is v_i. This means that if cow j wants to be heard by cow i, the volume must be strictly greater than
\( v_i \times dis(i, j) \),
where \( dis(i,j) \) is the distance between them. Thus, if cows i and j wish to converse, they must use a volume of at least
\( \max(v_i,v_j) \times dis(i,j) \).

All N cows are standing on a straight line with coordinate x_i for the i-th cow. Assuming that every pair of cows converse using the minimum required volume, compute the total sum of volumes over all \( \frac{N(N-1)}{2} \) pairs.

Note: If the cows are not given in increasing order of their coordinates, you should sort them first by x_i before processing.

inputFormat

The first line contains a single integer N (the number of cows). Each of the following N lines contains two integers xi and vi, representing the position and hearing threshold of the i-th cow respectively.

You may assume that all xi are distinct.

outputFormat

Output a single integer, the total sum of required conversation volumes for all pairs of cows.

sample

2
1 2
3 1
4