AtCoder Beginner Contest 181
B
Trapezoid Sum
AtCoder
⌀ 0
原题
← AC →
翻译中…

Problem Statement

翻译中…

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

翻译中…

In the $i$-th operation, he will write each integer from $A_i$ through $B_i$ 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.

翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $1 \leq N \leq 10^5$
  • $1 \leq A_i \leq B_i \leq 10^6$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
\vdots
A_N B_N

翻译中…

Output

翻译中…

Print the sum of the integers written on the blackboard after the $N$ operations.

翻译中…

样例

Input #1
2
1 3
3 5
Output #1
18
In the $1$-st operation, he will write $1$, $2$, and $3$ on the blackboard. In the $2$-nd operation, he will write $3$, $4$, and $5$ on the blackboard. The sum of the integers written is $1+2+3+3+4+5=18$.
Input #2
3
11 13
17 47
359 44683
Output #2
998244353
Input #3
1
1 1000000
Output #3
500000500000
题目信息
题号
abc181_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。