text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
Constraints
* 1 ≤ a,b ≤ 10000
* a and b are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If the product is odd, print `Odd`; if it is even, print `Even`.
Examples
Input
3 4
Output
Even
Input
1 21
Output
Odd
Submitted Solution:
```
#入力値の取得
_in =input().split()
#文字の結合
cont_str = _in[0] + _in[1]
#数字に変換
cont_num = int(cont_str)
#平方数の判定
#総当たり頭悪そう 1<= ab <= 100 なので 4*4~ 100*100
sqrt_flag = False
for i in range(4, 102):
sqrt = i * i
print(sqrt)
if cont_num == sqrt:
sqrt_flag = True
break
if sqrt_flag:
print('Yes')
else:
print('No')
```
No
| 86,400 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
import bisect
def inpl(): return [int(i) for i in input().split()]
X = int(input())
K = int(input())
r = [0] + inpl()
stu = [()]*(K+1)
stu[0] = (X, 0, 0)
for i, v in enumerate(r[1:], 1):
s, t, u = stu[i-1]
if i%2:
rs = r[i-1] - r[i]
ap = - rs - t
if ap >= s:
stu[i] = 0, 0, 0
elif ap >= u:
stu[i] = s, t+rs, ap
else:
stu[i] = s, t+rs, u
else:
rs = r[i] - r[i-1]
ap = X - rs - t
if ap >= s:
stu[i] = s, t+rs, u
elif ap >= u:
stu[i] = ap, t+rs, u
else:
stu[i] = X, 0, X
Q = int(input())
for _ in range(Q):
ti, a = inpl()
x = bisect.bisect_right(r, ti)
ti -= r[x-1]
s, t, u = stu[x-1]
if a >= s:
R = s + t
elif a >= u:
R = a + t
else:
R = u + t
if x % 2:
print(max(0, R - ti))
else:
print(min(X, R + ti))
```
| 86,401 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
def calc_ans(x):
if x < 0:
return 0
elif x < X:
return x
else:
return X
if __name__ == '__main__':
# 砂の合計量
X = int(input())
# ひっくり返す回数
K = int(input())
# ひっくり返す秒数
r = list(map(int, input().split()))
# クエリの個数
Q = int(input())
# r の制御のための変数
j = 0
sign = -1
s = 0
e = X
y = 0
sand_quantity = [r[0]]
for i in range(1, K):
sand_quantity.append(r[i] - r[i - 1])
chasm_time = 0
for i in range(Q):
# t:時刻 a:初期に A に入っている砂の量
t, a = list(map(int, input().split()))
while j < K and r[j] < t:
y += sign * sand_quantity[j]
# sについて更新
if y < 0:
s += -y
if e < s:
s = e
y = 0
# eについて更新
if X < y + e - s:
tmp_diff = (y + e - s) - X
e -= tmp_diff
if e < s:
e = s
if X < y:
y = X
chasm_time = r[j]
j += 1
sign *= -1
tmp_time = t - chasm_time
if a < s:
ret = y
elif a < e:
ret = y + a - s
else:
ret = y + e - s
ret += tmp_time * sign
print(calc_ans(ret))
# print("s:" + str(s) + " e:" + str(e) + " y:" + str(y) + " a:" + str(a) + " ret:" + str(ret))
```
| 86,402 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
def main():
import sys
from operator import itemgetter
input = sys.stdin.readline
X = int(input())
K = int(input())
R = list(map(int, input().split()))
Q = []
for r in R:
Q.append((r, -1))
q = int(input())
for _ in range(q):
t, a = map(int, input().split())
Q.append((t, a))
Q.sort(key=itemgetter(0))
#print(Q)
prev = 0
m = 0
M = X
flg = -1
R_cs = 0
for t, a in Q:
if a < 0:
r = t - prev
R_cs -= r * flg
if flg == -1:
m = max(0, m-r)
M = max(0, M-r)
flg = 1
else:
m = min(X, m+r)
M = min(X, M+r)
flg = -1
prev = t
else:
if m == M:
if flg == 1:
print(min(X, m + t - prev))
else:
print(max(0, m - t + prev))
else:
am = m + R_cs
aM = M + R_cs
#print('am', am, 'aM', aM, m, M)
if a <= am:
if flg == 1:
print(min(X, m + t - prev))
else:
print(max(0, m - t + prev))
elif a >= aM:
if flg == 1:
print(min(X, M + t - prev))
else:
print(max(0, M - t + prev))
else:
if flg == 1:
print(min(X, m + (a - am) + t - prev))
else:
print(max(0, m + (a - am) - t + prev))
if __name__ == '__main__':
main()
```
| 86,403 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
X = int(input())
K = int(input())
r_lst = [int(_) for _ in input().split()]
Q = int(input())
t_lst, a_lst = [], []
for i in range(Q):
buf = input().split()
t_lst.append(int(buf[0]))
a_lst.append(int(buf[1]))
pos_lst = []
for i, r in enumerate(r_lst):
direc = "+" if i%2==0 else "-"
pos_lst.append((r, direc))
for i, t in enumerate(t_lst):
pos_lst.append((t, i))
pos_lst = sorted(pos_lst, key=lambda tup: tup[0])
left, right = 0, X
val = [0, 0, X]
direc = "-"
prv = 0
for pos in pos_lst:
# print(left, right)
# print(val)
# print(pos)
# print()
elapsed = pos[0] - prv
prv = pos[0]
if direc == "+":
val[0] = min(X, val[0] + elapsed)
val[1] += elapsed
val[2] = min(X, val[2] + elapsed)
right = min(right, X - val[1])
else:
val[0] = max(0, val[0] - elapsed)
val[1] -= elapsed
val[2] = max(0, val[2] - elapsed)
left = max(left, -(val[1]))
if pos[1] == "+" or pos[1] == "-":
direc = pos[1]
else: #is query
a = a_lst[pos[1]]
if a <= left:
print(val[0])
elif a >= right:
print(val[2])
else:
print( a + val[1])
```
| 86,404 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
import sys
input = sys.stdin.readline
"""
X定数だった。両極端な場合が合流する。
[0,L]上定数A、[R,X]上定数B、その間は線形
"""
X = int(input())
K = int(input())
R = [int(x) for x in input().split()]
Q = int(input())
TA = [tuple(int(x) for x in input().split()) for _ in range(Q)]
task = sorted([(r,-1) for r in R] + [(t,a) for t,a in TA])
L = 0
R = X
A = 0
B = X
dx = -1 # 初めは減る方
current = 0
answer = []
for t,a in task:
# とりあえず上限を突破して落とす
A += dx * (t-current)
B += dx * (t-current)
current = t
if a != -1:
# 体積の計算
if a <= L:
x = A
elif a >= R:
x = B
else:
x = A+(B-A)//(R-L)*(a-L)
if x < 0:
x = 0
if x > X:
x = X
answer.append(x)
else:
dx = -dx
if A < B:
if A < 0:
L += (-A)
A = 0
if B > X:
R -= (B-X)
B = X
if A > X:
A = X
B = X
L = 0
R = 0
if B < 0:
A = 0
B = 0
L = 0
R = 0
elif A >= B:
if A > X:
L += (A-X)
A = X
if B < 0:
R -= (-B)
B = 0
if A < 0:
A = 0
B = 0
L = 0
R = 0
if B > X:
A = X
B = X
L = 0
R = 0
if R < L:
R = L
print(*answer,sep='\n')
```
| 86,405 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
# F
# input
from bisect import bisect
X = int(input())
K = int(input())
r_list = [0] + list(map(int, input().split()))
Q = int(input())
query_list = [list(map(int, input().split())) for _ in range(Q)]
MmRL_list = []
# M:max, m:min, R:min_a(M), L:max_a(m)
M = X
m = 0
R = X
L = 0
MmRL_list.append([M, m, R, L])
for i in range(K):
M_ = M
m_ = m
R_ = R
L_ = L
lag = r_list[i+1] - r_list[i]
# update
if i % 2 == 0:
if M_ - lag < 0:
M = 0
R = 0
else:
M = M_ - lag
R = R_
if m_ - lag < 0:
m = 0
L = L_ + lag - m_
else:
m = m_ - lag
L = L_
else:
if M_ + lag > X:
M = X
R = R_ - (M_ + lag - X)
else:
M = M_ + lag
R = R_
if m_ + lag > X:
m = X
L = X
else:
m = m_ + lag
L = L_
MmRL_list.append([M, m, R, L])
# print(MmRL_list)
for q in range(Q):
t, a = query_list[q]
j = bisect(r_list, t) - 1
# find status then
M, m, R, L = MmRL_list[j]
if a <= L:
a_ = m
elif a >= R:
a_ = M
else:
a_ = m + (a - L)
t_ = t - r_list[j]
if j % 2 == 0:
res = max(a_ - t_, 0)
else:
res = min(a_ + t_, X)
print(res)
```
| 86,406 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
X = int(input())
K = int(input())
rs = list(map(int,input().split()))
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]
dx = -1
ri = 0
offset = 0
upper,lower = X,0
prev_r = 0
ans = []
for t,a in qs:
while ri < len(rs) and rs[ri] <= t:
tmp_offset = dx * (rs[ri] - prev_r)
if dx == 1:
upper = min(X, upper + tmp_offset)
lower = min(X, lower + tmp_offset)
else:
upper = max(0, upper + tmp_offset)
lower = max(0, lower + tmp_offset)
offset += tmp_offset
dx *= -1
prev_r = rs[ri]
ri += 1
a = max(lower, min(upper, a+offset))
dt = t - prev_r
a = max(0, min(X, a + dx*dt))
ans.append(a)
print(*ans, sep='\n')
```
| 86,407 |
Provide a correct Python 3 solution for this coding contest problem.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
"Correct Solution:
```
X = int(input())
K = int(input())
R = list(map(int, input().split()))
Q = int(input())
ami = [0]*(K+1)
ama = [X] + [0]*K
cusummi = [0]*(K+1)
cusumma = [0]*(K+1)
cusum = [0]*(K+1)
pr = 0
for i, r in enumerate(R):
d = pr-r if i%2==0 else r-pr
cusum[i+1] = cusum[i] + d
cusummi[i+1] = min(cusummi[i], cusum[i+1])
cusumma[i+1] = max(cusumma[i], cusum[i+1])
ami[i+1] = min(max(ami[i] + d, 0), X)
ama[i+1] = min(max(ama[i] + d, 0), X)
pr = r
import bisect
for _ in range(Q):
t, a = map(int, input().split())
i = bisect.bisect_right(R, t)
t1 = R[i-1] if i!=0 else 0
t2 = t-t1
d = -t2 if i%2==0 else t2
if ama[i]==ami[i]:
print(min(max(ama[i] + d, 0), X))
continue
ans = a+cusum[i]
if -cusummi[i]>a:
ans += -cusummi[i]-a
if cusumma[i]>(X-a):
ans -= cusumma[i]-(X-a)
print(min(max(ans+d, 0), X))
```
| 86,408 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
#!/usr/bin/env python3
import bisect
def main():
X = int(input())
K = int(input())
r = list(map(int, input().split()))
Q = int(input())
q_list = []
for i in range(Q):
q_list.append(list(map(int, input().split())))
r = [0] + r
a = [0]
upper_limit = [X]
lower_limit = [0]
x, ux, lx = 0, X, 0
for i in range(1, K + 1):
diff = r[i] - r[i - 1]
if i % 2 == 1:
x -= diff
ux -= diff
ux = max(ux, 0)
lx -= diff
lx = max(lx, 0)
else:
x += diff
ux += diff
ux = min(ux, X)
lx += diff
lx = min(lx, X)
a.append(x)
upper_limit.append(ux)
lower_limit.append(lx)
asc_i = [0]
dsc_i = [1]
x = 0
for i in range(2, K + 1, 2):
if x < a[i]:
x = a[i]
asc_i.append(i)
x = a[1]
for i in range(3, K + 1, 2):
if a[i] < x:
x = a[i]
dsc_i.append(i)
asc_a = [a[i] for i in asc_i]
dsc_a = [-a[i] for i in dsc_i]
for [t, a0] in q_list:
ri = bisect.bisect_right(r, t) - 1
ui = bisect.bisect_left(asc_a, X - a0)
li = bisect.bisect_left(dsc_a, a0)
ai, di = None, None
if ui < len(asc_i):
ai = asc_i[ui]
if ri < ai:
ai = None
if li < len(dsc_i):
di = dsc_i[li]
if ri < di:
di = None
d = 0
if (not ai is None) or (not di is None):
if ai is None:
d = -1
elif di is None:
d = 1
else:
d = 1 if ai < di else -1
x = a0 + a[ri]
if d == 1:
x = upper_limit[ri]
elif d == -1:
x = lower_limit[ri]
x += (t - r[ri]) * (-1 if ri % 2 == 0 else 1)
x = min(max(x, 0), X)
print(x)
if __name__ == '__main__':
main()
```
Yes
| 86,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc082/tasks/arc082_d
aiが固定ならば、ただクエリをソートしてシミュレーションしながら答えを出せばよい
今回はそうでないので、方法を考える
一度でも砂が落ち切ってしまえば、その後はaiに関わらず、答えは等しくなる
おちきっていない場合、常に砂が移動し続けるので、初期値からの差分が常に等しくなる
よって、落ち切らないaの範囲を保持し、一度も落ち切らない場合の初期からの差分
& 落ち切ってしまった場合のシミュレーション結果を用いて答えればよい
→どのタイミング(区間)で落ち切るかでその後の動きが違くね???
→死
→aの区間は高々3つに分けられる
→ aが少なく、a=0と同じに収束する場合、 aが大きく、a=Xと同じに収束する場合。、一度も落ち切らない場合
→そして、a=0,a=Xと同じになる場合は、それぞれaの初期値の区間の両端から侵食していく
→よって、a=0のシミュ、a=Xのシミュ、落ち切らない差分シミュ。その時あるaがどれに属すかの区間
を用いてシミュレーションしながらdp的に処理してあげればよい
あとは実装が面倒そう
"""
from collections import deque
X = int(input())
K = int(input())
r = list(map(int,input().split()))
#番兵
r.append(float("inf"))
r.append(0)
ta = deque([])
Q = int(input())
for i in range(Q):
t,a = map(int,input().split())
ta.append([t,a])
ZA = 0 #初期がa=0の時のシミュ結果
XA = X #初期がXの時
D = 0 #差分計算
Zmax = 0 #aがZmax以下ならZAと等しくなる
Xmin = X #aがXmin以上ならXAと等しくなる
for i in range(K+1):
time = r[i] - r[i-1]
#クエリの処理(r[i]以下に関して)
if i % 2 == 0: #Aが減っていく
while len(ta) > 0 and ta[0][0] <= r[i]:
t,a = ta.popleft()
td = t - r[i-1]
if a <= Zmax:
print (max( 0 , ZA-td ))
elif a >= Xmin:
print (max (0 , XA-td ))
else:
print (max (0 , a+D-td))
D -= time
Zmax = max(Zmax,-1*D)
ZA = max(0,ZA-time)
XA = max(0,XA-time)
else: #Aが増えていく
while len(ta) > 0 and ta[0][0] <= r[i]:
t,a = ta.popleft()
td = t - r[i-1]
if a <= Zmax:
print (min( X , ZA+td ))
elif a >= Xmin:
print (min (X , XA+td ))
else:
print (min (X , a+D+td))
D += time
Xmin = min(Xmin,X-D)
ZA = min(X,ZA+time)
XA = min(X,XA+time)
```
Yes
| 86,410 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
x, = map(int,readline().split())
k, = map(int,readline().split())
*r, = map(int,readline().split())
q, = map(int,readline().split())
r.append(1<<30)
INF = 1<<30
ID_M = (-INF,INF,0)
def compose(lst1,lst2):
return (funcval(lst1[0],lst2),funcval(lst1[1],lst2),lst1[2]+lst2[2])
def funcval(x,lst):
a,b,c = lst
if x <= a-c: return a
elif x >= b-c: return b
else: return x+c
#seg = segment_tree_dual(q, compose, funcval, ID_M)
#seg.build([a for a,t,i in ati])
seg = (0,x,0)
tai = []
for i in range(q):
t,a = map(int,readline().split())
tai.append((t,a,i))
tai.sort(key=lambda x:x[0])
idx = 0
ans = [0]*q
t0 = 0
coeff = -1
for i,ri in enumerate(r):
while idx < q and tai[idx][0] < ri:
t,a,j = tai[idx]
v = funcval(a,seg)
ans[j] = min(x,max(v+coeff*(t-t0),0))
idx += 1
seg = compose(seg,(0,x,coeff*(ri-t0)))
t0 = ri
coeff *= -1
#print(seg)
print(*ans,sep="\n")
```
Yes
| 86,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
X = int(input())
K = int(input())
R = [int(x) for x in reversed(input().split())]
for i in range(0,K-1): R[i] -= R[i+1]
Q = int(input())
aM = X
M = X
am = 0
m = 0
now = 0
sign = -1
timer = R.pop()
def Go(time):
global aM,M,am,m
if sign==1:
if m+time>X:
m = X
M = X
aM = am
elif M+time>X:
m += time
M = X
aM = am + M - m
else:
m += time
M += time
else:
if M-time<0:
m = 0
M = 0
am = aM
elif m-time<0:
m = 0
M -= time
am = aM + m - M
else:
m -= time
M -= time
for i in range(Q):
t,a = [int(x) for x in input().split()]
t -= now
now += t
while t>=timer:
Go(timer)
t -= timer
if R:
timer = R.pop()
else:
timer = float("inf")
sign *= -1
Go(t)
timer -= t
if a<am:
print(m)
elif a>aM:
print(M)
else:
print(m+a-am)
```
Yes
| 86,412 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
import sys
input = sys.stdin.readline
"""
X定数だった。両極端な場合が合流する。
[0,L]上定数A、[R,X]上定数B、その間は線形
"""
X = int(input())
K = int(input())
R = [int(x) for x in input().split()]
Q = int(input())
TA = [tuple(int(x) for x in input().split()) for _ in range(Q)]
task = sorted([(r,-1) for r in R] + [(t,a) for t,a in TA])
L = 0
R = X
A = 0
B = X
dx = -1 # 初めは減る方
current = 0
answer = []
for t,a in task:
# とりあえず上限を突破して落とす
A += dx * (t-current)
B += dx * (t-current)
current = t
if a != -1:
# 体積の計算
if a <= L:
x = A
elif a >= R:
x = B
else:
x = A+(B-A)//(R-L)*(a-L)
if x < 0:
x = 0
if x > X:
x = X
answer.append(x)
else:
dx = -dx
if A < B:
if A < 0:
L += (-A)
A = 0
if B > X:
R -= (B-X)
B = X
if A > X:
A = X
B = X
L = 0
R = 0
if B < 0:
A = 0
B = 0
L = 0
R = 0
elif A > B:
if A > X:
L += (A-X)
A = X
if B < 0:
R -= (-B)
B = 0
if A < 0:
A = 0
B = 0
L = 0
R = 0
if B > X:
A = X
B = X
L = 0
R = 0
if R < L:
R = L
print(*answer,sep='\n')
```
No
| 86,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
def read_data_f(filename='arc082-e.dat'):
try:
LOCAL_FLAG
import codecs
import os
lines = []
file_path = os.path.join(os.path.dirname(__file__), filename)
with codecs.open(file_path, 'r', 'utf-8') as f:
for each in f:
lines.append(each.rstrip("\r\n"))
except NameError:
lines = []
lines.append(input())
lines.append(input())
lines.append(input())
lines.append(input())
Q = int(lines[3])
for i in range(Q):
lines.append(input())
return lines
def F_Sandglass():
#
# 180
# 3
# 60 120 180
# 3
# 30 90
# 61 1
# 180 180
raw_data = read_data_f('arc082-f.dat')
X = int(raw_data[0])
K = int(raw_data[1])
r = list(map(int, raw_data[2].split()))
Q = int(raw_data[3])
a = []
t = []
for i in range(Q):
tt, aa = list(map(int, raw_data[i+4].split()))
a.append(aa)
t.append(tt)
# print(r)
# print(t)
# print(a)
time = 0
i = j = 0
U = X
L = 0
c = 0
isUp = True
time_diff = 0
r.append(2000000000)
t.append(1)
while (i < K+1) and (time < t[Q-1]):
while((time <= t[j] and t[j] < r[i])):
time_diff_temp = t[j] - time
if(isUp):
c_temp = max(c - time_diff_temp, -X)
U_temp = U
L_temp = L
if(L + c_temp) < 0:
L_temp = min(L + time_diff_temp, X)
else:
c_temp = min(c + time_diff_temp, X)
U_temp = U
if(U + c_temp) > X:
U_temp = max(U - time_diff_temp, 0)
L_temp = L
if(a[j] > U_temp):
print(min(U_temp + c_temp, X))
elif(a[j] < L_temp):
print(max(L_temp + c_temp, 0))
else:
print(a[j] + c_temp)
j += 1
time_diff = r[i] - time
if(isUp):
c = max(c - time_diff, -X)
if(L + c) < 0:
L = -c
if(L > U):
U = L
else:
c = min(c + time_diff, X)
if(U + c) > X:
U = X - c
if(L > U):
L = U
time = r[i]
isUp = not isUp
i += 1
# result = remain(X, A[start_time], t[j] - start_time, start_status)
# print(result)
F_Sandglass()
```
No
| 86,414 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
if __name__ == '__main__':
# 砂の合計量
X = int(input())
# ひっくり返す回数
K = int(input())
# ひっくり返す秒数
r = list(map(int, input().split()))
# クエリの個数
Q = int(input())
# r の制御のための変数
j = 0
sign = -1
'''
ある時刻を切り取り、横軸を最初のAの砂の量、縦軸をその時の砂の量とする。
s:傾き始め
e:傾き終わり
c:切片
'''
s = 0
e = X
c = 0
# 出入りする砂の量
sand_quantity = [r[0]]
for i in range(1, K):
sand_quantity.append(r[i] - r[i - 1])
chasm_time = 0
for i in range(Q):
# t:時刻 a:初期に A に入っている砂の量
t, a = list(map(int, input().split()))
while j < K and r[j] < t:
c += sign * sand_quantity[j]
c = max(min(X, c), -X)
# sについて更新
if s < -c:
s = -c
if e < s:
s = e
# eについて更新
if X - c < e:
e = X - c
if e < s:
e = s
chasm_time = r[j]
j += 1
sign *= -1
tmp_time = t - chasm_time
if a < s:
print(max(min(s + c + tmp_time * sign, X), 0))
elif a < e:
print(max(min(a + c + tmp_time * sign, X), 0))
else:
print(max(min(e + c + tmp_time * sign, X), 0))
# print("s:" + str(s) + " e:" + str(e) + " c:" + str(c) + " a:" + str(a))
```
No
| 86,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
* 1≤X≤10^9
* 1≤K≤10^5
* 1≤r_1<r_2< .. <r_K≤10^9
* 1≤Q≤10^5
* 0≤t_1<t_2< .. <t_Q≤10^9
* 0≤a_i≤X (1≤i≤Q)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q
Output
For each query, print the answer in its own line.
Examples
Input
180
3
60 120 180
3
30 90
61 1
180 180
Output
60
1
120
Input
100
1
100000
4
0 100
90 100
100 100
101 100
Output
100
10
0
0
Input
100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10
Output
19
52
91
10
58
42
100
Submitted Solution:
```
input = __import__('sys').stdin.readline
MIS = lambda: map(int,input().split())
# f(a) = z a <= x1
# a+z-x1 x1 <= a <= x2
# x2+z-x1 x2 <= a
class Sandgraph:
def __init__(_, X):
_.z = _.x1 = 0
_.x2 = X
def __repr__(_):
return f"<{_.z} {_.x1} {_.x2}>"
def add(_, dt):
# Go towards the ceiling
d1 = min(dt, X-(_.x2+_.z-_.x1))
_.z+= d1
dt-= d1
# Reduce the diagonal
d1 = min(dt, _.x2-_.x1)
_.z+= d1
_.x2-= d1
def sub(_, dt):
# Go towards the floor
d1 = min(dt, _.z)
_.z-= d1
dt-= d1
# Reduce the diagonal
d1 = min(dt, _.x2-_.x1)
_.x1+= d1
def __call__(_, a):
if a <= _.x1: return _.z
elif a <= _.x2: return a + _.z - _.x1
else: return _.x2 + _.z - _.x1
X = int(input())
k = int(input())
rev = list(MIS())
Q = int(input())
sand = Sandgraph(X)
last_t = 0
i = 0 # even -, odd +
for QUERY in range(Q):
t, a = MIS()
while i<k and rev[i] <= t:
dt = rev[i] - last_t
if i%2 == 0: sand.sub(dt)
else: sand.add(dt)
last_t = rev[i]
i+= 1
dt = t - last_t
if i%2 == 0: sand.sub(dt)
else: sand.add(dt)
print(sand(a))
last_t = t
```
No
| 86,416 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(M)]
for ab in AB:
man = [(abs(ab[0]-CD[i][0]) + abs(ab[1]-CD[i][1])) for i in range(len(CD))]
print(man.index(min(man))+1)
```
| 86,417 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
n,m = map(int,input().split())
a = [list(map(int,input().split()))for x in range(n)]
b = [list(map(int,input().split()))for x in range(m)]
for x in range(n):
c = list()
for y in range(m):
c.append(abs(a[x][0]-b[y][0]) + abs(a[x][1]-b[y][1]))
print(c.index(min(c))+1)
```
| 86,418 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
N,M=map(int,input().split())
n=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(M)]
result=[]
for i in range(len(n)):
result=[]
for j in range(len(m)):
result.append(abs(n[i][0]-m[j][0])+abs(n[i][1]-m[j][1]))
print(result.index(min(result))+1)
```
| 86,419 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
N, M = map(int, input().split())
p_s = [list(map(int, input().split())) for _ in range(N)]
p_f = [list(map(int, input().split())) for _ in range(M)]
length = []
for s in p_s:
for f in p_f:
length.append(abs(s[0]-f[0]) + abs(s[1]-f[1]))
print(length.index(min(length))+1)
length = []
```
| 86,420 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
N,M = list(map(int, input().split()))
s = []
for i in range(N):
s.append(list(map(int, input().split())))
c = []
for j in range(M):
c.append(list(map(int, input().split())))
for t1 in s:
l = list(map(lambda x: abs(t1[0] - x[0]) + abs(t1[1] - x[1]), c))
print(l.index(min(l)) + 1)
```
| 86,421 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
n, m = map(int, input().split())
abes = [list(map(int, input().split())) for _ in range(n)]
cdes = [list(map(int, input().split())) for _ in range(m)]
for a, b in abes:
mi = sorted(cdes, key=lambda x : abs(x[0]-a)+abs(x[1]-b))
print(cdes.index(mi[0])+1)
```
| 86,422 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
n,m=map(int,input().split())
std = [list(map(int,input().split())) for i in range(n)]
chk = [list(map(int,input().split())) for i in range(m)]
for s in std:
ans=[]
for i in range(m):
ans.append([abs(s[0]-chk[i][0])+abs(s[1]-chk[i][1]),i+1])
ans.sort()
print(ans[0][1])
```
| 86,423 |
Provide a correct Python 3 solution for this coding contest problem.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
"Correct Solution:
```
N, M = map(int, input().split())
Ss = [tuple(map(int, input().split())) for i in range(N)]
CPs = [tuple(map(int, input().split())) for i in range(M)]
for a, b in Ss:
dist = [abs(a - c) + abs(b - d) for c, d in CPs]
print(dist.index(min(dist)) + 1)
```
| 86,424 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
#57b
n,m = map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
ans=[]
for j in range(m):
ans.append(abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]))
print(ans.index(min(ans))+1)
```
Yes
| 86,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
N, M = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]
C = [tuple(map(int, input().split())) for _ in range(M)]
for i in S:
ans = 0
k = 10 ** 10
for j in range(M):
n = abs(i[0] - C[j][0]) + abs(i[1] - C[j][1])
if k > n:
k = n
ans = j + 1
else:
print(ans)
```
Yes
| 86,426 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
n,m = map(int, input().split())
stu = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]
for x, y in stu:
k = []
for c, d in p:
k.append(abs(x-c)+abs(y-d))
print(k.index(min(k))+1)
```
Yes
| 86,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]
for ab in AB:
dist = [abs(ab[0] - cd[0]) + abs(ab[1] - cd[1]) for cd in CD]
print(dist.index(min(dist)) + 1)
```
Yes
| 86,428 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
N, M = map(int,input().split())
list_a = []
list_b = []
ans_x = [10**8 for i in range(N)]
count = 0
for i in range(N):
a = [int(i) for i in input().split()]
list_a.append(a)
for i in range(M):
b = [int(i) for i in input().split()]
list_b.append(b)
for i in range(N):
for j in range(M):
x = abs(list_a[i][0]-list_b[j][0])
y = abs(list_a[i][1]-list_b[j][1])
xxx = x + y
if xxx < ans_x[i]:
ans_x[i] = xxx
count = j+1
print(count)
```
No
| 86,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
#!/usr/bin/env python
nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
student = list()
point = list()
for i in range(n):
student.append([int(a) for a in input().split()])
for j in range(m):
point.append([int(b) for b in input().split()])
mat = [[abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1]) for i in range(n)] for j in range(m)]
for i in range(n):
print(mat[i].index(min(mat[i]))+1)
```
No
| 86,430 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
if __name__ == '__main__':
a, b = map(int, input().split())
lista=[]
for i in range(a):
c = [int(i) for i in input().split()]
lista.append(c)
listb=[]
for i in range(b):
c = [int(i) for i in input().split()]
listb.append(c)
listc =[]
for i in lista:
min = 51*51
minroot=-1
for j in range(len(listb)):
root = (i[0] - listb[j][0]) + (i[1] - listb[j][1])
if root <min:
min =root
minroot=j+1
listc.append(minroot)
for i in listc:
print(i)
```
No
| 86,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?
Constraints
* 1 \leq N,M \leq 50
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M
Output
Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
Examples
Input
2 2
2 0
0 0
-1 0
1 0
Output
2
1
Input
3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
Output
3
1
2
Input
5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
Output
5
4
3
2
1
Submitted Solution:
```
N,M=map(int,input().split())
stand=[list(map(int,input().split())) for _ in range(N)]
point=[list(map(int,input().split())) for _ in range(M)]
new_stand=[None]*N
for i in range(N):
nearest=abs(stand[i][0]-point[0][0])+abs(stand[i][1]-point[i][1])
near_ind=M
for j in range(N):
man=abs(point[j][0]-stand[i][0]) + abs(point[j][1]-stand[i][1])
if nearest>man:
nearest=man
near_ind=j
new_stand[i]=near_ind+1
for i in range(N):
print(new_stand[i])
```
No
| 86,432 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
A = sorted(map(int, input().split()))
print("Yes" if sum(A[:2]) == A[2] else "No")
```
| 86,433 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
A = list(map(int, input().split()))
print('Yes' if sum(A)/2 in A else 'No')
```
| 86,434 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
L=list(map(int,input().split()))
print('YNeos'[2*max(L)!=sum(L)::2])
```
| 86,435 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
A=list(map(int,input().split()))
print('Yes' if 2*max(A)==sum(A) else 'No')
```
| 86,436 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
a,b,c=map(int,input().split())
print("Yes" if 2*max(a,b,c)==a+b+c else "No")
```
| 86,437 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
a,b,c=map(int,input().split())
if 2*max(a,b,c)==a+b+c:
print("Yes")
else:
print("No")
```
| 86,438 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
a,b,c=sorted(map(int,input().split()));print("YNeos"[a+b!=c::2])
```
| 86,439 |
Provide a correct Python 3 solution for this coding contest problem.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
"Correct Solution:
```
a,b,c = map(int, input().split())
print('Yes' if a+b==c or a==b+c or b==a+c else 'No')
```
| 86,440 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
a,b,c=sorted(list(map(int,input().split())))
if a+b==c:print("Yes")
else:print("No")
```
Yes
| 86,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
l, m, h = sorted(map(int, input().split()))
print(['No', 'Yes'][h == (l+m)])
```
Yes
| 86,442 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
s=input();print('NYoe s'[' 2'in s or' 5'in s::2])
```
Yes
| 86,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
a,b,c=map(int,input().split())
if max(a,b,c)==(a+b+c)/2:print("Yes")
else:print("No")
```
Yes
| 86,444 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
a,b,c = map(int,input().split())
big = max(a,b,c)
total = a + b + c
if total = big*2:
print("Yes")
else:
print("No")
```
No
| 86,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
p = list(map(int, input().split())).sort()
print('Yes' if p[0]+p[1]==p[2] else 'No')
```
No
| 86,446 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
sc.close();
if(a + b == c || a + c == b || b + c == a) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}
```
No
| 86,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
Constraints
* 1 ≦ a, b, c ≦ 100
Input
The input is given from Standard Input in the following format:
a b c
Output
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
Examples
Input
10 30 20
Output
Yes
Input
30 30 100
Output
No
Input
56 25 31
Output
Yes
Submitted Solution:
```
n = input().split()
a = int(n[0])
b = int(n[1])
c = int(n[2])
if (a + b) == c:
print('Yes')
elif (a + b) == c:
print('Yes')
elif (a + c) == b:
print('Yes')
else:
print('No')
```
No
| 86,448 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
import sys
for e in sys.stdin:
e=list(map(float,e.split(',')))
print(['YES','NO'][sum((e[i]-e[(2+i)%8])*(e[(5+i)%8]-e[(3+i)%8])-(e[1+i]-e[(3+i)%8])*(e[(4+i)%8]-e[(2+i)%8])>0 for i in range(0,8,2))%4>0])
```
| 86,449 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def cross3(a, b, c):
return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
def solve():
for line in readlines():
xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(","))
P = [(xa, ya), (xb, yb), (xc, yc), (xd, yd)]
D = []
for i in range(4):
p0 = P[i-2]; p1 = P[i-1]; p2 = P[i]
D.append(cross3(p0, p1, p2))
if all(e > 0 for e in D) or all(e < 0 for e in D):
write("YES\n")
else:
write("NO\n")
solve()
```
| 86,450 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
import sys
def solve():
for line in sys.stdin:
xa,ya,xb,yb,xc,yc,xd,yd = map(float, line.split(','))
def fac(x, y):
if xa == xc:
return x - xa
else:
return ((ya-yc)/(xa-xc))*(x-xa) - y + ya
def fbd(x, y):
if xb == xd:
return x - xb
else:
return ((yb-yd)/(xb-xd))*(x-xb) - y + yb
if fac(xb, yb) * fac(xd, yd) > 0:
print('NO')
elif fbd(xa, ya) * fbd(xc, yc) > 0:
print('NO')
else:
print('YES')
if __name__ == "__main__":
solve()
```
| 86,451 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
def judge(p1,p2,p3,p4):
t1 = (p3[0] - p4[0]) * (p1[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p1[0])
t2 = (p3[0] - p4[0]) * (p2[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p2[0])
t3 = (p1[0] - p2[0]) * (p3[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p3[0])
t4 = (p1[0] - p2[0]) * (p4[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p4[0])
return t1*t2>0 and t3*t4>0
while True:
try:
x1,y1,x2,y2,x3,y3,x4,y4=map(float, input().split(","))
A=[x1,y1]
B=[x2,y2]
C=[x3,y3]
D=[x4,y4]
if judge(A,B,C,D)==False :
print("NO")
else:
print("YES")
except EOFError:
break
```
| 86,452 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
def cross(v1, v2):
return v1[0] * v2[1] - v1[1] * v2[0]
def sign(v):
if v >= 0:
return 1
else:
return -1
for s in sys.stdin:
ax, ay, bx, by, cx, cy, dx, dy = map(float, s.split(','))
AB = (bx - ax, by - ay)
BC = (cx - bx, cy - by)
CD = (dx - cx, dy - cy)
DA = (ax - dx, ay - dy)
c0 = cross(AB, BC)
c1 = cross(BC, CD)
c2 = cross(CD, DA)
c3 = cross(DA, AB)
if sign(c0) == sign(c1) == sign(c2) == sign(c3):
print('YES')
else:
print('NO')
```
| 86,453 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
import math
def eq(x, y):
return abs(x - y) <= 10e-10
def get_r(_a, _b, _c):
return math.acos((-_a ** 2 + _b ** 2 + _c ** 2) / (2 * _b * _c))
def _len(_ax, _ay, _bx, _by):
return math.sqrt((_ax - _bx) ** 2 + (_ay - _by) ** 2)
try:
while 1:
xa,ya,xb,yb,xc,yc,xd,yd = map(float, input().split(','))
ab = _len(xa,ya,xb,yb)
bc = _len(xc,yc,xb,yb)
cd = _len(xc,yc,xd,yd)
ad = _len(xa,ya,xd,yd)
bd = _len(xd,yd,xb,yb)
ac = _len(xa,ya,xc,yc)
A = get_r(bd, ab, ad)
B = get_r(ac, ab, bc)
C = get_r(bd, bc, cd)
D = get_r(ac, ad, cd)
if eq(A + B + C + D, 2 * math.pi):
print("YES")
else:
print("NO")
except:
pass
```
| 86,454 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
#凸包を求める
def quickhull(l,r,s,k):
if not s:
return
su = []
sd = []
a = (r[0]-l[0],r[1]-l[1])
for x,y in s:
b = (x-l[0],y-l[1])
cro = cross(a,b)
if cro > 0:
su.append((x,y)) #上半分
elif cro < 0:
sd.append((x,y)) #下半分
if su:
c,d = direction(l,r,su[0])
p = su[0]
for i in range(1,len(su)):
c_,d_ = direction(l,r,su[i])
if c*d_ < c_*d:
c,d = c_,d_
p = su[i]
k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加
b = (l[0]-p[0],l[1]-p[1])
c = (p[0]-r[0],p[1]-r[1])
s1 = []
s2 = []
for x,y in su:
b_ = (x-p[0],y-p[1])
c_ = (x-r[0],y-r[1])
cro_b,cro_c = cross(b,b_),cross(c,c_)
if cro_b >= 0 and cro_c >= 0: #三角形内部判定
continue
else:
if cro_b < 0:
s1.append((x,y))
elif cro_c < 0:
s2.append((x,y))
quickhull(l,p,s1,k) #再帰
quickhull(p,r,s2,k)
if sd:
c,d = direction(l,r,sd[0])
p = sd[0]
for i in range(1,len(sd)):
c_,d_ = direction(l,r,sd[i])
if c*d_ < c_*d:
c,d = c_,d_
p = sd[i]
k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加
b = (l[0]-p[0],l[1]-p[1])
c = (p[0]-r[0],p[1]-r[1])
s1 = []
s2 = []
for x,y in sd:
b_ = (x-p[0],y-p[1])
c_ = (x-r[0],y-r[1])
cro_b,cro_c = cross(b,b_),cross(c,c_)
if cro_b <= 0 and cro_c <= 0: #三角形内部判定(ベクトルの向きにより上下で判定が異なることに注意)
continue
else:
if cro_b > 0:
s1.append((x,y))
elif cro_c > 0:
s2.append((x,y))
quickhull(l,p,s1,k) #再帰
quickhull(p,r,s2,k)
return k
def cross(a,b): #外積
return a[0]*b[1]-a[1]*b[0]
def direction(l,r,p): #点と直線の距離
a = r[1]-l[1]
b = l[0]-r[0]
return (a*(p[0]-l[0])+b*(p[1]-l[1]))**2, a**2+b**2 #分子の2乗,分母の2乗
while 1:
try:
t = [float(x) for x in input().split(",")]
s = []
for i in range(len(t)//2):
s.append((t[2*i],t[2*i+1]))
s.sort()
l = tuple(s.pop(0))
r = tuple(s.pop(-1))
k = quickhull(l,r,s,[l,r])
if len(k) < 4:
print("NO")
else:
print("YES")
except:
quit()
```
| 86,455 |
Provide a correct Python 3 solution for this coding contest problem.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
"Correct Solution:
```
from decimal import Decimal
import sys
for l in sys.stdin:
xa,ya,xb,yb,xc,yc,xd,yd=list(map(Decimal,l.split(",")))
a=xd-xb
b=yd-yb
c=xa-xb
d=ya-yb
e=xc-xb
f=yc-yb
try:
s=(a*f-b*e)/(c*f-d*e)
t=(-a*d+b*c)/(c*f-d*e)
except:
print("NO")
if s>=0 and t>=0 and s+t>=1:
print("YES")
else:
print("NO")
```
| 86,456 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
def cross(x, y):
return (x.conjugate() * y).imag
def is_convex(points):
n = len(points)
x = points[1] - points[0]
y = points[2] - points[1]
c0 = cross(x, y)
for i in range(1, n):
x = y
y = points[(i+2)%n] - points[(i+1)%n]
if c0 * cross(x, y) < 0:
return False
return True
import sys
for line in sys.stdin:
li = list(map(float, line.split(',')))
p = []
for i in range(0, len(li), 2):
p.append(complex(li[i], li[i+1]))
if is_convex(p):
print('YES')
else:
print('NO')
```
Yes
| 86,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
import sys
f = sys.stdin
def take2(iterable):
i = iter(iterable)
while True:
yield next(i), next(i)
def cross(a, b):
return a.real * b.imag - a.imag * b.real
# 砂時計型の場合は考慮しない
def is_convex(a, b, c, d):
v1 = cross(a - b, b - c)
v2 = cross(b - c, c - d)
v3 = cross(c - d, d - a)
v4 = cross(d - a, a - b)
return 0 < v1 * v2 and 0 < v2 * v3 and 0 < v3 * v4
for line in f:
a, b, c, d = [x + y *1j for x, y in take2(map(float, line.split(',')))]
print('YES' if is_convex(a,b,c,d) else 'NO')
```
Yes
| 86,458 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
# AOJ 00035: Is it Convex?
# Python3 2018.6.17 bal4u
EPS = 0.0001
# a, b, はラインの同一側にあるか。 -1, 0, 1
def atSameSide(a, b, line):
sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \
+ (line[1].imag-line[0].imag)*(line[0].real-a.real);
sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \
+ (line[1].imag-line[0].imag)*(line[0].real-b.real);
if -EPS <= sa and sa <= EPS: return 0 # a in line
if -EPS <= sb and sb <= EPS: return 0 # b in line
if sa*sb >= 0: return 1 # a,b at same side
return -1;
while True:
try: p = list(map(float, input().split(',')))
except: break
p1 = complex(p[0], p[1])
p2 = complex(p[2], p[3])
p3 = complex(p[4], p[5])
p4 = complex(p[6], p[7])
if atSameSide(p2, p4, [p1, p3]) == -1 and \
atSameSide(p1, p3, [p2, p4]) == -1: print('YES')
else: print('NO')
```
Yes
| 86,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
while True:
try:
data = list(map(float,input().split(",")))
except EOFError:
break
vec1 = [data[2]-data[0],data[3]-data[1]]
vec2 = [data[4]-data[0],data[5]-data[1]]
vec3 = [data[6]-data[0],data[7]-data[1]]
a = (vec2[0]*vec3[1] - vec2[1]*vec3[0]) / (vec1[0]*vec3[1] - vec1[1]*vec3[0])
b = (vec2[0]*vec1[1] - vec2[1]*vec1[0]) / (vec1[1]*vec3[0] - vec1[0]*vec3[1])
if (a < 0 or b < 0) or a+b < 1.0:
print("NO")
else:
print("YES")
```
Yes
| 86,460 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
import fileinput
for line in fileinput.input():
xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(','))
x = ((yb * xd - yd * xb) * (xc - xa) - (ya * xc - yc * xa) * (xd - xb)) \
/ ((yc - ya) * (xd - xb) - (yd - yb) * (xc - xa))
print('NO' if (x - xa) * (x - xc) > 0 or (x - xb) * (x - xd) > 0 else 'YES')
```
No
| 86,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
import sys
for e in sys.stdin:
e=list(map(float,e.split(',')));f=1
for i in range(0,8,2):
s=(e[i]-e[(2+i)%8])*(e[(4+i)%8]-e[(2+i)%8])+(e[1+i]-e[(3+i)%8])*(e[(5+i)%8]-e[(3+i)%8])
if s:f*=s
print(['YES','NO'][f<0])
```
No
| 86,462 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
import math
def get_data():
xa,ya,xb,yb,xc,yc,xd,yd = map(float,input().split(','))
return xa,ya,xb,yb,xc,yc,xd,yd
def dist(x1,y1,x2,y2):
d = ((x2-x1)**2 + (y2-y1)**2)**0.5
return d
def lin(x1,y1,x2,y2):
if x1 == x2:
m = 10000000000 ac = dist(xa,ya,xc,yc)
bd = dist(xb,yb,xd,yd)
m1,n1 = lin(xb,yb,xd,yd)
d1 = p_l(xa,ya,m1,n1)
if ac < d1:
print('NO')
return 0
m2,n2 = lin(xb,yb,xd,yd)
d2 = p_l(xc,yc,m2,n2)
if ac < d2:
print('NO')
return 0
m3,n3 = lin(xa,ya,xc,yc)
d3 = p_l(xb,yb,m3,n3)
if bd < d3:
print('NO')
return 0
m4,n4 = lin(xa,ya,xc,yc)
d4 = p_l(xd,yd,m4,n4)
if bd < d4:
print('NO')
return 0
print('YES')
return 0
while True:
try:
xa,ya,xb,yb,xc,yc,xd,yd = get_data()
convex(xa,ya,xb,yb,xc,yc,xd,yd)
except EOFError:
break
```
No
| 86,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a dent is a quadrangle as shown in Figure 1.
<image>
Input
Given multiple datasets. The format of each dataset is as follows.
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
The number of datasets does not exceed 100.
Output
Print YES or NO on one line for each dataset.
Example
Input
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
Output
YES
NO
Submitted Solution:
```
class Vector2:
"""
A simple 2D vector class.
@Author:whitestone0811(Vir_MeL0)
"""
def __init__(self,x,y):
self.x=x
self.y=y
def __add__(self,other):
return Vector2(self.x+other.x,self.y+other.y)
def __sub__(self,other):
return Vector2(self.x-other.x,self.y-other.y)
def __mul__(self,other):
if isinstance(other, Vector2):
return self.x*other.x+self.y*other.y
else:
return Vector2(self.x*other,self.y*other)
def __rmul__(self,other):
if not isinstance(other,Vector2):
return Vector2(self.x*other,self.y*other)
def abs(self):
return (self.x**2+self.y**2)**0.5
def cos(self,other):
return (self*other)/(self.abs()*other.abs())
def __str__(self):
return "[{0},{1}]".format(self.x,self.y)
def __neg__(self):
return Vector2(-self.x,-self.y)
#
_in=input()
while _in!='':
cors=[float(cor)for cor in _in.split(',')]
vAB=Vector2(cors[2]-cors[0],cors[3]-cors[1])
vBC=Vector2(cors[4]-cors[2],cors[5]-cors[3])
vCD=Vector2(cors[6]-cors[4],cors[7]-cors[5])
vDA=Vector2(cors[0]-cors[6],cors[1]-cors[7])
cnv_a=True if(vAB-vDA)*(vAB+vBC)>0 else False
cnv_b=True if(vBC-vAB)*(vBC+vCD)>0 else False
cnv_c=True if(vCD-vBC)*(vCD+vDA)>0 else False
cnv_d=True if(vDA-vCD)*(vDA+vAB)>0 else False
print("YES" if cnv_a and cnv_b and cnv_c and cnv_d else "NO")
_in=input()
```
No
| 86,464 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
L=[]
for _ in range(n):
L.append(int(input()))
cnt = 0
for k in range(1,len(L))[::-1]:
for i in range(k):
if L[i+1] < L[i]:
cnt += 1
L[i+1], L[i] = L[i], L[i+1]
print(cnt)
```
| 86,465 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
def b_sort(lst):
limit = len(lst) - 1
cnt = 0
while limit:
for i in range(limit):
if lst[i] > lst[i + 1]:
lst[i], lst[i + 1] = lst[i + 1], lst[i]
cnt += 1
limit -= 1
return cnt
while True:
n = int(input())
if n == 0:
break
alst = []
for _ in range(n):
alst.append(int(input()))
print(b_sort(alst))
```
| 86,466 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
def bs(v):
nc = 0
m = len(v)
while m > 0:
j=0
while j < m-1:
if v[j] > v[j+1]:
x = v[j+1]
v[j+1] = v[j]
v[j] = x
nc += 1
j += 1
m -= 1
return(nc)
while True:
n = int(input())
if n==0:
break
v = []
for _ in range(n):
x = int(input())
v.append(x)
print(bs(v))
```
| 86,467 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
def solve(A):
res = 0
right = len(A)
while right != 0:
for left in range(0, right):
if left + 1 < len(A) and A[left] > A[left + 1]:
A[left], A[left + 1] = A[left + 1], A[left]
res += 1
right -= 1
return res
while True:
n = int(input())
if n == 0 : break
A = [int(input()) for i in range(n)]
print(solve(A))
```
| 86,468 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
Num_lis = []
cou = 0
for i in range(n):
Num_lis.append(int(input()))
S_lis = sorted(Num_lis)
while Num_lis != S_lis:
for j in range(n - 1):
if Num_lis[j] > Num_lis[j + 1]:
Num_lis[j],Num_lis[j + 1] = Num_lis[j + 1],Num_lis[j]
cou += 1
print(cou)
```
| 86,469 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
# coding: utf-8
import math
import fractions
import heapq
import collections
import re
import array
import bisect
from collections import Counter, defaultdict
class BIT(object):
"""Bibary Indexed Tree / Fenwick Tree"""
# 1-indexed
def __init__(self, size):
self.size = size
self.l = [0] * (size + 1)
def sum(self, i):
r = 0
while i > 0:
r += self.l[i]
i -= i & -i
return r
def add(self, i, x):
while i <= self.size:
self.l[i] += x
i += i & -i
max_a = 1000000
def solve(a):
bit = BIT(max_a)
ans = 0
for i, x in enumerate(a):
ans += i - bit.sum(x)
bit.add(x, 1)
return ans
def main():
while True:
N = int(input())
if N == 0:
return
a = []
for i in range(N):
a.append(int(input()))
print(solve(a))
if __name__ == "__main__":
main()
```
| 86,470 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
def bubble_sort(n):
arr = [int(input()) for _ in range(n)]
cnt = 0
for i in range(n):
for j in range(n-1, i, -1):
if arr[j] < arr[j-1]:
arr[j], arr[j-1] = arr[j-1], arr[j]
cnt += 1
return cnt
while True:
n = int(input())
if n == 0: break
print(bubble_sort(n))
```
| 86,471 |
Provide a correct Python 3 solution for this coding contest problem.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
"Correct Solution:
```
def bubbleSort(list):
j = len(list) - 1
bcnt = 0
while j:
for i in range(j):
if list[i] > list[i + 1]:
list[i], list[i + 1] = list[i + 1], list[i]
bcnt += 1
j -= 1
return bcnt
while True:
n = int(input())
if n == 0:
break
A = []
for _ in range(n):
A.append(int(input()))
print(bubbleSort(A))
```
| 86,472 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
# AOJ 0167 Bubble Sort
# Python3 2018.6.20 bal4u
while True:
n = int(input())
if n == 0: break
a = [0]*105
for i in range(n): a[i] = int(input())
cnt = 0
for i in range(n-1, 0, -1):
for j in range(i):
if a[j] > a[j+1]:
cnt += 1
a[j], a[j+1] = a[j+1], a[j]
print(cnt)
```
Yes
| 86,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
while True:
n = int(input())
if n==0: break
a = [int(input()) for _ in range(n)]
count = 0
for i in range(n):
for j in range(n)[:0:-1]:
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count+=1
print(count)
```
Yes
| 86,474 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
# Aizu Problem 00167: Bubble Sort
#
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def bubble_sort(N, A):
cnt = 0
last = N - 1
while last > 0:
for k in range(last):
if A[k] > A[k+1]:
A[k], A[k+1] = A[k+1], A[k]
cnt += 1
last -= 1
return cnt
while True:
N = int(input())
if N == 0:
break
A = [int(input()) for _ in range(N)]
print(bubble_sort(N, A))
```
Yes
| 86,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
while True:
n =int(input())
A=[]
if n==0:
break
for i in range(n):
num =int(input())
A.append(num)
cnt=0
for i in range(n):
for j in range(n-1, 0, -1):
if A[j]<A[j-1]:
A[j], A[j-1]=A[j-1],A[j]
cnt+=1
print(cnt)
```
Yes
| 86,476 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
while True:
n = int(input())
if n==0: break
a = [input() for _ in range(n)]
count = 0
for i in range(n):
for j in range(n)[:0:-1]:
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count+=1
print(count)
```
No
| 86,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
<image>
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
<image>
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
Repeat this step until the unsorted part has a length of 1.
<image>
<image>
<image>
When the length of the unsorted part becomes 1, the sorting process ends.
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
The number of datasets does not exceed 20.
Output
Outputs the number of data element exchanges (integer) for each data set on one line.
Example
Input
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
Output
7
0
3
Submitted Solution:
```
ans = []
while True:
n = int(input())
if n==0: break
a = [input() for _ in range(n)]
count = 0
for i in range(n):
for j in range(n)[:0:-1]:
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count+=1
ans.append(count)
print('\n'.join(map(str, ans)))
```
No
| 86,478 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
"Correct Solution:
```
n = int(input())
size = 200100
total = [0 for _ in range(size)]
for _ in range(n):
s = sum(map(int, input().split()))
total[s] += 1
for i in range(size - 1):
if total[i] % 2:
print(i, 0)
total[i + 1] += total[i] // 2
```
| 86,479 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
"Correct Solution:
```
N=200020
a=[0]*N
for _ in range(int(input())): a[sum(map(int,input().split()))]+=1
for i in range(N-1):
a[i+1]+=a[i]>>1
if a[i]&1:
print(i,0)
```
| 86,480 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
"Correct Solution:
```
n = int(input())
s = 0
for i in range(n):
a, b = map(int, input().split())
s += 1 << (a+b)
i = 0
ans = []
while s:
if s & 1:
ans.append(i)
s >>= 1
i += 1
for e in ans:
print(e, 0)
```
| 86,481 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
"Correct Solution:
```
N=200020
a=[0]*N
n=int(input())
for _ in range(n): a[sum(map(int,input().split()))]+=1
for i in range(N-1):
a[i+1]+=a[i]//2
a[i]&=1
if a[i]:
print(i,0)
```
| 86,482 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
"Correct Solution:
```
m = set()
for _ in range(int(input())):
a, b = map(int, input().split())
i = 0
while True:
if a + b + i in m:
m.remove(a + b + i)
i += 1
else:
m.add(a + b + i)
break
m = list(m)
m.sort()
for i in m:print("{} 0".format(i))
```
| 86,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0
Submitted Solution:
```
n = int(input())
s = 0
for i in range(n):
a, b = map(int, input().split())
s += 1 << (a+b)
i = 0
ans = []
while s:
if s & 1:
ans.append(i)
s >>= 1
i += 1
print(len(ans))
for e in ans:
print(e, 0)
```
No
| 86,484 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza". Let's call it. For example, 2947 is a zigzag number because the digit numbers are in the order of 2 → 9 → 4 → 7 and increase → decrease → increase. In addition, 71946 is a zigzag number because it is in the order of decrease → increase → decrease → increase. On the other hand, 123, 71446, 71442 and 88 are not zigzag numbers. A one-digit positive integer is considered to be a zigzag number.
Create a program that finds the remainder of the number of zigzags divided by 10000 out of multiples of M between A and B.
input
The input consists of three lines, with one positive integer written on each line.
The integer on the first line represents A, the integer on the second line represents B, and the integer on the third line represents M. These satisfy 1 ≤ A ≤ B ≤ 10500 and 1 ≤ M ≤ 500.
* Note that the values of A and B may not fit in the data types that represent ordinary integers.
output
Output the remainder of the number of zigzag numbers divided by 10000 out of multiples of M between A and B in one line.
Input / output example
Input example 1
100
200
Five
Output example 1
13
In I / O example 1, the number of zigzags that are multiples of 5 from 100 to 200 is 13 of 105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195. ..
Input example 2
6
1234567
3
Output example 2
246
In I / O example 2, there are 50246 zigzag numbers that are multiples of 3 from 6 to 1234567, so 246, which is the remainder of dividing it by 10000, is output.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
100
200
5
Output
13
Submitted Solution:
```
def main():
A = int(input())
B = int(input())
M = int(input())
num = []
for x in range(A, B + 1):
if x % M == 0:
num.append(x)
else:
pass
cnt = 0
for x in range(len(num)):
num[x] = list(str(num[x]))
for y in range(len(num[x])):
num[x][y] = int(num[x][y])
if len(num[x]) < 2:
cnt += 1
elif len(num[x]) == 2:
if num[x][0] == num[x][1]:
pass
else:
cnt += 1
elif len(num[x]) > 2:
listcnt = 0
if num[x][0] > num[x][1]:
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
pass
elif y % 2 == 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
pass
if listcnt == len(num[x]) - 2:
cnt += 1
else:
pass
elif num[x][0] < num[x][1]:
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
pass
elif y % 2 == 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
pass
if listcnt == len(num[x]) - 2:
cnt += 1
else:
pass
elif num[x][0] == num[x][1]:
pass
hoge = ""
for y in range(len(num[x])):
num[x][y] = str(num[x][y])
hoge += num[x][y]
num[x] = int(hoge)
print(cnt % 10000)
if __name__ == "__main__":
main()
```
No
| 86,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza". Let's call it. For example, 2947 is a zigzag number because the digit numbers are in the order of 2 → 9 → 4 → 7 and increase → decrease → increase. In addition, 71946 is a zigzag number because it is in the order of decrease → increase → decrease → increase. On the other hand, 123, 71446, 71442 and 88 are not zigzag numbers. A one-digit positive integer is considered to be a zigzag number.
Create a program that finds the remainder of the number of zigzags divided by 10000 out of multiples of M between A and B.
input
The input consists of three lines, with one positive integer written on each line.
The integer on the first line represents A, the integer on the second line represents B, and the integer on the third line represents M. These satisfy 1 ≤ A ≤ B ≤ 10500 and 1 ≤ M ≤ 500.
* Note that the values of A and B may not fit in the data types that represent ordinary integers.
output
Output the remainder of the number of zigzag numbers divided by 10000 out of multiples of M between A and B in one line.
Input / output example
Input example 1
100
200
Five
Output example 1
13
In I / O example 1, the number of zigzags that are multiples of 5 from 100 to 200 is 13 of 105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195. ..
Input example 2
6
1234567
3
Output example 2
246
In I / O example 2, there are 50246 zigzag numbers that are multiples of 3 from 6 to 1234567, so 246, which is the remainder of dividing it by 10000, is output.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
100
200
5
Output
13
Submitted Solution:
```
def main():
A = int(input())
B = int(input())
M = int(input())
num = []
for x in range(A, B + 1):
if x % M == 0:
num.append(x)
else:
pass
cnt = 0
for x in range(len(num)):
num[x] = list(str(num[x]))
c = len(num[x]) #checker
if c == 1:
cnt += 1
elif c == 2:
if num[x][0] == num[x][1]:
pass
else:
cnt += 1
elif c >= 3:
if num[x][0] == num[x][1]:
pass
elif num[x][0] > num[x][1]:
listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
elif num[x][0] < num[x][1]:
listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
#hoge = ""
#for y in range(len(num[x])):
# hoge += num[x][y]
#num[x] = int(hoge)
ans = cnt % 10000
print(ans)
if __name__ == "__main__":
main()
```
No
| 86,486 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza". Let's call it. For example, 2947 is a zigzag number because the digit numbers are in the order of 2 → 9 → 4 → 7 and increase → decrease → increase. In addition, 71946 is a zigzag number because it is in the order of decrease → increase → decrease → increase. On the other hand, 123, 71446, 71442 and 88 are not zigzag numbers. A one-digit positive integer is considered to be a zigzag number.
Create a program that finds the remainder of the number of zigzags divided by 10000 out of multiples of M between A and B.
input
The input consists of three lines, with one positive integer written on each line.
The integer on the first line represents A, the integer on the second line represents B, and the integer on the third line represents M. These satisfy 1 ≤ A ≤ B ≤ 10500 and 1 ≤ M ≤ 500.
* Note that the values of A and B may not fit in the data types that represent ordinary integers.
output
Output the remainder of the number of zigzag numbers divided by 10000 out of multiples of M between A and B in one line.
Input / output example
Input example 1
100
200
Five
Output example 1
13
In I / O example 1, the number of zigzags that are multiples of 5 from 100 to 200 is 13 of 105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195. ..
Input example 2
6
1234567
3
Output example 2
246
In I / O example 2, there are 50246 zigzag numbers that are multiples of 3 from 6 to 1234567, so 246, which is the remainder of dividing it by 10000, is output.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
100
200
5
Output
13
Submitted Solution:
```
def main():
A = int(input())
B = int(input())
M = int(input())
num = []
for x in range(A, B + 1):
if x % M == 0:
num.append(x)
else:
pass
cnt = 0
for x in range(len(num)):
num[x] = list(str(num[x]))
c = len(num[x]) #checker
if c == 1:
cnt += 1
elif c == 2:
if num[x][0] == num[x][1]:
pass
else:
cnt += 1
elif c >= 3:
if num[x][0] == num[x][1]:
pass
elif num[x][0] > num[x][1]:
listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
elif num[x][0] < num[x][1]:
listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
hoge = ""
for y in range(len(num[x])):
hoge += num[x][y]
num[x] = int(hoge)
ans = cnt % 10000
print(ans)
if __name__ == "__main__":
main()
```
No
| 86,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza". Let's call it. For example, 2947 is a zigzag number because the digit numbers are in the order of 2 → 9 → 4 → 7 and increase → decrease → increase. In addition, 71946 is a zigzag number because it is in the order of decrease → increase → decrease → increase. On the other hand, 123, 71446, 71442 and 88 are not zigzag numbers. A one-digit positive integer is considered to be a zigzag number.
Create a program that finds the remainder of the number of zigzags divided by 10000 out of multiples of M between A and B.
input
The input consists of three lines, with one positive integer written on each line.
The integer on the first line represents A, the integer on the second line represents B, and the integer on the third line represents M. These satisfy 1 ≤ A ≤ B ≤ 10500 and 1 ≤ M ≤ 500.
* Note that the values of A and B may not fit in the data types that represent ordinary integers.
output
Output the remainder of the number of zigzag numbers divided by 10000 out of multiples of M between A and B in one line.
Input / output example
Input example 1
100
200
Five
Output example 1
13
In I / O example 1, the number of zigzags that are multiples of 5 from 100 to 200 is 13 of 105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195. ..
Input example 2
6
1234567
3
Output example 2
246
In I / O example 2, there are 50246 zigzag numbers that are multiples of 3 from 6 to 1234567, so 246, which is the remainder of dividing it by 10000, is output.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
100
200
5
Output
13
Submitted Solution:
```
def main():
A = int(input())
B = int(input())
M = int(input())
num = []
for x in range(A, B + 1):
if x % M == 0:
num.append(x)
else:
pass
cnt = 0
for x in range(len(num)):
num[x] = list(str(num[x]))
c = len(num[x]) #checker
if c == 1:
cnt += 1
elif c == 2:
if num[x][0] == num[x][1]:
pass
else:
cnt += 1
elif c >= 3:
listcnt = 0
if num[x][0] == num[x][1]:
pass
elif num[x][0] > num[x][1]:
#listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
elif num[x][0] < num[x][1]:
#listcnt = 0
for y in range(1, len(num[x]) - 1):
if y % 2 != 0:
if num[x][y] > num[x][y + 1]:
listcnt += 1
else:
break
if y % 2 == 0:
if num[x][y] < num[x][y + 1]:
listcnt += 1
else:
break
if listcnt == len(num[x]) - 2:
cnt += 1
#hoge = ""
#for y in range(len(num[x])):
# hoge += num[x][y]
#num[x] = int(hoge)
ans = cnt % 10000
print(ans)
if __name__ == "__main__":
main()
```
No
| 86,488 |
Provide a correct Python 3 solution for this coding contest problem.
You are the God of Wind.
By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.
But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as “weather forecast”.
You are in charge of a small country, called Paccimc. This country is constituted of 4 × 4 square areas, denoted by their numbers.
<image>
Your cloud is of size 2 × 2, and may not cross the borders of the country.
You are given the schedule of markets and festivals in each area for a period of time.
On the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule.
On each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day.
You should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You don’t have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes.
Input
The input is a sequence of data sets, followed by a terminating line containing only a zero.
A data set gives the number N of days (no more than 365) in the period on a single line, followed by N lines giving the schedule for markets and festivals. The i-th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces.
Output
The answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it.
Example
Input
1
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1
0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0
0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0
0
Output
0
1
0
1
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
mij = []
for i in range(3):
mi = []
for j in range(3):
mi.append([i*4+j,i*4+j+1,i*4+j+4,i*4+j+5])
mij.append(mi)
def f(n):
a = [LI() for _ in range(n)]
fs = set()
def _f(i,j,d,d1,d4,d13,d16):
if d >= n:
return True
key = (i,j,d,d1,d4,d13,d16)
if key in fs:
return False
if i == 0:
if j == 0:
d1 = d
elif j == 2:
d4 = d
elif i == 2:
if j == 0:
d13 = d
elif j == 2:
d16 = d
for mm in mij[i][j]:
if a[d][mm] > 0:
fs.add(key)
return False
if d - min([d1,d4,d13,d16]) >= 7:
fs.add(key)
return False
if _f(i,j,d+1,d1,d4,d13,d16):
return True
for ni in range(3):
if i == ni:
continue
if _f(ni,j,d+1,d1,d4,d13,d16):
return True
for nj in range(3):
if j == nj:
continue
if _f(i,nj,d+1,d1,d4,d13,d16):
return True
fs.add(key)
return False
if _f(1,1,0,-1,-1,-1,-1):
return 1
return 0
while True:
n = I()
if n == 0:
break
rr.append(f(n))
return '\n'.join(map(str,rr))
print(main())
```
| 86,489 |
Provide a correct Python 3 solution for this coding contest problem.
You are the God of Wind.
By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.
But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as “weather forecast”.
You are in charge of a small country, called Paccimc. This country is constituted of 4 × 4 square areas, denoted by their numbers.
<image>
Your cloud is of size 2 × 2, and may not cross the borders of the country.
You are given the schedule of markets and festivals in each area for a period of time.
On the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule.
On each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day.
You should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You don’t have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes.
Input
The input is a sequence of data sets, followed by a terminating line containing only a zero.
A data set gives the number N of days (no more than 365) in the period on a single line, followed by N lines giving the schedule for markets and festivals. The i-th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces.
Output
The answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it.
Example
Input
1
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1
0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0
0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0
0
Output
0
1
0
1
"Correct Solution:
```
from collections import deque
while True:
n=int(input())
if n==0:
exit()
data = []
for i in range(n):
tmp = list(map(int,input().split()))
tmp = [tmp[:4],tmp[4:8],tmp[8:12],tmp[12:]]
d = [ [0 for i in range(3)]for i in range(3)]
for i in range(3):
for j in range(3):
for k in range(2):
for l in range(2):
d[i][j] += tmp[i+k][j+l]
data.append(d)
q = deque()
memo = set()
if data[0][1][1]:
print(0)
continue
q.append((0,1,1,(0,0,0,0)))
while len(q):
z,y,x,h = q.popleft()
if (y,x) == (0,0):
h = (0,h[1]+1,h[2]+1,h[3]+1)
elif (y,x) == (0,2):
h = (h[0]+1,0,h[2]+1,h[3]+1)
elif (y,x) == (2,0):
h = (h[0]+1,h[1]+1,0,h[3]+1)
elif (y,x) == (2,2):
h = (h[0]+1,h[1]+1,h[2]+1,0)
else:
h = (h[0]+1,h[1]+1,h[2]+1,h[3]+1)
if max(h)>6:
continue
if (z,y,x,h) in memo:
continue
memo.add((z,y,x,h))
if z==n-1:
print(1)
break
for i in range(3):
if not data[z+1][i][x]:
q.append((z+1,i,x,h))
if not data[z+1][y][i]:
q.append((z+1,y,i,h))
else:
print(0)
```
| 86,490 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
2 1
1 2 2
Output
1
Submitted Solution:
```
from collections import deque
n, m = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
x, y, w = map(int, input().split())
G[x-1].append((y-1, i))
if w == 2:
G[y-1].append((x-1, i))
used = {(i, -1) for i in range(n)}
prev = {(i, -1): [] for i in range(n)}
counter = {}
que = deque((i, -1) for i in range(n))
while que:
v, e = source = que.popleft()
counter[source] = 0
for target in G[v]:
t, f = target
if e == f:
continue
if target not in used:
used.add(target)
prev[target] = []
que.append(target)
prev[target].append(source)
counter[source] += 1
rest = len(counter)
for p in counter:
if counter[p] == 0:
que.append(p)
rest -= 1
while que:
target = que.popleft()
for source in prev[target]:
counter[source] -= 1
if counter[source] == 0:
que.append(source)
rest -= 1
if rest > 0:
print("Infinite")
exit(0)
memo = {}
def dfs(source):
if source in memo:
return memo[source]
res = 0
v, e = source
for target in G[v]:
t, f = target
if e == f:
continue
res = max(res, dfs(target) + 1)
memo[source] = res
return res
print(max(dfs((i, -1)) for i in range(n)))
```
No
| 86,491 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
class CheckError(Exception):
pass
def check(wclist, count):
c = 0
while True:
c += wclist.pop(0)
if c == count:
return wclist
elif c > count:
raise CheckError
def tanku_check(wclist):
for i in range(len(wclist)):
try:
wcl = wclist[:][i:]
wcl = check(wcl, 5)
wcl = check(wcl, 7)
wcl = check(wcl, 5)
wcl = check(wcl, 7)
wcl = check(wcl, 7)
return i+1
except CheckError:
pass
def main():
while True:
n = int(input().strip())
if n == 0:
break
wclist = [len(input().strip()) for _ in range(n)]
print(tanku_check(wclist))
if __name__ == '__main__':
main()
```
| 86,492 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
while True:
n = int(input())
if n==0:
break
w = [len(input()) for i in range(n)]
a = [5,7,5,7,7]
ans = n+1
for i in range(n):
k,s = 0,0
for j in range(i,n):
s += w[j]
if s==a[k]:
s,k=0,k+1
elif s>a[k]:
break
if k==5:
ans = min(ans,i+1)
break
print(ans)
```
| 86,493 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
else:
phlist=[]
phflag=0
for i in range(n):
phlist.append(input())
for i in range(len(phlist)-4):
cur=0
state=0
for j in range(i, len(phlist)):
s = phlist[j]
cur+=len(s)
if state==0 and cur<5:
continue
elif state==0 and cur==5:
cur=0
state=1
elif state==1 and cur<7:
continue
elif state==1 and cur==7:
cur=0
state=2
elif state==2 and cur<5:
continue
elif state==2 and cur==5:
cur=0
state=3
elif state==3 and cur<7:
continue
elif state==3 and cur==7:
cur=0
state=4
elif state==4 and cur<7:
continue
elif state==4 and cur==7:
print(i+1)
phflag=1
break
if phflag:
break
```
| 86,494 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())
while True:
n = int(input())
if n == 0:
break
else:
ww = [len(input()) for i in range(n)]
L = [5,7,5,7,7]
for i in range(n):
k = i
tmp = 0
S = 0
flag = False
while True:
w = ww[k]
if L[tmp] - S > w:
S += w
elif L[tmp] - S == w:
tmp += 1
S = 0
else:
break
if tmp == 5:
flag = True
break
k += 1
if flag:
print(i+1)
break
```
| 86,495 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
count = [0] * n
for i in range(n):
count[i] = len(input())
for i in range(n-4):
ind = i
fin = True
for tmp in [5, 7, 5, 7, 7]:
while tmp > 0 and ind < n:
tmp -= count[ind]
ind += 1
if tmp != 0:
fin = False
break
if fin:
print(i+1)
break
```
| 86,496 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
a = []
for i in range(n):
p = list(input())
a.append(len(p))
def solve(a):
N = len(a)
for i in range(N):
judge = 0
rest = 5
for j in range(i,N):
if judge == 0:
rest -= a[j]
if rest == 0:
judge = 1
rest = 7
elif rest < 0:
break
elif judge == 1:
rest -= a[j]
if rest == 0:
judge = 2
rest = 5
if rest < 0:
break
elif judge == 2:
rest -= a[j]
if rest == 0:
judge = 3
rest = 7
elif rest < 0:
break
elif judge == 3:
rest -= a[j]
if rest == 0:
judge = 4
rest = 7
elif rest < 0:
break
elif judge == 4:
rest -= a[j]
if rest == 0:
judge = 5
break
elif rest < 0:
break
if judge == 5:
return i+1
print(solve(a))
```
| 86,497 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
# AOJ 1601: Short Phrase
# Python3 2018.7.13 bal4u
a = [5,7,5,7,7]
while True:
n = int(input())
if n == 0: break
ans = 0
w = [len(input()) for i in range(n)]
for i in range(n):
k = s = 0
for j in range(i, n):
s += w[j]
if s == a[k]:
s, k = 0, k+1
if k == 5: ans = i+1; break
elif s > a[k]: break
if ans: break
print(ans)
```
| 86,498 |
Provide a correct Python 3 solution for this coding contest problem.
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
Input
The input consists of multiple datasets, each in the following format.
> n
> w1
> ...
> wn
>
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero.
Output
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
Sample Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output for the Sample Input
1
2
6
Example
Input
9
do
the
best
and
enjoy
today
at
acm
icpc
14
oh
yes
by
far
it
is
wow
so
bad
to
me
you
know
hey
15
abcde
fghijkl
mnopq
rstuvwx
yzz
abcde
fghijkl
mnopq
rstuvwx
yz
abcde
fghijkl
mnopq
rstuvwx
yz
0
Output
1
2
6
"Correct Solution:
```
def solve():
n = int(input())
if n == 0: return False
ok = [5, 7, 5, 7, 7]
inputs = [input() for x in range(n)]
for i in range(n):
target = 0
cnt = i
for v in ok:
while target < v:
s = inputs[cnt]
target += len(s)
cnt += 1
if target != v:
break
else:
target = 0
else:
print(i + 1)
return True
return True
while solve(): pass
```
| 86,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.