5640: ABC181——B - Trapezoid Sum
[Creator : ]
Description
We have a blackboard with nothing written on it. Takahashi will do $N\ (1 \leq N \leq 10^5)$ operations to write integers on it.
In the $i$-th operation, he will write each integer from $A_i\ (1 \leq A_i \leq 10^6)$ through $B_i\ (1 \leq B_i \leq 10^6)$ once, for a total of $B_i−A_i+1$ integers.
Find the sum of the integers written on the blackboard after the $N$ operations.
In the $i$-th operation, he will write each integer from $A_i\ (1 \leq A_i \leq 10^6)$ through $B_i\ (1 \leq B_i \leq 10^6)$ once, for a total of $B_i−A_i+1$ integers.
Find the sum of the integers written on the blackboard after the $N$ operations.
Input
Input is given from Standard Input in the following format:
$N$
$A_1\ B_1$
$\dots$
$A_N\ B_N$
$N$
$A_1\ B_1$
$\dots$
$A_N\ B_N$
Output
Print the sum of the integers written on the blackboard after the $N$ operations.
Sample 1 Input
2
1 3
3 5
Sample 1 Output
18
In the $1$-st operation, he will write $1,\ 2,\ 3$ on the blackboard.
In the $2$-nd operation, he will write $3,\ 4,\ 5$ on the blackboard.
The sum of the integers written is $1+2+3+3+4+5=18$.
In the $2$-nd operation, he will write $3,\ 4,\ 5$ on the blackboard.
The sum of the integers written is $1+2+3+3+4+5=18$.
Sample 2 Input
3
11 13
17 47
359 44683
Sample 2 Output
998244353
Sample 3 Input
1
1 1000000
Sample 3 Output
500000500000