description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = [int(x) for x in input().split()]
ans = 0
for y in range(b, c + 1):
u = min(d - y, b - 1)
l = c - y
if l <= u:
left = (u - l + 1) * (b + 1)
L = c - y
U = min(d - y, b - 1, a - 1)
s = 0
if L <= U:
p1 = (U - L + 1) * a
s += p1
L = max(a, c - y)
U = min(d - y, b - 1)
if L <= U:
p2 = (U + 1 - (L + 1) + 1) * (U + 1 + L + 1) // 2
s += p2
ans += left - s
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
cnt = 0
for s in range(a + b, b + c + 1):
maxZ = s - 1
if maxZ < c:
continue
goodZ = min(d, maxZ) - c + 1
minX = a
maxX = min(s // 2, b)
if minX > maxX:
continue
minY = max(s - s // 2, b)
maxY = min(s - 1, c)
if minY > maxY:
continue
begin1 = minX - 1
end1 = maxX - 1 + 1
begin2 = s - 1 - maxY
end2 = s - 1 - minY + 1
begin = max(begin1, begin2)
end = min(end1, end2)
if begin < end:
cnt += goodZ * (end - begin)
print(cnt)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
x = input().split(" ")
A = int(x[0])
B = int(x[1])
C = int(x[2])
D = int(x[3])
def gauss_count(n):
if n <= 0:
return 0
return n * (n + 1) // 2
count = 0
for z in range(C, D + 1):
if A + B > z:
count += (B - A + 1) * (C - B + 1)
continue
x0 = z - C + 1
y0 = z - B + 1
incl1 = gauss_count(B - x0 + 1)
excl1 = gauss_count(A - x0)
excl2 = gauss_count(B - y0)
count += max(0, incl1 - excl1 - excl2)
print(count)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
for xy in range(c + 1, b + c + 1):
if xy < a + b:
continue
temp = 0
if xy - b > b:
temp = min(b - a, c - (xy - b)) + 1
else:
temp = min(xy - b - a, c - b) + 1
ans += (min(d + 1, xy) - c) * temp
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
pprint = lambda s: print(" ".join(map(str, s)))
input = lambda: sys.stdin.readline().strip()
ipnut = input
a, b, c, d = map(int, input().split())
z = d
dp = 0
for y in range(b, c + 1):
dp += max(0, b - max(z - y + 1, a) + 1)
z += 1
ans = dp
for i in range(d - c):
z -= 1
dp += min(
max(0, min(z - a, c) - max(b, z - b) + 1),
max(0, min(z - b, b) - max(a, z - c) + 1),
)
ans += dp
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
ans = 0
def len(a, b):
return b - a + 1
for z in range(C, D + 1):
if z - A + 1 < B:
ans += (C - B + 1) * (B - A + 1)
elif B <= z - A + 1 <= C:
l1 = len(z - A + 1, C)
ans += l1 * (B - A + 1)
miny1 = B
miny2 = z - A
len1 = max(0, B - z + miny1)
len2 = max(0, B - z + miny2)
ans += (len1 + len2) * len(len1, len2) // 2
elif C < z - A + 1:
miny1 = B
miny2 = C
len1 = max(0, B - z + miny1)
len2 = max(0, B - z + miny2)
ans += (len1 + len2) * len(len1, len2) // 2
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = int(0)
for i in range(c, d + 1):
bi = b
delta1 = i - b + 1
if delta1 <= a:
ans += (c - b + 1) * (b - a + 1)
continue
if delta1 > b:
bi = bi + delta1 - b
delta1 = b
if bi > c:
continue
ost = c - bi + 1
if delta1 - ost + 1 < a:
ans += (b + 1 - a + (b + 1 - delta1)) * (b + 1 - a - (b + 1 - delta1) + 1) // 2
ans += (a - (delta1 - ost + 1)) * (b - a + 1)
else:
ans += (
(b + 1 - (delta1 - ost + 1) + (b + 1 - delta1))
* (b + 1 - (delta1 - ost + 1) - (b + 1 - delta1) + 1)
// 2
)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = list(map(int, input().split()))
rows, columns, maxEntry = c - b + 1, b - a + 1, d - c + 1
count, prev = 0, 0
for n in range(1, a):
prev += rows - sorted([n - maxEntry, rows, 0])[1] - max(0, rows - n)
for n in range(a, b + 1):
prev += rows - sorted([n - maxEntry, rows, 0])[1] - max(0, rows - n)
count += prev
print(count)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def rn():
a = int(input())
return a
def rl():
a = list(map(int, input().split()))
return a
[a, b, c, d] = rl()
C = b - a + 1
R = c - b + 1
Per = min(R, C)
mul = [Per for i in range(R + C)]
for i in range(1, Per):
mul[i] = i
mul[-i] = i
curr = a + b
mul2 = [(0) for i in range(R + C)]
ans = 0
for i in range(1, R + C):
mul2[i] = max(0, min(curr - 1, d) - c + 1)
ans += mul[i] * mul2[i]
curr += 1
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
from sys import stdin, stdout
int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
def solve(a, b, c, d):
result = 0
p1 = b
p2 = c
while p2 - p1 + 1 > b:
p1 += 1
while p1 <= c and p2 <= d:
x = p2 - p1 + 1
if x <= a:
result += (b - a + 1) * (c - p1 + 1)
elif x <= b:
n = b - x + 1
m = n + x - a
m = min(m, n + c - p1)
result += m * (m + 1) // 2 - n * (n - 1) // 2 + m * max(c - p1 - m + n, 0)
else:
break
p2 += 1
while p2 - p1 + 1 > b:
p1 += 1
return result
a, b, c, d = arr_in()
out(solve(a, b, c, d))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def check(a, b, c, d):
ans = 0
for z in range(c, d + 1):
z_ans = 0
for x in range(a, b + 1):
for y in range(b, c + 1):
if x + y > z:
z_ans += 1
print(z, z_ans)
ans += z_ans
print(ans)
a, b, c, d = map(int, input().split())
ans = 0
h = c - b + 1
w = b - a + 1
for z in range(c, d + 1):
if b + c <= z:
break
if a + b > z:
ans += h * w
continue
e = z + 1 - b
f = z + 1 - a
if e < b:
if f < c:
ans += h * w - (e - a) * (f - b + 1) // 2
else:
ans += (b - e + 1) * h + h * (h - 1) // 2
elif f < c:
ans += (c - f + 1) * w + w * (w - 1) // 2
else:
ans += (h + b - e) * (h + b - e + 1) // 2
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
res = 0
for i in range(max(A + B, C), C + D + 1):
res += (
i - A - B + 1 + max(0, i - B - C - 1) - max(0, i - A - C) - max(0, i - B - B)
) * min(i - C, D - C + 1)
print(int(res))
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
arr = [0] * 1000077
for i in range(A, B + 1):
arr[i + B] += 1
arr[i + C + 1] -= 1
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
Sum = 0
for i in range(C, D + 1):
Sum += arr[len(arr) - 1] - arr[i]
print(Sum)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda: int(input())
ip = lambda: [int(w) for w in input().split()]
a, b, c, d = ip()
dp = [0] * (b + c + 2)
for i in range(a, b + 1):
dp[i + b] += 1
dp[i + c + 1] -= 1
for i in range(1, len(dp)):
dp[i] += dp[i - 1]
ans = 0
for i in range(a + b, b + c + 2):
if i > d:
ans += dp[i] * (d - c + 1)
elif i > c:
ans += dp[i] * (i - c)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def f(n):
if n <= 0:
return 0
return n * (n + 1) // 2
a, b, c, d = map(int, input().split())
ans = 0
for z in range(c, d + 1):
ans += (
f(b + c - z)
- f(2 * b - z - 1)
- f(a + c - z - 1)
+ (2 * b - z - 1 > b - a) * f(2 * b - z - 2 + a - b)
)
print(ans)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
ans = 0
for i in range(A, B + 1):
a = i - C + max(C - i + 1, B)
d = 1
n = max(min(D + 1 - i + 1, C + 1) - max(C - i + 1, B), 0)
ans += a * n + n * (n - 1) * d // 2
ans += (D + 1 - C) * max(0, C + 1 - max(min(D + 1 - i + 1, C + 1), B))
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = lambda: sys.stdin.readline().strip()
a, b, c, d = map(int, input().split())
dp = [0] * (11 * 10**5)
for x in range(a, b + 1):
dp[x + b] += 1
dp[x + c + 1] -= 1
for i in range(1, 11 * 10**5):
dp[i] += dp[i - 1]
for i in range(11 * 10**5 - 2, 0, -1):
dp[i] += dp[i + 1]
ans = 0
for z in range(c, d + 1):
ans += dp[z + 1]
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
def main():
A, B, C, D = map(int, input().split())
mx = A
my = C
mz = C
iv = 0
val = 0
for i in range(1, B + 1):
val = val + (C - my + 1) * (B - max(i, A) + 1)
if mz + 1 > D:
C = C - 1
my = max(my - 1, B)
mz = mz + 1
if C < B:
break
print(val)
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def readStr():
return input()
def readInts():
return list(map(int, readStr().split(" ")))
def s(a, b, c, z):
s = 0
if b + c - z > 0:
s += (b + c - z) * (b + c - z + 1) // 2
if a + c - z > 1:
s -= (a + c - z - 1) * (a + c - z) // 2
if 2 * b - z > 1:
s -= (2 * b - z - 1) * (2 * b - z) // 2
if a + b - z > 2:
s += (a + b - z - 2) * (a + b - z - 1) // 2
return s
def main(a, b, c, d):
v = 0
for z in range(c, d + 1):
v += s(a, b, c, z)
return v
a, b, c, d = readInts()
x = main(a, b, c, d)
print(x)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = list(map(int, input().split()))
ans = 0
y = b
x = a
while y + a < d + 1 and y <= c:
if y + b > c:
j = max(a, c + 1 - y) + y - c
i = min(y + b - c, d - c + 1)
if (d - c + 1) * (y + b - d - 1) > 0:
ans += i * (i + 1) // 2 - j * (j - 1) // 2 + (d - c + 1) * (y + b - d - 1)
else:
ans += i * (i + 1) // 2 - j * (j - 1) // 2
y += 1
ans += (c - y + 1) * (b - a + 1) * (d - c + 1)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
x = [0] * (2 * 5 * 10**5 + 1)
ans = 0
for i in range(a + b, b + c + 1):
v = min(i - a - b + 1, b - a + 1, c - b + 1, abs(i - b - c) + 1)
x[i] += v
for i in range(len(x) - 1):
x[i + 1] += x[i]
for i in range(c, d + 1):
ans += x[-1] - x[i]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
pref = [(0) for i in range(2 * d + 10)]
for i in range(a, b + 1):
l = i + b
r = i + c
pref[l] += 1
pref[r + 1] -= 1
sums = [(0) for i in range(2 * d + 10)]
for i in range(1, len(sums)):
sums[i] = sums[i - 1] + pref[i]
ans = 0
j = 1
for i in range(c + 1, d + 2):
ans += sums[i] * j
j += 1
for i in range(d + 2, len(sums)):
ans += (d - c + 1) * sums[i]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def solve(a: int, b: int, c: int, d: int) -> int:
return sum(
[
((v - u + 1) * w)
for u, v, w in [
(max(summa - c, a), min(summa - b, b), min(summa - c, d - c + 1))
for summa in range(c + 1, b + c + 1)
]
if u <= v
]
)
a, b, c, d = map(int, input().split())
print(solve(a, b, c, d))
|
FUNC_DEF VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = [int(i) for i in input().split()]
count = 0
for x in range(a, b + 1):
min_b = c - x + 1
if min_b < b:
min_b = b
iters = c - min_b
max_sum = x + min_b
if max_sum > d:
max_sum = d + 1
i0 = max_sum - c
last_max_sum = max_sum + iters
if last_max_sum > d:
extra_iters = last_max_sum - d - 1
iters = iters - extra_iters
last_max_sum = max_sum + iters
count += extra_iters * (last_max_sum - c)
i_n = last_max_sum - c
if iters == 0:
total = i0
else:
total = i_n * (i_n + 1) // 2 - i0 * (i0 - 1) // 2
count += total
print(count)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def findFor(x):
reqForb1 = x - B[1]
reqForb0 = x - B[0]
ans = 0
if reqForb1 > A[1]:
return 0
else:
if A[0] <= reqForb1 <= A[1]:
no1 = A[1] - reqForb1 + 1
ans += (no1 + 1) * no1 // 2
if reqForb0 > A[1]:
no2 = 1
else:
no2 = A[1] - reqForb0 + 1
ans -= (no2 - 1) * no2 // 2
else:
no1 = A[1] - reqForb1 + 1
ans += (no1 + 1) * no1 // 2
if reqForb0 < A[0]:
ans = (A[1] - A[0] + 1) * (B[1] - B[0] + 1)
elif reqForb0 > A[1]:
ans = (A[1] - A[0] + 1) * (A[0] - reqForb1)
no1 = A[1] - A[0] + 1
ans += no1 * (no1 + 1) // 2
else:
ans = (A[1] - A[0] + 1) * (A[0] - reqForb1)
no1 = A[1] - A[0] + 1
no2 = A[1] - reqForb0
ans += no1 * (no1 + 1) // 2
ans -= no2 * (no2 + 1) // 2
return ans
a, b, c, d = list(map(int, input().split()))
A = [a, b]
B = [b, c]
C = [c, d]
sum = 0
for i in range(c, d + 1, 1):
sum += findFor(i + 1)
print(sum)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
def countt(z):
if b + c <= z:
return 0
if a + b > z:
return (b - a + 1) * (c - b + 1)
xstart = max(z - c + 1, a)
xfin = min(b, z + 1 - b)
ilo = (
(abs(xstart - xfin) + 1)
* (c + 1 - (z - xstart + 1) + c + 1 - (z - xfin + 1))
// 2
)
ilo += (b - xfin) * (c - b + 1)
return ilo
wyn = 0
for z in range(c, d + 1):
wyn += countt(z)
print(wyn)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
f = b - c
ans = [0]
for x in range(1, b + 1):
asd = ans[-1]
asd -= max(0, f)
asd += min(d - c + 1, x)
f = min(f + 1, min(d - c + 1, x))
ans.append(asd)
print(sum(ans[a:]))
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def func(z, a, b, c):
if c + b <= z:
return 0
yMin = z - b + 1
if yMin < b:
yMin = b
xMax = max(z + 1 - yMin, a)
num = min([c - yMin + 1, xMax - a + 1])
s = b - xMax + 1
res = (s + s + num - 1) * num // 2
res += max(c - yMin + 1 - (xMax - a + 1), 0) * (b - a + 1)
return res
a, b, c, d = map(int, input().split())
ans = 0
for z in range(c, d + 1):
ans += func(z, a, b, c)
print(ans)
|
FUNC_DEF IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
def read_integer():
return int(sys.stdin.readline())
def read_integers():
return [int(x) for x in sys.stdin.readline().split(" ")]
def print_integers(nums):
print(" ".join([str(x) for x in nums]))
def f1(i, a, b, c, d):
ret = 0
for j in range(b, c + 1):
ret += max(0, min(d, i + j - 1) - max(c, j - i + 1) + 1)
return ret
def f2(i, a, b, c, d):
if c + i - 1 <= d:
top = c + i - 1 - c + 1
bottom = max(1, b + i - 1 - c + 1)
num = top - bottom + 1
return (top + bottom) * num // 2
else:
ret = (c + i - 1 - d) * (d - c + 1)
if b + i - 2 > d:
ret -= (b + i - 2 - d) * (d - c + 1)
else:
ret += (d - c + 1 + 1) * (d - c + 1) // 2
if b + i - 1 > c:
ret -= (b + i - 2 - c + 1 + 1) * (b + i - 2 - c + 1) // 2
return ret
def func(a, b, c, d):
ans = 0
for i in range(a, b + 1):
r = f2(i, a, b, c, d)
ans += r
print(ans)
func(*read_integers())
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
arr = [0] * max(b + c + 2, d + 1)
for i in range(a, b + 1):
arr[i + b] += 1
arr[i + c + 1] += -1
prefix = [0] * max(b + c + 2, d + 1)
curr = 0
for i in range(len(arr)):
curr += arr[i]
prefix[i] = curr
prefix2 = [0] * max(b + c + 2, d + 1)
curr = 0
for i in range(len(arr) - 1, -1, -1):
curr += prefix[i]
prefix2[i] = curr
print(sum(prefix2[c + 1 : d + 2]))
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D, ans = [int(s) for s in input().split()] + [0]
for z in range(C, D + 1):
l, r = B - min(z - B + 1, B) + 1, B - max(z - C + 1, A) + 1
ans += (B - A + 1) * (min(A, z - B + 2) - (z - C + 1)) if z - C + 1 < A else 0
ans += (l + r) * (r - l + 1) // 2 if l <= r else 0
print(ans)
|
ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def solve(a, b, c, d):
ans = 0
for x in range(a, b + 1):
y_s = max(b, c - x + 1)
y_e = max(min(d + 1 - x, c), y_s)
t_s, t_e = min(y_s + x - 1, d) - c + 1, min(y_e + x - 1, d) - c + 1
ans += (t_s + t_e) * (y_e - y_s + 1) // 2
if y_e < c:
ans += (c - y_e) * (d - c + 1)
return ans
a, b, c, d = list(map(int, input().split()))
print(solve(a, b, c, d))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
I = sys.stdin.readline
def read_ints():
return list(map(int, I().split(" ")))
def sum_up_to(num):
return num * (num + 1) // 2
def solve():
a, b, c, d = read_ints()
ans = 0
for z in range(c, d + 1):
p = max(z + 1 - b, b)
if p > c:
break
x_base = z - p + 1
if x_base < a:
x_base = a
y_range = c - p
x_range = min(x_base - a, y_range)
l = b - x_base + 1
r = l + x_range
ans += sum_up_to(r) - sum_up_to(l - 1)
ans += (b - a + 1) * (y_range - x_range)
return ans
print(solve())
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def search(low, high, check):
mid = (high + low) // 2
while high >= low:
if check(mid):
low = mid + 1
else:
high = mid - 1
mid = (high + low) // 2
return mid
a, b, c, d = map(int, input().split())
num = min(b - a, c - b)
num2 = max(b - a, c - b)
num3 = a + b
ans = 0
i = num3 - 1
def check(num):
global i
return num < i
for i in range(num3, num3 + num2 + num + 1):
high = search(c, d, check)
num4 = min(min(i - num3 + 1, num + 1), num3 + num2 + num + 1 - i)
ans += (high - c + 1) * num4
print(ans)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
for z in range(c, d + 1):
if b + c > z:
ans += (b - a + 1) * (c - b + 1)
if z >= a + b:
ans -= (z - a - b + 1) * (z - a - b + 2) // 2
if a + c <= z:
ans += (z - a - c) * (z - a - c + 1) // 2
if b + b <= z:
ans += (z - b - b) * (z - b - b + 1) // 2
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
def solve():
input = sys.stdin.readline
A, B, C, D = map(int, input().split())
ans = 0
fib = [0] * (D + 1)
fib[1] = 1
for i in range(2, D + 1):
if i <= C - B + 1:
fib[i] = fib[i - 1] + i
else:
fib[i] = fib[i - 1] + (C - B + 1)
for z in range(C, D + 1):
if B + C <= z:
continue
else:
xlow = z - C + 1
pN = B - xlow + 1
psubN = A - xlow
if xlow >= A:
ans += fib[pN]
else:
ans += fib[pN] - fib[psubN]
print(ans)
return 0
def __starting_point():
solve()
__starting_point()
|
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
from sys import stdin
input = stdin.readline
a, b, c, d = [int(x) for x in input().strip().split()]
ans = 0
n = 10**6 + 100
m = [0] * n
for i in range(a, b + 1):
m[i + b] += 1
m[i + c + 1] -= 1
i = 1
while i < n:
m[i] += m[i - 1]
i += 1
i = 1
while i < n:
m[i] += m[i - 1]
i += 1
ans = 0
for i in range(c, d + 1):
ans += m[n - 1] - m[i]
print(ans)
|
ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
from itertools import accumulate
a, b, c, d = map(int, input().split())
num = [0] * (b + c + 1)
for i in range(a, b + 1):
num[i + b - 1] += 1
num[i + c] -= 1
num = list(accumulate(num))
ans = 0
for i in range(len(num)):
ans += num[i] * min(max(i + 1 - c, 0), d - c + 1)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
N = 10**6 + 77
A, B, C, D = map(int, input().strip().split())
cnt = 0
a = [0] * N
for i in range(A, B + 1):
a[i + B] += 1
a[i + C + 1] -= 1
for i in range(1, N):
a[i] += a[i - 1]
for i in range(1, N):
a[i] += a[i - 1]
ans = 0
for i in range(C, D + 1):
ans += a[N - 1] - a[i]
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
a, b, c, d = list(map(int, input().split()))
ans = 0
for i in range(a + b, b + c + 1):
if i - a <= c:
tempa = a
tempb = i - a
else:
tempb = c
tempa = i - c
if i > d:
ans += min(b - tempa + 1, tempb - b + 1) * (d - c + 1)
elif min(b - tempa + 1, tempb - b + 1) * (i - c) >= 0:
ans += min(b - tempa + 1, tempb - b + 1) * (i - c)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = [int(j) for j in input().split()]
l1 = [i for i in range(a + b, b + c + 1)]
l2 = [(0) for i in range(a + b, b + c + 1)]
stop1 = min(2 * b, a + c) - (a + b)
stop2 = max(2 * b, a + c) - (a + b)
n = len(l1)
l2[0] = 1
flag1 = True
flag2 = True
if stop1 == 0:
flag1 = False
for i in range(1, n):
if flag1 and flag2:
l2[i] = l2[i - 1] + 1
elif flag1 == False and flag2 == True:
l2[i] = l2[i - 1]
else:
l2[i] = max(0, l2[i - 1] - 1)
if i == stop1:
flag1 = False
if i == stop2:
flag2 = False
c = [(i + 1) for i in range(c, d + 1)]
ans = 0
for i in range(n - 2, -1, -1):
l2[i] += l2[i + 1]
for i in range(len(c)):
ind = max(c[i] - (a + b), 0)
if ind >= n:
continue
ans += l2[ind]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
l = input().split()
A = int(l[0])
B = int(l[1])
C = int(l[2])
D = int(l[3])
num = 0
for x in range(A, B + 1):
left = max(C - x, B)
right = min(C, D + 1 - x)
if right < left:
rem = C - left + 1
num += rem * (D - C + 1)
else:
rem = C - right
num += rem * (D - C + 1)
curr = max(0, x + left - C)
num += (right - left + 1) * (right - left) // 2
num += (right - left + 1) * curr
print(num)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
A, B, C, D = list(map(int, input().split()))
def sm2(x, A, B, C):
MIN = A + B
MAX = B + C
fr = min(B - A, C - B)
sa = min(x - MIN, MAX - x, fr)
return sa + 1
def calc(x, C, D):
return max(0, min(x - 1, D) - C + 1)
ANS = 0
for x in range(A + B, B + C + 1):
smplus = sm2(x, A, B, C)
ANS += smplus * calc(x, C, D)
print(ANS)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
l = list(map(int, input().split()))
lt = [0] * (l[1] + l[2] + 2)
for i in range(l[0], l[1] + 1):
lt[i + l[1]] += 1
lt[i + l[2] + 1] -= 1
for i in range(1, l[1] + l[2] + 2):
lt[i] += lt[i - 1]
c = 0
for i in range(len(lt)):
if i > l[2]:
c += lt[i] * (min(i, l[3] + 1) - l[2])
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
j = a
s = 0
while j <= b:
l = j + b
r = j + c
p = l - c
q = r - c
if l > d:
s += (r - l + 1) * (d - c + 1)
elif r > d and l <= d:
if p > 0:
s += (r - d) * (d - c + 1) + (d - c) * (d - c + 1) // 2 - (p - 1) * p // 2
else:
s += (r - d) * (d - c + 1) + (d - c) * (d - c + 1) // 2
elif r <= d:
if p <= 0 and q <= 0:
s += 0
elif p <= 0 and q > 0:
s += q * (q + 1) // 2
elif p > 0 and q > 0:
s += q * (q + 1) // 2 - (p - 1) * p // 2
j += 1
print(s)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
X = A, B
Y = B, C
Z = C, D
z_max = min(B + C - 1, D)
z_min = C
ans = 0
for z in range(z_min, z_max + 1):
x_min = max(0, A)
x_max = min(B, z)
y_min = max(0, B)
y_max = min(C, z)
if z < x_min + y_min:
ans += (x_max - x_min + 1) * (y_max - y_min + 1)
elif z > x_max + y_max:
continue
else:
z_up = z - y_max
z_down = z - y_min
z_left = z - x_min
z_right = z - x_max
if z_left <= y_max and z_left >= y_min:
if z_down <= x_max and z_down >= x_min:
ans += (x_max - x_min + 1) * (y_max - y_min + 1) - (
z_left - y_min + 1
) * (z_left - y_min + 2) // 2
else:
ke = y_max - z_right
ek = y_max - z_left
ans += (ke - ek + 1) * (ke + ek) // 2
elif z_right <= y_max and z_right >= y_min:
ans += (y_max - z_right + 1) * (y_max - z_right) // 2
else:
ans += (y_max - y_min + 1) * (x_max - z_up + x_max - z_down) // 2
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = map(int, input().split())
Ans = 0
for i in range(C, D + 1):
k = i + 1 - B
j = B
if k > B:
j += k - B
if B <= j <= C:
k = max(i - j + 1, A)
t = k - A + 1
p = C - j + 1
q = B - k
if p >= t:
Ans += t * (t + 1) // 2 + (p - t) * t + p * q
else:
Ans += p * (p + 1) // 2 + p * q
print(Ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
st = input()
getting = ""
num = []
for i in st:
if i == " ":
num.append(int(getting))
getting = ""
else:
getting += i
num.append(int(getting))
A = num[0]
B = num[1]
C = num[2]
D = num[3]
ans = 0
if C - B > B - A:
min = B - A
else:
min = C - B
def large(add):
if add <= C:
return 0
elif add > C and add <= D:
return add - C
else:
return D - C + 1
def combin(sum):
if sum < min + 1:
return sum + 1
elif sum > C - A - min - 1:
return C - A - sum + 1
else:
return min + 1
for i in range(C - A + 1):
ans = ans + large(i + A + B) * combin(i)
print(f"{ans}")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
tri2 = lambda x: x * (x + 1) // 2
tri = lambda x: tri2(max(x, 0))
total = 0
for x in range(a, b + 1):
total += tri(x) - tri(c - (d - x) - 1) - tri(b - (c - x) - 1) + tri(b - (d - x) - 2)
print(total)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
l = []
l1 = []
for i in range(a + b, b + c + 1):
l.append(i)
x = i - c
y = i - b
l1.append(max(0, min(b, y) - max(a, x) + 1))
ans = 0
for i in range(len(l)):
if l[i] > c:
ans += l1[i] * min(l[i] - c, d - c + 1)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def num_x(A, B, C, D, t):
low = max(C - t, A)
high = min(B, D - t)
return max(0, high - low + 1)
def ans(A, B, C, D):
ret = 0
for t in range(0, D + 1):
nx = num_x(A, B, C, D, t)
f = C - max(B, t + 1) + 1
if nx > 0 and f > 0:
ret += nx * f
return ret
A, B, C, D = input().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
print(ans(A, B, C, D))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = [int(x) for x in input().split()]
ans = 0
for xpy in range(a + b, b + c + 1):
v = min(b - a + 1, c - b + 1, min(xpy - a - b + 1, b + c - xpy + 1))
l = c
r = min(xpy - 1, d)
ans += v * max(0, r - l + 1)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
def sigma(x):
return x * (x + 1) // 2
def answer(A, B, C, D):
_sum = 0
for i in range(A, B + 1):
_sum += i * (i + 1) // 2
_length = C - B + 1
if i - _length > 0:
_sum -= sigma(i - _length)
headMax = D - C + 1
if i > headMax:
_sum -= sigma(i - headMax)
if i - headMax > _length:
_sum += sigma(i - headMax - _length)
return _sum
A, B, C, D = map(int, input().split())
print(answer(A, B, C, D))
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
for x in range(a, b + 1):
if x + b <= d:
x0 = max(0, x + b - c)
xn = min(x, d - c)
p = max(0, x + c - d) * (d - c + 1)
tmp = (x0 + xn) * (xn - x0 + 1) // 2 + p
else:
tmp = (c - b + 1) * (d - c + 1)
ans += tmp
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
from sys import stdin as si
def evaluate(a, b, c, d):
count = 0
for i in range(max(c + 1, a + b), b + c + 1):
count += (min(d + 1, i) - c) * (min(i - b, b) - max(i - c, a) + 1)
return count
a, b, c, d = map(int, si.readline().strip().split())
print(evaluate(a, b, c, d))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
gr = max(a + b, c + 1)
ans = 0
for i in range(gr, c + b + 1):
x = a
y = b
cur = i - a - b
if cur <= b - a:
x += cur
cur = 0
else:
cur += a - b
x = b
y += cur
ans += (min(d, i - 1) - c + 1) * (min(x - a, c - y) + 1)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
for i in range(a, b + 1):
x = i + b
y = i + c
if y <= c:
continue
if x <= c and y <= d:
ans += (y - c + 1) * (y - c) // 2
continue
if x >= d:
ans += (d - c + 1) * (y - x + 1)
if x == d:
ans -= 1
continue
if x > c and y <= d:
ans += (y - c) * (y - c + 1) // 2
ans -= (x - c) * (x - c - 1) // 2
continue
if x > c and y > d:
ans += (d - c) * (d - c + 1) // 2
ans -= (x - c) * (x - c - 1) // 2
ans += (y - d) * (d - c + 1)
continue
if x <= c and y > d:
ans += (d - c + 1) * (d - c) // 2
ans += (y - d) * (d - c + 1)
continue
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
[a, b, c, d] = input().split(" ")
a = int(a)
b = int(b)
c = int(c)
d = int(d)
def f(x):
if x < 1:
return 0
else:
return x * (x + 1) * (x + 2) // 6
print(
(a + 2 * b - c) * (b + 1 - a) * (c + 1 - b) // 2
+ f(c - a - b)
- f(c - 2 * b - 1)
- f(b + c - d - 1)
+ f(a + c - d - 2)
+ f(2 * b - d - 2)
- f(a + b - d - 3)
)
|
ASSIGN LIST VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
a, b, c, d = nm()
m = 10**6 + 10
l = [0] * m
for i in range(a, b + 1):
l[i + b] += 1
l[i + c + 1] += -1
for i in range(m - 1):
l[i] += l[i - 1]
for i in range(m - 2, -1, -1):
l[i] += l[i + 1]
print(sum(l[i + 1] for i in range(c, d + 1)))
return
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
readline = sys.stdin.readline
A, B, C, D = map(int, readline().split())
ans = 0
for z in range(C, D + 1):
a = max(A, z + 1 - C)
b = min(B, z - B)
c = max(A, z - B + 1)
d = B
if a <= b:
ans += (C - z + a + C - z + b) * (b - a + 1) // 2
if c <= d:
ans += (C - B + 1) * (d - c + 1)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
minz = c
for i in range(a, b + 1):
lenz = d - c + 1
ymore = minz - i
if ymore < b - 1:
alpha = min(b - ymore, lenz)
ans += alpha * (c - b + 1)
cury = c - b
lenz = lenz - alpha
else:
cury = c - ymore
if cury > lenz:
ans += lenz * (lenz + 1) // 2 + (cury - lenz) * lenz
else:
ans += cury * (cury + 1) // 2
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
s = 0
f = [(0) for i in range(2000003)]
for i in range(a, b + 1, 1):
f[b + i] += 1
f[c + i + 1] -= 1
u = 0
for i in range(1, 1000002, 1):
u += f[i]
f[i] = f[i - 1] + u
for i in range(c, d + 1, 1):
s += f[1000001] - f[i]
print(s)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
ru = [0] * (10**6 + 10)
for x in range(a, b + 1):
l = x + b
r = x + c + 1
ru[l] += 1
ru[r] -= 1
for i in range(10**6 + 9):
ru[i + 1] += ru[i]
for i in range(10**6 + 9):
ru[i + 1] += ru[i]
ans = 0
for z in range(c, d + 1):
ans += ru[-1] - ru[z]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
xy = dict()
for i in range(a + b, b + c + 1):
f = min(i - a - b + 1, b + c - i + 1)
f = min(f, b - a + 1, c - b + 1)
xy[i] = f
ans = 0
for i in range(a + b, b + c + 1):
if i > d:
ans += xy[i] * (d - c + 1)
elif i <= c:
continue
else:
ans += xy[i] * (i - c)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
mi = a + b
mx = c + b
ans = 0
p = min(c - b + 1, b - a + 1)
q = max(c - b, b - a)
f = {}
for i in range(mi, mx + 1):
t = 0
l, r = a, b + 1
for kek in range(20):
j = (l + r) // 2
if i - j <= c:
r = j
else:
l = j
funny1 = r
l, r = funny1, b + 1
for kek in range(20):
j = (l + r) // 2
if b <= i - j:
l = j
else:
r = j
funny2 = l
f[i] = funny2 - funny1 + 1 + f.get(i - 1, 0)
for z in range(c, d + 1):
if z >= mx:
break
g = min(mx - z, mx - mi + 1)
ans += f[mx] - f.get(mx - g, 0)
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = [int(i) for i in input().split()]
cnt = 0
cmp = [0] * (c + d + 2)
for x in range(a, b + 1):
cmp[x + b] += 1
cmp[x + c + 1] -= 1
for i in range(1, c + d + 1):
cmp[i + 1] += cmp[i]
res = 0
for i in range(c + d + 2):
res += cmp[i] * max(0, min(d, i - 1) - c + 1)
print(res)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import itertools
a, b, c, d = map(int, input().split())
def solve(a, b, c, d):
ans = 0
pre = [0] * (b + c + 2)
for i in reversed(range(a, b + 1)):
pre[i + b] += 1
pre[i + c + 1] -= 1
pre = list(itertools.accumulate(pre))
pre = list(itertools.accumulate(pre))
a = max(pre)
last = 0
for i in range(c, d + 1):
if i < b + c + 1:
last = a - pre[i]
ans += last
return ans
print(solve(a, b, c, d))
|
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
A, B, C, D = map(int, input().split())
ans = 0
dic2 = {z: (0) for z in range(C, min(D, B + C - 1) + 1)}
for z in range(C, min(D, B + C - 1) + 1):
if 2 * B >= z + 1:
if A >= z + 1 - B:
ans += (B - A + 1) * (C - B + 1)
dic2[z] = (B - A + 1) * (C - B + 1)
elif A >= z + 1 - C:
ans += (
(B + C - z) * (B + C + 1 - z) // 2
- (2 * B - z) * (2 * B - z - 1) // 2
- (A + C - z) * (A + C - z - 1) // 2
)
dic2[z] = (
(B + C - z) * (B + C + 1 - z) // 2
- (2 * B - z) * (2 * B - z - 1) // 2
- (A + C - z) * (A + C - z - 1) // 2
)
else:
ans += (B + C - z) * (B + C + 1 - z) // 2 - (2 * B - z) * (
2 * B - z - 1
) // 2
dic2[z] = (B + C - z) * (B + C + 1 - z) // 2 - (2 * B - z) * (
2 * B - z - 1
) // 2
elif A >= z + 1 - C:
ans += (B + C - z) * (B + C - z + 1) // 2 - (A + C - z) * (A + C - z - 1) // 2
dic2[z] = (B + C - z) * (B + C - z + 1) // 2 - (A + C - z) * (
A + C - z - 1
) // 2
else:
ans += (B + C - z) * (B + C - z + 1) // 2
dic2[z] = (B + C - z) * (B + C - z + 1) // 2
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
array = list(map(int, input().split()))
a = array[0]
b = array[1]
c = array[2]
d = array[3]
x, y = a + b, b + c
m, n = b + b, a + c
if m > n:
t = n
n = m
m = t
add = 0
jod = 0
flag = 0
i = x
while i <= y:
if flag == 0:
jod += 1
if i >= m and i <= n:
flag = 1
elif flag == 1:
jod -= 1
if i > d:
add += (d - c + 1) * jod
elif i <= d and i > c:
add += (i - c) * jod
i += 1
print(add)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
l = list(map(int, input().split(" ")))
ans = 0
def ssum(n):
return n * (n + 1) // 2
a = l[0]
b = l[1]
c = l[2]
d = l[3]
for x in range(a, b + 1):
yy = c - x + 1
yyy = d - x + 1
if yy < b:
yy = b
if yyy >= c:
yyy = c
ans += x * (yyy - yy + 1) - c * (yyy - yy + 1) + (ssum(yyy) - ssum(yy - 1))
if yyy < c:
if yyy >= yy:
ans += x * (yyy - yy + 1) - c * (yyy - yy + 1) + (ssum(yyy) - ssum(yy - 1))
ans += (d - c + 1) * (c - yyy)
if yyy < yy:
ans += (d - c + 1) * (c - yy + 1)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
ans = 0
count = [0] * (10**6 + 10)
for x in range(a, b + 1):
count[x + b] += 1
count[x + c + 1] -= 1
for j in range(2):
for i in range(1, 10**6 + 10):
count[i] += count[i - 1]
for z in range(c, d + 1):
ans += (b - a + 1) * (c - b + 1) - count[z]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.buffer.readline
A, B, C, D = map(int, input().split())
tmp = 0
ans = 0
for k in reversed(range(C, B + C + 1)):
if k <= D:
ans += tmp
tmp += max(min(B, k - B) - max(A, k - C) + 1, 0)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
a, b, c, d = map(int, input().split())
mn = a + b
mx = b + c
cnt = [0] * (10**6 + 4)
l = 1
for i in range(mn, mx + 1):
if l == min(c - b + 1, b - a + 1):
break
cnt[i] = l
l += 1
l = 1
for i in range(mx, mn - 1, -1):
if l == min(c - b + 1, b - a + 1):
break
cnt[i] = l
l += 1
for i in range(mn, mx + 1):
if cnt[i] == 0:
cnt[i] = l
for i in range(len(cnt) - 2, -1, -1):
cnt[i] += cnt[i + 1]
ans = 0
for i in range(c, d + 1):
ans += cnt[i + 1]
print(ans)
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
import sys
input = sys.stdin.readline
A, B, C, D = map(int, input().split())
imos = [0] * (2 * D + 2)
res = 0
for x in range(A, B + 1):
imos[x + B] += 1
imos[x + C + 1] -= 1
for i in range(2 * D + 1):
imos[i + 1] += imos[i]
for i in range(2 * D + 1, 0, -1):
imos[i - 1] += imos[i]
for z in range(C + 1, D + 2):
res += imos[z]
print(res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
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.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----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$.
|
A, B, C, D = list(map(int, input().strip().split()))
triangles = 0
for x in range(A, B + 1):
y_min = C + 1 - x
y_for_z_max = D + 1 - x
if y_min < B and y_for_z_max < B:
triangles += (D - C + 1) * (C - B + 1)
elif y_min < B and B <= y_for_z_max <= C:
triangles += (C - y_for_z_max) * (D - C + 1) + (y_for_z_max - B + 1) * (
(x + B - C + (D - C + 1)) / 2
)
elif y_min < B and y_for_z_max > C:
triangles += (x + B - C + x) / 2 * (C - B + 1)
elif B <= y_min <= C and B <= y_for_z_max <= C:
triangles += (C - y_for_z_max) * (D - C + 1) + (y_for_z_max - y_min + 1) * (
(1 + (D - C + 1)) / 2
)
elif B <= y_min <= C and y_for_z_max > C:
triangles += (x + 1) / 2 * (C - y_min + 1)
else:
print("ERROR")
print(int(triangles))
|
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
from sys import stdin
def main():
n, k = list(map(int, stdin.readline().split()))
ar = list(map(int, stdin.readline().split()))
lk = {(ar[i] - 1): i for i in range(n)}
pair = [(-1) for _ in range(n)]
for _ in range(k):
x, y = list(map(int, stdin.readline().split()))
if lk[y - 1] > lk[x - 1]:
pair[y - 1] = max(pair[y - 1], lk[x - 1])
else:
pair[x - 1] = max(pair[x - 1], lk[y - 1])
start = 0
end = 0
ok = True
ans = 0
while end < n:
while end < n and ok:
curr = ar[end] - 1
if start <= pair[curr]:
ok = False
else:
end += 1
if end < n:
while start <= pair[ar[end] - 1]:
ans += end - start
start += 1
else:
ans += (end - start + 1) * (end - start) // 2
ok = True
print(ans)
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
from sys import stdin
def main():
from sys import stdin
n, m = list(map(int, input().split()))
n += 1
aa, pos, duo = [0] * n, [0] * n, [0] * n
for i, a in enumerate(map(int, input().split()), 1):
aa[i] = a
pos[a] = i
for s in stdin.read().splitlines():
x, y = list(map(int, s.split()))
px, py = pos[x], pos[y]
if px > py:
if duo[x] < py:
duo[x] = py
elif duo[y] < px:
duo[y] = px
res = mx = 0
for i, a in enumerate(aa):
if mx < duo[a]:
mx = duo[a]
res += i - mx
print(res)
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
from sys import stdin
def main():
n, m = map(int, input().split())
pos, left = [0] * n, [0] * n
for i, a in enumerate(map(int, input().split())):
pos[a - 1] = i
for s in stdin.read().splitlines():
l, r = map(int, s.split())
l, r = pos[l - 1], pos[r - 1]
if l > r:
l, r = r, l
if l >= left[r]:
left[r] = l + 1
ans = l = 0
for i in range(n):
if left[i] > l:
l = left[i]
ans += i - l + 1
print(ans)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
import sys
n, m = map(int, sys.stdin.buffer.readline().decode("utf-8").split())
a = list(map(int, sys.stdin.buffer.readline().decode("utf-8").split()))
index = [0] * (n + 1)
ng = [-1] * n
for i, x in enumerate(a):
index[x] = i
for x, y in (map(int, line.decode("utf-8").split()) for line in sys.stdin.buffer):
s, t = min(index[x], index[y]), max(index[x], index[y])
ng[t] = max(ng[t], s)
left = -1
ans = 0
for i in range(n):
left = max(left, ng[i])
ans += i - left
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
import sys
def FoePairs():
n, m = sys.stdin.readline().split()
n = int(n)
m = int(m)
s = n + 1
p = [0] * s
pos_p = [0] * s
closest_pos = [0] * s
i = 1
line = sys.stdin.readline().split()
while i < s:
t = int(line[i - 1])
p[i] = t
pos_p[t] = i
i += 1
for x in range(0, m):
start, finish = sys.stdin.readline().split()
start = int(start)
finish = int(finish)
p_finish = pos_p[finish]
p_start = pos_p[start]
if p_finish > p_start:
closest_pos[finish] = max(closest_pos[finish], p_start)
else:
closest_pos[start] = max(closest_pos[start], p_finish)
i = 1
respuesta = 0
current_closest_pos = 0
while i < s:
current_closest_pos = max(current_closest_pos, closest_pos[p[i]])
respuesta += i - current_closest_pos
i += 1
print(respuesta)
FoePairs()
|
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
import sys
n, m = map(int, input().split())
pos = [None] * (n + 1)
for i, a in enumerate(map(int, input().split())):
pos[a] = i
z = [300005] * (n + 1)
for pr in sys.stdin.read().splitlines():
x, y = map(int, pr.split())
if pos[x] > pos[y]:
x, y = y, x
z[pos[x]] = min(z[pos[x]], pos[y])
lf, rg = n - 1, n - 1
ans = 0
while lf >= 0:
if z[lf] is not None:
rg = min(rg, z[lf] - 1)
ans += rg - lf + 1
lf -= 1
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
def f():
sizes = input().split(" ")
n, m = int(sizes[0]), int(sizes[1])
permStr = input().split(" ")
pairsStr = [input() for i in range(m)]
indexes = [(0) for i in range(n + 1)]
for i in range(n):
indexes[int(permStr[i])] = i + 1
lowerNums = [(0) for i in range(n + 1)]
for i in range(m):
pair = pairsStr[i].split(" ")
a, b = indexes[int(pair[0])], indexes[int(pair[1])]
if a < b:
l = a
h = b
else:
l = b
h = a
if l > lowerNums[h]:
lowerNums[h] = l
counter = 0
left = 0
for i in range(1, n + 1):
candidate = lowerNums[i]
if candidate > left:
r = i - 1 - left
q = i - 1 - candidate
counter += (r * (r - 1) - q * (q - 1)) // 2
left = candidate
r = i - left
counter += r * (r - 1) // 2
print(counter + n)
f()
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
n, x, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans, l, r = 0, 0, 0
for y in a:
kol = (y // x - k) * x
ml = min(kol, y)
mr = min(kol + x, y)
while l < n:
if a[l] > ml:
break
l += 1
while r < n:
if a[r] > mr:
break
r += 1
ans += r - l
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
f = lambda: map(int, input().split())
n, x, k = f()
t = sorted(f())
s = i = j = 0
for y in t:
d = (y // x - k) * x
while i < n and t[i] <= min(d, y):
i += 1
while j < n and t[j] <= min(d + x, y):
j += 1
s += j - i
print(s)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
import sys
sys.setrecursionlimit(100000000)
def iin():
return int(input())
def impin():
return list(map(int, input().split()))
def irrin():
return [int(x) for x in input().split()]
def imrin(n):
return [int(input()) for _ in range(n)]
def c(n, k):
if n < k:
return 0
s = 1
for i in range(1, k + 1):
s *= n - i + 1
s //= i
return s
n, x, k = impin()
arr = irrin()
if k == 0:
trr = {}
frr = {}
for a in arr:
if a % x != 0:
p = a // x
if p in trr:
trr[p] += 1
else:
trr[p] = 1
if a in frr:
frr[a] += 1
else:
frr[a] = 1
s = 0
for p in trr:
s += c(trr[p] + 1, 2)
for a in frr:
s += c(frr[a], 2)
print(s)
else:
urr = {}
lrr = {}
for a in arr:
u = (a - 1) // x + 1
l = a // x
if u in urr:
urr[u] += 1
else:
urr[u] = 1
if l in lrr:
lrr[l] += 1
else:
lrr[l] = 1
s = 0
for u in urr:
l = u + k - 1
if l in lrr:
s += urr[u] * lrr[l]
print(s)
|
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
def bina(arr, i, n, x, k, j):
l, h, ans = i, n - 1, n
while l <= h:
m = (l + h) // 2
cnt = arr[m] // x - (arr[i] - 1) // x
if cnt <= k:
l = m + 1
else:
ans = m
h = m - 1
l, h, ans2 = j, ans - 1, j - 1
while l <= h:
m = (l + h) // 2
cnt = arr[m] // x - (arr[i] - 1) // x
if cnt < k:
ans2 = m
l = m + 1
else:
h = m - 1
return ans, ans2
n, x, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
j = 0
ind, ind2 = bina(arr, 0, n, x, k, 0)
ans = ind - ind2 - 1
for i in range(1, n):
if arr[i] > arr[j]:
j = i
ind, ind2 = bina(arr, i, n, x, k, j)
ans += ind - ind2 - 1
print(ans)
|
FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
n, x, k = map(int, input().split())
array = list(map(int, input().split()))
def next_x(n):
return (n + x - 1) // x * x
valcount = {}
for a in array:
valcount[a] = valcount.get(a, 0) + 1
begs = {}
pairs = 0
for val, count in sorted(valcount.items()):
if k > 0 or val % x != 0:
beg = next_x(val)
begs[beg] = begs.get(beg, 0) + count
from_ = next_x(val - k * x + 1)
pairs += count * begs.get(from_, 0)
print(pairs)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that a_{i} ≤ a_{j} and there are exactly k integers y such that a_{i} ≤ y ≤ a_{j} and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
-----Input-----
The first line contains 3 integers n, x, k (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9, 0 ≤ k ≤ 10^9), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print one integer — the answer to the problem.
-----Examples-----
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
-----Note-----
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
|
n, x, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
ans = 0
s, t = 0, 0
for j in range(n):
cur = (a[j] // x - k) * x
while s < n and a[s] <= min(cur, a[j]):
s += 1
while t < n and a[t] <= min(cur + x, a[j]):
t += 1
ans += t - s
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Iahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n). Iahub can go from one cell (i, j) only down or right, that is to cells (i + 1, j) or (i, j + 1).
Also, there are m cells that are occupied by volcanoes, which Iahub cannot enter.
Iahub is initially at cell (1, 1) and he needs to travel to cell (n, n). Knowing that Iahub needs 1 second to travel from one cell to another, find the minimum time in which he can arrive in cell (n, n).
-----Input-----
The first line contains two integers n (1 ≤ n ≤ 10^9) and m (1 ≤ m ≤ 10^5). Each of the next m lines contains a pair of integers, x and y (1 ≤ x, y ≤ n), representing the coordinates of the volcanoes.
Consider matrix rows are numbered from 1 to n from top to bottom, and matrix columns are numbered from 1 to n from left to right. There is no volcano in cell (1, 1). No two volcanoes occupy the same location.
-----Output-----
Print one integer, the minimum time in which Iahub can arrive at cell (n, n). If no solution exists (there is no path to the final cell), print -1.
-----Examples-----
Input
4 2
1 3
1 4
Output
6
Input
7 8
1 6
2 6
3 5
3 6
4 3
5 1
5 2
5 3
Output
12
Input
2 2
1 2
2 1
Output
-1
-----Note-----
Consider the first sample. A possible road is: (1, 1) → (1, 2) → (2, 2) → (2, 3) → (3, 3) → (3, 4) → (4, 4).
|
__author__ = "Pavel Mavrin"
n, m = [int(x) for x in input().split()]
a = []
for i in range(m):
a.append([(int(x) - 1) for x in input().split()])
a.sort(key=lambda x: x[0] * n + x[1])
a.append([n - 1, n])
d = [[0, 1]]
r = 0
i = 0
while i < len(a):
if a[i][0] == r:
dd = []
j = 0
while i < len(a) and a[i][0] == r and j < len(d):
if a[i][1] < d[j][0]:
i += 1
elif a[i][1] == d[j][0]:
d[j][0] += 1
if d[j][0] >= d[j][1]:
j += 1
i += 1
else:
dd.append([d[j][0], a[i][1]])
d[j][0] = a[i][1] + 1
while j < len(d) and d[j][1] <= a[i][1] + 1:
j += 1
if j < len(d):
d[j][0] = max(d[j][0], a[i][1] + 1)
if j < len(d):
dd.append([d[j][0], n])
while i < len(a) and a[i][0] == r:
i += 1
d = dd
r += 1
if len(d) == 0:
break
else:
r = a[i][0]
d = [[d[0][0], n]]
if len(d) == 0 or d[len(d) - 1][1] < n:
print(-1)
else:
print(2 * (n - 1))
|
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR LIST LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
b.reverse()
Res = 0
for i in range(min(n, m)):
if a[i] < b[i]:
Res += b[i] - a[i]
print(Res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
from sys import stdin
n, m = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
l = min(min(a), min(b))
r = max(max(a), max(b))
ans = 10**20
while l <= r:
lo = l + (r - l) // 3
hi = r - (r - l) // 3
cou = 0
for i in a:
cou += max(0, lo - i)
for j in b:
cou += max(0, j - lo)
cou1 = 0
for i in a:
cou1 += max(0, hi - i)
for j in b:
cou1 += max(0, j - hi)
if cou1 > cou:
r = hi - 1
elif cou1 < cou:
l = lo + 1
else:
l = lo + 1
r = hi - 1
ans = min(ans, cou, cou1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inara():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
n, m = invr()
a = inara()
b = inara()
a.sort()
b.sort(reverse=True)
dpA = [0] * (n + 1)
for i in range(n):
dpA[i + 1] = dpA[i] + a[i]
dpB = [0] * (m + 1)
for i in range(m):
dpB[i + 1] = dpB[i] + b[i]
def Find(val, flag):
if flag == True:
lo = 0
hi = n - 1
ans = 0
while hi >= lo:
mid = (hi + lo) // 2
if a[mid] <= val:
ans = val * (mid + 1) - dpA[mid + 1]
assert ans >= 0
lo = mid + 1
else:
hi = mid - 1
return ans
else:
lo = 0
hi = m - 1
ans = 0
while hi >= lo:
mid = (hi + lo) // 2
if b[mid] >= val:
ans = dpB[mid + 1] - val * (mid + 1)
assert ans >= 0
lo = mid + 1
else:
hi = mid - 1
return ans
def f(val):
return Find(val, True) + Find(val, False)
hi = int(1000000000.0)
lo = 1
ans = -1
while hi >= lo:
m1 = lo + (hi - lo) // 3
m2 = hi - (hi - lo) // 3
if f(m1) <= f(m2):
hi = m2 - 1
ans = f(m1)
else:
lo = m1 + 1
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
def read(mode=2):
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2:
return [int(x) for x in inputs.split()]
def write(s="\n"):
if isinstance(s, list):
s = " ".join(s)
s = str(s)
print(s, end="")
n, m = read()
a = read()
b = read()
s = [(0, 2)] + [(i, 0) for i in a] + [(i, 1) for i in b]
s.sort()
t = sum(b)
al = 0
br = m
mn = t
for i in range(1, n + m + 1):
t += (al - br) * (s[i][0] - s[i - 1][0])
mn = min(mn, t)
if s[i][1]:
br -= 1
else:
al += 1
print(mn)
|
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
def f(m):
ans = 0
for i in a:
ans += max(0, m - i)
for i in b:
ans += max(0, i - m)
return ans
l = 0
r = 10**9 + 3
while r - l > 2:
m1 = l + (r - l) // 3
m2 = m1 + (r - l) // 3
if f(m1) >= f(m2):
l = m1
else:
r = m2
print(min(f(l), f(l + 1), f(r)))
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
def costo(a, b, t):
resultado = 0
for elem in a:
resultado += max(t - elem, 0)
for elem in b:
resultado += max(elem - t, 0)
return resultado
m, n = tuple(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
inf, sup = min(a), max(b)
while inf < sup:
t = (inf + sup) // 2
if costo(a, b, t + 1) - costo(a, b, t) >= 0:
sup = t
else:
inf = t + 1
print(costo(a, b, inf))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
n, m = map(int, input().split())
a, b = list(map(int, input().split())), list(map(int, input().split()))
a.sort()
b.sort()
i = j = 0
s = t = sum(b)
while True:
if i == n or j < m and a[i] > b[j]:
if j == m:
break
x = b[j]
j += 1
else:
x = a[i]
i += 1
t -= x
s = min(t - x * (m - j - i), s)
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR WHILE NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
def getIndexA(a, value, l, r):
ans = -1
while l <= r:
m = int((l + r) / 2)
if a[m] < value:
ans = m
l = m + 1
else:
r = m - 1
return ans
def getIndexB(b, value, l, r):
ans = -1
while l <= r:
m = int((l + r) / 2)
if b[m] > value:
ans = m
l = m + 1
else:
r = m - 1
return ans
def main():
string = input().split()
n = int(string[0])
m = int(string[1])
a = [int(value) for value in input().split()]
b = [int(value) for value in input().split()]
a.sort()
b.sort(reverse=True)
sum_a = [0] * n
sum_a[0] = a[0]
for i in range(1, n):
sum_a[i] = sum_a[i - 1] + a[i]
sum_b = [0] * m
sum_b[0] = b[0]
for i in range(1, m):
sum_b[i] = sum_b[i - 1] + b[i]
if a[0] >= b[0]:
print("0")
return
l = a[0]
r = b[0]
ans = 9223372036854775807
for i in range(n):
mid = a[i]
index_a = i
index_b = getIndexB(b, mid, 0, m - 1)
req_sum_a = mid * (index_a + 1) - sum_a[index_a]
req_sum_b = 0
if index_b != -1:
req_sum_b = req_sum_b + sum_b[index_b]
req_sum_b = req_sum_b - mid * (index_b + 1)
if req_sum_a + req_sum_b <= ans:
ans = req_sum_b + req_sum_a
for i in range(m):
mid = b[i]
index_a = getIndexA(a, mid, 0, n - 1)
index_b = i
req_sum_a = mid * (index_a + 1)
if index_a != -1:
req_sum_a = req_sum_a - sum_a[index_a]
req_sum_b = sum_b[index_b] - mid * (index_b + 1)
if req_sum_a + req_sum_b <= ans:
ans = req_sum_b + req_sum_a
print(ans)
main()
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
n, m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
a.sort()
b.sort()
c = list(set(a + b))
c.sort()
ans = 1e18
less = 0
big = sum(b)
i1, k1 = 0, 0
i2, k2 = 0, len(b)
for border in c:
while i1 < len(a) and a[i1] < border:
less += a[i1]
i1 += 1
k1 += 1
while i2 < len(b) and b[i2] < border:
big -= b[i2]
i2 += 1
k2 -= 1
ans = min(ans, border * k1 - less + big - border * k2)
print(int(ans))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = sorted(list(zip(a, [1] * n)) + list(zip(b, [2] * m)))
ans = 10**18
less_sum, less_cnt = 0, 0
more_sum, more_cnt = sum(b), m
for x, y in arr:
if y == 1:
less_sum += x
less_cnt += 1
else:
more_sum -= x
more_cnt -= 1
ans = min(ans, less_cnt * x - less_sum + (more_sum - more_cnt * x))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
-----Input-----
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9).
-----Output-----
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
-----Examples-----
Input
2 2
2 3
3 5
Output
3
Input
3 2
1 2 3
3 4
Output
4
Input
3 2
4 5 6
1 2
Output
0
-----Note-----
In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inara():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
n, m = invr()
a = inara()
b = inara()
a.sort()
b.sort(reverse=True)
def f(val):
res = 0
for x in a:
if x <= val:
res += val - x
else:
break
for x in b:
if x >= val:
res += x - val
else:
break
return res
hi = int(1000000000.0)
lo = 1
ans = -1
while hi >= lo:
m1 = lo + (hi - lo) // 3
m2 = hi - (hi - lo) // 3
if f(m1) <= f(m2):
hi = m2 - 1
ans = f(m1)
else:
lo = m1 + 1
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.