Codeforces Round 643 (Div. 2)
C
Count Triangles
Codeforces
1800
原题
← BD →
翻译中…

Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds?

翻译中…

Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.

翻译中…

The triangle is called non-degenerate if and only if its vertices are not collinear.

翻译中…

Input

翻译中…

The first line contains four integers: $A$, $B$, $C$ and $D$ ($1 \leq A \leq B \leq C \leq D \leq 5 \cdot 10^5$) — Yuri's favourite numbers.

翻译中…

Output

翻译中…

Print the number of non-degenerate triangles with integer sides $x$, $y$, and $z$ such that the inequality $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds.

翻译中…

Note

翻译中…

In the first example Yuri can make up triangles with sides $(1, 3, 3)$, $(2, 2, 3)$, $(2, 3, 3)$ and $(2, 3, 4)$.

翻译中…

In the second example Yuri can make up triangles with sides $(1, 2, 2)$, $(2, 2, 2)$ and $(2, 2, 3)$.

翻译中…

In the third example Yuri can make up only one equilateral triangle with sides equal to $5 \cdot 10^5$.

翻译中…

样例

Input #1
1 2 3 4
Output #1
4
InputCopy OutputCopy
Input #2
1 2 2 5
Output #2
3
InputCopy OutputCopy
Input #3
500000 500000 500000 500000
Output #3
1
InputCopy OutputCopy
题目信息
题号
1355C
时间限制
1 s
内存限制
256 MB
标签
二分
模拟
数学
双指针

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