message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,192 | 5 | 80,384 |
"Correct Solution:
```
n, a, b, c = map(int, input().split())
variables = [a, b, c]
alph = ["A", "B", "C"]
s = [[] for _ in range(n)]
for i in range(n):
u, v = map(lambda x: alph.index(x) , list(input()))
s[i] = [u, v]
# print(s)
can_do = True
ans = []
for i in range(n):
u, v = s[i][0], s[i][1]
if variables[u] + variables[v] == 0:
can_do = False
elif variables[v] == 0:
variables[u] -= 1
variables[v] += 1
ans.append(alph[v])
elif variables[u] == 0:
variables[v] -= 1
variables[u] += 1
ans.append(alph[u])
else:
# both are > 0
if i == n-1:
# do whatever you want
variables[u] -= 1
variables[v] += 1
ans.append(alph[v])
else:
# need to think about next step
if variables[u] > 0 and variables[v] > 0:
next_u, next_v = s[i+1][0], s[i+1][1]
if variables[next_u] + variables[next_v] >= 2:
# can subsctact and whatever
if variables[u] < variables[v]:
u, v = v, u
variables[u] -= 1
variables[v] += 1
ans.append(alph[v])
else:
# need to sponsor
common = list( {u, v}.intersection({next_u, next_v}) )[0]
# print("common", common)
not_common = u + v - common
variables[common] += 1
variables[not_common] -= 1
ans.append(alph[common])
if can_do:
print("Yes")
for item in ans:
print(item)
else:
print("No")
``` | output | 1 | 40,192 | 5 | 80,385 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,193 | 5 | 80,386 |
"Correct Solution:
```
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, A: int, B: int, C: int, s: "List[int]"):
v = [A, B, C]
ans = []
for i in range(N):
l, r = s[i]
if v[l] + v[r] == 0:
return None
if v[l] > v[r] or v[l] == v[r] and i != N - 1 and r in s[i + 1]:
ans.append(r)
v[l] -= 1
v[r] += 1
else:
ans.append(l)
v[l] += 1
v[r] -= 1
return ans
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
def s2index(s: "List[str]"):
return [ord(c)-ord('A') for c in s]
def index2s(i: int):
return chr(i + ord('A'))
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
s = [s2index(next(tokens)) for _ in range(N)] # type: "List[int]"
ans = solve(N, A, B, C, s)
if ans == None:
print(NO)
else:
print(YES)
print("\n".join(list(map(index2s, ans))))
if __name__ == '__main__':
main()
``` | output | 1 | 40,193 | 5 | 80,387 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,195 | 5 | 80,390 |
"Correct Solution:
```
n,a,b,c = map(int,input().split())
s = []
for i in range(n):
tmp_s = input()
s.append(tmp_s)
ans = []
for i,val in enumerate(s):
if val == 'AB':
if a == b == 0:
print('No')
exit(0)
elif a < b or (a == b and i != n-1 and 'A' in s[i+1]):
ans.append('A')
a += 1
b -= 1
else:
ans.append('B')
a -= 1
b += 1
elif val == 'BC':
if b == c == 0:
print('No')
exit(0)
elif b < c or (b == c and i != n-1 and 'B' in s[i+1]):
ans.append('B')
b += 1
c -= 1
else:
ans.append('C')
b -= 1
c += 1
else:
if c == a == 0:
print('No')
exit(0)
elif c < a or (c == a and i != n-1 and 'C' in s[i+1]):
ans.append('C')
c += 1
a -= 1
else:
ans.append('A')
c -= 1
a += 1
print('Yes')
print(*ans,sep='\n')
``` | output | 1 | 40,195 | 5 | 80,391 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,196 | 5 | 80,392 |
"Correct Solution:
```
N,A,B,C=map(int,input().split())
S=[]
d={'A':A, 'B':B, 'C':C}
for i in range(N):
S.append(input())
out=[]
for i in range(N):
s=S[i]
s0=s[0]
s1=s[1]
if d[s0]==d[s1]==0:
print('No')
break
elif d[s0]==0:
d[s0]+=1
d[s1]-=1
out.append(s0)
elif d[s1]==0:
d[s0]-=1
d[s1]+=1
out.append(s1)
elif i == N-1:
out.append(s0)
elif s0 in S[i+1]:
d[s0]+=1
d[s1]-=1
out.append(s0)
else:
d[s0]-=1
d[s1]+=1
out.append(s1)
else:
print('Yes')
for o in out:
print(o)
``` | output | 1 | 40,196 | 5 | 80,393 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,197 | 5 | 80,394 |
"Correct Solution:
```
#!python3
# input
N, A, B, C = list(map(int, input().split()))
S = [input() for _ in range(N)]
def main():
l = [A, B, C]
d = {"AB": (0, 1, 2), "AC": (0, 2, 1), "BC": (1, 2, 0)}
dl = ["A", "B", "C"]
ans = []
for n in range(N):
i, j, k = d[S[n]]
if l[i] < l[j]:
l[i] += 1
l[j] -= 1
ans.append(dl[i])
elif l[i] > l[j]:
l[i] -= 1
l[j] += 1
ans.append(dl[j])
elif l[i] == 0:
print("No")
return
else:
if n < N - 1 and j == d[S[n + 1]][2]:
i, j = j, i
l[i] -= 1
l[j] += 1
ans.append(dl[j])
print("Yes")
print("\n".join(ans))
if __name__ == "__main__":
main()
``` | output | 1 | 40,197 | 5 | 80,395 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,198 | 5 | 80,396 |
"Correct Solution:
```
def solve():
ans = []
for i, (x, y) in enumerate(s):
if num[x]>num[y]: x, y = y, x
if num[x]==num[y] and i < n-1:
if y == s[i+1][0] or y == s[i+1][1]:
x, y = y, x
num[x]+=1
num[y]-=1
ans.append(x)
if num[y]<0: return False
return ans
from collections import defaultdict
import sys
n, a, b, c = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
ans = solve()
if ans:
print('Yes')
print(*ans, sep = '\n')
else:
print('No')
``` | output | 1 | 40,198 | 5 | 80,397 |
Provide a correct Python 3 solution for this coding contest problem.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A | instruction | 0 | 40,199 | 5 | 80,398 |
"Correct Solution:
```
from collections import deque
from copy import copy
n, a, b, c = map(int, input().split())
s = [input().rstrip() for _ in range(n)]
m = {'A': a, 'B': b, 'C': c}
ans = []
for i in range(n):
if m[s[i][0]] > m[s[i][1]]:
ans.append(s[i][1])
m[s[i][0]] -= 1
m[s[i][1]] += 1
elif m[s[i][0]] < m[s[i][1]]:
ans.append(s[i][0])
m[s[i][0]] += 1
m[s[i][1]] -= 1
else:
if m[s[i][0]] == 0:
print('No')
exit()
if i != n-1:
if s[i][0] in s[i+1]:
ans.append(s[i][0])
m[s[i][0]] += 1
m[s[i][1]] -= 1
else:
ans.append(s[i][1])
m[s[i][0]] -= 1
m[s[i][1]] += 1
else:
ans.append(s[i][0])
print('Yes')
print('\n'.join(ans))
``` | output | 1 | 40,199 | 5 | 80,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
n,a,b,c = map(int,input().split())
s = [input() for i in range(n)]
dic = {'A':a,'B':b,'C':c}
ans = ["Yes"]
for i in range(n):
if dic[s[i][0]] == 0 and dic[s[i][1]] == 0:
print("No")
exit()
elif dic[s[i][0]] == 0:
dic[s[i][0]] += 1
dic[s[i][1]] -= 1
ans.append(s[i][0])
elif dic[s[i][1]] == 0:
dic[s[i][1]] += 1
dic[s[i][0]] -= 1
ans.append(s[i][1])
elif i != n-1:
if s[i][0] in s[i+1]:
dic[s[i][0]] += 1
dic[s[i][1]] -= 1
ans.append(s[i][0])
else:
dic[s[i][1]] += 1
dic[s[i][0]] -= 1
ans.append(s[i][1])
else:
dic[s[i][0]] += 1
dic[s[i][1]] -= 1
ans.append(s[i][0])
print(*ans,sep="\n")
``` | instruction | 0 | 40,200 | 5 | 80,400 |
Yes | output | 1 | 40,200 | 5 | 80,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
sys.setrecursionlimit(500000)
N,A,B,C = map(int,input().split())
ABC = [A,B,C]
S = []
SS = ('A','B','C')
d = [0,0,0]
flag = True
for i in range(N):
s = input()
if s=="AB":
S.append(2)
d[0] += 1
d[1] += 1
elif s=="BC":
S.append(0)
d[1] += 1
d[2] += 1
else:
S.append(1)
d[2] += 1
d[0] += 1
ans = []
for i in range(N):
x,y = (S[i]+1)%3,(S[i]+2)%3
if ABC[x]<ABC[y]:
ans.append(SS[x])
ABC[y] -= 1
ABC[x] += 1
elif ABC[x]>ABC[y]:
ans.append(SS[y])
ABC[y] += 1
ABC[x] -= 1
else:
if i < N-1:
if S[i+1]==y:
ans.append(SS[x])
ABC[y] -= 1
ABC[x] += 1
else:
ans.append(SS[y])
ABC[y] += 1
ABC[x] -= 1
else:
ans.append(SS[y])
ABC[y] += 1
ABC[x] -= 1
if ABC[0]<0 or ABC[1]<0 or ABC[2]<0:
flag = False
break
if flag:
print('Yes')
print(*ans,sep='\n')
else:
print('No')
``` | instruction | 0 | 40,201 | 5 | 80,402 |
Yes | output | 1 | 40,201 | 5 | 80,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
n,*abc=map(int,input().split())
ip=[0]*n
for i in range(n):
tmp=input()
if tmp=="AB":
ip[i]=[0,1]
elif tmp=="BC":
ip[i]=[1,2]
else:
ip[i]=[0,2]
ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
ans="No"
elif s==1:
for i in range(n):
i1=ip[i][0]
i2=ip[i][1]
if abc[i1]+abc[i2]==0:
ans="No"
elif abc[i1]+abc[i2]==1:
if abc[i1]==0:
abc[i1]+=1
abc[i2]-=1
res[i]=i1
else:
abc[i1]-=1
abc[i2]+=1
res[i]=i2
else:
i1=ip[0][0]
i2=ip[0][1]
if abc[i1]+abc[i2]==0:
ans="No"
else:
for i in range(n):
i1=ip[i][0]
i2=ip[i][1]
if abc[i1]*abc[i2]==0:
if abc[i1]==0:
abc[i1]+=1
abc[i2]-=1
res[i]=i1
else:
abc[i1]-=1
abc[i2]+=1
res[i]=i2
elif i+1<n and ip[i+1]!=ip[i]:
c=list(set(ip[i])&set(ip[i+1]))[0]
if i1==c:
abc[i1]+=1
abc[i2]-=1
res[i]=i1
else:
abc[i1]-=1
abc[i2]+=1
res[i]=i2
else:
abc[i1]+=1
abc[i2]-=1
res[i]=i1
print(ans)
dic={0:"A",1:"B",2:"C"}
if ans=="Yes":
for i in range(n):
'''
if res[i]==0:
print("A")
elif res[i]==1:
print("B")
else:
print("C")
'''
print(dic[res[i]])
``` | instruction | 0 | 40,202 | 5 | 80,404 |
Yes | output | 1 | 40,202 | 5 | 80,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
import sys
n,a,b,c = map(int,input().split())
abc = {"A":a,"B":b,"C":c}
s = [input() for _ in range(n)]
ans = [None]*n
i = 0
while i <n:
x = s[i][0]
y = s[i][1]
if abc[x] == 0 and abc[y] ==0:
print("No")
sys.exit()
elif abc[x] == 1 and abc[y] ==1 and i<n-1:
if s[i] == s[i+1]:
ans[i] = x
ans[i+1] = y
i += 1
elif x in s[i+1]:
ans[i] = x
abc[x] += 1
abc[y] -= 1
else:
ans[i] = y
abc[x] -= 1
abc[y] += 1
else:
if abc[x]<=abc[y]:
ans[i] = x
abc[x] += 1
abc[y] -= 1
else:
ans[i] = y
abc[x] -= 1
abc[y] += 1
i += 1
print("Yes")
print("\n".join(ans))
``` | instruction | 0 | 40,203 | 5 | 80,406 |
Yes | output | 1 | 40,203 | 5 | 80,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
Q, A, B, C = map(int, readline().split())
N = A + B + C
S = read().split()
S = tuple(0 if s == b'BC' else 1 if s == b'AC' else 2 for s in S)
def solve_1(N, A, B, C, S):
nums = [A, B, C]
for s in S:
if nums[s] == N:
raise Exception
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if nums[i] < nums[j]:
i, j = j, i
yield j
nums[j] += 1
nums[i] -= 1
def solve_2(N, A, B, C, S):
nums = [A, B, C]
s = S[0]
# 初手で死亡
if nums[s] == N:
raise Exception
# あとはできる。きわどいときは 2 手読み
S = S + (0, )
for s, t in zip(S, S[1:]):
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if (nums[i], nums[j]) != (1, 1):
if nums[i] < nums[j]:
i, j = j, i
elif s != t:
i, j = t, 3 - s - t
yield j
nums[j] += 1
nums[i] -= 1
def large(N, A, B, C, S):
nums = [A, B, C]
for s in S:
if nums[s] == N:
raise Exception
i, j = (0, 1) if s == 2 else (0, 2) if s == 1 else (1, 2)
if nums[i] < nums[j]:
i, j = j, i
yield j
nums[j] += 1
nums[i] -= 1
print(s, nums)
N = 2
A, B, C = 1, 1, 0
S = (0, 1, 2, 1, 2, 2, 2, 1, 2, 1)
f = solve_1 if N == 1 else solve_2 if N == 2 else large
try:
cmds = list(f(N, A, B, C, S))
print('Yes')
answer = ('ABC' [i] for i in cmds)
print('\n'.join(answer))
except Exception:
print('No')
``` | instruction | 0 | 40,204 | 5 | 80,408 |
No | output | 1 | 40,204 | 5 | 80,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
n,a,b,c = map(int, input().split())
d = {}
d["A"] = a
d["B"] = b
d["C"] = c
al = [0]*(n+1)
bl = [0]*(n+1)
cl = [0]*(n+1)
pl = []
for i in range(n):
p = input()
pl.append(p)
al[i+1] = al[i]
bl[i+1] = bl[i]
cl[i+1] = cl[i]
if p[0]=="A" or p[1]=="A":
al[i+1] += 1
if p[0]=="B" or p[1]=="B":
bl[i+1] += 1
if p[0]=="C" or p[1]=="C":
cl[i+1] += 1
dp = {}
dp["A"] = al
dp["B"] = bl
dp["C"] = cl
res = []
for i in range(n):
p = pl[i]
if d[p[0]]>d[p[1]]:
if d[p[0]]<=0:
print("No")
exit()
res.append(p[1])
d[p[0]] -= 1
d[p[1]] += 1
elif d[p[0]]<d[p[1]]:
if d[p[1]]<=0:
print("No")
exit()
res.append(p[0])
d[p[0]] += 1
d[p[1]] -= 1
else:
if dp[p[0]][-1] - dp[p[0]][i] > dp[p[1]][-1] - dp[p[1]][i]:
if d[p[1]]<=0:
print("No")
exit()
res.append(p[0])
d[p[0]] += 1
d[p[1]] -= 1
else:
if d[p[0]]<=0:
print("No")
exit()
res.append(p[1])
d[p[0]] -= 1
d[p[1]] += 1
print("Yes")
for p in res:
print(p)
``` | instruction | 0 | 40,205 | 5 | 80,410 |
No | output | 1 | 40,205 | 5 | 80,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
n,A,B,C = map(int, readline().split())
N = A + B + C
S = [readline().strip() for _ in range(n)]
ans = []
possible = True
for i, s in enumerate(S):
if s == "AB":
if A + B == 0:
print("No")
possible = False
break
if i < n - 1 and A == B:
if S[i+1] == "AC":
A += 1
B -= 1
ans.append("A")
elif S[i+1] == "BC":
A -= 1
B += 1
ans.append("B")
else:
A += 1
B -= 1
ans.append("A")
else:
if A < B:
A += 1
B -= 1
ans.append("A")
else:
A -= 1
B += 1
ans.append("B")
elif s == "AC":
if A + C == 0:
print("No")
possible = False
break
if i < n - 1 and A == C:
if S[i+1] == "AB":
A += 1
B -= 1
ans.append("A")
elif S[i+1] == "BC":
A -= 1
C += 1
ans.append("C")
else:
A += 1
B -= 1
ans.append("A")
else:
if A < C:
A += 1
C -= 1
ans.append("A")
else:
A -= 1
C += 1
ans.append("C")
else:
if B + C == 0:
print("No")
possible = False
break
if i < n - 1 and B == C:
if S[i+1] == "AB":
B += 1
C -= 1
ans.append("B")
elif S[i+1] == "AC":
B -= 1
C += 1
ans.append("C")
else:
B += 1
C -= 1
ans.append("B")
else:
if B < C:
B += 1
C -= 1
ans.append("B")
else:
B -= 1
C += 1
ans.append("C")
if possible:
print("Yes")
print("\n".join(ans))
if __name__ == "__main__":
main()
``` | instruction | 0 | 40,206 | 5 | 80,412 |
No | output | 1 | 40,206 | 5 | 80,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq A,B,C \leq 10^9
* N, A, B, C are integers.
* s_i is `AB`, `AC`, or `BC`.
Input
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N
Output
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice.
Examples
Input
2 1 3 0
AB
AC
Output
Yes
A
C
Input
3 1 0 0
AB
BC
AB
Output
No
Input
1 0 9 0
AC
Output
No
Input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Output
Yes
C
B
B
C
C
B
A
A
Submitted Solution:
```
import sys
l = sys.stdin.readline().strip()
N, A, B, C = map(int, l.split())
history = []
for _ in range(N):
cmd = sys.stdin.readline().strip()
history.append(cmd)
if A+B+C == 0:
print("No")
elif A+B+C == 1:
fail = False
path = ""
for one in history:
if one == "AB":
if A == 0 and B==0:
fail = True
break
else:
if A == 0:
A = 1
B = 0
path += "A"
else:
A = 0
B = 1
path += "B"
if one == "AC":
if A== 0 and C == 0:
fail = True
break
else:
if A==0:
A = 1
C = 0
path += "A"
else:
A = 0
C = 1
path += "C"
if one == "BC":
if B == 0 and C == 0:
fail = True
break
else:
if B == 0:
B = 1
C = 0
path += "B"
else:
C,B = 1,0
path += "C"
if fail:
print("No")
else:
print ("Yes")
for one in path:
print(one)
else:
fail = False
path = ""
for idx, one in enumerate(history):
if A < 0 or B < 0 or C<0:
fail = True
break
if one == "AB":
if A <= 0 and B<=0:
fail = True
break
else:
if idx == N-1 or history[idx+1] == "AB":
if A > B:
A, B,path = A-1, B+1, path +"B"
else:
A, B, path = A+1, B-1, path+"A"
else:
if "A" in history[idx+1]:
if B > 0:
A, B, path = A+1, B-1, path+"A"
else:
A, B, path = A-1, B+1, path+"A"
else:
if A > 0:
A, B,path = A-1, B+1, path +"B"
else:
A, B, path = A+1, B-1, path+"A"
elif one =="AC":
if A<=0 and C<=0:
fail =True
break
else:
if idx == N-1 or history[idx+1] == "AC":
if A > C:
A, C, path = A -1, C+1, path+"C"
else:
A,C,path = A+1, C-1, path +"A"
else:
if "A" in history[idx+1]:
if C > 0:
A,C,path = A+1, C-1, path +"A"
else:
A, C, path = A -1, C+1, path+"C"
else:
if A > 0:
A, C, path = A -1, C+1, path+"C"
else:
A,C,path = A+1, C-1, path +"A"
else:
if B<=0 and C<=0:
fail = True
break
else:
if idx == N-1 or history[idx+1] == "BC":
if B > C:
B,C,path = B-1,C+1, path+"C"
else:
B,C,path = B+1,C-1,path+"B"
else:
if "B" in history[idx+1]:
if C > 0:
B,C,path = B+1,C-1,path+"B"
else:
B,C,path = B-1,C+1, path+"C"
else:
if B > 0:
B,C,path = B-1,C+1, path+"C"
else:
B,C,path = B+1,C-1,path+"B"
if fail:
print("No")
else:
print("Yes")
for one in path:
print(one)
``` | instruction | 0 | 40,207 | 5 | 80,414 |
No | output | 1 | 40,207 | 5 | 80,415 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,224 | 5 | 80,448 |
"Correct Solution:
```
A, B = map(int, input().split())
print((A + B) // 2 if not (A + B) % 2 else "IMPOSSIBLE")
``` | output | 1 | 40,224 | 5 | 80,449 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,225 | 5 | 80,450 |
"Correct Solution:
```
a,b=map(int,input().split())
print("IMPOSSIBLE" if abs(a-b)%2==1 else (a+b)//2)
``` | output | 1 | 40,225 | 5 | 80,451 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,226 | 5 | 80,452 |
"Correct Solution:
```
a,b=map(int,input().split())
print (int((a+b)/2) if (a-b)%2==0 else "IMPOSSIBLE")
``` | output | 1 | 40,226 | 5 | 80,453 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,227 | 5 | 80,454 |
"Correct Solution:
```
a,b = map(int, input().split())
ans="IMPOSSIBLE"
if (a+b)%2==0:
ans=(a+b)//2
print(ans)
``` | output | 1 | 40,227 | 5 | 80,455 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,228 | 5 | 80,456 |
"Correct Solution:
```
A,B = map(int,input().split())
K = 'IMPOSSIBLE' if (A+B) % 2 != 0 else (A+B) // 2
print(K)
``` | output | 1 | 40,228 | 5 | 80,457 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,229 | 5 | 80,458 |
"Correct Solution:
```
A,B=map(int,input().split())
print((A+B)//2 if (A+B)%2==0 else "IMPOSSIBLE")
``` | output | 1 | 40,229 | 5 | 80,459 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,230 | 5 | 80,460 |
"Correct Solution:
```
a,b = map(int, input().split())
x = a +b
print(int(x/2) if x%2 == 0 else "IMPOSSIBLE")
``` | output | 1 | 40,230 | 5 | 80,461 |
Provide a correct Python 3 solution for this coding contest problem.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394 | instruction | 0 | 40,231 | 5 | 80,462 |
"Correct Solution:
```
a, b = map(int,input().split())
print('IMPOSSIBLE' if (a+b)%2 else abs((a+b)//2))
``` | output | 1 | 40,231 | 5 | 80,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
A,B = map(int,input().split())
print("IMPOSSIBLE" if (A+B)%2!=0 else int((A+B)/2))
``` | instruction | 0 | 40,232 | 5 | 80,464 |
Yes | output | 1 | 40,232 | 5 | 80,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
a,b=map(int,input().split())
print((a+b)//2 if (a+b)//2 == (a+b)/2 else 'IMPOSSIBLE')
``` | instruction | 0 | 40,233 | 5 | 80,466 |
Yes | output | 1 | 40,233 | 5 | 80,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
a,b = map(int, input().split())
print(int(a+((b-a)/2)) if (b-a)%2 == 0 else "IMPOSSIBLE")
``` | instruction | 0 | 40,234 | 5 | 80,468 |
Yes | output | 1 | 40,234 | 5 | 80,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
a,b=map(int,input().split())
print(int(min(a,b)+abs(a-b)/2) if (a-b)%2==0 else "IMPOSSIBLE")
``` | instruction | 0 | 40,235 | 5 | 80,470 |
Yes | output | 1 | 40,235 | 5 | 80,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
a,b=int(input().split())
print(a+b //2 if a+b % 2==0 else 'IMPSSIBLE')
``` | instruction | 0 | 40,236 | 5 | 80,472 |
No | output | 1 | 40,236 | 5 | 80,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
n, m = map(int, input().split())
if (n+m)%2 == 0:print((n+m)/2)
else:print("IMPOSSIBLE")
``` | instruction | 0 | 40,237 | 5 | 80,474 |
No | output | 1 | 40,237 | 5 | 80,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
p,q=map(int,input().split())
if (p-q)%2==1:
print("IMPOSSIBLE")
else:
print(abs((p-q)//2))
``` | instruction | 0 | 40,238 | 5 | 80,476 |
No | output | 1 | 40,238 | 5 | 80,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the integer K satisfying the condition.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Examples
Input
2 16
Output
9
Input
0 3
Output
IMPOSSIBLE
Input
998244353 99824435
Output
549034394
Submitted Solution:
```
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
A, B = li()
if A + B % 2 == 1:
print("IMPOSSIBLE")
else:
C = (A + B)/2
print(int(C))
``` | instruction | 0 | 40,239 | 5 | 80,478 |
No | output | 1 | 40,239 | 5 | 80,479 |
Provide a correct Python 3 solution for this coding contest problem.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0 | instruction | 0 | 40,241 | 5 | 80,482 |
"Correct Solution:
```
n, m = map(int, input().split())
a = sorted([int(x) for x in input().split()])
def chk(x):
for i in range(2*x, 2*n):
if i != 2*n - 1 - (i - 2*x) and a[i] + a[2*n-1-(i-2*x)] < m:
return False
return True
bottom = -1
top = n
while top - bottom > 1:
mid = (top + bottom)//2
if chk(mid):
top = mid
else:
bottom = mid
ans = -1
for i in range(2*top, 2*n):
ans = max(ans, (a[i]+a[2*n-1-(i-2*top)]) % m)
for i in range(2*top):
ans = max(ans, (a[i] + a[2*top-1-i]) % m)
print(ans)
``` | output | 1 | 40,241 | 5 | 80,483 |
Provide a correct Python 3 solution for this coding contest problem.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0 | instruction | 0 | 40,242 | 5 | 80,484 |
"Correct Solution:
```
def check(k):
ret = 0
b = 2 * k - 1
for j in range(k):
t = aaa[j] + aaa[b - j]
if t >= m:
return -1
ret = max(ret, t)
b = 2 * k
c = 2 * n - 1
for j in range(n - k):
t = aaa[b + j] + aaa[c - j]
if t < m:
return -2
ret = max(ret, t - m)
return ret
n, m = map(int, input().split())
aaa = sorted(map(int, input().split()))
l, r = 0, n
ans = -1
while l < r:
mid = (l + r) // 2
res = check(mid)
if res == -1:
r = mid
elif res == -2:
l = mid + 1
else:
ans = res
r = mid
if ans == -1:
ans = check(n)
print(ans)
``` | output | 1 | 40,242 | 5 | 80,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0
Submitted Solution:
```
n = int(input())
list = []
a = []
for i in range(n):
list.append(int(input))
for i in range(1, n):
for j in range(1, i):
if list[i] == j:
a.insert(j, j)
if a == list:
for i in range(n):
print(list[i])
else:
print(-1)
``` | instruction | 0 | 40,243 | 5 | 80,486 |
No | output | 1 | 40,243 | 5 | 80,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0
Submitted Solution:
```
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
med = m / 2
a = [i if (i <= med) else (i - m) for i in a]
a = sorted(a)
ans = []
for i in range(n):
temp = a[i] + a[-i-1]
ans.append(temp)
ans = [i % m for i in ans]
print(max(ans))
``` | instruction | 0 | 40,244 | 5 | 80,488 |
No | output | 1 | 40,244 | 5 | 80,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0
Submitted Solution:
```
import sys
import numpy as np
from itertools import combinations
from itertools import permutations
### 方針
### 実行時間は最大でも2N!で収まる気がする
### 最悪全ての組み合わせの数列に対して、上から2桁ずつ足し算してあまりを求め続けてその時の最大値を全部とって比較すればいい
### 流石に↑は嘘っぽいので、ひとつの数列を作成したい気がする
### a[0]:N a[1]:M
a = list(map(int,input().split()))
input = list(map(int,input().split()))
min=4
for i in permutations(input,len(input)):
max=0
for j in range(0,len(i),2):
mod = (i[j]+i[j+1])%a[1]
if max < mod:
max=mod
if min > max:
min = max
print(min)
``` | instruction | 0 | 40,245 | 5 | 80,490 |
No | output | 1 | 40,245 | 5 | 80,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let M be a positive integer.
You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for each i.
Consider dividing the 2 N integers into N pairs. Here, each integer must belong to exactly one pair.
We define the ugliness of a pair (x, y) as (x + y) \mod M. Let Z be the largest ugliness of the N pairs. Find the minimum possible value of Z.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 0 \leq a_i < M
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 \cdots a_{2N}
Output
Print the minimum possible value of Z, where Z is the largest ugliness of the N pairs.
Examples
Input
3 10
0 2 3 4 5 9
Output
5
Input
2 10
1 9 1 9
Output
0
Submitted Solution:
```
n, m = map(int, input().split())
a = sorted([int(x) for x in input().split()])
if n == 1:
print(sum(a) % m)
exit()
def chk(x):
for i in range(2*x, 2*n):
if i != 2*n - 1 - (i - 2*x) and a[i] + a[2*n-1-(i-2*x)] < m:
return False
for i in range(2*x):
if i != 2*x-1-i and a[i] + a[2*x-1-i] >= m:
return False
return True
bottom = -1
top = n
while top - bottom > 1:
mid = (top + bottom)//2
if chk(mid):
top = mid
else:
bottom = mid
if top == 0:
break
ans = -1
for i in range(2*top, 2*n):
ans = max(ans, (a[i]+a[2*n-1-(i-2*top)]) % m)
for i in range(2*top):
ans = max(ans, (a[i] + a[2*top-1-i]) % m)
print(ans)
``` | instruction | 0 | 40,246 | 5 | 80,492 |
No | output | 1 | 40,246 | 5 | 80,493 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
Real variables $ x_1, x_2, ..., x_N $ satisfy the following conditions.
1. $ 0 \ leq x_i \ leq 1 $ ($ 1 \ leq i \ leq N $)
2. $ w_1x_1 + w_2x_2 + ... + w_Nx_N \ leq W $
At this time, find the maximum value that $ v_1x_1 + v_2x_2 + ... + v_Nx_N $ can take. It is known that such a maximum actually exists.
Constraint
* $ 1 \ leq N \ leq 10 ^ 5 $
* $ 1 \ leq W \ leq 10 ^ 5 $
* $ -10 ^ 4 \ leq w_i \ leq 10 ^ 4 $
* $ -10 ^ 4 \ leq v_i \ leq 10 ^ 4 $
input
Input follows the following format. All given numbers are integers.
$ N $ $ W $
$ w_1 $ $ v_1 $
$ w_2 $ $ v_2 $
$ ... $
$ w_N $ $ v_N $
output
Output the maximum possible value of $ v_1x_1 + v_2x_2 + ... + v_Nx_N $ on one line. The output must not have an error greater than $ 10 ^ {-3} $.
Examples
Input
1 1
3 1
Output
0.333333
Input
2 3
3 3
1 2
Output
4.000000
Input
2 1
-1 -3
3 10
Output
3.666667 | instruction | 0 | 40,396 | 5 | 80,792 |
"Correct Solution:
```
import heapq
N, W = [int(n) for n in input().split()]
tmpw = 0
tmpv = 0
minheap = []
for i in range(N):
w, v = [int(n) for n in input().split()]
if(w < 0):
tmpw += w
tmpv += v
w *= -1
v *= -1
if(v > 0):
if w == 0:
tmpv += v
else:
heapq.heappush(minheap, (-(v/w), w, v))
while(W-tmpw > 1e-9 and not minheap == []):
p = heapq.heappop(minheap)
w = p[1]
v = p[2]
x = min(1, (W-tmpw)/w)
tmpw += x*w
tmpv += x*v
print(tmpv)
``` | output | 1 | 40,396 | 5 | 80,793 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
R?????,2?)
Output
29 | instruction | 0 | 40,401 | 5 | 80,802 |
"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():
s = S()
l = len(s)
fm = {}
fm[''] = -1
def f(s):
if s in fm:
return fm[s]
l = len(s)
r = -1
if l > 5 and s[1] in '(?' and s[-1] in ')?':
if s[0] in 'R?':
for i in range(3,l-2):
if s[i] not in ',?':
continue
tl = f(s[2:i])
tr = f(s[i+1:-1])
if tl >= 0 and tr >= 0 and r < tr:
r = tr
if s[0] in 'L?':
for i in range(3,l-2):
if s[i] not in ',?':
continue
tl = f(s[2:i])
tr = f(s[i+1:-1])
if tl >= 0 and tr >= 0 and r < tl:
r = tl
ff = True
if s[0] == '0' and l > 1:
ff = False
for tc in 'RL,()':
if tc in s:
ff = False
break
if ff:
r = int(s.replace('?', '9'))
fm[s] = r
return r
r = f(s)
if r < 0:
return 'invalid'
return r
print(main())
``` | output | 1 | 40,401 | 5 | 80,803 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,403 | 5 | 80,806 |
"Correct Solution:
```
n, m = [int(i) for i in input().split()]
print(n*m)
``` | output | 1 | 40,403 | 5 | 80,807 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,404 | 5 | 80,808 |
"Correct Solution:
```
def nums():
return list(map(int,input().split()))
N,M = nums()
print(N*M)
``` | output | 1 | 40,404 | 5 | 80,809 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,405 | 5 | 80,810 |
"Correct Solution:
```
a,b=map(int,input().split())
print(a*b)
``` | output | 1 | 40,405 | 5 | 80,811 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,406 | 5 | 80,812 |
"Correct Solution:
```
print(eval(input().replace(" ", "*")))
``` | output | 1 | 40,406 | 5 | 80,813 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,407 | 5 | 80,814 |
"Correct Solution:
```
n,m=map(int,input().split())
print(n*m)
``` | output | 1 | 40,407 | 5 | 80,815 |
Provide a correct Python 3 solution for this coding contest problem.
Oranges on Cans
square1001 You put a $ N $ can of aluminum on the table.
E869120 You put $ M $ of oranges on each aluminum can on the table.
How many oranges are on the aluminum can?
input
Input is given from standard input in the following format.
$ N $ $ M $
output
Output the number of oranges on the aluminum can in one line.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 9 $
* $ 1 \ leq M \ leq 9 $
* All inputs are integers.
Input example 1
3 4
Output example 1
12
Input example 2
7 7
Output example 2
49
Example
Input
3 4
Output
12 | instruction | 0 | 40,408 | 5 | 80,816 |
"Correct Solution:
```
N,M = map(int,input().split())
print(N*M)
``` | output | 1 | 40,408 | 5 | 80,817 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
Constraints
* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$
Input
$n$ $q$
$query_1$
$query_2$
:
$query_q$
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:
0 $s$ $t$ $x$
or
1 $s$ $t$
The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.
Output
For each $find$ query, print the minimum value.
Example
Input
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
Output
-2
0
1
-1 | instruction | 0 | 40,409 | 5 | 80,818 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def indexes(L,R): # 遅延伝搬すべきノードのリストを返す. (つまり, updateやgetvaluesで見るノードより上にあるノードたち)
INDLIST=[]
R-=1
L>>=1
R>>=1
while L!=R:
if L>R:
INDLIST.append(L)
L>>=1
else:
INDLIST.append(R)
R>>=1
while L!=0:
INDLIST.append(L)
L>>=1
return INDLIST
def adds(l,r,x): # 区間[l,r)を +x 更新
L=l+seg_el
R=r+seg_el
L//=(L & (-L))
R//=(R & (-R))
UPIND=indexes(L,R)
while L!=R:
if L > R:
SEG[L]+=x
LAZY[L]+=x
L+=1
L//=(L & (-L))
else:
R-=1
SEG[R]+=x
LAZY[R]+=x
R//=(R & (-R))
for ind in UPIND:
SEG[ind]=min(SEG[ind<<1],SEG[1+(ind<<1)])+LAZY[ind]
def getvalues(l,r): # 区間[l,r)に関するminを調べる
L=l+seg_el
R=r+seg_el
L//=(L & (-L))
R//=(R & (-R))
UPIND=indexes(L,R)
for ind in UPIND[::-1]: # 遅延伝搬
if LAZY[ind]!=0:
plus_lazy=LAZY[ind]
SEG[ind<<1]+=plus_lazy
SEG[1+(ind<<1)]+=plus_lazy
LAZY[ind<<1]+=plus_lazy
LAZY[1+(ind<<1)]+=plus_lazy
LAZY[ind]=0
ANS=1<<31
while L!=R:
if L > R:
ANS=min(ANS , SEG[L])
L+=1
L//=(L & (-L))
else:
R-=1
ANS=min(ANS , SEG[R])
R//=(R & (-R))
return ANS
ANS=[]
for _ in range(Q):
query=list(map(int,input().split()))
if query[0]==0:
adds(query[1],query[2]+1,query[3])
else:
ANS.append(getvalues(query[1],query[2]+1))
print("\n".join([str(ans) for ans in ANS]))
``` | output | 1 | 40,409 | 5 | 80,819 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
Constraints
* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$
Input
$n$ $q$
$query_1$
$query_2$
:
$query_q$
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:
0 $s$ $t$ $x$
or
1 $s$ $t$
The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.
Output
For each $find$ query, print the minimum value.
Example
Input
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
Output
-2
0
1
-1 | instruction | 0 | 40,410 | 5 | 80,820 |
"Correct Solution:
```
# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_H
class SegmentTreeForRMQandRAQ: # range minimum query and range add query
def __init__(self, ls: list, segfunc=min, identity_element=2**31, lazy_ide=0):
'''
セグ木
一次元のリストlsを受け取り初期化する。O(len(ls))
区間のルールはsegfuncによって定義される
identity elementは単位元。e.g., 最小値を求めたい→inf, 和→0, 積→1, gcd→0
[単位元](https://ja.wikipedia.org/wiki/%E5%8D%98%E4%BD%8D%E5%85%83)
'''
self.ide = identity_element
self.lide = lazy_ide # lazy用単位元
self.func = segfunc
n = len(ls)
self.num = 2 ** (n - 1).bit_length() # n以上の最小の2のべき乗
self.tree = [self.ide] * (2 * self.num) # 関係ない値を-1においてアクセスを許すと都合が良い
self.lazy = [self.lide] * (2 * self.num) # 遅延配列
for i, l in enumerate(ls): # 木の葉に代入
self.tree[i + self.num - 1] = l
for i in range(self.num - 2, -1, -1): # 子を束ねて親を更新
self.tree[i] = segfunc(self.tree[2 * i + 1], self.tree[2 * i + 2])
def _gidx(self, l, r):
'''
lazy propagation用idx生成器 木の下から生成される。1based-indexなので注意.(使うときは-1するとか)
もとの配列において[l,r)を指定したときに更新すべきidxをyieldする
treesizeは多くの場合self.num
'''
L, R = l + self.num, r + self.num
lm = (L // (L & -L)) >> 1 # これで成り立つの天才か?
rm = (R // (R & -R)) >> 1
while L < R:
if R <= rm:
yield R
if L <= lm:
yield L
L >>= 1
R >>= 1
while L: # Rでもいいけどね
yield L
L >>= 1
def _lazyprop(self, *ids):
'''
遅延評価用の関数
- self.tree[i] に self.lazy[i]の値を伝播させて遅延更新する
- 子ノードにself.lazyの値を伝播させる **ここは問題ごとに書き換える必要がある**
- self.lazy[i]をリセットする
'''
for i in reversed(ids):
i -= 1 # 0basedindexに修正
v = self.lazy[i]
if v == self.lide:
continue # 単位元ならする必要のNASA
# どうやって遅延更新するかは問題によってことなる
# 今回なら範囲(最小値を持つ)に加算なので、そのままvを加算すればよい
self.tree[2 * i + 1] += v
self.tree[2 * i + 2] += v
self.lazy[2 * i + 1] += v
self.lazy[2 * i + 2] += v
self.lazy[i] = self.lide # 遅延配列を空に戻す
def update(self, l, r, x):
'''
[l,r)番目の要素をxに変更する(木の中間ノードも更新する) O(logN)
'''
# 1, 根から区間内においてlazyの値を伝播しておく(self.treeの値が有効になる)
ids = tuple(self._gidx(l, r))
# self._lazyprop(*ids) # 足し算はlazyに対し込んでも良いのでupdate時にpropしなくても良い
# 2, 区間に対してtree,lazyの値を更新 (treeは根方向に更新するため、lazyはpropで葉方向に更新するため)
if r <= l:
return ValueError('invalid index (l,rがありえないよ)')
l += self.num
r += self.num
while l < r:
# ** 問題によって値のセットの仕方も変えるべし**
if r & 1:
r -= 1
self.tree[r - 1] += x
self.lazy[r - 1] += x
if l & 1:
self.tree[l - 1] += x
self.lazy[l - 1] += x
l += 1
l >>= 1
r >>= 1
# 3, 伝播させた区間について下からdataの値を伝播する
for i in ids:
i -= 1 # to 0based
self.tree[i] = self.func( # ここでlazyの値を考慮しなければ行けない
self.tree[2 * i + 1], self.tree[2 * i + 2]) + self.lazy[i]
def query(self, l, r):
'''
区間[l,r)に対するクエリをO(logN)で処理する。例えばその区間の最小値、最大値、gcdなど
'''
if r <= l:
return ValueError('invalid index (l,rがありえないよ)')
# 1, 根からにlazyの値を伝播させる
self._lazyprop(*self._gidx(l, r))
# 2, 区間[l,r)の最小値を求める
l += self.num
r += self.num
res = self.ide
while l < r: # 右から寄りながら結果を結合していくイメージ
if r & 1:
r -= 1
res = self.func(res, self.tree[r - 1])
if l & 1:
res = self.func(res, self.tree[l - 1])
l += 1
l >>= 1
r >>= 1 # 親の一つ左に移動
return res
n, q = map(int, input().split())
ls = [0] * n
seg = SegmentTreeForRMQandRAQ(ls)
for _ in range(q):
cmd, *tmp = map(int, input().split())
if cmd == 0:
s, t, x = tmp
seg.update(s, t + 1, x)
else:
s, t = tmp
print(seg.query(s, t + 1))
``` | output | 1 | 40,410 | 5 | 80,821 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
Constraints
* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$
Input
$n$ $q$
$query_1$
$query_2$
:
$query_q$
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:
0 $s$ $t$ $x$
or
1 $s$ $t$
The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.
Output
For each $find$ query, print the minimum value.
Example
Input
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
Output
-2
0
1
-1 | instruction | 0 | 40,411 | 5 | 80,822 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 2 ** 31 - 1
MOD = 10 ** 9 + 7
class StarrySkyTree:
""" Starry Sky Tree """
def __init__(self, N, func, intv):
self.intv = intv
self.func = func
LV = (N-1).bit_length()
self.N0 = 2**LV
self.data = [0]*(2*self.N0)
self.lazy = [0]*(2*self.N0)
# 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
def gindex(self, l, r):
L = l + self.N0; R = r + self.N0
lm = (L // (L & -L)) >> 1
rm = (R // (R & -R)) >> 1
while L < R:
if R <= rm:
yield R
if L <= lm:
yield L
L >>= 1; R >>= 1
while L:
yield L
L >>= 1
# 遅延評価の伝搬処理
def propagates(self, *ids):
# 1-indexedで単調増加のインデックスリスト
for i in reversed(ids):
v = self.lazy[i-1]
if not v:
continue
self.lazy[2*i-1] += v; self.lazy[2*i] += v
self.data[2*i-1] += v; self.data[2*i] += v
self.lazy[i-1] = 0
def update(self, l, r, x):
""" 区間[l,r)の値にxを加算 """
# 1. lazyの値は伝搬させない
# 2. 区間[l,r)のdata, lazyの値を更新
L = self.N0 + l; R = self.N0 + r
while L < R:
if R & 1:
R -= 1
self.lazy[R-1] += x; self.data[R-1] += x
if L & 1:
self.lazy[L-1] += x; self.data[L-1] += x
L += 1
L >>= 1; R >>= 1
# 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
for i in self.gindex(l, r):
self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i]) + self.lazy[i-1]
def query(self, l, r):
""" 区間[l,r)の最小値を取得 """
# 1. トップダウンにlazyの値を伝搬
self.propagates(*self.gindex(l, r))
L = self.N0 + l; R = self.N0 + r
# 2. 区間[l, r)の最小値を求める
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.func(s, self.data[R-1])
if L & 1:
s = self.func(s, self.data[L-1])
L += 1
L >>= 1; R >>= 1
return s
N, Q = MAP()
sst = StarrySkyTree(N+1, min, INF)
ans = []
for i in range(Q):
cmd, *arg = MAP()
if cmd == 0:
s, t, x = arg
sst.update(s, t+1, x)
else:
s, t = arg
ans.append(str(sst.query(s, t+1)))
print('\n'.join(ans))
``` | output | 1 | 40,411 | 5 | 80,823 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
Constraints
* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$
Input
$n$ $q$
$query_1$
$query_2$
:
$query_q$
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:
0 $s$ $t$ $x$
or
1 $s$ $t$
The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.
Output
For each $find$ query, print the minimum value.
Example
Input
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
Output
-2
0
1
-1 | instruction | 0 | 40,412 | 5 | 80,824 |
"Correct Solution:
```
#!/usr/bin/env python3
# DSL_2_H: RMQ and RAQ
# Range Minimum Query and Range Add Query
# Lazy propagate segment tree
from array import array
import sys
class SegmentTree:
MAXV = 1000 * 10**5 + 1
def __init__(self, n):
size = 1
while size < n:
size *= 2
self.size = 2*size - 1
self.data = array('i', [0] * self.size)
self.lazy = array('i', [0] * self.size)
def add(self, lo, hi, v):
def _add(r, i, j, lz):
left, right = r*2 + 1, r*2 + 2
if lazy[r]:
lz += lazy[r]
lazy[r] = 0
if lo <= i and j <= hi:
lz += v
if lz:
data[r] += lz
if i < j:
lazy[left] += lz
lazy[right] += lz
else:
mid = (i + j) // 2
if mid >= lo:
lv = _add(left, i, mid, lz)
else:
lazy[left] += lz
lv = data[left] + lazy[left]
if mid < hi:
rv = _add(right, mid+1, j, lz)
else:
lazy[right] += lz
rv = data[right] + lazy[right]
if lv < rv:
data[r] = lv
else:
data[r] = rv
return data[r]
lazy = self.lazy
data = self.data
_add(0, 0, self.size//2, 0)
def min(self, lo, hi):
def _min(r, i, j, lz):
left, right = r*2 + 1, r*2 + 2
if lazy[r]:
lz += lazy[r]
lazy[r] = 0
if lz:
data[r] += lz
if lo <= i and j <= hi:
if lz and i < j:
lazy[left] += lz
lazy[right] += lz
return data[r]
else:
mid = (i + j) // 2
if mid >= lo:
lv = _min(left, i, mid, lz)
else:
lazy[left] += lz
lv = self.MAXV
if mid < hi:
rv = _min(right, mid+1, j, lz)
else:
lazy[right] += lz
rv = self.MAXV
if lv < rv:
return lv
else:
return rv
lazy = self.lazy
data = self.data
return _min(0, 0, self.size//2, 0)
def run():
n, q = [int(i) for i in input().split()]
tree = SegmentTree(n)
ret = []
for line in sys.stdin:
com, *args = line.split()
if com == '0':
s, t, x = map(int, args)
tree.add(s, t, x)
elif com == '1':
s, t = map(int, args)
ret.append(tree.min(s, t))
sys.stdout.write("\n".join([str(i) for i in ret]))
sys.stdout.write("\n")
if __name__ == '__main__':
run()
``` | output | 1 | 40,412 | 5 | 80,825 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.
Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.
Constraints
* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$
Input
$n$ $q$
$query_1$
$query_2$
:
$query_q$
In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:
0 $s$ $t$ $x$
or
1 $s$ $t$
The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.
Output
For each $find$ query, print the minimum value.
Example
Input
6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5
Output
-2
0
1
-1 | instruction | 0 | 40,413 | 5 | 80,826 |
"Correct Solution:
```
import sys
class Lazysegtree:
#RAQ
def __init__(self, A, intv, initialize = True, segf = min):
#区間は 1-indexed で管理
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.intv = intv
self.segf = segf
self.lazy = [0]*(2*self.N0)
if initialize:
self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
for i in range(self.N0-1, 0, -1):
self.data[i] = self.segf(self.data[2*i], self.data[2*i+1])
else:
self.data = [intv]*(2*self.N0)
def _ascend(self, k):
k = k >> 1
c = k.bit_length()
for j in range(c):
idx = k >> j
self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
+ self.lazy[idx]
def _descend(self, k):
k = k >> 1
idx = 1
c = k.bit_length()
for j in range(1, c+1):
idx = k >> (c - j)
ax = self.lazy[idx]
if not ax:
continue
self.lazy[idx] = 0
self.data[2*idx] += ax
self.data[2*idx+1] += ax
self.lazy[2*idx] += ax
self.lazy[2*idx+1] += ax
def query(self, l, r):
L = l+self.N0
R = r+self.N0
Li = L//(L & -L)
Ri = R//(R & -R)
self._descend(Li)
self._descend(Ri - 1)
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.segf(s, self.data[R])
if L & 1:
s = self.segf(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def update(self, l, r, x):
L = l+self.N0
R = r+self.N0
Li = L//(L & -L)
Ri = R//(R & -R)
while L < R :
if R & 1:
R -= 1
self.data[R] += x
self.lazy[R] += x
if L & 1:
self.data[L] += x
self.lazy[L] += x
L += 1
L >>= 1
R >>= 1
self._ascend(Li)
self._ascend(Ri-1)
N, Q = map(int, input().split())
T = Lazysegtree([0]*N, 2<<31)
Ans = []
for jq in range(Q):
t, *q = map(int, sys.stdin.readline().split())
q[1] += 1
if t:
Ans.append(T.query(*q))
else:
T.update(*q)
print('\n'.join(map(str, Ans)))
``` | output | 1 | 40,413 | 5 | 80,827 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.