Collisions#1233

Collisions

1 second
64 megabytes
Very easy

Identical small balls are placed on a straight line and can move only along this line. Each ball initially moves with a constant velocity; the sign of the velocity indicates its direction. When two balls meet, they collide and swap their velocities: if ball moves at velocity V_A and ball at V_B, after the collision, ball moves at velocity V_B and ball moves at velocity V_A.

Calculate the total number of collisions that occur.

Input

The first line contains the number of balls (3 \leq N \leq 200\,000). Each of the following lines contains space-separated integers: the initial coordinate and the velocity of the corresponding ball. All initial coordinates are different and satisfy -10^{11} < x_i < 10^{11}. All velocities satisfy -10^{8} < v_i < 10^{8}. It is guaranteed that each collision involves exactly two balls (no collision involves three or more balls simultaneously).

Output

Output a single integer — the total number of collisions, or if the number of collisions is infinite.

Examples

Example 1

Loading
Loading