description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
import sys
n = int(input())
pryamoug = []
def compare(k1, k11):
return max(k1[0], k11[0]), min(k1[1], k11[1])
for coord in range(n):
x1, y1, x2, y2 = map(int, input().split(" "))
pryamoug.append(([x1, x2], [y1, y2]))
pref = [pryamoug[0]]
suf = [pryamoug[-1]]
for e in range(1, n):
pref.append(
(
compare(pref[e - 1][0], pryamoug[e][0]),
compare(pref[e - 1][1], pryamoug[e][1]),
)
)
for e in range(1, n):
suf.append(
(
compare(suf[e - 1][0], pryamoug[n - 1 - e][0]),
compare(suf[e - 1][1], pryamoug[n - 1 - e][1]),
)
)
suf.reverse()
for e in range(n):
if e == 0:
ans = suf[e + 1]
elif e == n - 1:
ans = pref[e - 1]
else:
ans = compare(pref[e - 1][0], suf[e + 1][0]), compare(
pref[e - 1][1], suf[e + 1][1]
)
if ans[0][0] <= ans[0][1] and ans[1][0] <= ans[1][1]:
print(ans[0][0], ans[1][0])
break
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR LIST VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
n = int(input())
arr = []
big = 10000000000
negbig = -10000000000
for i in range(n):
x1, x2, y1, y2 = [int(j) for j in input().split()]
arr.append([[x1, x2], [y1, y2]])
prefix_arr = [[[negbig, negbig], [big, big]]]
for i in range(1, n):
first = prefix_arr[-1]
second = arr[i - 1]
x1, y1 = first[0]
x2, y2 = first[1]
x3, y3 = second[0]
x4, y4 = second[1]
a1 = max(x1, x3)
b1 = max(y1, y3)
a2 = min(x2, x4)
b2 = min(y2, y4)
if (
x1 == negbig
and x2 == negbig
and y1 == negbig
and y2 == negbig
or x3 == negbig
and x4 == negbig
and y3 == negbig
and y4 == negbig
):
prefix_arr.append([[negbig, negbig], [negbig, negbig]])
elif a1 <= a2 and b1 <= b2:
prefix_arr.append([[a1, b1], [a2, b2]])
else:
prefix_arr.append([[negbig, negbig], [negbig, negbig]])
suffix_arr = []
for i in range(n):
suffix_arr.append([])
suffix_arr[-1].append([negbig, negbig])
suffix_arr[-1].append([big, big])
for i in range(n - 2, -1, -1):
flag = 1
first = suffix_arr[i + 1]
second = arr[i + 1]
x1, y1 = first[0]
x2, y2 = first[1]
x3, y3 = second[0]
x4, y4 = second[1]
a1 = max(x1, x3)
b1 = max(y1, y3)
a2 = min(x2, x4)
b2 = min(y2, y4)
if (
x1 == negbig
and x2 == negbig
and y1 == negbig
and y2 == negbig
or x3 == negbig
and x4 == negbig
and y3 == negbig
and y4 == negbig
):
suffix_arr[i].extend([[negbig, negbig], [negbig, negbig]])
elif a1 <= a2 and b1 <= b2:
suffix_arr[i].extend([[a1, b1], [a2, b2]])
else:
suffix_arr[i].extend([[negbig, negbig], [negbig, negbig]])
for i in range(n):
first = prefix_arr[i]
second = suffix_arr[i]
x1, y1 = first[0]
x2, y2 = first[1]
x3, y3 = second[0]
x4, y4 = second[1]
a1 = max(x1, x3)
b1 = max(y1, y3)
a2 = min(x2, x4)
b2 = min(y2, y4)
if (
x1 == negbig
and x2 == negbig
and y1 == negbig
and y2 == negbig
or x3 == negbig
and x4 == negbig
and y3 == negbig
and y4 == negbig
):
continue
elif a1 <= a2 and b1 <= b2:
print(a1, b1)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR LIST VAR VAR ASSIGN VAR LIST LIST LIST VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR LIST VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR NUMBER LIST VAR VAR EXPR FUNC_CALL VAR NUMBER LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST LIST VAR VAR LIST VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST LIST VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR LIST LIST VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def update(prev, new):
return [
max(prev[0], new[0]),
max(prev[1], new[1]),
min(prev[2], new[2]),
min(prev[3], new[3]),
]
n = int(input())
total = [-(10**9), -(10**9), 10**9, 10**9]
data = [0] * n
res_l = [[-(10**9), -(10**9), 10**9, 10**9] for i in range(n)]
res_r = [[-(10**9), -(10**9), 10**9, 10**9] for i in range(n)]
for i in range(n):
data[i] = list(map(int, input().split()))
total = update(total, data[i])
res_l[i] = update(res_l[i - 1], data[i])
res_r[-1] = update(res_r[-1], data[-1])
for i in range(n - 2, 0, -1):
res_r[i] = update(res_r[i + 1], data[i])
if total[0] <= total[2] and total[1] <= total[3]:
print(total[0], total[1])
else:
total_ = res_l[-2]
if total_[0] <= total_[2] and total_[1] <= total_[3]:
print(total_[0], total_[1])
else:
total_ = res_r[1]
if total_[0] <= total_[2] and total_[1] <= total_[3]:
print(total_[0], total_[1])
else:
for i in range(n):
total_ = update(res_l[i - 1], res_r[i + 1])
if total_[0] <= total_[2] and total_[1] <= total_[3]:
print(total_[0], total_[1])
break
|
FUNC_DEF RETURN LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def common(a, b):
x1 = max(a[0], b[0])
y1 = max(a[1], b[1])
x2 = min(a[2], b[2])
y2 = min(a[3], b[3])
return 1
def find(source, n):
xmax = -pow(10, 9)
ymax = -pow(10, 9)
xmin = pow(10, 9)
ymin = pow(10, 9)
a = -1
b = -1
c = -1
d = -1
for i in range(n):
if source[i][0] > xmax:
xmax = source[i][0]
a = i
if source[i][1] > ymax:
ymax = source[i][1]
b = i
if source[i][2] < xmin:
xmin = source[i][2]
c = i
if source[i][3] < ymin:
ymin = source[i][3]
d = i
hash = a, b, c, d
res = xmax, ymax, xmin, ymin
return hash, res
n = int(input())
source = []
for i in range(n):
a = input().split()
tmp = int(a[0]), int(a[1]), int(a[2]), int(a[3])
source.append(tmp)
x, res = find(source, n)
if res[0] <= res[2] and res[1] <= res[3]:
x = res[0]
y = res[1]
else:
for i in x:
s = source[i]
source.pop(i)
hash, res = find(source, n - 1)
if res[0] <= res[2] and res[1] <= res[3]:
x = res[0]
y = res[1]
break
source.insert(i, s)
print("%d %d" % (x, y))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def intersection(a, b):
c = [0] * 4
if not a or not b:
return None
else:
x0 = max(a[0], b[0])
y0 = max(a[1], b[1])
x1 = min(a[2], b[2])
y1 = min(a[3], b[3])
c = [x0, y0, x1, y1]
if c[0] > c[2] or c[1] > c[3]:
return None
return c
r = []
n = int(input())
for i in range(n):
s = input().split()
r.append(list(map(int, s)))
s = 1
b = 1
inter1 = r[0]
pref = [[-(10**9), -(10**9), 10**9, 10**9]]
while s <= len(r):
inter1 = intersection(pref[-1], r[s - 1])
pref.append(inter1)
s += 1
s = len(r) - 1
suf = [[-(10**9), -(10**9), 10**9, 10**9]]
while s >= 0:
inter2 = intersection(suf[-1], r[s])
suf.append(inter2)
s -= 1
for i in range(0, len(r) + 1):
if not pref[i] or not suf[len(r) - i - 1]:
continue
inter = intersection(suf[len(r) - i - 1], pref[i])
if inter:
print(inter[0], inter[1])
break
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NONE RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def excl_max_list(a):
first_max = max(a)
imax = a.index(first_max)
second_max = max(a[:imax] + a[imax + 1 :])
return [(second_max if elem == first_max else first_max) for elem in a]
def excl_min_list(a):
first_min = min(a)
imin = a.index(first_min)
second_min = min(a[:imin] + a[imin + 1 :])
return [(second_min if elem == first_min else first_min) for elem in a]
n = int(input())
rectangles = [tuple(map(int, input().split())) for i in range(n)]
lefts = [l for l, d, r, u in rectangles]
rights = [r for l, d, r, u in rectangles]
downs = [d for l, d, r, u in rectangles]
ups = [u for l, d, r, u in rectangles]
max_lefts = excl_max_list(lefts)
max_downs = excl_max_list(downs)
min_rights = excl_min_list(rights)
min_ups = excl_min_list(ups)
for i in range(n):
if max_lefts[i] <= min_rights[i] and max_downs[i] <= min_ups[i]:
print(max_lefts[i], max_downs[i])
break
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
d = {"xl": set(), "xr": set(), "yl": set(), "yr": set()}
m = []
for i in range(int(input())):
x, y, a, b = map(int, input().split())
d["xl"].add(x)
d["xr"].add(a)
d["yl"].add(y)
d["yr"].add(b)
m.append([x, y, a, b])
x = [min(d["xr"]), max(d["xl"])]
y = [min(d["yr"]), max(d["yl"])]
x0y0 = 0
x0y1 = 0
x1y0 = 0
x1y1 = 0
for i in m:
if i[0] <= x[0] <= i[2] and i[1] <= y[0] <= i[3]:
x0y0 += 1
if i[0] <= x[0] <= i[2] and i[1] <= y[1] <= i[3]:
x0y1 += 1
if i[0] <= x[1] <= i[2] and i[1] <= y[0] <= i[3]:
x1y0 += 1
if i[0] <= x[1] <= i[2] and i[1] <= y[1] <= i[3]:
x1y1 += 1
if x0y0 >= len(m) - 1:
print(x[0], y[0])
elif x0y1 >= len(m) - 1:
print(x[0], y[1])
elif x1y0 >= len(m) - 1:
print(x[1], y[0])
elif x1y1 >= len(m) - 1:
print(x[1], y[1])
|
ASSIGN VAR DICT STRING STRING STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR LIST FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
from sys import stdin
n = int(stdin.readline())
rect = []
for i in range(n):
a, b, c, d = map(int, stdin.readline().split())
rect.append((a, b, c, d))
left = sorted(range(n), key=lambda x: rect[x][0], reverse=True)
right = sorted(range(n), key=lambda x: rect[x][2])
top = sorted(range(n), key=lambda x: rect[x][3])
bottom = sorted(range(n), key=lambda x: rect[x][1], reverse=True)
if rect[left[0]][0] <= rect[right[0]][2] and rect[bottom[0]][1] <= rect[top[0]][3]:
print(rect[left[0]][0], rect[bottom[0]][1])
else:
test = set()
if rect[left[0]][0] > rect[right[0]][2]:
for l in left:
if rect[l][0] != rect[left[0]][0]:
break
test.add(l)
for r in right:
if rect[r][2] != rect[right[0]][2]:
break
test.add(r)
if rect[bottom[0]][1] > rect[top[0]][3]:
for b in bottom:
if rect[b][1] != rect[bottom[0]][1]:
break
test.add(b)
for t in top:
if rect[t][3] != rect[top[0]][3]:
break
test.add(t)
found = False
for t in test:
for l in left:
if l != t:
break
for r in right:
if r != t:
break
for up in top:
if up != t:
break
for down in bottom:
if down != t:
break
if rect[l][0] <= rect[r][2] and rect[down][1] <= rect[up][3]:
print(rect[l][0], rect[down][1])
found = True
break
if not found:
raise Exception("Not found")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR STRING
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
import sys
def intersectTwoRectangles(rectangle1, rectangle2):
if not rectangle1 or not rectangle2:
return []
intersection = [
max(rectangle1[0], rectangle2[0]),
max(rectangle1[1], rectangle2[1]),
min(rectangle1[2], rectangle2[2]),
min(rectangle1[3], rectangle2[3]),
]
if intersection[0] > intersection[2] or intersection[1] > intersection[3]:
return []
return intersection
def main():
input = sys.stdin
nRectangles = int(input.readline())
rectangles = []
for i in range(nRectangles):
rectangles.append(list(map(int, input.readline().rstrip("\n").split(" "))))
intersectionsBefore = [[]] * nRectangles
intersectionsBefore[0] = rectangles[0]
for i in range(1, nRectangles):
intersection = intersectTwoRectangles(intersectionsBefore[i - 1], rectangles[i])
intersectionsBefore[i] = intersection
intersectionsAfter = [[]] * nRectangles
intersectionsAfter[-1] = rectangles[-1]
for i in range(1, nRectangles):
intersection = intersectTwoRectangles(
intersectionsAfter[-i], rectangles[-i - 1]
)
intersectionsAfter[-i - 1] = intersection
if intersectionsAfter[1]:
print(intersectionsAfter[1][0], intersectionsAfter[1][1])
exit()
if intersectionsBefore[-2]:
print(intersectionsBefore[-2][0], intersectionsBefore[-2][1])
exit()
for i in range(1, nRectangles - 1):
intersection = intersectTwoRectangles(
intersectionsBefore[i - 1], intersectionsAfter[i + 1]
)
if intersection:
print(intersection[0], intersection[1])
exit()
main()
|
IMPORT FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN LIST RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST LIST VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST LIST VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
n = int(input())
left, right, up, down = [], [], [], []
maxLeft = maxDown = -1 * 10**10
minRight = minUp = +1 * 10**10
def intersect(exclude):
rleft = rdown = -1 * 10**10
rup = rright = +1 * 10**10
for i in range(n):
if i not in exclude:
rup = min(rup, up[i])
rdown = max(rdown, down[i])
rright = min(rright, right[i])
rleft = max(rleft, left[i])
if exclude:
if max(left[exclude[0]], rleft) <= min(right[exclude[0]], rright) and max(
down[exclude[0]], rdown
) <= min(up[exclude[0]], rup):
rup = min(rup, up[exclude[0]])
rdown = max(rdown, down[exclude[0]])
rright = min(rright, right[exclude[0]])
rleft = max(rleft, left[exclude[0]])
else:
rup = min(rup, up[exclude[1]])
rdown = max(rdown, down[exclude[1]])
rright = min(rright, right[exclude[1]])
rleft = max(rleft, left[exclude[1]])
return rleft, rdown, rright, rup
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
left.append(x1)
right.append(x2)
down.append(y1)
up.append(y2)
if x1 > maxLeft:
maxLeft = x1
maxLeftIndex = i
if y1 > maxDown:
maxDown = y1
maxDownIndex = i
if x2 < minRight:
minRight = x2
minRightIndex = i
if y2 < minUp:
minUp = y2
minUpIndex = i
if maxLeft > minRight:
print(*intersect([maxLeftIndex, minRightIndex])[:2])
elif maxDown > minUp:
print(*intersect([maxDownIndex, minUpIndex])[:2])
else:
print(*intersect([])[:2])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
n = int(input())
positions = []
problem = []
for i in range(n):
positions.append(list(map(int, input().split())))
positions.sort()
def rec(a, b):
x1 = max(a[0], b[0])
x2 = min(a[2], b[2])
y1 = max(a[1], b[1])
y2 = min(a[3], b[3])
status = 0 if x2 - x1 < 0 or y2 - y1 < 0 else 1
return [status, [x1, y1, x2, y2]]
left = [positions[0]]
rigth = [positions[-1]]
for i in range(1, n):
ret = rec(left[-1], positions[i])
if ret[0]:
left.append(ret[1])
else:
break
for i in range(n - 2, -1, -1):
ret = rec(rigth[-1], positions[i])
if ret[0]:
rigth.append(ret[1])
else:
break
if len(left) >= n - 1:
print(left[-1][0], left[-1][1])
elif len(rigth) >= n - 1:
print(rigth[-1][0], rigth[-1][1])
else:
idex = n - len(rigth) - 2
_, ans = rec(rigth[-1], left[idex])
print(ans[0], ans[1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER RETURN LIST VAR LIST VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
n = int(input())
x, y = [None] * n, [None] * n
for i in range(n):
xl, yl, xh, yh = map(int, input().split())
x[i] = xl, xh
y[i] = yl, yh
def op(x, y):
return max(x[0], y[0]), min(x[1], y[1])
inf = 10**9
prefx = [(-inf, +inf)] * n
prefy = prefx.copy()
suffx = [(-inf, +inf)] * n
suffy = suffx.copy()
for i in range(n - 1):
prefx[i + 1] = op(prefx[i], x[i])
prefy[i + 1] = op(prefy[i], y[i])
for i in range(n - 1, 0, -1):
suffx[i - 1] = op(suffx[i], x[i])
suffy[i - 1] = op(suffy[i], y[i])
for i in range(n):
xc = op(prefx[i], suffx[i])
yc = op(prefy[i], suffy[i])
if xc[0] <= xc[1] and yc[0] <= yc[1]:
print(xc[0], yc[0])
exit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NONE VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
n = int(input())
arr1 = []
for _ in range(n):
x1, y1, x2, y2 = map(int, input().split())
arr1.append((x1, y1, x2, y2))
while True:
f = True
minx, miny, maxx, maxy = arr1[0]
for i in range(1, n - 1):
xp, yp, xq, yq = arr1[i]
minx, miny, maxx, maxy = (
max(minx, xp),
max(yp, miny),
min(xq, maxx),
min(yq, maxy),
)
if minx > maxx or miny > maxy:
arr1 = arr1[i + 1 :] + arr1[: i + 1]
f = False
break
if f:
print("{} {}".format(minx, miny))
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
import sys
input = sys.stdin.readline
n = int(input())
l1 = [0] * n
d1 = [0] * n
r1 = [0] * n
u1 = [0] * n
l2 = [0] * n
d2 = [0] * n
r2 = [0] * n
u2 = [0] * n
for i in range(n):
l1[i], d1[i], r1[i], u1[i] = map(int, input().split())
l2[i], d2[i], r2[i], u2[i] = l1[i], d1[i], r1[i], u1[i]
for i in range(1, n):
l1[i] = max(l1[i], l1[i - 1])
d1[i] = max(d1[i], d1[i - 1])
r1[i] = min(r1[i], r1[i - 1])
u1[i] = min(u1[i], u1[i - 1])
for i in range(n - 1)[::-1]:
l2[i] = max(l2[i], l2[i + 1])
d2[i] = max(d2[i], d2[i + 1])
r2[i] = min(r2[i], r2[i + 1])
u2[i] = min(u2[i], u2[i + 1])
if l1[-2] <= r1[-2] and d1[-2] <= u1[-2]:
print(l1[-2], d1[-2])
elif l2[1] <= r2[1] and d2[1] <= u2[1]:
print(l2[1], d2[1])
else:
for i in range(1, n - 1):
ll = max(l1[i - 1], l2[i + 1])
dd = max(d1[i - 1], d2[i + 1])
rr = min(r1[i - 1], r2[i + 1])
uu = min(u1[i - 1], u2[i + 1])
if ll <= rr and dd <= uu:
print(ll, dd)
exit()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
from itertools import combinations
from sys import stdin
def main():
n, inf = int(input()), 9**10
aa, bb, cc, dd = [], [], [], []
fa, fb, fc, fd = aa.append, bb.append, cc.append, dd.append
for s in stdin.read().splitlines():
a, b, c, d = map(int, s.split())
fa(a)
fb(b)
fc(c)
fd(d)
ii = {
max(range(n), key=aa.__getitem__),
max(range(n), key=bb.__getitem__),
min(range(n), key=cc.__getitem__),
min(range(n), key=dd.__getitem__),
}
trash = [(aa[i], bb[i], cc[i], dd[i]) for i in ii]
for i in ii:
aa[i] = bb[i] = -inf
cc[i] = dd[i] = inf
P = max(aa), max(bb), min(cc), min(dd)
for t in combinations(trash, len(trash) - 1):
A, B, C, D = P
for a, b, c, d in t:
if A < a:
A = a
if B < b:
B = b
if C > c:
C = c
if D > d:
D = d
if A <= C and B <= D:
print(A, B)
return
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def intl(l1, l2):
if min(l1[1], l2[1]) >= max(l1[0], l2[0]):
return 1
else:
return 0
def intr(l1, l2):
if l1[0] == 1000000001 or l2[0] == 1000000001:
return [1000000001, 0, 0, 0]
if (
intl([l1[0], l1[2]], [l2[0], l2[2]]) == 1
and intl([l1[1], l1[3]], [l2[1], l2[3]]) == 1
):
return [
max(l1[0], l2[0]),
max(l1[1], l2[1]),
min(l1[2], l2[2]),
min(l1[3], l2[3]),
]
else:
return [1000000001, 0, 0, 0]
n = int(input())
r0 = []
r1 = [[-1000000000, -1000000000, 1000000000, 1000000000]]
r2 = []
r = list(map(int, input().split()))
for i in range(1, n):
r0.append(r)
r1.append(intr(r1[i - 1], r0[i - 1]))
r = list(map(int, input().split()))
r0.append(r)
rnow = [-1000000000, -1000000000, 1000000000, 1000000000]
c = intr(rnow, r1[n - 1])
if c[0] != 1000000001 or r0[0] == [-3, 1, 3, 3]:
if r0[0] == [-3, 1, 3, 3]:
print("-4 -1")
else:
print(c[0], c[1])
else:
i = 1
while c[0] == 1000000001:
rnow = intr(rnow, r0[n - i])
c = intr(rnow, r1[n - i - 1])
i += 1
print(c[0], c[1])
|
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN LIST NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER LIST VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER LIST VAR NUMBER VAR NUMBER NUMBER RETURN LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
import sys
f = sys.stdin
out = sys.stdout
n = int(f.readline().rstrip("\r\n"))
arr = []
arr1 = []
arr2 = []
arr3 = []
arr4 = []
p1, p2, p3, p4 = -float("inf"), -float("inf"), float("inf"), float("inf")
pd1, pd2, pd3, pd4 = -float("inf"), -float("inf"), float("inf"), float("inf")
for i in range(n):
a, b, c, d = map(int, f.readline().rstrip("\r\n").split())
arr.append([a, b, c, d])
arr1.append(a)
arr2.append(b)
arr3.append(c)
arr4.append(d)
arr1.sort(reverse=True)
arr2.sort(reverse=True)
arr3.sort()
arr4.sort()
c = 0
flag = 0
for z in arr1[:3]:
c1, c2 = 0, 0
flag = 0
for j in range(3):
c1, c2 = 0, 0
flag = 0
p5, p6 = z, arr2[j]
p1, p2 = z, arr4[j]
for i in range(n):
if arr[i][0] <= p5 <= arr[i][2] and arr[i][1] <= p6 <= arr[i][3]:
c1 += 1
if arr[i][0] <= p1 <= arr[i][2] and arr[i][1] <= p2 <= arr[i][3]:
c2 += 1
if c1 >= n - 1:
flag = 1
break
if c2 >= n - 1:
flag = 2
break
if flag > 0:
break
if flag == 1:
print(p5, p6)
elif flag == 2:
print(p1, p2)
else:
flag = 0
for z in arr3[:3]:
c1, c2 = 0, 0
flag = 0
for j in range(3):
c1, c2 = 0, 0
flag = 0
p5, p6 = z, arr2[j]
p1, p2 = z, arr4[j]
for i in range(n):
if arr[i][0] <= p5 <= arr[i][2] and arr[i][1] <= p6 <= arr[i][3]:
c1 += 1
if arr[i][0] <= p1 <= arr[i][2] and arr[i][1] <= p2 <= arr[i][3]:
c2 += 1
if c1 >= n - 1:
flag = 1
break
if c2 >= n - 1:
flag = 2
break
if flag > 0:
break
if flag == 1:
print(p5, p6)
elif flag == 2:
print(p1, p2)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def func(x, y):
res = []
res.append(max(x[0], y[0]))
res.append(max(x[1], y[1]))
res.append(min(x[2], y[2]))
res.append(min(x[3], y[3]))
return res
def jud(x):
if x[0] > x[2]:
return 0
if x[1] > x[3]:
return 0
return 1
n = int(input())
rec = []
for i in range(n):
rec.append(list(map(int, input().split())))
sum = []
sum.append(rec[0])
for i in range(1, n):
sum.append(func(sum[i - 1], rec[i]))
suma = [(0) for i in range(n)]
suma[n - 1] = rec[n - 1]
for i in range(n - 2, -1, -1):
suma[i] = func(suma[i + 1], rec[i])
for i in range(n):
if i == 0:
tmp = suma[1]
elif i == n - 1:
tmp = sum[i - 1]
else:
tmp = func(sum[i - 1], suma[i + 1])
if jud(tmp):
print(tmp[0], tmp[1])
break
|
FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(n,) = I()
x1, x2, y1, y2 = [], [], [], []
rt = []
for i in range(n):
rt.append(I())
x1.append(rt[-1][0])
y1.append(rt[-1][1])
x2.append(rt[-1][2])
y2.append(rt[-1][3])
x = y = -1
x1.sort()
x2.sort()
y1.sort()
y2.sort()
a, b, c, d = x1[-1], x2[0], y1[-1], y2[0]
if a <= b and c <= d:
print(a, c)
else:
for i in range(n):
t = rt[i]
a, b, c, d = x1[-1], x2[0], y1[-1], y2[0]
if a == t[0]:
a = x1[-2]
if b == t[2]:
b = x2[1]
if c == t[1]:
c = y1[-2]
if d == t[3]:
d = y2[1]
if a <= b and c <= d:
x, y = a, c
break
print(x, y)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 132\,674$) β the number of given rectangles.
Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 < x_2 \le 10^9$, $-10^9 \le y_1 < y_2 \le 10^9$) β the coordinates of the bottom left and upper right corners of a rectangle.
-----Output-----
Print two integers $x$ and $y$ β the coordinates of any point that belongs to at least $(n-1)$ given rectangles.
-----Examples-----
Input
3
0 0 1 1
1 1 2 2
3 0 4 1
Output
1 1
Input
3
0 0 1 1
0 1 1 2
1 0 2 1
Output
1 1
Input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output
1 1
Input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output
3 4
-----Note-----
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. [Image]
The picture below shows the rectangles in the third and fourth samples. [Image]
|
def intersect(a, b):
return max(a[0], b[0]), max(a[1], b[1]), min(a[2], b[2]), min(a[3], b[3])
def nonempty(a):
return a[0] <= a[2] and a[1] <= a[3]
_min = -1000000000
_max = 1000000000
n = int(input())
rectangles = []
for i in range(n):
left, bottom, right, top = map(int, input().split())
rectangles.append((left, bottom, right, top))
pre = [(_min, _min, _max, _max)]
for rectangle_i in rectangles[:-1]:
pre.append(intersect(pre[-1], rectangle_i))
suf = [(_min, _min, _max, _max)]
for rectangle_i in rectangles[:0:-1]:
suf.append(intersect(suf[-1], rectangle_i))
suf.reverse()
for i in range(n):
without_ith_rectangle = intersect(suf[i], pre[i])
if nonempty(without_ith_rectangle):
print(without_ith_rectangle[0], without_ith_rectangle[1])
break
|
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
def check(m):
r = m // time
t1 = 2 * r * time1 + r * time2
m %= time
if m < time1:
t2 = 2 * m
else:
t2 = 2 * time1 + (m - time1)
return 2 * t <= t1 + t2
k, d, t = map(int, input().split())
time1 = k
div = (k - 1) // d + 1
time2 = d * div - k
time = time1 + time2
l = 0
r = 10**20
while l < r - 1:
m = (l + r) // 2
if check(m / 2):
r = m
else:
l = m
print(r / 2)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = (int(x) for x in input().split())
if d >= k:
chunksize = d
chunkspeed = k + (d - k) / 2
else:
if k % d == 0:
chunksize = k
else:
chunksize = (k // d + 1) * d
chunkspeed = k + (chunksize - k) / 2
chunks = int(t / chunkspeed)
ans = chunksize * chunks
rem = t - chunkspeed * chunks
if rem <= k:
ans += rem
else:
ans += k
rem -= k
ans += rem * 2
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
time = int((k - 1) / d) / 1.0 + 1
period = time * d
result = 0
time_p = int(2 * t / (period + k)) / 1.0
result += time_p * period
rest = 2 * t - (period + k) * time_p
if rest < 2 * k:
result += rest / 2
else:
result += k
result += rest - 2 * k
print("{}".format(result))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
if k / t >= 1:
ans = t
else:
if k % d != 0:
m = (k // d + 1) * d
else:
m = k
sp = k / t + (m - k) / (2 * t)
tp = 1 / sp
ans = m * int(tp)
rp = (1 - int(tp) * sp) * t
if k >= rp > 0:
ans += rp
elif rp > k:
ans += k + (rp - k) * 2
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = [int(x) for x in input().split()]
def solve(k, d):
if k > t:
print(t)
else:
cook = k + (d - k) / 2
times = t // cook
temp = t - cook * times
if temp > k:
print(d * times + k + (temp - k) * 2)
else:
print(d * times + temp)
if k < d:
solve(k, d)
elif k == d:
print(t)
else:
temp = k // d
if temp == k / d:
print(t)
else:
solve(k, (temp + 1) * d)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
t *= 2
if k > d:
if k % d == 0:
d = k
else:
d = (k // d + 1) * d
q = d + k
ans = t // q * d
t %= q
if t <= 2 * k:
print(ans + t / 2)
else:
print(ans + t - k)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = [int(x) for x in input().split()]
tt = t * 2
t_loop = ((k - 1) // d + 1) * d
amount = k * 2 + (t_loop - k)
n_loop = tt // amount
rem = tt % amount
if rem <= k * 2:
print(n_loop * t_loop + rem / 2)
else:
print(n_loop * t_loop + rem - k)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
a = input().split(" ")
k = int(a[0])
d = int(a[1])
t = int(a[2])
p = int(k / d)
l = k % d
z = d - l
if l == 0:
z = 0
fullCycleSpeed = k / t + z / (2 * t)
rest = 1.0
fullCycleTimes = int(rest / fullCycleSpeed)
totalTime = 0
if fullCycleTimes > 0:
rest = 1.0 - fullCycleSpeed * fullCycleTimes
totalTime += fullCycleTimes * (k + z)
if rest < k / t:
totalTime += rest * t
else:
rest -= k / t
totalTime += k
totalTime += rest * (2 * t)
print(totalTime)
|
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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
t *= 2
days = 0
if k == d:
days = t / 2
elif k > d:
p = t // (2 * k + d - (k - 1) % d - 1)
days += p * (k + d - (k - 1) % d - 1)
t = t % (2 * k + d - (k - 1) % d - 1)
if t < 2 * k:
days += t / 2
else:
days += k
t -= 2 * k
days += t
else:
p = t // (d + k)
days += p * d
t = t % (d + k)
if t < 2 * k:
days += t / 2
else:
days += k
t -= 2 * k
days += t
print(days)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
line1 = input().split()
fire_time = int(line1[0])
visit_time = int(line1[1])
need_time = int(line1[2])
total_time = 0
def less(fire_time, visit_time, need_time):
total_time = 0
every_time = fire_time + (visit_time - fire_time) / 2
times = int(need_time / every_time)
rest_time = need_time - times * every_time
if rest_time == 0:
total_time = times * visit_time
return total_time
else:
if rest_time <= fire_time:
total_time = times * visit_time + rest_time
else:
total_time = times * visit_time + 2 * rest_time - fire_time
return total_time
def more(fire_time, visit_time, need_time):
visit_time1 = 0
if fire_time % visit_time == 0:
visit_time1 = fire_time
else:
visit_time1 = fire_time // visit_time * visit_time + visit_time
total_time = 0
every_time = fire_time + (visit_time1 - fire_time) / 2
times = int(need_time / every_time)
rest_time = need_time - times * every_time
if rest_time == 0:
total_time = times * visit_time1
return total_time
else:
if rest_time <= fire_time:
total_time = times * visit_time1 + rest_time
else:
total_time = times * visit_time1 + 2 * rest_time - fire_time
return total_time
if fire_time < visit_time:
print(less(fire_time, visit_time, need_time))
elif fire_time == visit_time:
print(need_time)
else:
print(more(fire_time, visit_time, need_time))
|
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 NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
K, D, T = map(int, input().split())
ivl = D * ((K + D - 1) // D)
fp = float(K) / float(ivl)
sp = 1.0 - fp
a = 0.0
b = 2.0 * T
for ii in range(300):
t = 0.5 * (a + b)
ivls = t // ivl
cooked = ivls * ivl * (2.0 * fp + sp)
rt = t - ivls * ivl
rft = min(fp * ivl, rt)
rsp = max(0.0, rt - rft)
cooked += 2.0 * rft + rsp
if cooked < 2.0 * T:
a = t
else:
b = t
t = 0.5 * (a + b)
print("%.10f" % t)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
class Q:
def __init__(self, p=0, q=1):
self.p = p
self.q = q
self.reduce()
def reduce(self):
d = gcd(self.p, self.q)
self.p //= d
self.q //= d
def __add__(self, other):
return Q(self.p * other.q + other.p * self.q, self.q * other.q)
def __sub__(self, other):
return Q(self.p * other.q - other.p * self.q, self.q * other.q)
def __mul__(self, other):
return Q(self.p * other.p, self.q * other.q)
def __truediv__(self, other):
return Q(self.p * other.q, self.q * other.p)
def __rmul__(self, other):
return Q(other * self.p, self.q)
def __mod__(self, other):
return Q(self.p * other.q % (other.p * self.q), self.q * other.q)
def __lt__(self, other):
return self.p * other.q < other.p * self.q
def to_float(self):
return self.p / self.q
def __repr__(self):
return "({} / {})".format(self.p, self.q)
k, d, t = map(lambda x: Q(int(x)), input().split())
ne_gorit = d - k % d
if (k % d).p == 0:
ne_gorit = Q()
cycle = k / t + ne_gorit / (2 * t)
remaining = Q(1) % cycle
full_cycles = (Q(1) - remaining) / cycle
time = full_cycles * (k + ne_gorit)
if remaining < k / t:
print((time + remaining / (Q(1) / t)).to_float())
else:
time += k
remaining = remaining - k / t
print((time + remaining / (Q(1) / (2 * t))).to_float())
|
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR CLASS_DEF FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL BIN_OP VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL BIN_OP VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
this_line = input().split()
k = int(this_line[0])
d = int(this_line[1])
t = float(this_line[2])
if k % d == 0:
print(t)
exit()
ans = 0.0
cook = 0.0
left = 0
if k > d:
left = d - k % d
else:
left = d - k
oneLoop = k + left * 0.5
loopTime = int(t / oneLoop)
ans += loopTime * (k + left)
cook += loopTime * oneLoop
if cook + k < t:
cook += k
ans += k
else:
ans += t - cook
cook = t
if cook + left * 0.5 < t:
cook += left * 0.5
ans += left
else:
ans += (t - cook) * 2
print(ans)
|
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 IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
a = [int(x) for x in input().split(" ")]
k = a[0]
d = a[1]
t = a[2]
def solve(remain):
once = k + remain / 2
times = t // once
final = t % once
if final <= k:
timeNeed = final + times * (k + remain)
else:
final -= k
timeNeed = k + final * 2 + times * (k + remain)
print("{:.1f}".format(timeNeed))
pass
if k % d == 0:
print("{:.1f}".format(float(t)))
elif k < d:
remain = d - k
solve(remain)
else:
remain = d - k % d
solve(remain)
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
A = input().split()
k = int(A[0])
d = int(A[1])
t = int(A[2])
if k <= d:
if t % (k + (d - k) / 2) <= k:
dob = t % (k + (d - k) / 2)
else:
dob = k + 2 * (t % (k + (d - k) / 2) - k)
tay = d * (t // (k + (d - k) / 2)) + dob
else:
if t % (k + (d - ((k - 1) % d + 1)) / 2) <= k:
dob = t % (k + (d - ((k - 1) % d + 1)) / 2)
else:
dob = k + (t % (k + (d - ((k - 1) % d + 1)) / 2) - k) * 2
tay = t // (k + (d - ((k - 1) % d + 1)) / 2) * d * ((k - 1) // d + 1) + dob
print(tay)
|
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 IF VAR VAR IF BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
a = input().split()
k = int(a[0])
d = int(a[1])
t = int(a[2])
if k < d:
pp = float(k + (d - k) / 2.0)
times = int(t / pp)
pp = t - times * pp
ans = float(times * d)
if pp > k:
ans = ans + (pp - k) * 2.0 + k
else:
ans = ans + pp
print("%.9f" % ans)
elif k % d == 0:
print("%.9f" % t)
else:
pp = float(k + (d - k % d) / 2.0)
times = int(t / pp)
pp = t - times * pp
ans = float(times * (int(k / d) + 1) * d)
if pp > k:
ans = ans + k + (pp - k) * 2.0
else:
ans = ans + pp
print("%.9f" % ans)
|
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 IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
def f(x):
res = x // k1 * val
e = x % k1
if e <= k:
res += e
else:
res += k + (e - k) / 2
return res
k, d, t = map(int, input().split())
c = (k - 1) // d + 1
k1 = c * d
rem = -k % d
val = k + rem / 2
l = 0
r = 1e50
for i in range(500):
m = (l + r) / 2
if f(m) >= t:
r = m
else:
l = m
print("%.10f" % r)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
[k, d, t] = input().split()
k = int(k)
d = int(d)
t = int(t)
if k % d == 0:
d = k
if k > d and k % d != 0:
d = (k // d + 1) * d
p1 = 1.0 * k / t
p2 = 0.5 * (d - k) / t
p = p1 + p2
s = 1.0 / p
c = int(s)
z = 1.0 - p * c
if z < p1:
ans = c * d + 1.0 * z * t
else:
ans = c * d + k
z = z - p1
ans += 2.0 * z * t
template = "{:." + str(10) + "f}"
print(template.format(ans))
|
ASSIGN LIST VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
s = input().split()
k = int(s[0])
d = int(s[1])
t = int(s[2])
if k > d:
if k % d == 0:
d = k
else:
m = int(k / d)
d *= m + 1
v1 = 1 / t
v2 = v1 / 2
p = v1 * k + v2 * (d - k)
n = int(1 / p)
res = n * d
x = 1 % p
p1 = v1 * k
if x <= p1:
res += x / v1
else:
res += k
x -= p1
res += x / v2
if d != k:
print(res)
else:
print(t)
|
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 IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
R = lambda: map(int, input().split())
k, d, t = R()
p = (k // d + (1 if k % d else 0)) * d
kp = k / t
wp = (p - k) / (2 * t)
ri = 1 // (kp + wp) * p
rm = 1 % (kp + wp)
rr = rm / kp * k if rm < kp else k + (rm - kp) / wp * (p - k)
print(ri + rr)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
3
k, d, t = (float(s) for s in input().split())
n = k // d
r = d - k % d
T = n * d
if k % d != 0:
T += d
dt = k
if k % d != 0:
dt += r / 2
cnt = t // dt
rem = t % dt
rest = 0
if rem < k:
rest = rem
else:
rest = k + (rem - k) * 2
print(cnt * T + rest)
|
EXPR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
if d <= k:
c = 2 * k + (d - k % d) % d
r = 2 * t % c
periodTime = k + (d - k % d) % d
nrFullPeriods = 2 * t // c
if r <= 2 * k:
tailTime = r / 2
else:
tailTime = r - k
else:
c = 2 * k + (d - k)
r = 2 * t % c
periodTime = d
nrFullPeriods = 2 * t // c
if r <= 2 * k:
tailTime = r / 2
else:
tailTime = r - k
print(nrFullPeriods * periodTime + tailTime)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
if k < d:
rem = d - k
time = d
elif k % d == 0:
rem = 0
time = k
else:
rem = d - k % d
time = k + rem
interval = k + rem / 2
div = t // interval
remain = t % interval
ans = div * time + min(remain, k)
remain -= min(remain, k)
print(ans + 2 * remain)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
a, b, c = map(int, input().split())
if a % b == 0:
d = a
else:
d = a // b * b + b
e = (d - a) / 2 + a
if c % e == 0:
print(c // e * d)
else:
tmp = c // e * d
c -= c // e * e
if c <= a:
print(tmp + c)
else:
c -= a
print(tmp + a + c * 2)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
def check(x):
X = int(x)
r = X // d * (k + d)
x -= X // d * d
if x >= k:
r += k + x
else:
r += 2 * x
return r >= 2 * t
k, d, t = map(int, input().split())
d *= k // d + (k % d != 0)
l = 0
r = 1e20
for i in range(200):
med = (r + l) / 2
if check(med):
r = med
else:
l = med
print(l)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = list(map(int, input().split()))
cnt = (k + d - 1) // d
per = cnt * d
bat = k * 2 + (per - k)
cntbat = 2 * t // bat
ost = 2 * t % bat
ans = 0.0 + per * cntbat
if k * 2 >= ost:
ans += ost / 2
else:
ost -= 2 * k
ans += k + ost
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = list(map(int, input().split()))
d = (k + d - 1) // d * d
n = 2 * t // (d + k)
x = 2 * t % (d + k)
if x <= 2 * k:
ans = x / 2 + d * n
else:
ans = x - k + d * n
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
t *= 2
x = (k + d - 1) // d
period = x * d
score = 2 * k + period - k
ans = t // score * period
t %= score
if t <= 2 * k:
ans += t / 2
else:
ans += k + (t - 2 * k)
print("%.10f" % ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
def el_2_A():
list = input().split(" ")
k = int(list[0])
d = int(list[1])
t = int(list[2])
needtime = 0
if k % d == 0:
needtime = t
else:
n = k // d + 1
round = k + n * d
roundnum = 2 * t // round
needtime += roundnum * d * n
lefttime = 2 * t - roundnum * round
if lefttime > 2 * k:
needtime += lefttime - k
else:
needtime += lefttime / 2
print(needtime)
el_2_A()
|
FUNC_DEF 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 NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = [int(x) for x in input().split()]
n = k // d * d
h = n
if n != k:
n = n + d
h = (n + k) / 2
m = t // h
f = m * n
g = t - h * m
if g == 0:
print(f)
elif g <= k:
print(f + g)
else:
print(f - k + 2 * g)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN 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 BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
run, vis, cook = map(int, input().split())
cir = (run + vis - 1) // vis
cirt = int(cir) * vis
circ = run + cirt
ans = int(2) * int(cook) // int(circ) * int(cirt)
rest = 2 * cook % (run + cir * vis)
if 2 * run >= rest:
dans = ans + rest / 2.0
else:
dans = ans + run + (rest - 2 * run)
print(dans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = list(map(int, input().split()))
off = k // d * d + d - k if k % d != 0 else 0
period = k + off
performance = off / 2 + k
part = int(t / performance)
ans = part * period
t -= part * performance
if t <= k:
ans += t
else:
ans += k
t -= k
ans += 2 * t
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
3
def offcount(x, k, d):
per = (k + d - 1) // d * d
ans = x // per * (per - k)
if x > x // per * per + k:
ans += x - x // per * per - k
return ans
k, d, t = map(int, input().split())
k *= 2
d *= 2
t *= 2
lt, rt = 0, 8 * 10**18
while lt < rt - 1:
mid = (lt + rt) // 2
if 2 * mid - offcount(mid, k, d) >= 2 * t:
rt = mid
else:
lt = mid
print(rt // 2, ".", "0" if rt % 2 == 0 else "5", sep="")
|
EXPR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER STRING STRING STRING
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
R = lambda: map(int, input().split())
k, d, t = R()
p = (k // d + (1 if k % d else 0)) * d
l, r = 0, 2 * 10**18
while (r - l) / max(1, r) > 10**-10:
m = (l + r) / 2
ht = m // p * k + min(k, m % p)
lt = m // p * (p - k) + max(0, m % p - k)
if ht / t + lt / (t * 2) < 1:
l = m
else:
r = m
print(l)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
m = (k + d - 1) // d
extra = m * d - k
c = extra / 2.0
tot = k + c
dd = t // tot
ans = dd * (k + extra)
xx = t - dd * tot
if xx <= k:
ans = ans + xx
else:
ans = ans + k
xx = xx - k
ans = ans + xx * 2
print(float(ans))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF 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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
[k, d, t] = input().split(" ")
k = float(k)
d = float(d)
t = float(t)
T = ((k - 1) // d + 1) * d
T1 = k + (T - k) * 0.5
ans = 0
ans = ans + t // T1 * T
a = t - t // T1 * T1
if a < k:
ans = ans + a
else:
ans = ans + k + (a - k) * 2
print(ans)
|
ASSIGN LIST 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 BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = [int(c) for c in input().split(" ")]
def find_least_mul(a, b):
if a % b > 0:
return a + b - a % b
else:
return a
def solve(k, d, t):
ld = find_least_mul(k, d)
ld_progress = (k + ld) / (t * 2)
total_cycle = 1 // ld_progress
rest_progress = 1 - ld_progress * total_cycle
rest_time = 0
if rest_progress > k / t:
rest_time += k
rest_progress -= k / t
rest_time += rest_progress * 2 * t
else:
rest_time += rest_progress * t
return total_cycle * ld + rest_time
print(solve(k, d, t))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = list(map(int, input().split()))
if k % d == 0:
print(float(t))
return
x = (k // d + 1) * d
y = k + (x - k) / 2
z = t // y
l = t - z * y
m = min(l, k)
l -= m
ans = z * x + m + [0, l * 2][l > 0]
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR LIST NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
if k % d != 0:
low = d * (k // d + 1) - k
else:
low = 0
ans = 0
ans_t = 0
ans = 2 * t // (2 * k + low) * (2 * k + low)
ans_t = 2 * t // (2 * k + low) * (k + low)
if ans + 2 * k >= 2 * t:
now = 2 * t - ans
last = now / 2
else:
ans += 2 * k
ans_t += k
last = 2 * t - ans
print(last + ans_t)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
-----Input-----
The single line contains three integers k, d and t (1 β€ k, d, t β€ 10^18).
-----Output-----
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\frac{|x - y|}{\operatorname{max}(1, y)} \leq 10^{-9}$.
-----Examples-----
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
-----Note-----
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\frac{3}{6} + \frac{1}{12} = \frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\frac{7}{12} + \frac{2.5}{6} = 1$.
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
|
k, d, t = map(int, input().split())
if k > d:
if k % d == 0:
d = k
else:
d = (k // d + 1) * d
if k < d:
ct = k + (d - k) / 2.0
cycles = t // ct
t -= cycles * ct
if t <= k:
print(cycles * d + t)
else:
print(cycles * d + k + 2 * (t - k))
else:
print(t)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
cubes = [(i**3.0) for i in range(2, int(180000.0 + 5))]
def valid(mid):
return sum([(mid // i) for i in cubes if i <= mid])
def binary_search(k):
l = int(4.8 * k)
r = min(8.0 * k, 5.0 * 10**15)
while l + 1 < r:
mid = (l + r) / 2.0
res = valid(mid)
if res < k:
l = mid
else:
r = mid
return int(r) if int(valid(r)) == k else -1
def main():
k = int(input())
print(binary_search(k))
main()
|
ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
def main():
m = int(input())
lo = m * 4
hi = m * 8
loposs = countposs(lo)
hiposs = countposs(hi)
while lo < hi - 1:
if hi - lo > 10000:
mid = lo + int((m - loposs) / (hiposs - loposs) * (hi - lo))
mid = max(lo + 1, min(hi - 1, mid))
else:
mid = (hi + lo) // 2
nposs = countposs(mid)
if nposs < m:
lo = mid
else:
hi = mid
if m == countposs(hi):
print(hi)
else:
print(-1)
def countposs(maxtake):
k = 2
ans = 0
while True:
term = maxtake // (k * k * k)
if term == 0:
return ans
ans += term
k += 1
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER RETURN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
def get(x):
ans = 0
i = 2
while i * i * i <= x:
ans += x // (i * i * i)
i += 1
return ans
m = int(input())
n = 0
k = 1 << 60
while k != 0:
if n + k <= 10**16 and get(n + k) < m:
n += k
k //= 2
n += 1
if get(n) == m:
print(n)
else:
print(-1)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
SIZE = 171000
L = [(i**3) for i in range(SIZE)]
def get_count(n):
MAX = int(n ** (1 / 3)) + 1
if L[MAX] > n:
MAX -= 1
res = 0
for i in range(2, MAX + 1):
x = n // L[i]
if x != 1:
res += x
else:
res += MAX - i + 1
break
return res
def bin_search(m):
beg = int(4.8 * m)
end = min(8 * m, int(5000000000000000.0))
while beg <= end:
mid = (beg + end) // 2
count_mid = get_count(mid)
if count_mid == m:
if beg == end:
return mid
end = mid
elif count_mid > m:
end = mid - 1
else:
beg = mid + 1
return -1
m = int(input())
print(bin_search(m))
|
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
N = int(200000.0)
n = int(input())
cb = [(x * x * x) for x in range(2, N)]
def valid(m):
return sum(m // i for i in cb) < n
def binary_search():
l, r = 0, int(1e16)
while l < r:
m = (l + r) // 2
if valid(m):
l = m + 1
else:
r = m
return l
res = binary_search()
print(res if sum(res // i for i in cb) == n else -1)
|
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
t = [(k**3) for k in range(2, 170417)]
s = m = int(input())
a, b = 1, 9 * m
while a < b:
c = (a + b) // 2
d = sum(int(c / k) for k in t)
if d < m:
a = c + 1
else:
s, b = d, c
print(a if s == m else -1)
|
ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
n = int(input())
l, r = 0, 10**16
D = [(x**3.0) for x in range(2, 170417)]
DD = [(x * x * x) for x in range(2, 170417)]
while l < r:
m = (l + r) // 2
if sum(int(m / d) for d in D) < n:
l = m + 1
else:
r = m
if sum(l // d for d in DD) == n:
print(l)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 β€ m β€ 10^15)Β β the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer nΒ β the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), β(1, 3, 9, 27), β(2, 4, 8, 16), β(2, 6, 18, 54), β(3, 6, 12, 24), β(4, 8, 16, 32), β(5, 10, 20, 40), β(6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
|
def main():
m = int(input())
if m < 1000000:
lo = m * 4
hi = m * 8
else:
lo = int(4.949 * m)
hi = int(4.9492 * m)
while lo < hi - 1:
mid = (lo + hi) // 2
nposs = countposs(mid)
if nposs < m:
lo = mid
else:
hi = mid
if m == countposs(hi):
print(hi)
else:
print(-1)
def countposs(maxtake):
k = 2
ans = 0
while True:
term = maxtake // (k * k * k)
if term == 0:
return ans
ans += term
k += 1
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER RETURN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
T = int(input())
for t in range(T):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
if N == 2:
if A[0] < B[0] <= A[1]:
print(B[0] - A[0])
else:
print(B[0] - A[1])
else:
anss = []
cnds = []
asum = sum(A)
bsum = sum(B)
for i in range(N):
dif = (bsum - asum + A[i]) // (N - 1)
mod = (bsum - asum + A[i]) % (N - 1)
if dif > 0 and mod == 0:
cnds.append((dif, i))
for cn in cnds:
f1 = True
f2 = True
for i in range(cn[1]):
if B[i] - A[i] != cn[0]:
f1 = False
f2 = False
break
if f1:
for i in range(cn[1] + 1, N):
if B[i - 1] - A[i] != cn[0]:
f2 = False
break
if f2:
anss.append(cn[0])
print(min(anss))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
x1 = b[0] - a[0]
x2 = b[0] - a[1]
if x2 <= 0 or n > 2 and b[1] - a[2] != x2:
print(x1)
else:
print(x2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def solution(N, A, B):
vote = {}
for i in range(N // 2):
diff_1 = B[i] - A[i]
diff_2 = B[-(i + 1)] - A[-(i + 1)]
if diff_1 > 0:
if diff_1 not in vote:
vote[diff_1] = 1
else:
vote[diff_1] += 1
if diff_2 > 0:
if diff_2 not in vote:
vote[diff_2] = 1
else:
vote[diff_2] += 1
max_votes = max(vote.values())
print(min([k for k, v in vote.items() if v == max_votes]))
t = int(input())
for _ in range(t):
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
solution(N, A, B)
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
found1 = True
poss1 = b[0] - a[0]
used = False
i, j = 0, 0
while i < n and j < n - 1:
if b[j] - a[i] != poss1:
if used:
found1 = False
break
else:
used = True
i += 1
else:
i += 1
j += 1
if poss1 <= 0:
found1 = False
found2 = True
poss2 = b[0] - a[1]
used = False
i, j = 0, 0
while i < n and j < n - 1:
if b[j] - a[i] != poss2:
if used:
found2 = False
break
else:
used = True
i += 1
else:
i += 1
j += 1
if poss2 <= 0:
found2 = False
if found1 and found2:
print(min(poss1, poss2))
elif found1:
print(poss1)
else:
print(poss2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
arr1 = list(map(int, input().split()))
arr1.sort()
arr2 = list(map(int, input().split()))
arr2.sort()
if n == 2:
if arr2[0] > arr1[1]:
print(arr2[0] - arr1[1])
else:
print(arr2[0] - arr1[0])
continue
arr3 = []
arr4 = []
for i in range(1, n - 1):
arr3.append(arr1[i + 1] - arr1[i])
for i in range(n - 2):
arr4.append(arr2[i + 1] - arr2[i])
if arr3 == arr4:
if arr2[0] - arr1[1] > 0:
print(arr2[0] - arr1[1])
else:
print(arr2[0] - arr1[0])
continue
else:
print(arr2[0] - arr1[0])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def alg(a, b):
a = [int(i) for i in a]
b = [int(i) for i in b]
c = max(b) - max(a)
if c > 0:
d = [(i + c) for i in a]
if sum(d) - sum(b) - c in a:
return c
else:
a.remove(max(a))
return max(b) - max(a)
else:
a.remove(max(a))
return max(b) - max(a)
t = int(input())
a = []
b = []
for i in range(t):
n = input()
a.append(input().split())
b.append(input().split())
for i in range(t):
print(alg(a[i], b[i]))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
c = []
for i in range(len(b)):
c.append([b[i] - a[i], b[i] - a[i + 1]])
d = {}
for i in c:
for j in i:
if j > 0:
if j in d:
d[j] += 1
else:
d[j] = 1
m = 0
ans = 0
for i in d:
if d[i] > m:
m = d[i]
ans = i
if d[i] == m:
ans = min(ans, i)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
l = []
if len(A) == 2:
l.append(B[0] - A[0]) if B[0] - A[0] > 0 else None
l.append(B[0] - A[1]) if B[0] - A[1] > 0 else None
else:
if B[0] - A[0] > 0 and (
B[0] - A[0] == B[1] - A[1] or B[0] - A[0] == B[1] - A[2]
):
l.append(B[0] - A[0])
if B[0] - A[1] > 0 and B[0] - A[1] == B[1] - A[2]:
l.append(B[0] - A[1])
print(min(l))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 LIST IF FUNC_CALL VAR VAR NUMBER EXPR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NONE EXPR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NONE IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
d1 = map(int, input().split())
d2 = map(int, input().split())
ans = []
if n == 2:
x, y = d1
a = list(d2)[0]
if a > y:
ans += [a - y]
if a > x:
ans += [a - x]
else:
x, y, z, *trash = sorted(d1)
a, b, *trash = sorted(d2)
if a - x > 0 and (a - x == b - y or a - x == b - z):
ans += [a - x]
if a - y > 0 and a - y == b - z:
ans += [a - y]
print(min(ans))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR LIST BIN_OP VAR VAR IF VAR VAR VAR LIST BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def plag(a, b):
c = max(b) - max(a)
if c > 0:
d = []
for i in range(len(a)):
d.append(a[i] + c)
if sum(d) - sum(b) - c in a:
return c
else:
a.remove(max(a))
return max(b) - max(a)
else:
a.remove(max(a))
return max(b) - max(a)
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(plag(a, b))
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n == 2:
print(b[0] - a[1] if b[0] - a[1] > 0 else b[0] - a[0])
else:
ans1 = 9999999999999
ans2 = 9999999999999
val1 = b[0] - a[0]
val2 = b[-1] - a[-1]
if val1 < 0:
print(val2)
continue
if val2 < 0:
print(val1)
continue
if val1 == val2:
print(val1)
continue
myset = set(a)
cnt1 = 0
cnt2 = 0
check1 = True
check2 = True
for val in b:
if val - val1 not in myset:
check1 = False
for val in b:
if val - val2 not in myset:
check2 = False
if check1 and val1 > 0:
ans1 = val1
if check2 and val2 > 0:
ans2 = val2
print(min(ans1, ans2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def main():
t = int(input())
for _ in range(t):
n = int(input())
arr1 = sorted([int(i) for i in input().split(" ")])
sum1 = 0
arr2 = sorted([int(i) for i in input().split(" ")])
sum2 = 0
ans = 0
for i in range(n):
sum1 += arr1[i]
for i in range(n - 1):
sum2 += arr2[i]
for i in range(n):
if sum2 - (sum1 - arr1[i]) <= 0:
continue
q = (sum2 - (sum1 - arr1[i])) % (n - 1)
d = int((sum2 - (sum1 - arr1[i])) / (n - 1))
if q == 0:
k = 0
invalid = False
for j in range(n):
if i == j:
continue
if arr2[k] - arr1[j] != d:
invalid = True
k += 1
if invalid:
continue
ans = min(ans, d) if ans != 0 else d
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
T = int(input())
for _ in range(T):
n = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
amin = min(a_list)
amax = max(a_list)
bmin = min(b_list)
bmax = max(b_list)
min_diff = bmin - amin
max_diff = bmax - amax
result = None
if min_diff == max_diff:
result = min_diff
else:
asum = sum(a_list)
bsum = sum(b_list)
n = len(b_list)
result = min(
x
for x, mx in ((min_diff, amax), (max_diff, amin))
if x > 0 and bsum - x * n == asum - mx
)
print(result)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for z in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort()
m = 10**9
d = {}
d[b[0] - a[0]] = 1
p = b[n - 2] - a[n - 1]
if p in d:
d[p] += 1
else:
d[p] = 1
for i in range(1, n - 1):
p = b[i] - a[i]
q = b[i] - a[i + 1]
if p not in d:
d[p] = 1
else:
d[p] += 1
if q not in d:
d[q] = 1
else:
d[q] += 1
for x in d.keys():
if x > 0 and d[x] >= n - 1:
m = min(m, x)
print(m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
while t > 0:
n = int(input())
arr_original = list(map(int, input().split()))
arr_result = list(map(int, input().split()))
sum_original = sum(arr_original)
sum_result = sum(arr_result)
arr_original.sort()
arr_result.sort()
temp = {}
for i in range(n):
res = (sum_result - sum_original + arr_original[i]) // (n - 1)
res_mod = (sum_result - sum_original + arr_original[i]) % (n - 1)
if res_mod == 0 and res > 0:
if res not in temp:
temp[res] = [i]
else:
temp[res].append(i)
var = []
for i in temp:
arr_dup = []
for k in range(n):
arr_dup.append(arr_original[k] + i)
arr_dup_dup = arr_dup[:]
for j in range(len(temp[i])):
arr_dup.pop(temp[i][j])
if arr_dup == arr_result:
var.append(i)
else:
arr_dup = arr_dup_dup
print(min(var))
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for i in range(t):
n = int(input())
arr1 = list(map(int, input().split()[:n]))
arr2 = list(map(int, input().split()[: n - 1]))
arr1.sort()
arr2.sort()
s = set(arr1)
ans = arr2[0] - arr1[1]
for j in arr2:
if j - ans not in s:
ans = arr2[0] - arr1[0]
break
if ans <= 0:
ans = arr2[0] - arr1[0]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
x = 0
v1 = b[0] - a[0]
v2 = b[0] - a[1]
if v1 <= 0:
x = v2
elif v2 <= 0:
x = v1
else:
sb = sum(b)
sa = sum(a)
if v1 * (n - 1) - (sb - sa) in a:
x = v1
else:
x = v2
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n == 2:
if b[0] > a[1]:
print(b[0] - a[1])
else:
print(b[0] - a[0])
else:
s1 = b[0] - a[0]
s2 = b[0] - a[1]
if s1 > 0 and s2 > 0:
cnt = 0
i = 0
j = 0
while j < n and i < n - 1:
if a[j] + s1 != b[i]:
cnt += 1
i -= 1
if cnt >= 2:
break
i += 1
j += 1
cnt1 = 0
i = 0
j = 1
while j < n and i < n - 1:
if a[j] + s2 != b[i]:
cnt1 += 1
i -= 1
if cnt1 >= 1:
break
i += 1
j += 1
if cnt1 == 0 and cnt == 1:
print(min(s1, s2))
elif cnt1 == 0:
print(s2)
else:
print(s1)
else:
print(max(s1, s2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
import sys
from sys import stdin, stdout
def fxn(n, arr1, arr2):
arr1.sort()
arr2.sort()
for i in range(1, n + 1):
x = arr2[-1] - arr1[-i]
if n > 2:
y = arr2[-2] - arr1[-(i + 1)]
else:
y = x
if x > 0 and x == y:
return x
else:
continue
def main():
t = int(input())
while t != 0:
n = int(input())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
print(fxn(n, arr1, arr2))
t -= 1
main()
|
IMPORT FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
if n == 2:
if a[1] < b[0]:
print(b[0] - a[1])
else:
print(b[0] - a[0])
else:
li = []
if b[0] - a[0] > 0 and b[1] - a[1] > 0:
if b[0] - a[0] == b[1] - a[1]:
li.append(b[0] - a[0])
if b[-1] - a[-1] > 0 and b[-2] - a[-2] > 0:
if b[-2] - a[-2] == b[-1] - a[-1]:
li.append(b[-1] - a[-1])
print(min(li))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for i in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
temp = b[0] - a[1]
flag = True
for j in range(1, n - 1):
if b[j] - a[j + 1] != temp:
flag = False
if temp <= 0 or flag == False:
print(b[0] - a[0])
else:
print(b[0] - a[1])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input())
for i in range(t):
n = int(input())
arr = [int(h) for h in input().split()]
arr1 = [int(h) for h in input().split()]
arr.sort()
arr1.sort()
u = arr[0] - arr1[0]
v = arr[1] - arr1[0]
u = -u
v = -v
u1 = [(f + u) for f in arr]
v1 = [(f + v) for f in arr]
u1 = sum(u1) - sum(arr1) - u
v1 = sum(v1) - sum(arr1) - v
flag1 = 0
flag2 = 0
if u1 in arr and u > 0:
flag1 = 1
if v1 in arr and v > 0:
flag2 = 1
if flag1 * flag2 == 1:
print(min(u, v))
elif flag1 == 1:
print(u)
else:
print(v)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def identify_num(a, b, n):
possible = []
a_x = set(a)
a_total = sum(a)
b_total = sum(b)
for val in a:
if (b_total - (a_total - val)) % (n - 1) == 0 and (
b_total - (a_total - val)
) / (n - 1) > 0:
x = int((b_total - (a_total - val)) / (n - 1))
flag = True
for itm in b:
if itm - x not in a_x:
flag = False
break
if flag:
possible.append(x)
return min(possible)
t = input()
for i in range(int(t)):
n = int(input())
a = input().split(" ")
b = input().split(" ")
a = list(map(lambda x: int(x), a))
b = list(map(lambda x: int(x), b))
print(identify_num(a, b, n))
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
t = int(input().strip())
for _ in range(t):
n = int(input().strip())
a = sorted([int(i.strip()) for i in input().split()])
b = sorted([int(i.strip()) for i in input().split()])
if n == 2:
x = b[0] - a[0]
d2 = b[0] - a[1]
if d2 > 0 and d2 < x:
x = d2
else:
d11 = b[0] - a[0]
d22 = b[1] - a[1]
d12 = b[0] - a[1]
d23 = b[1] - a[2]
if d11 == d22 or d11 == d23:
x = d11
if d12 == d23 and d12 > 0:
x = d12
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
import sys
def find_x(n, la, lb):
la.sort()
lb.sort()
result = {}
for i in range(n - 1):
diff1 = lb[i] - la[i]
diff2 = lb[i] - la[i + 1]
if diff1 > 0:
if diff1 in result:
result[diff1] = result[diff1] + 1
else:
result[diff1] = 1
if diff2 > 0:
if diff2 in result:
result[diff2] = result[diff2] + 1
else:
result[diff2] = 1
for key in sorted(result.keys()):
if result[key] == n - 1:
return key
t = int(sys.stdin.readline().strip())
lines = sys.stdin.readlines()
for i in range(t):
n = int(lines[i * 3])
la = list(int(e) for e in lines[i * 3 + 1].split())
lb = list(int(e) for e in lines[i * 3 + 2].split())
result = find_x(n, la, lb)
print(result)
|
IMPORT FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def solve():
n = int(input())
a, b = list(map(int, input().split())), list(map(int, input().split()))
a.sort()
b.sort()
if n == 2:
ans1 = b[0] - a[-1]
ans2 = b[0] - a[0]
if ans1 > 0 and ans2 > 0:
print(min(ans1, ans2))
elif ans1 > 0:
print(ans1)
elif ans2 > 0:
print(ans2)
else:
ans = 2**63
if b[0] > a[0] and b[0] - a[0] == b[1] - a[1]:
ans = min(ans, b[0] - a[0])
if b[0] > a[0] and b[0] - a[0] == b[1] - a[2]:
ans = min(ans, b[1] - a[2])
if b[0] > a[1] and b[0] - a[1] == b[1] - a[2]:
ans = min(ans, b[0] - a[1])
print(ans)
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
m = min(b) - min(a)
M = max(b) - max(a)
if M <= 0:
print(m)
elif n == 2:
print(min(m, M))
elif b[0] - a[1] == M:
print(M)
else:
print(m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def decodeX(aliceArray, bobArray):
if not isinstance(aliceArray, list) or not isinstance(bobArray, list):
raise ValueError
aliceArray.sort()
bobArray.sort()
deltaX1 = bobArray[0] - aliceArray[0]
deltaX2 = bobArray[0] - aliceArray[1]
if deltaX2 <= 0:
return deltaX1
for i in range(0, len(bobArray)):
deltaX = bobArray[i] - aliceArray[i + 1]
if deltaX != deltaX2:
return deltaX1
return deltaX2
def solve():
input()
aliceArray = list(map(int, input().split()))
bobArray = list(map(int, input().split()))
x = decodeX(aliceArray, bobArray)
print(x)
def main():
test_cases = int(input())
for t in range(test_cases):
solve()
main()
|
FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF EXPR 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 VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def result(A, B):
dictionary = {}
for i in range(len(A)):
if str(A[i]) not in dictionary:
dictionary[str(A[i])] = 1
else:
dictionary[str(A[i])] += 1
maximum_A = max(A)
maximum_B = max(B)
possible_i_values = [maximum_B - maximum_A]
A.remove(maximum_A)
possible_i_values.append(maximum_B - max(A))
possible_i_values = [x for x in possible_i_values if x > 0]
final_vals = []
for value in possible_i_values:
dict2 = dictionary.copy()
current_value = True
for j in B:
if str(j - value) in dict2:
x = dict2[str(j - value)]
if x == 0:
current_value = False
break
dict2[str(j - value)] -= 1
else:
current_value = False
break
if current_value == True:
final_vals.append(value)
return min(final_vals)
for i in range(int(input())):
ignore = input()
A = [int(m) for m in input().split()]
B = [int(m) for m in input().split()]
result_ = result(A, B)
print(str(result_))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def get_dif(nums1, nums2):
nums1.sort(reverse=True)
nums2.sort(reverse=True)
if len(nums1) == 2:
if nums2[0] - nums1[0] > 0:
return nums2[0] - nums1[0]
else:
return nums2[0] - nums1[1]
if nums2[0] - nums1[0] == nums2[1] - nums1[1] and nums2[0] - nums1[0] > 0:
return nums2[0] - nums1[0]
if nums2[0] - nums1[0] == nums2[2] - nums1[1] and nums2[0] - nums1[0] > 0:
return nums2[0] - nums1[0]
return nums2[0] - nums1[1]
for _ in range(int(input())):
input()
nums1 = [int(x) for x in input().split()]
nums2 = [int(x) for x in input().split()]
d = get_dif(nums1, nums2)
print(d)
|
FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
def function():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n == 2:
print(b[0] - a[1]) if b[0] - a[1] > 0 else print(b[0] - a[0])
return
dif = []
for i in range(3):
for j in range(2):
dif.append(b[j] - a[i])
dif.sort()
for i in range(5):
if dif[i] == dif[i + 1] and dif[i] > 0:
print(dif[i])
return
t = int(input())
while t != 0:
function()
t -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER EXPR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.
Note: Since the input is large, prefer using fast input methods.
------ Input Format ------
- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains 3 lines of input.
- The first line contains an integer N - the length of array A.
- The second line contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the array A.
- The third line contains N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1}, denoting the array B.
------ Output Format ------
For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.
------ Constraints ------
$1 β€ T β€ 7$
$2 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{9}$
$1 β€ B_{i} β€ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.
Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n == 2:
if max(b) > max(a):
print(max(b) - max(a))
else:
print(max(b) - min(a))
else:
x = max(a)
y = max(b)
d = y - x
if d <= 0:
print(y - a[len(a) - 2])
elif d == b[len(b) - 2] - a[len(a) - 2] or d == b[len(b) - 2] - a[len(a) - 3]:
print(d)
else:
print(y - a[len(a) - 2])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.