Under construction

Still being built. Things may change

Gate 21

Time limit2sMemory limit512 MB

Summary
Count the straight lines that pass through exactly one integer checkpoint at each gate i, where gate i covers y from l_i to r_i.
Level

Hard8 of 10

Topics
Math, Geometry
Solved
No attempts yet

Problem

You are participating in a ski race. It is rumored that an autograph of Serj Tankian is the grand prize.

Every racer must pass through nn gates numbered from 1 to nn. The ii-th gate consists of several equivalent checkpoints, which can be considered as points on a plane having coordinates (i,j)(i, j) for all integers jj between lil_i and rir_i, inclusive. It is required to pass through exactly one checkpoint at every gate in increasing order of gate numbers.

Unfortunately, you are very bad at turning on skis. Thus, you would like to prepare a route for yourself, which is a straight line passing through a single checkpoint at every gate. How many route options do you have?

Input

The first line contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

Each of the next nn lines contains two integers lil_i and rir_i (1≤li≤ri≤1091 \le l_i \le r_i \le 10^9).

Output

Output a single integer, the number of valid straight routes you can take.

Hint

In the example test case, all possible routes are:

  • (1,1)→(2,2)→(3,3)(1, 1) \rightarrow (2, 2) \rightarrow (3, 3);
  • (1,2)→(2,2)→(3,2)(1, 2) \rightarrow (2, 2) \rightarrow (3, 2);
  • (1,3)→(2,3)→(3,3)(1, 3) \rightarrow (2, 3) \rightarrow (3, 3);
  • (1,2)→(2,3)→(3,4)(1, 2) \rightarrow (2, 3) \rightarrow (3, 4);
  • (1,3)→(2,2)→(3,1)(1, 3) \rightarrow (2, 2) \rightarrow (3, 1);
  • (1,1)→(2,3)→(3,5)(1, 1) \rightarrow (2, 3) \rightarrow (3, 5).

Examples1

  1. Example 1

    Input
    3
    1 3
    2 3
    1 5
    
    Expected output
    6