cho.sh
Notes
Loading...

Visible Mountain Range

Time limit

2s

Memory limit

128 MB

Problem

On a clear day from Ulleungdo, several mountain peaks of the Taebaek range can be seen above the horizon. Treat every mountain as an isosceles triangle placed on the same baseline.

The following drawing illustrates a scene with 5 mountains.

                   /\      /\          /  \  /\     /  \/\    /\/    \/  \    /    \ \  /  \    /    \  -----------------------------

The height of each mountain is twice the length of its base. A mountain is described by the integer x-coordinates of the left and right endpoints of its base.

When all mountains are drawn in the same plane, compute the area of the mountain range that is actually visible above the horizon.

Input

The first line contains the number of mountains N. (1 ≤ N ≤ 100,000)

Each of the next N lines contains two integers l and r separated by a space, describing one mountain. l is the x-coordinate of the left endpoint of the base, and r is the x-coordinate of the right endpoint.

Every x-coordinate in the input is a positive integer not greater than 32767.

Output

Print the visible area of the mountain range on the first line.

The answer fits in a signed 32-bit integer.

                   /\      /\          /  \  /\     /  \/\    /\/    \/  \    /    \ \  /  \    /    \  -----------------------------