Collisions

No attempts yetTime limit1sMemory limit128 MB

Problem

Identical small balls sit on a straight line and can move only along that line. Each ball moves at a constant velocity, but different balls may have different velocities. When two balls meet, a perfectly elastic collision occurs. It is a well-known physical fact that when two bodies of equal mass A and B collide perfectly elastically, they exchange velocities: after the collision A moves with B's previous velocity and B moves with A's previous velocity.

Write a program that computes the total number of collisions.

Input

The first line contains the number of balls N (3N2000003 \le N \le 200000).

Each of the next N lines contains two space-separated integers: the starting coordinate and the velocity of one ball. All starting coordinates satisfy 1011<x<1011-10^{11} < x < 10^{11} and all velocities satisfy 108<v<108-10^{8} < v < 10^{8}. All starting coordinates are distinct. It is guaranteed that every collision involves exactly two balls (no collision involves three or more balls at the same instant).

Output

Print a single integer on one line: the total number of collisions. If the number of collisions were infinite, print 987654321987654321 instead.