100 atcoder#ABC181B. [ABC181B] Trapezoid Sum

[ABC181B] Trapezoid Sum

Score : 200200 points

Problem Statement

We have a blackboard with nothing written on it. Takahashi will do NN operations to write integers on it.

In the ii-th operation, he will write each integer from AiA_i through BiB_i once, for a total of BiAi+1B_i - A_i + 1 integers.

Find the sum of the integers written on the blackboard after the NN operations.

Constraints

  • All values in input are integers.
  • 1N1051 \leq N \leq 10^5
  • 1AiBi1061 \leq A_i \leq B_i \leq 10^6

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

\vdots

ANA_N BNB_N

Output

Print the sum of the integers written on the blackboard after the NN operations.

2
1 3
3 5
18

In the 11-st operation, he will write 11, 22, and 33 on the blackboard.

In the 22-nd operation, he will write 33, 44, and 55 on the blackboard.

The sum of the integers written is 1+2+3+3+4+5=181+2+3+3+4+5=18.

3
11 13
17 47
359 44683
998244353
1
1 1000000
500000500000