#P2345. Cows’ Moo Conference Volume

    ID: 15618 Type: Default 1000ms 256MiB

Cows’ Moo Conference Volume

Cows’ Moo Conference Volume

John’s n cows, each with a unique coordinate xi and hearing sensitivity vi, attend the annual "Moo Conference" where each pair of cows communicates simultaneously. When cow i and cow j communicate, they produce a volume of
\[ \max\{v_i,v_j\}\times |x_i-x_j| \]

Compute the sum of the volumes generated by all pairs of cows.

Note: No two cows have the same xi. You are given n on the first line followed by n lines, each containing two integers representing xi and vi.

inputFormat

The first line contains an integer n representing the number of cows.
Each of the next n lines contains two integers x and v describing a cow’s coordinate and hearing sensitivity respectively.

outputFormat

Output a single integer, the sum of the volumes produced by all pairs of cows.

sample

3
1 1
2 2
3 3
11