lang stringclasses 1
value | prompt stringlengths 1.38k 11.3k | eval_prompt stringlengths 37 8.09k | ground_truth stringlengths 1 328 | unit_tests stringclasses 145
values | task_id stringlengths 23 25 | split stringclasses 2
values |
|---|---|---|---|---|---|---|
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | def dfs(tree,i,h):
if i>=2**(h-1)-1:
return [tree[i],1]
ls,li=dfs(tree,i*2+1,h)
rs,ri=dfs(tree,i*2+2,h)
res=li*ri
if {{completion}}:
res*=2
if ls>rs:
return [tree[i]+rs+ls,res]
else:
return [tree[i]+ls+rs,res]
h=int(input())
tree=input()
prin... | ls!=rs | [{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}] | control_completion_001667 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | import sys
N = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
# print(N, s)
m = 1 << N
mod = 998244353
def dfs(i):
if i >= m: return (1, '')
ln, ls = dfs(i * 2)
rn, rs = dfs(i * 2 + 1)
ln = ln % mod
rn = rn % mod
if ls < rs:
return ln * rn * 2, ls + s[i - 1] + rs
... | ls > rs | [{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}] | control_completion_001668 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | # trans rights
N = int(input())
N = 2 ** N
S = input()
U = [0] * N
cnt = 0
for i in range(N - 2, -1, -1):
a = 2 * i + 1
b = 2 * i + 2
if {{completion}}:
U[i] = ord(S[i])
continue
if U[a] != U[b]:
cnt += 1
U[i] = ord(S[i]) + 331 * min(U[a], U[b]) + 3331 * max(U[a... | b >= N | [{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}] | control_completion_001669 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | # trans rights
N = int(input())
N = 2 ** N
S = input()
U = [0] * N
cnt = 0
for i in range(N - 2, -1, -1):
a = 2 * i + 1
b = 2 * i + 2
if b >= N:
U[i] = ord(S[i])
continue
if {{completion}}:
cnt += 1
U[i] = ord(S[i]) + 331 * min(U[a], U[b]) + 3331 * max(U[a], U[b... | U[a] != U[b] | [{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}] | control_completion_001670 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys;I=sys.stdin.readline;R,P,G=lambda:map(int,I().split()),print,range
n,q=R();n+=1;a=[0]+[*R()];p,s,last,oe=[0]*n,[0]*n,[0]*n,[{},{}]
for i in G(1,n):
p[i]=a[i]^p[i-1]
if a[i]==0:s[i]=s[i-1]+1
d=oe[i&1]
if p[i] in d:last[i]=d[p[i]]
oe[i&1][p[i-1]]=i
for _ in G(q):
l,r=R()
if s[r]>=r-l+1:... | (r-l)&1==0 or a[l]==0 or a[r]==0 | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001766 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys;I=sys.stdin.readline;R,P,G=lambda:map(int,I().split()),print,range
n,q=R();n+=1;a=[0]+[*R()];p,s,last,oe=[0]*n,[0]*n,[0]*n,[{},{}]
for i in G(1,n):
p[i]=a[i]^p[i-1]
if a[i]==0:s[i]=s[i-1]+1
d=oe[i&1]
if p[i] in d:last[i]=d[p[i]]
oe[i&1][p[i-1]]=i
for _ in G(q):
l,r=R()
if s[r]>=r-l+1:... | last[r]>l | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001767 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys
n, q = [int(i) for i in sys.stdin.readline().split()]
a = [int(i) for i in sys.stdin.readline().split()]
cur = 0
odd = {}
even = {}
last = [-1]*(n+1)
pxor = [0]*(n+1)
psum = [0]*(n+1)
for i, num in enumerate(a):
pxor[i+1] = pxor[i] ^ num
psum[i+1] = psum[i] + num
cur = pxor[i+1]... | last[r] >= l | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001768 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys
input = sys.stdin.readline
n,q = map(int,input().split())
a = [0] + list(map(int,input().split()))
cml = a[::1]
for i in range(1, n+1):
a[i] ^= a[i-1]
cml[i] += cml[i-1]
qs = [list(map(int,input().split())) for i in range(q)]
from collections import defaultdict
d = defaultdict(list)
dd = def... | tot == rr-ll or tot == 0 | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001769 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys
def input():
return sys.stdin.readline().strip()
n, q = map(int, input().split())
a = list(map(int, input().split()))
b, s = [0], [0]
nx = [n+5] * (n + 1)
d = {0: [0]}
for i, e in enumerate(a):
bx = b[-1]^e
sx = s[-1] + e
b.append(bx)
s.append(sx)
if bx in d.keys... | nx[l-1] <= r | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001770 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import collections
import sys
input = sys.stdin.readline
def sol(arr, n, m, q):
xor = [0]
curr = 0
for i in arr:
curr ^= i
xor.append(curr)
pre = [0]
curr = 0
for i in arr:
curr += i
pre.append(curr)
qd = collections.defaultdict(list)
for i ... | last[(r & 1) ^ 1][xor[r]] >= l | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001771 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import collections
import sys
input = sys.stdin.readline
def sol(arr, n, m, q):
xor = [0]
curr = 0
for i in arr:
curr ^= i
xor.append(curr)
pre = [0]
curr = 0
for i in arr:
curr += i
pre.append(curr)
qd = collections.defaultdict(list)
for i ... | pre[r] == pre[l - 1] | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001772 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | for t in range(int(input())):
n = int(input())
if {{completion}}:
print("1\n1 2")
continue
i = 2
j = 3*n
ans = []
while i<j:
ans.append((i,j))
i += 3
j -= 3
print(len(ans))
for i in ans:
print(i[0],i[1])
| n == 1 | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001791 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | for t in range(int(input())):
n = int(input())
if n == 1:
print("1\n1 2")
continue
i = 2
j = 3*n
ans = []
while {{completion}}:
ans.append((i,j))
i += 3
j -= 3
print(len(ans))
for i in ans:
print(i[0],i[1])
| i<j | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001792 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | t = int(input())
for i in range(t):
n = int(input())
if n == 1:
print(1)
print(1,2)
elif n%2 :
print(int((n+1)/2))
for e in range(2, int((3 * n + 1)/2) + 1, 3):
print(e,e + int((3*n)/2))
else :
print(int(n/2))
for {{completion}}:
... | e in range(2, int((3 * n + 1)/2) + 1, 3) | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001793 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
n = int(stdin.readline().strip())
b = list('ban'*n)
if n==1:
print(1)
print(1, 2)
else:
z = n*3-1
print(n//2+n%2)
for i3 in range(n//2+n%2):
for i2 in range(n*3):
... | b[i2]=='a' | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001794 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | # get testcase input
t = int(input())
result = ""
while t:
t -= 1
n = int(input())
aux = int(n/2 if n%2==0 else n/2+1)
if {{completion}}:
result += "1\n1 2\n"
continue
result += str(aux) + "\n"
for i in range(aux):
result += str(2+3*i) + ' ' + str(3+... | n == 1 | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001795 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | # get testcase input
t = int(input())
result = ""
while t:
t -= 1
n = int(input())
aux = int(n/2 if n%2==0 else n/2+1)
if n == 1:
result += "1\n1 2\n"
continue
result += str(aux) + "\n"
for {{completion}}:
result += str(2+3*i) + ' ' + str(3+3*(n-i-1)... | i in range(aux) | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001796 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | def ban(n):
if {{completion}}:
return [1, [[1, 2]]]
x = 0
lt = []
i = 2
j = 3 * n
while i < j:
lt.append([i, j])
x += 1
i += 3
j -= 3
return [x, lt]
OUTPUT = []
for _ in range(int(input())):
N = int(input())
OUTPUT.append(ban(N))
for _ in OUTPUT:
print(_[0])
for i in _[1]... | n == 1 | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001797 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | def ban(n):
if n == 1:
return [1, [[1, 2]]]
x = 0
lt = []
i = 2
j = 3 * n
while {{completion}}:
lt.append([i, j])
x += 1
i += 3
j -= 3
return [x, lt]
OUTPUT = []
for _ in range(int(input())):
N = int(input())
OUTPUT.append(ban(N))
for _ in OUTPUT:
print(_[0])
for i in _[1... | i < j | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001798 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | n = int(input())
for i in range(n):
k = int(input())
if k == 1:
ans = max(1, k - 1)
print(ans)
print(1, 2)
else:
t = []
p = [0, 1, 2] * k
x, y = 0, len(p) - 1
while x < y:
while {{completion}}: x += 1
while x < y and p[y] != 2:... | x < y and p[x] != 1 | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001799 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | n = int(input())
for i in range(n):
k = int(input())
if k == 1:
ans = max(1, k - 1)
print(ans)
print(1, 2)
else:
t = []
p = [0, 1, 2] * k
x, y = 0, len(p) - 1
while x < y:
while x < y and p[x] != 1: x += 1
while {{completion}}:... | x < y and p[y] != 2 | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | control_completion_001800 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... | input = __import__('sys').stdin.readline
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
u, v, x = map(lambda x: int(x)-1, input().split())
adj[u].append((v, x))
adj[v].append((u, x))
TRAVERSE = 0
UPDATE_DP = 1
prev_node_stack = [[0] for _ in range(n)]
prev_node = [0... | i < len(adj[u]) and adj[u][i][0] == par | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001874 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... | input = __import__('sys').stdin.readline
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
u, v, x = map(lambda x: int(x)-1, input().split())
adj[u].append((v, x))
adj[v].append((u, x))
TRAVERSE = 0
UPDATE_DP = 1
prev_node_stack = [[0] for _ in range(n)]
prev_node = [0... | i < len(adj[u]) | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001875 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... |
import sys
input=sys.stdin.readline #文字列入力はするな!!
n=int(input())
root=[[] for i in range(n+3)]
col=dict()
e=[]
from _collections import defaultdict
for i in range(n-1):
a,b,x=map(int,input().split())
root[a].append(b)
root[b].append(a)
col[a,b]=x
col[b,a]=x
e.append((a,b,x))
p=[0]*(n+2)
num... | c in range(1,n+1) | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001876 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... |
##########################
def tree_search(n,G,s,func1,func2,func3):
seen = [0] * (n + 1) # 場合によっては外に出す
ind = [0] * (n + 1) ##
search=[s]
while search:
now=search[-1]
if seen[now]==0 and func1!=0:func1(now)
seen[now]=1
if len(G[now])>ind[now]:
next=G[n... | func3!=0 | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001877 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... |
##########################
def tree_search(n,G,s,func1,func2,func3):
seen = [0] * (n + 1) # 場合によっては外に出す
ind = [0] * (n + 1) ##
search=[s]
while search:
now=search[-1]
if seen[now]==0 and func1!=0:func1(now)
seen[now]=1
if len(G[now])>ind[now]:
next=G[n... | ke in dp[y] | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001878 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You found a map of a weirdly shaped labyrinth. The map is a grid, consisting of $$$n$$$ rows and $$$n$$$ columns. The rows of the grid are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns of the grid are numbered from $$$1$$$ t... | import sys
input = sys.stdin.readline
N = int(input())
logN = (N - 2).bit_length()
door = []
for _ in range(N - 1):
_, a, b, _ = map(int, input().split())
door.append([a - 1, b - 1])
# door = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
dist = [[[-1] * 4 for _ in range(logN)] for ... | l >> i & 1 | [{"input": "2\n1 1 1 1\n10\n1 1 1 1\n1 1 1 2\n1 1 2 1\n1 1 2 2\n1 2 1 2\n1 2 2 1\n1 2 2 2\n2 1 2 1\n2 1 2 2\n2 2 2 2", "output": ["0\n1\n1\n2\n0\n2\n1\n0\n1\n0"]}, {"input": "4\n1 1 1 1\n2 1 2 2\n3 2 1 3\n5\n2 4 4 3\n4 4 3 3\n1 2 3 3\n2 2 4 4\n1 4 2 3", "output": ["3\n4\n3\n6\n2"]}] | control_completion_001911 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You found a map of a weirdly shaped labyrinth. The map is a grid, consisting of $$$n$$$ rows and $$$n$$$ columns. The rows of the grid are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns of the grid are numbered from $$$1$$$ t... | input = __import__('sys').stdin.readline
def manhattan(A, B, dA=None, dB=None):
if dA is not None:
A = list(A)
A[0] += dA[0]
A[1] += dA[1]
if dB is not None:
B = list(B)
B[0] += dB[0]
B[1] += dB[1]
return abs(A[0] - B[0]) + abs(A[1] - B[1])
... | dist is None | [{"input": "2\n1 1 1 1\n10\n1 1 1 1\n1 1 1 2\n1 1 2 1\n1 1 2 2\n1 2 1 2\n1 2 2 1\n1 2 2 2\n2 1 2 1\n2 1 2 2\n2 2 2 2", "output": ["0\n1\n1\n2\n0\n2\n1\n0\n1\n0"]}, {"input": "4\n1 1 1 1\n2 1 2 2\n3 2 1 3\n5\n2 4 4 3\n4 4 3 3\n1 2 3 3\n2 2 4 4\n1 4 2 3", "output": ["3\n4\n3\n6\n2"]}] | control_completion_001912 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You found a map of a weirdly shaped labyrinth. The map is a grid, consisting of $$$n$$$ rows and $$$n$$$ columns. The rows of the grid are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns of the grid are numbered from $$$1$$$ t... | input = __import__('sys').stdin.readline
def manhattan(A, B, dA=None, dB=None):
if dA is not None:
A = list(A)
A[0] += dA[0]
A[1] += dA[1]
if dB is not None:
B = list(B)
B[0] += dB[0]
B[1] += dB[1]
return abs(A[0] - B[0]) + abs(A[1] - B[1])
... | (sz >> i) & 1 == 1 | [{"input": "2\n1 1 1 1\n10\n1 1 1 1\n1 1 1 2\n1 1 2 1\n1 1 2 2\n1 2 1 2\n1 2 2 1\n1 2 2 2\n2 1 2 1\n2 1 2 2\n2 2 2 2", "output": ["0\n1\n1\n2\n0\n2\n1\n0\n1\n0"]}, {"input": "4\n1 1 1 1\n2 1 2 2\n3 2 1 3\n5\n2 4 4 3\n4 4 3 3\n1 2 3 3\n2 2 4 4\n1 4 2 3", "output": ["3\n4\n3\n6\n2"]}] | control_completion_001913 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Consider an array $$$a$$$ of $$$n$$$ positive integers.You may perform the following operation: select two indices $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$), then decrease all elements $$$a_l, a_{l + 1}, \dots, a_r$$$ by $$$1$$$. L... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | tc in range(testcaseCount) | [{"input": "3\n\n4\n\n2 3 5 4\n\n3\n\n1 2 3\n\n4\n\n3 1 3 2", "output": ["YES\nYES\nNO"]}] | control_completion_001993 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).More formally, if you are standing at the point $$$(x, y)$$$, you can: go left,... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | tc in range(testcaseCount) | [{"input": "3\n\n4\n\n0 -2\n\n1 0\n\n-1 0\n\n0 2\n\n3\n\n0 2\n\n-3 0\n\n0 -1\n\n1\n\n0 0", "output": ["12\n12\n0"]}] | control_completion_002026 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: My orzlers, we can optimize this problem from $$$O(S^3)$$$ to $$$O\left(T^\frac{5}{9}\right)$$$!— Spyofgame, founder of Orzlim religionA long time ago, Spyofgame invented the famous array $$$a$$$ ($$$1$$$-indexed) of length $$$n$$$ that contai... | a=[*map(int,[*open(0)][1].split())]
for k in 0,1:
for i in range(19):
z=1<<i
for j in range(len(a)):
if {{completion}}:a[j-k*z]^=a[j+k*z-z]
print(*reversed(a))
| j&z | [{"input": "3\n0 2 1", "output": ["1 2 3"]}, {"input": "1\n199633", "output": ["199633"]}, {"input": "10\n346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607", "output": ["725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365... | control_completion_002076 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: My orzlers, we can optimize this problem from $$$O(S^3)$$$ to $$$O\left(T^\frac{5}{9}\right)$$$!— Spyofgame, founder of Orzlim religionA long time ago, Spyofgame invented the famous array $$$a$$$ ($$$1$$$-indexed) of length $$$n$$$ that contai... | a=[*map(int,[*open(0)][1].split())]
n=len(a)
for k in 0,1:
for i in range(19):
for j in range(n):
l=j^1<<i
if {{completion}}:
a[j]^=a[l]
print(*reversed(a))
| k^(l<j)and l<n | [{"input": "3\n0 2 1", "output": ["1 2 3"]}, {"input": "1\n199633", "output": ["199633"]}, {"input": "10\n346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607", "output": ["725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365... | control_completion_002077 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | input()
n = int(input(), 2)
m = n
for {{completion}}:
n = max(n, m | m >> i)
print(bin(n)[2:]) | i in range(30) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002115 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = int(input())
s=input()
b=int(s,2)
a=b;
mx=a|b
for i in range(0,7):
a=a>>1
m=a|b
if {{completion}}:
mx=m
st=format(mx ,"b")
print(st) | m>mx | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002116 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = input()
s = int(input(),2)
res = 0
for {{completion}}:
res = max(res,(s | (s >> i)))
ans = bin(res)[2:]
print(ans) | i in range(100) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002117 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | input()
n=int(input(),2)
ans=0
for {{completion}}:
ans=max(ans,n|(n>>i))
print(bin(ans)[2:])
| i in range(1,64) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002118 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = input()
s = int(input(), base=2)
t = s
for {{completion}}:
t = max(t, s | s >> i)
print("{0:b}".format(t)) | i in range(1,10) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002119 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = int(input())
s = input().strip()
s1 = int('0b'+s,2)
res = s1
for {{completion}}:
res = max(s1 | (s1 >> i), res)
print(bin(res)[2:]) | i in range(1,8) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002120 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | def random(st):
n = 8
st = int(st, 2)
MAX = st
for {{completion}}:
MAX = max((st >> t) | st, MAX)
return bin(MAX)[2:]
N = input()
b = input()
print(random(b))
| t in range(n) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002121 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | # وده اقل حاجه ببايثون
input()
n=int(input(),2)
m=n
for {{completion}}:m=max(m,n|n>>i)
print("{0:b}".format(m)) | i in range(1,100) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002122 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = int(input())
a = int(input(), 2)
temp = a
mx = a|temp
for i in range(7):
temp = temp >> 1
m = a|temp
if {{completion}}:
mx = m
print(bin(mx).replace('0b', ''))
| mx < m | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | control_completion_002123 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$.Let $$$A \cup B$$$ be the union of two sets $$$A$$$ ... | import sys
import heapq
from collections import Counter
# sys.setrecursionlimit(10000)
def input_general():
return sys.stdin.readline().rstrip('\r\n')
def input_num():
return int(sys.stdin.readline().rstrip("\r\n"))
def input_multi(x=int):
return map(x, sys.stdin.readline().rstrip("\r\n... | e & 1 | [{"input": "4\n3 5\n4 8\n2 2\n1 9", "output": ["162"]}, {"input": "4\n1 9\n3 5\n4 8\n2 2", "output": ["102"]}] | control_completion_002160 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$.Let $$$A \cup B$$$ be the union of two sets $$$A$$$ ... | import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappop,heappush
def solve():
N=int(input())
p=998244353
# 2와 3의 거듭제곱 저장
two=[1]
for _ in range(N):
two.append((two[-1]*2)%p)
three=[1]
for _ in range(N):
three.append((... | st[2*cur]<st[cur] | [{"input": "4\n3 5\n4 8\n2 2\n1 9", "output": ["162"]}, {"input": "4\n1 9\n3 5\n4 8\n2 2", "output": ["102"]}] | control_completion_002161 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$.Let $$$A \cup B$$$ be the union of two sets $$$A$$$ ... | import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappop,heappush
def solve():
N=int(input())
p=998244353
# 2와 3의 거듭제곱 저장
two=[1]
for _ in range(N):
two.append((two[-1]*2)%p)
three=[1]
for _ in range(N):
three.append((... | st[2*cur+1]<st[cur] | [{"input": "4\n3 5\n4 8\n2 2\n1 9", "output": ["162"]}, {"input": "4\n1 9\n3 5\n4 8\n2 2", "output": ["102"]}] | control_completion_002162 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | from collections import deque;I=input;R=lambda:map(int,I().split())
def f(x,pre):
global flg;dp=[0]*(n+1)
q=deque([(x,pre)]);R=[]
while q:
u,p=q.popleft()
R.append((u))
for v in g[u]:
if {{completion}}:q.append((v,u))
for u in R[::-1]:
path=0;dp[u]+=1 if u in s else 0
for v ... | v!=p | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002213 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
from collections import deque
n=I();adj=[[] for i in range(n)]
for i in range(n-1):
p,q=M()
adj[p-1].append(q-1)
adj[q-1].append(p-1)
p=... | v[j]==0 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002214 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
from collections import deque
n=I();adj=[[] for i in range(n)]
for i in range(n-1):
p,q=M()
adj[p-1].append(q-1)
adj[q-1].append(p-1)
p=... | d[i-1]>m | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002215 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | def solve():
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
u, v = [int(t) for t in input().split()]
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
q = int(input())
for _ in range(q):
input()
S = [int(t)-1 for t i... | depth[nei] == -1 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002216 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | def solve():
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
u, v = [int(t) for t in input().split()]
u -= 1
v -= 1
g[u].append(v)
g[v].append(u)
q = int(input())
for _ in range(q):
input()
S = [int(t)-1 for t i... | prev[nei] == -1 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002217 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | import sys
from array import array
class graph:
def __init__(self, n):
self.n, self.gdict = n, [array('i') for _ in range(n + 1)]
def add_edge(self, node1, node2):
self.gdict[node1].append(node2)
self.gdict[node2].append(node1)
def dfs(self, root):
stk, ret =... | mem[ch] and stk | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002218 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = [int(x) - 1 for x in input().split()]
G[u].append(v)
G[v].append(u)
# build a tree with ... | v != par[u] | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002219 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = [int(x) - 1 for x in input().split()]
G[u].append(v)
G[v].append(u)
# build a tree with ... | u not in path | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002220 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | input = __import__('sys').stdin.readline
mapnode = lambda x: int(x)-1
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
u, v = map(mapnode, input().split())
adj[u].append(v)
adj[v].append(u)
# dfs
jump = [[0] * n]
depth = [0] * n
stack = [(0, -1)]
while len(stack) > 0:
... | v != par | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002237 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | input = __import__('sys').stdin.readline
mapnode = lambda x: int(x)-1
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
u, v = map(mapnode, input().split())
adj[u].append(v)
adj[v].append(u)
# dfs
jump = [[0] * n]
depth = [0] * n
stack = [(0, -1)]
while len(stack) > 0:
... | (step >> i) & 1 == 1 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002238 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from collections import defaultdict, deque, Counter
import sys
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools impo... | self.depth[v] == -1 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002239 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from collections import defaultdict, deque, Counter
import sys
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools impo... | not (opt_p == lca_p or ((D.lca(p1, opt_p) == opt_p) ^ (D.lca(p2, opt_p) == opt_p))) | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002240 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from collections import deque;import math
import sys;I=sys.stdin.readline;R=lambda:map(lambda x:int(x)-1,input().split())
n=int(I());g=[[] for _ in range(n)]
for _ in [0]*(n-1):
u,v=R();g[u].append(v);g[v].append(u)
h=math.ceil(math.log2(n))
fa=[[-1]*(h+1) for _ in range(n)];dep=[0]*n
q=deque([0])
while q:
... | v!=fa[u][0] | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002241 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from collections import deque;import math
import sys;I=sys.stdin.readline;R=lambda:map(lambda x:int(x)-1,input().split())
n=int(I());g=[[] for _ in range(n)]
for _ in [0]*(n-1):
u,v=R();g[u].append(v);g[v].append(u)
h=math.ceil(math.log2(n))
fa=[[-1]*(h+1) for _ in range(n)];dep=[0]*n
q=deque([0])
while q:
... | dep[v]+(1<<i)<=dep[u] | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002242 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def dfs(p , prev , lvl):
s = [[p , prev , lvl]]
while(len(s)):
p , prev , lvl = s.pop()
level[p] = lvl
parent[p][0] = prev
for i in child[p]:
if(i == prev)... | (maxval < level[a[i]]) | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002243 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def dfs(p , prev , lvl):
s = [[p , prev , lvl]]
while(len(s)):
p , prev , lvl = s.pop()
level[p] = lvl
parent[p][0] = prev
for i in child[p]:
if{{completio... | (i == prev) | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002244 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | import sys
class LCA:
def __init__(self, g, root=0):
self.g = g
self.root = root
n = len(g)
self.logn = (n - 1).bit_length()
self.depth = [None] * n
self.parent = [[None] * self.logn for _ in range(n)]
self._dfs()
self._doubling()
def _dfs(self)... | self.depth[v] is None | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002245 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | import sys
class LCA:
def __init__(self, g, root=0):
self.g = g
self.root = root
n = len(g)
self.logn = (n - 1).bit_length()
self.depth = [None] * n
self.parent = [[None] * self.logn for _ in range(n)]
self._dfs()
self._doubling()
def _dfs(self)... | p[i] is not None | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002246 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | from collections import Counter
for _ in range(int(input())):
n=int(input());
l=list(map(int, input().split()));c = Counter(l);
if {{completion}}:
print(-1); continue
print(*[i if i!=0 and l[i]==l[i-1] else i+c[l[i]] for i in range(n)]) | any(x == 1 for x in c.values()) | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002353 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | import collections
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
data = dict(collections.Counter(map(int, input().split())))
if min(list(data.values())) > 1:
last = 1
for i in data.keys():
print(last + data[i] - 1, end=' ')
... | j in range(last, last + data[i] - 1) | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002354 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | for t in range(int(input())):
n=int(input())
x=list(map(int,input().split()))
g={}
if n==1:
print(-1)
else:
for i in range(n-1):
if not((x[i]==x[i+1] or x[i]==x[i-1]) and ( x[-1]==x[-2])):
print(-1)
break
g[x[i]]=[]
... | q in range(len(j)) | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002355 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | t = int(input())
for i in range(t):
n = int(input())
s = [int(x) for x in input().split(' ')]
s.append('A')
f = 0
p = s[0]
c = 0
for x in range(n+1):
if s[x] == p:
s[x] = str(x)
c+=1
else:
if {{completion}}:
s ... | c == 1 | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002356 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
x=tuple(map(int,input().split()))
if n==1:
print(-1)
continue
ans=[-1]*n
extra=[]
visited=[False]*n
for i in range(n-1,-1,-1):
if i!=0 and x[i]==x[i-1]:
ans[i]=i
... | extra | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002357 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | from sys import stdin
input = stdin.readline
I = lambda : list(map(int, input().split()))
def solve(N,A):
dic = {}
for i in range(N):
if {{completion}}:
dic[A[i]] = []
dic[A[i]].append(i)
ans = [0]*N
for k in dic.keys():
l = dic[k]
if l... | A[i] not in dic | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002358 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | from sys import stdin
input = stdin.readline
I = lambda : list(map(int, input().split()))
def solve(N,A):
dic = {}
for i in range(N):
if A[i] not in dic:
dic[A[i]] = []
dic[A[i]].append(i)
ans = [0]*N
for k in dic.keys():
l = dic[k]
if ... | len(l) == 1 | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002359 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
freq = {}
for i in arr:
if(i in freq): freq[i] += 1
else: freq[i] = 1
for i in freq:
if(freq[i] == 1): #not in pairs
print(-1);break
else:
ans2 = []
... | j in range(1,freq[i]) | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002360 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | from bisect import bisect_left
cases = int(input())
for run in range(cases):
n = int(input())
shoes = input().split()
for x in range(len(shoes)):
shoes[x] = int(shoes[x])
perm = []
i = 0
while i < len(shoes) and perm != [-1]:
p = bisect_left(shoes,shoes[i]+1)-... | p == i | [{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}] | control_completion_002361 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(... | import sys
sys.setrecursionlimit(300000)
import faulthandler
faulthandler.enable()
n, k = map(int, input().split())
MOD = 10**9 + 7
fact = [1 for i in range(n+1)]
for i in range(2, n+1):
fact[i] = i*fact[i-1] % MOD
inv_fact = [1 for i in range(n+1)]
inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
for i in ... | visited[next_node] == 0 | [{"input": "3 2\n1 2\n1 3", "output": ["25"]}, {"input": "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7", "output": ["849"]}] | control_completion_002439 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(... | import sys
sys.setrecursionlimit(300000)
import faulthandler
faulthandler.enable()
n, k = map(int, input().split())
MOD = 10**9 + 7
fact = [1 for i in range(n+1)]
for i in range(2, n+1):
fact[i] = i*fact[i-1] % MOD
inv_fact = [1 for i in range(n+1)]
inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
for i in ... | visited[next_node] == 2 | [{"input": "3 2\n1 2\n1 3", "output": ["25"]}, {"input": "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7", "output": ["849"]}] | control_completion_002440 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(... | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
M = 10 ** 9 + 7
n, k = I()
binomk = [0] * k
binomk.append(1)
for i in range(k + 1, n + 1):
binomk.append(binomk[-1] * i *... | boi != parents[guy] | [{"input": "3 2\n1 2\n1 3", "output": ["25"]}, {"input": "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7", "output": ["849"]}] | control_completion_002441 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(... | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
M = 10 ** 9 + 7
n, k = I()
binomk = [0] * k
binomk.append(1)
for i in range(k + 1, n + 1):
binomk.append(binomk[-1] * i *... | boi in neighbors[guy] | [{"input": "3 2\n1 2\n1 3", "output": ["25"]}, {"input": "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7", "output": ["849"]}] | control_completion_002442 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Mike and Joe are playing a game with some stones. Specifically, they have $$$n$$$ piles of stones of sizes $$$a_1, a_2, \ldots, a_n$$$. These piles are arranged in a circle.The game goes as follows. Players take turns removing some positive nu... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | tc in range(testcaseCount) | [{"input": "2\n\n1\n\n37\n\n2\n\n100 100", "output": ["Mike\nJoe"]}] | control_completion_002447 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i == 0 and j == 0 | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002468 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002469 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i == 0 and j == 0 | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002470 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002471 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i == 0 and j == 0 | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002472 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | i | [{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}] | control_completion_002473 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Michael and Joe are playing a game. The game is played on a grid with $$$n$$$ rows and $$$m$$$ columns, filled with distinct integers. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by ... | import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]
def next(): return tokens.pop()
def nextInt(): return int(next())
def nextFloat(): return float(next())
def getIntArray(n): return [nextInt() for _ in range(n)]
def getFloatArray(n): return [nextFloat() for _ in range(n)]
def getStringArray(n): r... | A[i][j] > A[X][Y] | [{"input": "3\n\n1 1\n\n3\n\n4 4\n\n2 12 6 10\n\n3 15 16 4\n\n1 13 8 11\n\n14 7 9 5\n\n2 3\n\n-7 5 2\n\n0 8 -3", "output": ["1\n9\n4"]}] | control_completion_002489 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: AquaMoon has two binary sequences $$$a$$$ and $$$b$$$, which contain only $$$0$$$ and $$$1$$$. AquaMoon can perform the following two operations any number of times ($$$a_1$$$ is the first element of $$$a$$$, $$$a_2$$$ is the second element of... | import sys
def _input_iter():
for line in sys.stdin:
for part in line.strip().split(' '):
stripped = part.strip()
if {{completion}}:
yield stripped
def read_int():
return int(next(stream))
def read_str():
return next(stream)
def get_... | stripped | [{"input": "10\n\n6 2\n\n001001\n\n11\n\n6 2\n\n110111\n\n01\n\n6 2\n\n000001\n\n11\n\n6 2\n\n111111\n\n01\n\n8 5\n\n10000101\n\n11010\n\n7 4\n\n1010001\n\n1001\n\n8 6\n\n01010010\n\n010010\n\n8 4\n\n01010101\n\n1001\n\n8 4\n\n10101010\n\n0110\n\n7 5\n\n1011100\n\n11100", "output": ["YES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\... | control_completion_002573 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | R=lambda:map(int,input().split());G=range;t,=R()
for {{completion}}:
n,m=R();s=[sum(i*v for i,v in enumerate(R()))for _ in G(n)]
mx=max(s);print(s.index(mx)+1,mx-min(s)) | _ in G(t) | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002575 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | for _ in range(int(input())):
n, m = map(int, input().split())
vals = []
for _ in range(n):
count = 0
for {{completion}}:
count += a*b
vals.append(count)
c = vals.index(max(vals))
print(c + 1, vals[c] - vals[c-1]) | a, b in enumerate(map(int, input().split())) | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002576 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | case=int(input())
for i in range(case):
n,m = (int(v) for v in input().split())
tmp=0
for j in range(n):
list1 = [int(v) for v in input().split()]
value = 0
for k in range(m):
value += list1[k]*(k+1)
if j==0:
tmp = value
else:
if value > tmp:
print(str(j+... | value < tmp | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002577 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | input = __import__('sys').stdin.readline
def solve():
n, m = map(int, input().split())
mx = (0, -1)
mn = (10**18, -1)
for i in range(n):
current, total = 0, 0
for {{completion}}:
current += x
total += current
mx = max(mx, (total, ... | x in map(int, input().split()) | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002578 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | import sys
input= sys.stdin.readline
rn=lambda: [*map(int,input().split())]
for _ in range(*rn()):
n,m=rn()
b=[]
mm=0
for i in range(0,n):
a=sum([*map(lambda x,y:int(x)*y,input().split(),range(1,m+1))])
b.append(a)
if {{completion}}:
mm=i
print(mm... | a>b[mm] | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002579 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E... | for t in range(int(input())):
N, M = map(int, input().split())
minV = int(1e20)
maxV = -1
ret = 0
for index in range(N):
mlist = list(map(int, input().split()))
cur = sum([index*val for index, val in enumerate(mlist)])
minV = min(minV, cur)
if {{com... | maxV < cur | [{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ... | control_completion_002580 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$, consisting of lowercase Latin letters.You are asked $$$q$$$ queries about it: given another string $$$t$$$, consisting of lowercase Latin letters, perform the following steps: concatenate $$$s$$$ and $$$t$$$; ... | import sys
input = sys.stdin.readline
s = input().strip()
l = len(s)
d, p = [], [0]
d.append([1 if s[0] == chr(x+97) else 0 for x in range(26)])
for idx, i in enumerate(s):
if {{completion}}: continue
x = ord(i) - 97
d.append(d[p[idx-1]][:])
d[idx][x] = idx+1
p.append(d[p[idx-1]][x])
fo... | idx == 0 | [{"input": "aba\n6\ncaba\naba\nbababa\naaaa\nb\nforces", "output": ["0 1 2 3 \n1 2 3 \n2 3 4 5 6 7 \n1 1 1 1 \n2 \n0 0 0 0 0 0"]}, {"input": "aacba\n4\naaca\ncbbb\naab\nccaca", "output": ["2 2 3 1 \n0 0 0 0 \n2 2 0 \n0 0 1 0 1"]}] | control_completion_002643 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$, consisting of lowercase Latin letters.You are asked $$$q$$$ queries about it: given another string $$$t$$$, consisting of lowercase Latin letters, perform the following steps: concatenate $$$s$$$ and $$$t$$$; ... | import sys
input = sys.stdin.readline
s = input().strip()
l = len(s)
d, p = [], [0]
d.append([1 if s[0] == chr(x+97) else 0 for x in range(26)])
for idx, i in enumerate(s):
if idx == 0: continue
x = ord(i) - 97
d.append(d[p[idx-1]][:])
d[idx][x] = idx+1
p.append(d[p[idx-1]][x])
for i in... | idx, t in enumerate(input().strip()) | [{"input": "aba\n6\ncaba\naba\nbababa\naaaa\nb\nforces", "output": ["0 1 2 3 \n1 2 3 \n2 3 4 5 6 7 \n1 1 1 1 \n2 \n0 0 0 0 0 0"]}, {"input": "aacba\n4\naaca\ncbbb\naab\nccaca", "output": ["2 2 3 1 \n0 0 0 0 \n2 2 0 \n0 0 1 0 1"]}] | control_completion_002644 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pix... | import sys
if __name__ == "__main__":
input_arr = sys.stdin.read().split()
tc = int(input_arr[0])
pos = 1
for case in range(tc):
a1, a2 = input_arr[pos:pos + 2]
char = []
for i in a1:
char.append(i)
for j in a2:
char.append(j)
... | l == 3 | [{"input": "5\n\nrb\n\nbr\n\ncc\n\nwb\n\naa\n\naa\n\nab\n\ncd\n\nyy\n\nxx", "output": ["1\n2\n0\n3\n1"]}] | control_completion_002660 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pix... | import sys
if __name__ == "__main__":
input_arr = sys.stdin.read().split()
tc = int(input_arr[0])
pos = 1
for case in range(tc):
a1, a2 = input_arr[pos:pos + 2]
char = []
for i in a1:
char.append(i)
for j in a2:
char.append(j)
... | l == 2 | [{"input": "5\n\nrb\n\nbr\n\ncc\n\nwb\n\naa\n\naa\n\nab\n\ncd\n\nyy\n\nxx", "output": ["1\n2\n0\n3\n1"]}] | control_completion_002661 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given two arrays $$$a$$$ and $$$b$$$, consisting of $$$n$$$ integers each.Let's define a function $$$f(a, b)$$$ as follows: let's define an array $$$c$$$ of size $$$n$$$, where $$$c_i = a_i \oplus b_i$$$ ($$$\oplus$$$ denotes bitwise... | import sys
from itertools import permutations, combinations
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if len(lst) > 0:
ls.append(lst)
def solve(n, a, b):
ps = [((list(range(n))), (list(range(n))))]
res = (1<<30) - 1
for k in range(30, -1, -1):
next_ps ... | a[pai] & (1<<k) == 0 | [{"input": "3\n\n5\n\n1 0 0 3 3\n\n2 3 2 1 0\n\n3\n\n1 1 1\n\n0 0 3\n\n8\n\n0 1 2 3 4 5 6 7\n\n7 6 5 4 3 2 1 0", "output": ["2\n0\n7"]}] | control_completion_002690 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given two arrays $$$a$$$ and $$$b$$$, consisting of $$$n$$$ integers each.Let's define a function $$$f(a, b)$$$ as follows: let's define an array $$$c$$$ of size $$$n$$$, where $$$c_i = a_i \oplus b_i$$$ ($$$\oplus$$$ denotes bitwise... | import sys
from itertools import permutations, combinations
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if len(lst) > 0:
ls.append(lst)
def solve(n, a, b):
ps = [((list(range(n))), (list(range(n))))]
res = (1<<30) - 1
for k in range(30, -1, -1):
next_ps ... | b[pbi] & (1<<k) == 0 | [{"input": "3\n\n5\n\n1 0 0 3 3\n\n2 3 2 1 0\n\n3\n\n1 1 1\n\n0 0 3\n\n8\n\n0 1 2 3 4 5 6 7\n\n7 6 5 4 3 2 1 0", "output": ["2\n0\n7"]}] | control_completion_002691 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a_1, a_2, \dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, \dots, b_n$$$: Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-ne... | import sys
from math import ceil
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if len(lst) > 0:
ls.append(lst)
for l in ls:
sys.stderr.write(l + ('\n'))
sys.stderr.write("-- output --\n")
def at_least(L, x):
for i in range(len(L)):
if L[i] >= x:
return... | b[n-i-2] < a[n-i-1] | [{"input": "4\n\n3\n\n2 3 5\n\n7 11 13\n\n1\n\n1000\n\n5000\n\n4\n\n1 2 3 4\n\n1 2 3 4\n\n4\n\n10 20 30 40\n\n22 33 33 55", "output": ["5 4 2\n11 10 8\n4000\n4000\n0 0 0 0\n0 0 0 0\n12 2 3 15\n23 13 3 15"]}] | control_completion_002703 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a_1, a_2, \dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, \dots, b_n$$$: Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-ne... | import sys
from math import ceil
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if len(lst) > 0:
ls.append(lst)
for l in ls:
sys.stderr.write(l + ('\n'))
sys.stderr.write("-- output --\n")
def at_least(L, x):
for i in range(len(L)):
if L[i] >= x:
return... | b[imin] < a[i] | [{"input": "4\n\n3\n\n2 3 5\n\n7 11 13\n\n1\n\n1000\n\n5000\n\n4\n\n1 2 3 4\n\n1 2 3 4\n\n4\n\n10 20 30 40\n\n22 33 33 55", "output": ["5 4 2\n11 10 8\n4000\n4000\n0 0 0 0\n0 0 0 0\n12 2 3 15\n23 13 3 15"]}] | control_completion_002704 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: The robot is placed in the top left corner of a grid, consisting of $$$n$$$ rows and $$$m$$$ columns, in a cell $$$(1, 1)$$$.In one step, it can move into a cell, adjacent by a side to the current one: $$$(x, y) \rightarrow (x, y + 1)$$$; $... | import sys
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if {{completion}}:
ls.append(lst)
for l in ls:
sys.stderr.write(l + ('\n'))
sys.stderr.write("-- output --\n")
def ins(u, mn, mx):
return u[0] >= mn[0] and u[1] >= mn[1] and u[0] <= mx[0] and u[1] <= mx[1]
def clmp(... | len(lst) > 0 | [{"input": "3\n\n2 3 1 3 0\n\n2 3 1 3 1\n\n5 5 3 4 1", "output": ["3\n-1\n8"]}] | control_completion_002733 | control_fixed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.