시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB222100.000%

문제

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 $n$ gates numbered from 1 to $n$. The $i$-th gate consists of several equivalent checkpoints, which can be considered as points on a plane having coordinates $(i, j)$ for all integers $j$ between $l_i$ and $r_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 $n$ ($2 \le n \le 2 \cdot 10^5$).

Each of the next $n$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 10^9$).

출력

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

예제 입력 1

3
1 3
2 3
1 5

예제 출력 1

6

힌트

In the example test case, all possible routes are:

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