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: Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees.There ... | v = int(input())
while v > 0:
n = int(input())
arr = input().split()
ori = int(arr[0])
temp = 0
ans = 0
x = 1
while x < n:
nex = int(arr[x])
ans += abs(nex - ori)
if {{completion}}:
temp += abs(nex - ori)
ori = nex
x += 1
... | nex - ori < 0 | [{"input": "4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5", "output": ["2\n13\n36\n33"]}] | control_completion_004123 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees.There ... | import sys
T = int(sys.stdin.readline())
for t in range(T):
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().strip().split(' ')]
l, r = 0, 0
for i in range(len(a) - 1):
x, y = a[i], a[i+1]
if x > y:
l += x - y
elif {{completion}}:
... | x < y | [{"input": "4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5", "output": ["2\n13\n36\n33"]}] | control_completion_004124 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $$$2$$$ rows and $$$n$$$ columns, every element of which is either $$$0$$$ or $$... |
# 1 0 0 1 0 0
# 0 1 0 0 0 1
# 1 1 1 2 2 2
# 0 1 1 1 1 2
# swap two same number is useless
# each time we swap i and i+1, only prefix of i is changed, either increased by 1 or decreased by 1
# same argument as of inversion, each time inversion can only increased by 1 or decreased by 1
# so in one step we can always mo... | s0 < 0 and s1 > 0 | [{"input": "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0", "output": ["5"]}, {"input": "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0", "output": ["-1"]}] | control_completion_004172 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $$$2$$$ rows and $$$n$$$ columns, every element of which is either $$$0$$$ or $$... | n=int(input())
s=input()[::2],input()[::2]
t=input()[::2],input()[::2]
d=[0,0]
total=0
for y in range(n):
for x in 0,1:
d[x]+=(s[x][y]=="1")-(t[x][y]=="1")
if d[0]>0 and d[1]<0:
total+=1
d[0]-=1
d[1]+=1
elif {{completion}}:
total+=1
d[0]+=1
... | d[0]<0 and d[1]>0 | [{"input": "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0", "output": ["5"]}, {"input": "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0", "output": ["-1"]}] | control_completion_004173 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $$$2$$$ rows and $$$n$$$ columns, every element of which is either $$$0$$$ or $$... | def solve():
# Size of the matrices.
n = int(input())
# Data matrix (the first two rows correspond to the original matrix
# and the last two to the target matrix).
matrix = []
# Read the input data.
for _ in range(4):
matrix.append([int(data) for data in input().split()])
... | top < 0 and 0 < bottom | [{"input": "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0", "output": ["5"]}, {"input": "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0", "output": ["-1"]}] | control_completion_004174 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | import math
lines = [*open(0)]
sizes = lines[1].split(' ')
tot, running = 0, 0
minval = 0
for lock in sizes:
tot += int(lock)
running += 1
minval = max(minval, tot/running)
for mintime in lines[3:]:
if {{completion}}:
print("-1")
else:
print(math.ceil(tot/int(mintime))) | (int(mintime) < minval) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004177 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | I=input;n=int(I());p=m=0
for {{completion}}:
p+=int(v);m=max(m,(p+i)//(i+1))
for _ in [0]*int(I()):
t=int(I());print([-1,(p+t-1)//t][t>=m]) | i,v in enumerate(I().split()) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004178 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | I=input;n=int(I());p=m=0
for i,v in enumerate(I().split()):
p+=int(v);m=max(m,(p+i)//(i+1))
for {{completion}}:
t=int(I());print([-1,(p+t-1)//t][t>=m]) | _ in [0]*int(I()) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004179 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | import math as ma
r = range
R = lambda: int(input())
num_of_locks = R()
vols_arr = list(map(int, input().split(" ")))
sum_of_vols = 0
avg_vols = []
for _ in r(len(vols_arr)): sum_of_vols += vols_arr[_]; avg_vols += ma.ceil(sum_of_vols/(_ + 1)),
max_avg_vols = max(avg_vols)
for _ in r(R()):
liters = R();... | max_avg_vols > liters | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004180 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | n = int(input())
a = list(map(int, input().split()))
maxi = tot = 0
for i, j in enumerate(a, 1):
tot += j
maxi = max(maxi, (tot+i-1) // i)
q = int(input())
for _ in range(q):
k = int(input())
if {{completion}}:
print(-1)
else:
# open x pipe
# time = ceil(sum / x) => x increa... | k < maxi | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004181 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | from sys import stdin, stderr
def debug(*args, **kwargs):
print(*args, file=stderr, **kwargs)
_, volumes, _, *queries = stdin.readlines()
volumes = map(int, volumes.split())
queries = map(int, queries)
s = t_min = 0
for i, v in enumerate(volumes, 1):
s += v
div, mod = divmod(s, i)
t_min = max(t_min... | q < t_min | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004182 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | import itertools
m=0
n = int(input())
v = list(itertools.accumulate(map(int, input().split())))
for {{completion}}:
m=max((v[i]-1)//(i+1)+1,m)
for _ in range(int(input())):
t = int(input())
print((v[-1] - 1) // t + 1 if t >= m else -1)
| i in range(n) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004183 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | import itertools
m=0
n = int(input())
v = list(itertools.accumulate(map(int, input().split())))
for i in range(n):
m=max((v[i]-1)//(i+1)+1,m)
for {{completion}}:
t = int(input())
print((v[-1] - 1) // t + 1 if t >= m else -1)
| _ in range(int(input())) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004184 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | number = int(input())
V = [int(i) for i in input().split()]
time,total = 0,0
for i in range(number):
total += V[i]
time = max(time,(total+i)//(i+1))
pass
for q in range(int(input())):
t = int(input())
if{{completion}}: print(-1)
else: print((total+t-1)//t)
pass | (t<time) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004185 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | from math import ceil
r = range;i = lambda: int(input());s = lambda: input().split()
for _ in r(1):
n = i();v = list(map(int,s()))
dp = [];sum = 0;max = 0
for _ in r(n):
sum += v[_];val = ceil(sum/(_+1))
dp += val, #comma --> tuple element
if{{completion}}: max = val
for... | (val > max) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004186 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | #from math import ceil, floor, gcd, log
#import heapq as hq
#from collections import defaultdict as dd
#mydd=dd(list) for .append
#from collections import deque as dq #deque e.g. myqueue=dq(list)
#append/appendleft/appendright/pop/popleft
import sys
input = sys.stdin.readline
############ ---- Input Function... | chkb(b[k2][0],b[k2][1]) | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004218 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | #from math import ceil, floor, gcd, log
#import heapq as hq
#from collections import defaultdict as dd
#mydd=dd(list) for .append
#from collections import deque as dq #deque e.g. myqueue=dq(list)
#append/appendleft/appendright/pop/popleft
import sys
input = sys.stdin.readline
############ ---- Input Function... | chkb(k[0],k[1]) | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004219 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | (r1 != x or c1 != y) and swapAndCheck(r, c, x, y) | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004220 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.wri... | y in range(m) | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004221 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | import os
import sys
from io import BytesIO, IOBase
#_str = str
#str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "... | not check(bx, by) | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004222 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Little pirate Serega robbed a ship with puzzles of different kinds. Among all kinds, he liked only one, the hardest.A puzzle is a table of $$$n$$$ rows and $$$m$$$ columns, whose cells contain each number from $$$1$$$ to $$$n \cdot m$$$ exactl... | import os
import sys
from io import BytesIO, IOBase
#_str = str
#str = lambda x=b"": x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "... | bx, by in bad | [{"input": "3 3\n2 1 3\n6 7 4\n9 8 5", "output": ["0"]}, {"input": "2 3\n1 6 4\n3 2 5", "output": ["1 3"]}, {"input": "1 6\n1 6 5 4 3 2", "output": ["2"]}] | control_completion_004223 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from collections import Counter
import heapq
for _ in range(int(input())):
_ = input()
l = input().split()
cnt = Counter(l)
x = list(cnt.values())
x.append(1)
hp = []
x.sort()
for i, n in enumerate(x):
if {{completion}}:
heapq.heappush(hp, -(n-... | n-i-1 > 0 | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004306 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | t = int(input())
for i in range(t):
n = int(input())
p = [int(value) for value in input().split()]
tree = [0] * n
for i in range(len(p)):
tree[p[i] - 1] += 1
tree = sorted(tree)
resposta = 0
r = n
while resposta <= r:
s = 0
c = 1
... | tree[i] == 0 | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004307 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from heapq import *
for _ in range(int(input())):
n = int(input())
pp = list(map(int, input().split()))
sibs = [[] for _ in range(n+1)]
for i,p in enumerate(pp, 2):
sibs[p].append(i)
child_infected = [False] * (n+1)
isibs = sorted(range(1, n+1), key=lambda x:len(sibs[x]), reverse=True)
... | to_spread and to_spread[0][0] <= turn | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004308 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from heapq import *
for _ in range(int(input())):
n = int(input())
pp = list(map(int, input().split()))
sibs = [[] for _ in range(n+1)]
for i,p in enumerate(pp, 2):
sibs[p].append(i)
child_infected = [False] * (n+1)
isibs = sorted(range(1, n+1), key=lambda x:len(sibs[x]), reverse=True)
... | remain <= 0 | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004309 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from sys import stdin, stdout
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
parents = [int(x) for x in stdin.readline().split()]
counts = defaultdict(int)
counts[0] = 1
for i in parents:
counts[i] += 1
lives = [... | lives[i] > current_max | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004310 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | for _ in [0] * int(input()):
n = int(input())
a = list(map(int, input().split()))
c = [0] * n + [1]
for i in a:
c[i - 1] += 1
c = sorted(c, reverse=True)
ans = sum(i > 0 for i in c)
for i, j in enumerate(c):
if j > 0:
c[i] = i + j - ans
c = sorted([... | j > 0 | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004311 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | inf=10**18
dxy=[(0,1), (1,0), (-1, 0), (0, -1)]
mod=10**9+7
MOD=998244353
from collections import Counter
def solve():
n = int(input())
p = [int(i)-1 for i in input().split()]
c = Counter(p)
ans = len(c.values())+1
adi = []
for i, n in enumerate(sorted(c.values(), reverse=True)):
... | i in adi | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004312 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | inf=10**18
dxy=[(0,1), (1,0), (-1, 0), (0, -1)]
mod=10**9+7
MOD=998244353
from collections import Counter
def solve():
n = int(input())
p = [int(i)-1 for i in input().split()]
c = Counter(p)
ans = len(c.values())+1
adi = []
for i, n in enumerate(sorted(c.values(), reverse=True)):
... | is_ok(mid) | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004313 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from heapq import heappop, heappush
t = int(input())
const = 1 << 18
for T in range(t):
n = int(input())
arr = [int(x) for x in input().split(" ")]
things = {0: const}
for x in range(len(arr)):
if arr[x] in things:
things[arr[x]] += 1
else:
things... | f > time | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004314 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from heapq import heappop, heappush
t = int(input())
const = 1 << 18
for T in range(t):
n = int(input())
arr = [int(x) for x in input().split(" ")]
things = {0: const}
for x in range(len(arr)):
if arr[x] in things:
things[arr[x]] += 1
else:
things... | f > time | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004315 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from collections import defaultdict
counter = defaultdict(int)
def solve(a):
for ai in a:
counter[ai] += 1
count = list(counter.values())
num_level = len(count)
count.sort()
for i in range(num_level):
count[i] = max(count[i] - i - 2, 0)
L = 0; R = max(count)... | i in range(len(b)) | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004316 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from collections import defaultdict
counter = defaultdict(int)
def solve(a):
for ai in a:
counter[ai] += 1
count = list(counter.values())
num_level = len(count)
count.sort()
for i in range(num_level):
count[i] = max(count[i] - i - 2, 0)
L = 0; R = max(count)... | sum(b) <= k | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004317 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import Counter
for _ in range(int(input())):
n = int(input())
m = max(Counter(input().split()).values())
ans = n-m
while {{completion}}:
ans += 1
m *= 2
print(ans)
| m<n | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004333 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import*
for a in[*open(0)][2::2]:
n=len(a:=a.split());m=max(Counter(a).values());r=0
while {{completion}}:r+=min(m,n-m)+1;m*=2
print(r) | m<n | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004334 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | import math
for t in range(int(input())):
n=int(input())
L=input().split()
count={}
for {{completion}}:
try:
count[i]+=1
except:
count[i]=1
m=max(list(count.values()))
print(int(n-m + math.ceil(math.log(n/m,2)))) | i in L | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004335 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | if True:
from collections import Counter
t = int(input())
for {{completion}}:
n = int(input())
d = Counter(input().split()).most_common(1)[0][1]
print([i for i in range(18) if (2**i)*d >= n][0]+n-d) | _ in range(t) | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004336 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from sys import stdin
t = int(stdin.readline())
while t>0:
t -= 1
n = int(stdin.readline())
a = sorted(list(map(int,stdin.readline().split())))
M = 1
temp = 1
for i in range(1,n):
if {{completion}}:
temp = 1
else:
temp += 1
... | a[i]>a[i-1] | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004337 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | for i in range(int(input())):
n=int(input())
a=input().split()
from collections import Counter
e,bb=Counter(a).most_common(1)[0]
c=n-bb
while {{completion}}:
c+=1
bb*=2
print(c) | bb<n | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004338 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import Counter
for li in[*open(0)][2::2]:
n=len(li:=li.split());
m = max(Counter(li).values())
ans =n-m
while{{completion}}:
ans+=1
m=2*m
print(ans) | (m<n) | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004339 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import Counter
def solve():
n = int(input())
freq = max(Counter(input().split()).values())
left = n - freq
ans=0
while{{completion}}:
ans += 1+min(left,freq)
left = left - min(left,freq)
freq=2*freq
print(ans)
while(True):
... | (left) | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004340 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import Counter
def solve():
n = int(input())
freq = max(Counter(input().split()).values())
left = n - freq
ans=0
while(left):
ans += 1+min(left,freq)
left = left - min(left,freq)
freq=2*freq
print(ans)
while(True):
try:
... | i in range (test) | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004341 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from sys import stdin, stdout
from collections import Counter
for _ in range(int(stdin.readline().strip())):
n = int(stdin.readline().strip())
b = a = max(Counter(stdin.readline().split()).items(), key = lambda x:x[1])[1]
ans = n - a
while {{completion}}:
a = a + a
ans += 1
... | a < n | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004342 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | N=int(input())
for _ in range(N):
n = int(input())
list_num = input().split(' ')
d = dict()
for num in list_num:
if {{completion}}:
d[num] = d[num] + 1
else:
d[num] = 1
max_num = max(d.values())
now = max_num
ans = 0
copy = 0
... | num in d | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004343 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | N=int(input())
for _ in range(N):
n = int(input())
list_num = input().split(' ')
d = dict()
for num in list_num:
if num in d:
d[num] = d[num] + 1
else:
d[num] = 1
max_num = max(d.values())
now = max_num
ans = 0
copy = 0
while ... | copy > 0 | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | control_completion_004344 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | t=int(input())
for i in range (t):
n = int(input())
m=n//4
if n%4==0:
print(m,m,m,m,end=' ')
elif {{completion}}:
print(m,2*m,m,1,end=' ')
elif n%4==2:
print(2*m-1,2*m+1,1,1,end=' ')
else:
print(2,4*m-2,2,1,end=' ')
print(sep='') | n%4==1 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004366 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | t=int(input())
for i in range (t):
n = int(input())
m=n//4
if n%4==0:
print(m,m,m,m,end=' ')
elif n%4==1:
print(m,2*m,m,1,end=' ')
elif {{completion}}:
print(2*m-1,2*m+1,1,1,end=' ')
else:
print(2,4*m-2,2,1,end=' ')
print(sep='') | n%4==2 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004367 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | for _ in range(int(input())):
n = int(input())
if n == 4:
a = b = c = d = 1
elif n == 5:
a = c = d = 1
b = 2
elif n == 6:
a = c = d = 1
b = 3
elif {{completion}}:
c = d = b = 2
a = n-6
elif n%4 == 1:
d = 1
... | n%4 == 0 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004368 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | for _ in range(int(input())):
n = int(input())
if n == 4:
a = b = c = d = 1
elif n == 5:
a = c = d = 1
b = 2
elif n == 6:
a = c = d = 1
b = 3
elif n%4 == 0:
c = d = b = 2
a = n-6
elif {{completion}}:
d = 1
... | n%4 == 1 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004369 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | t = int(input())
for _ in range(t):
n = int(input())
ans = []
if n == 5:
ans = [1, 2, 1, 1]
elif {{completion}}:
ans = [n // 4] * 4
elif n % 2 == 0:
ans = [(n - 2) // 2 - 1, (n - 2) // 2 + 1, 1, 1]
else:
a, c, d = 2, 2, 1
b = n - a - c - d
... | n % 4 == 0 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004370 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | t = int(input())
for _ in range(t):
n = int(input())
ans = []
if n == 5:
ans = [1, 2, 1, 1]
elif n % 4 == 0:
ans = [n // 4] * 4
elif {{completion}}:
ans = [(n - 2) // 2 - 1, (n - 2) // 2 + 1, 1, 1]
else:
a, c, d = 2, 2, 1
b = n - a - c - d
... | n % 2 == 0 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004371 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | for _ in range(int(input())):
a=int(input())
if a%4==0:
print(a//4,a//4,a//4,a//4)
else:
if a%2==1:
a1=(a-1)
if a1%3==0:
print(a1//3,a1//3,a1//3,1)
elif a1%4!=0:
a1=a-2
print(a1//2,a1//2+1,1,1)
... | a1%4==0 | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | control_completion_004372 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bi... | t = int(input())
for test in range(t):
a = []
while len(a) != 8:
s = input()
if (len(s) == 8):
a.append(s)
x = 0
y = 0
for i in range(1, 7):
for j in range(1, 7):
if {{completion}}:
x = i
y = j
pr... | (a[i][j] == '#' and a[i-1][j+1] == '#' and a[i-1][j-1] == '#') | [{"input": "3\n\n\n\n\n.....#..\n\n#...#...\n\n.#.#....\n\n..#.....\n\n.#.#....\n\n#...#...\n\n.....#..\n\n......#.\n\n\n\n\n#.#.....\n\n.#......\n\n#.#.....\n\n...#....\n\n....#...\n\n.....#..\n\n......#.\n\n.......#\n\n\n\n\n.#.....#\n\n..#...#.\n\n...#.#..\n\n....#...\n\n...#.#..\n\n..#...#.\n\n.#.....#\n\n#......."... | control_completion_004538 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | import sys
n = int(input())
a = [int(x)-1 for x in sys.stdin.readline().split()]
depth = [1]*n
best = [0]*n
for i in range(n-1, -1, -1):
best[i] = max(best[i], depth[i])
if {{completion}}:
parent = a[i-1]
depth[parent] = max(depth[parent], 1 + depth[i])
best[parent] += best[i]
... | i != 0 | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004632 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | mod = 998244353
def main():
import sys
input = sys.stdin.readline
N = int(input())
P = [0, 0] + list(map(int, input().split()))
child = [[] for _ in range(N + 1)]
for v in range(2, N+1):
p = P[v]
child[p].append(v)
dp = [0] * (N + 1)
dp2 = [0] * (N + ... | c in child[v] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004633 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | n=int(input())
a=[-1]+[int(o)-1 for o in input().split()]
f=[0]*n
dp=[0]*n
for {{completion}}:
f[a[i]]=max(f[i]+1,f[a[i]])
for i in range(n-1,0,-1):
dp[i]=max(dp[i],f[i]+1)
dp[a[i]]+=dp[i]
print(max(dp[0],f[0]+1)) | i in range(n-1,0,-1) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004634 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | n=int(input())
a=[-1]+[int(o)-1 for o in input().split()]
f=[0]*n
dp=[0]*n
for i in range(n-1,0,-1):
f[a[i]]=max(f[i]+1,f[a[i]])
for {{completion}}:
dp[i]=max(dp[i],f[i]+1)
dp[a[i]]+=dp[i]
print(max(dp[0],f[0]+1)) | i in range(n-1,0,-1) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004635 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | I,G=input,range;n=int(I());p=[-1,0]+[*map(int,I().split())];h=[1]*(n+1);F=[0]*(n+1)
for {{completion}}:h[p[i]]=max(h[i]+1,h[p[i]])
for i in G(n,0,-1):F[i]=max(F[i],h[i]);F[p[i]]+=F[i]
print(F[1]) | i in G(n,1,-1) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004636 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | I,G=input,range;n=int(I());p=[-1,0]+[*map(int,I().split())];h=[1]*(n+1);F=[0]*(n+1)
for i in G(n,1,-1):h[p[i]]=max(h[i]+1,h[p[i]])
for {{completion}}:F[i]=max(F[i],h[i]);F[p[i]]+=F[i]
print(F[1]) | i in G(n,0,-1) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004637 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | n = int(input())
a = [*map(lambda x:int(x)-1,input().split())]
edge = [[] for _ in range(n)]
for i,p in enumerate(a,1): edge[p] += i,
dp = [[1,0] for _ in range(n)]
for r in range(n-1,-1,-1):
for {{completion}}:
k = max(dp[v])
dp[r][1] += k
dp[r][0] = max(dp[r][0],dp[v][0]+1)
pr... | v in edge[r] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004638 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is given an array $$$a$$$ of $$$n$$$ integers. For each $$$i$$$ ($$$1 \leq i \leq n$$$), Pak Chanek will write the one-element set $$$\{a_i\}$$$ on a whiteboard.After that, in one operation, Pak Chanek may do the following: Choose... | from sys import stdin, stdout
from collections import defaultdict
N = 998244353
n = int(stdin.readline())
a = [int(x)-1 for x in stdin.readline().split()]
count = [0]*n
row_values = [0]*n
for i in range(n):
row_values[count[a[i]]] += 1
count[a[i]] += 1
row_values_pref = [row_values[0]]
for i ... | last <= min(row_values_pref[i]-total, n-total) | [{"input": "6\n1 1 2 1 4 3", "output": ["7"]}, {"input": "7\n3 5 4 3 7 4 5", "output": ["11"]}] | control_completion_004651 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is given an array $$$a$$$ of $$$n$$$ integers. For each $$$i$$$ ($$$1 \leq i \leq n$$$), Pak Chanek will write the one-element set $$$\{a_i\}$$$ on a whiteboard.After that, in one operation, Pak Chanek may do the following: Choose... | import sys
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return map(int, s)
# t = getInt()
t = 1
M = 998244353
def solve():
n = getInt()
a ... | i + x <= lim[j+1] | [{"input": "6\n1 1 2 1 4 3", "output": ["7"]}, {"input": "7\n3 5 4 3 7 4 5", "output": ["11"]}] | control_completion_004652 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | g=10**9+7
v=[1]+[0]*40001
for i in range(1,40001):
if str(i)==str(i)[::-1]:
for {{completion}}:v[j]=v[j]%g+v[j-i]
for n in[*open(0)][1:]:print(v[int(n)]%g) | j in range(i,40001) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004686 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | p=[]
for i in range(1,40004):
s=str(i)
if s==s[::-1]:
p+=[i]
n=40004
d=[0]*(n+1)
for pj in p:
d[0] = 1
for i in range(1,n+1):
if {{completion}}:
d[i]+=d[i-pj]
d[i]=d[i]%int(1e9+7)
for _ in range(int(input())):
print(d[int(input())])
| pj<=i | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004687 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | n = int(input())
def getList():
return map(int, input().split())
def getInt():
return int(input())
N = 4 * 10 ** 4 + 10
M = 10 ** 9 + 7
dp = [0] * N
for i in range(1, N):
if str(i) == str(i)[::-1]:
dp[i] += 1
for {{completion}}:
dp[j] += dp[j-i]
dp[j] %= M
de... | j in range(i, N) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004688 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | from sys import stdin,stdout
input = lambda : stdin.readline().rstrip()
print =lambda x : stdout.write(str(x))
dp = [0 for _ in range(40002)]
dp[0] = 1
for i in range(1, 40001):
if str(i) == str(i)[::-1]:
for {{completion}}:
dp[j] = (dp[j]+dp[j-i])%int(1e9+7)
for _ in range(int(input(... | j in range(i, 40001) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004689 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | R=range
m=40001
d=10**9+7
p=[]
for i in R(1,m):
n=str(i)
if {{completion}}:p+=[i]
a=[1]+[0]*m
for i in p:
for j in R(i,m):
a[j]+=a[j-i];a[j]%=d
for n in[*open(0)][1:]:print(a[int(n)]) | n==n[::-1] | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004690 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | R=range
m=40001
d=10**9+7
p=[]
for i in R(1,m):
n=str(i)
if n==n[::-1]:p+=[i]
a=[1]+[0]*m
for i in p:
for {{completion}}:
a[j]+=a[j-i];a[j]%=d
for n in[*open(0)][1:]:print(a[int(n)]) | j in R(i,m) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004691 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | import sys
input = sys.stdin.readline
s = []
c = [1]
for y in range(1,40005):
if str(y) == (str(y))[::-1]:
s.append(y)
c.append(0)
for i in s:
for j in range(1,40005):
if {{completion}}:
c[j] += (c[j - i]) % ((10 ** 9) + 7)
a = int(input())
for... | j >= i | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004692 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | d=[0]*40001
d[0]=1
for x in range(1,40001):
if str(x)==str(x)[::-1]:
for {{completion}}:
d[i]=(d[i]+d[i-x])%(10**9+7)
for _ in range(int(input())):
print(d[int(input())])
| i in range(x,40001) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004693 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | size = int(4e4)+1
ps=[]
i=1
while (i<size):
if str(i) == str(i)[::-1]:
ps.append(i)
i+=1
pm = [0]*size
pm[0]=1
for p in ps:
i=0
while (i<size):
if {{completion}}:
break
pm[i+p]+=pm[i]
pm[i+p]%=int(1e9)+7
i+=1
T = int(input())
fo... | i+p >= size | [{"input": "2\n5\n12", "output": ["7\n74"]}] | control_completion_004694 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | for {{completion}}:
s = input()
c = len(set(s))
print("Yes" if all(len(set(s[i::c])) == 1 for i in range(c)) else "No")
| _ in range(int(input())) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004707 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
s = input()[:-1]
a = len(s)
b = len(set(s))
if b == 1 or a == b:
print('YES')
else:
for i in range(1, a):
if s[i] in s[:i]:
w = (s[:i]*a)[:a]
if {{comp... | s == w | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004708 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | t = int(input())
while (t > 0):
t -= 1
s = str(input())
var = set(s)
ans = "YES"
for i in range(len(s)-len(var)+1):
if {{completion}}:
ans = "NO"
break
print(ans) | len(set(s[i:i+len(var)])) != len(var) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004709 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | def solve(s):
st=set(s)
a=len(st)
f=1
for i in range(len(s)):
if {{completion}}:
f=0
if not f:
return "NO"
else:
return "YES"
for i in range(int(input())):
s=input()
print(solve(s)) | s[i]!=s[i%a] | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004710 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | for _ in range(int(input())):
n=input()
s=len(set(n))
for i in range(len(n)-s):
if {{completion}}:print("NO");break
else:print("YES") | n[i]!=n[i+s] | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004711 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | for i in range(int(input())):
count={}
str = input()
for char in str:
count[char] = 0
res = True
for i in range(len(str) - len(count.keys())):
if {{completion}}:
res = False
print("YES" if res else "NO")
| (str[i]!=str[i + len(count.keys())]) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004712 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | t = int(input())
while(t):
s = input()
d = len(set(s))
for i in range(d, len(s)):
if{{completion}}:
print("No")
break
else:
print("Yes")
t -= 1 | (s[i] != s[i - d]) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004713 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | n = int(input())
for i in range(n):
str1 = input()
set_char = set(str1)
req = len(set_char)
prev = dict()
truth = True
ind = 0
for i1 in str1:
if{{completion}}:
truth = False
break
prev[i1] = ind
ind += 1
print(truth and 'YES' or 'NO') | ( i1 in prev and ind - prev[i1] != req) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004714 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | for {{completion}}:
string=tuple(input().strip())
k=len(set(string))
print("NO" if any([string[i]!=string[i%k] for i in range (len(string))]) else "YES")
| _ in range(int(input())) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004715 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Alice and Bob are playing a game with strings. There will be $$$t$$$ rounds in the game. In each round, there will be a string $$$s$$$ consisting of lowercase English letters. Alice moves first and both the players take alternate turns. Alice ... | from sys import stdin
from collections import deque
lst = stdin.read().split()
_s = 0
def inp(n=1):
global _s
ret = lst[_s:_s + n]
_s += n
return ret
def inp1():
return inp()[0]
t = int(inp1())
for _ in range(t):
alph = "abcdefghijklmnopqrstuvwxyz"
a = list(map(lambda c: alph.ind... | o1 > o2 | [{"input": "5\n\naba\n\nabc\n\ncba\n\nn\n\ncodeforces", "output": ["Alice 2\nAlice 4\nAlice 4\nBob 14\nAlice 93"]}] | control_completion_004760 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Consider every tree (connected undirected acyclic graph) with $$$n$$$ vertices ($$$n$$$ is odd, vertices numbered from $$$1$$$ to $$$n$$$), and for each $$$2 \le i \le n$$$ the $$$i$$$-th vertex is adjacent to exactly one vertex with a smaller... | MOD = 998244353
def modmul(x, y, c = 0):
return (x * y + c) % MOD
def inv(x):
return pow(x, MOD - 2, MOD)
MAX = 10 ** 6
fact = [1]
for {{completion}}:
fact.append(modmul(i, fact[i-1]))
invfact = [1] * (MAX)
invfact[MAX - 1] = inv(fact[MAX - 1])
for i in range(MAX - 2, -1, -1):
invf... | i in range(1, MAX) | [{"input": "3", "output": ["1 1 0"]}, {"input": "5", "output": ["10 10 4 0 0"]}, {"input": "7", "output": ["276 276 132 36 0 0 0"]}] | control_completion_004994 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Consider every tree (connected undirected acyclic graph) with $$$n$$$ vertices ($$$n$$$ is odd, vertices numbered from $$$1$$$ to $$$n$$$), and for each $$$2 \le i \le n$$$ the $$$i$$$-th vertex is adjacent to exactly one vertex with a smaller... | MOD = 998244353
def modmul(x, y, c = 0):
return (x * y + c) % MOD
def inv(x):
return pow(x, MOD - 2, MOD)
MAX = 10 ** 6
fact = [1]
for i in range(1, MAX):
fact.append(modmul(i, fact[i-1]))
invfact = [1] * (MAX)
invfact[MAX - 1] = inv(fact[MAX - 1])
for {{completion}}:
invfact[i] = ... | i in range(MAX - 2, -1, -1) | [{"input": "3", "output": ["1 1 0"]}, {"input": "5", "output": ["10 10 4 0 0"]}, {"input": "7", "output": ["276 276 132 36 0 0 0"]}] | control_completion_004995 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three t... | import sys
# https://codeforces.com/contest/1701/problem/F
MAXN = 200000
class SegmentTree:
def __init__(self):
self.lazy = []
self.v0 = []
self.v1 = []
self.v2 = []
self.active = []
for _ in range(4 * MAXN + 1):
self.lazy.append(0)
... | up | [{"input": "7 5\n8 5 3 2 1 5 6", "output": ["0\n0\n1\n2\n5\n1\n5"]}] | control_completion_005124 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three t... | import sys
# https://codeforces.com/contest/1701/problem/F
MAXN = 200000
class SegmentTree:
def __init__(self):
self.lazy = []
self.v0 = []
self.v1 = []
self.v2 = []
self.active = []
for {{completion}}:
self.lazy.append(0)
... | _ in range(4 * MAXN + 1) | [{"input": "7 5\n8 5 3 2 1 5 6", "output": ["0\n0\n1\n2\n5\n1\n5"]}] | control_completion_005125 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three t... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer... | ((r >> i) << i) != r | [{"input": "7 5\n8 5 3 2 1 5 6", "output": ["0\n0\n1\n2\n5\n1\n5"]}] | control_completion_005126 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three t... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer... | l & 1 | [{"input": "7 5\n8 5 3 2 1 5 6", "output": ["0\n0\n1\n2\n5\n1\n5"]}] | control_completion_005127 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | n,k = map(int,input().split())
ns = set()
for {{completion}}:
s = tuple(int(v) for v in input().split())
ns.add(s)
arr = [[tuple((6-v1[i]-v2[i])%3 for i in range(k)) in ns for v1 in ns] for v2 in ns]
ans = 0
for i in range(n):
s = sum(arr[i])-2
ans += s*s//8
print(ans) | _ in range(n) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005220 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | n,k = map(int,input().split())
ns = set()
for _ in range(n):
s = tuple(int(v) for v in input().split())
ns.add(s)
arr = [[tuple((6-v1[i]-v2[i])%3 for i in range(k)) in ns for v1 in ns] for v2 in ns]
ans = 0
for {{completion}}:
s = sum(arr[i])-2
ans += s*s//8
print(ans) | i in range(n) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005221 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | from sys import stdin
def missing(c1, c2):
c3 = []
for i in range(len(c1)):
if c1[i] == c2[i]:
c3.append(c1[i])
else:
c3.append(next(iter({"0", "1", "2"}.difference({c1[i], c2[i]}))))
return "".join(c3)
def solve():
n, k = map(int, stdin.readline()... | m in off1 | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005222 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | ndfeagbb, dfeagbbk = map(int, input().split())
cards = [tuple(map(int, input().split())) for _ in range(ndfeagbb)]
cards_lookup, counter = {card: i for i, card in enumerate(cards)}, [0] * (ndfeagbb + 1)
for i in range(len(cards) - 1):
for {{completion}}:
counter[cards_lookup.get(tuple(x if x == y else ... | j in range(i + 1, len(cards)) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005223 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | from sys import stdin, stdout
n, k = [int(x) for x in stdin.readline().split()]
cards = set()
for i in range(n):
cards.add(tuple([int(x) for x in stdin.readline().split()]))
answer = 0
for card in cards:
yes_v = 0
for v in cards:
w = []
for {{completion}}:
w.append... | i in range(k) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005224 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | from sys import stdin, stdout
n, k = [int(x) for x in stdin.readline().split()]
cards = set()
for i in range(n):
cards.add(tuple([int(x) for x in stdin.readline().split()]))
answer = 0
for card in cards:
yes_v = 0
for v in cards:
w = []
for i in range(k):
w.append(... | tuple(w) in cards | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005225 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | import sys; R = sys.stdin.readline
n,k = map(int,R().split())
deck = [tuple(map(int,R().split())) for _ in range(n)]
dic = {}
for i in range(n): dic[deck[i]] = i
res = [0]*n
for p in range(n-2):
for q in range(p+1,n-1):
last = [0]*k
for {{completion}}:
last[j] = deck[p][j] if d... | j in range(k) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005226 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | import sys; R = sys.stdin.readline
n,k = map(int,R().split())
deck = [tuple(map(int,R().split())) for _ in range(n)]
dic = {}
for i in range(n): dic[deck[i]] = i
res = [0]*n
for p in range(n-2):
for q in range(p+1,n-1):
last = [0]*k
for j in range(k):
last[j] = deck[p][j] if de... | last in dic and dic[last]>q | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005227 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... |
n,k=map(int,input().split())
a=[]
d={}
for i in range(n):
a+=[''.join(input().split())]
d[a[-1]]=0
def cal(s,t):
res=""
for {{completion}}:
res+=str((9-int(s[i])-int(t[i]))%3)
return res
for i in range(n):
for j in range(i):
try:
d[cal(a[i],a... | i in range(k) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005228 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... |
n,k=map(int,input().split())
a=[]
d={}
for i in range(n):
a+=[''.join(input().split())]
d[a[-1]]=0
def cal(s,t):
res=""
for i in range(k):
res+=str((9-int(s[i])-int(t[i]))%3)
return res
for i in range(n):
for {{completion}}:
try:
d[cal(a[i],a... | j in range(i) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005229 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... | n, k = [int(i) for i in input().split()]
a = []
for _ in range(n):
a.append(tuple([int(i) for i in input().split()]))
a = tuple(a)
sus = set(a)
cs = [0 for i in range(n)]
for i in range(n):
p = a[i]
for j in set(range(n)) - set(tuple([i])):
q = a[j]
r = []
for o in rang... | p[o] == q[o] | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005230 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$... | for {{completion}}:
n = input()
a = sorted(map(int, input().split()))
print(a[-1] + a[-2] - a[0] - a[1]) | _ in range(int(input())) | [{"input": "4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8", "output": ["9\n297\n0\n14"]}] | control_completion_005295 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$... | for {{completion}}:a,b,*_,c,d=sorted(map(int,s.split()));print(c+d-a-b) | s in[*open(0)][2::2] | [{"input": "4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8", "output": ["9\n297\n0\n14"]}] | control_completion_005296 | control_fixed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.