Gate 21

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are participating in a ski race. It's 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 l_il\_i and r_ir\_i, inclusive. It's 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?

입력

The first line of the input contains a single integer nn (2n21052 \le n \le 2 \cdot 10^5).

Each of the next nn lines contains two integers l_il\_i and r_ir\_i (1l_ir_i1091 \le l\_i \le r\_i \le 10^9).

출력

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

힌트

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).