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: A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $$$5$$$ players in one team for each match). There are $$$N$$$ candidate players in the competition that will be t... | d = int(input().split(" ")[1])
p = sorted(map(int, input().split(" ")))
c = 0
l = 0
r = len(p) - 1
s = p[r]
while r > l:
while s <= d:
s += p[r]
l += 1
if l > r:
{{completion}}
r -= 1
s = p[r]
c += 1
if p[0] > d:
c += 1
print(c)
| break | [{"input": "6 180\n90 80 70 60 50 100", "output": ["2"]}] | block_completion_003730 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is playing one of his favourite board games. In the game, there is a directed graph with $$$N$$$ vertices and $$$M$$$ edges. In the graph, edge $$$i$$$ connects two different vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$... | import sys
input=sys.stdin.readline
from heapq import heappush,heappop,heapify
from collections import defaultdict
def main():
n,m=map(int,input().split())
gf=defaultdict(list)
gb=defaultdict(list)
for _ in range(m):
u,v,w=map(int,input().split())
gf[u].append((v,w))
gb[v].append((u,w))
dis... | dis[nn]=cd+nw
heappush(h,(nw+cd,nn)) | [{"input": "5 7\n1 2 2\n2 4 1\n4 1 4\n2 5 3\n5 4 1\n5 2 4\n2 1 1", "output": ["1 -1 3 4"]}] | block_completion_003746 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is playing one of his favourite board games. In the game, there is a directed graph with $$$N$$$ vertices and $$$M$$$ edges. In the graph, edge $$$i$$$ connects two different vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$... | import sys
input=sys.stdin.readline
from heapq import heappush,heappop,heapify
from collections import defaultdict
def main():
n,m=map(int,input().split())
gf=defaultdict(list)
gb=defaultdict(list)
for _ in range(m):
u,v,w=map(int,input().split())
gf[u].append((v,w))
gb[v].append((u,w))
dis... | res[nn]=cd+nw
heappush(h,(nw+cd,nn)) | [{"input": "5 7\n1 2 2\n2 4 1\n4 1 4\n2 5 3\n5 4 1\n5 2 4\n2 1 1", "output": ["1 -1 3 4"]}] | block_completion_003747 | block |
python | Complete the code in python to solve this programming problem:
Description: Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following: Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$). Let $$$c$$$ ... | def ev(x):
k = 0
while x%2 == 0:
x//=2
k+=1
return x+k
p,q = [int(i) for i in input().split()]
t,s,sum = 1,1,0
while True:
ss = s + (t+1)//2
if ss > p:
m = (p-s+1)
sum += m*t
break
sum += t*((t+1)//2)
s = ss
t += 1
mx = t-2*m+1
pr... | print(ev(x-ded)+mul)
break | [{"input": "6 3\n1\n4\n5", "output": ["17\n1\n3\n4"]}, {"input": "1 0", "output": ["1"]}] | block_completion_003753 | block |
python | Complete the code in python to solve this programming problem:
Description: Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following: Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$). Let $$$c$$$ ... | def ev(x):
k = 0
while x%2 == 0:
x//=2
k+=1
return x+k
p,q = [int(i) for i in input().split()]
t = 1
s = 1
sum = 0
while True:
ss = s + (t+1)//2
if ss > p:
m = (p-s+1)
sum += m*t
break
sum += t*((t+1)//2)
s = ss
t += 1
mx = t-2*m... | print(ev(x-ded)+mul)
break | [{"input": "6 3\n1\n4\n5", "output": ["17\n1\n3\n4"]}, {"input": "1 0", "output": ["1"]}] | block_completion_003754 | block |
python | Complete the code in python to solve this programming problem:
Description: Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following: Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$). Let $$$c$$$ ... | def ev(x):
k = 0
while x%2 == 0:
x//=2
k+=1
return x+k
p,q = [int(i) for i in input().split()]
t = 1
s = 1
sum = 0
while True:
ss = s + (t+1)//2
if ss > p:
m = (p-s+1)
sum += m*t
break
sum += t*((t+1)//2)
s = ss
t += 1
mx = t-2*m... | print(ev(x-ded)+mul)
break | [{"input": "6 3\n1\n4\n5", "output": ["17\n1\n3\n4"]}, {"input": "1 0", "output": ["1"]}] | block_completion_003755 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1... | import sys
#sys.stdin = open("C:\\Users\\asawe\\Documents\\input.txt","r")
mx = 3 * (10 ** 5) + 10
mod = 998244353
fact = [1]
inv_fact = [1]
def modpow(a, b, m):
res = 1
x = a
y = b
while (y > 0):
if (y & 1):
{{completion}}
y = y >> 1
x = ((x... | res = (res * x) % m | [{"input": "4 2\n10 10 6 14", "output": ["10"]}, {"input": "1 2\n10", "output": ["2"]}] | block_completion_003765 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1... | from math import comb
def bpow(a,n,p):
res = 1
while n:
if n%2:
res = (res*a)%p
n-=1
else:
{{completion}}
return res
N = 3 * 10**5 + 5
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)... | a = (a*a)%p
n//=2 | [{"input": "4 2\n10 10 6 14", "output": ["10"]}, {"input": "1 2\n10", "output": ["2"]}] | block_completion_003766 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1... | from math import comb
def bpow(a,n,p):
res = 1
while n:
if n%2:
{{completion}}
else:
a = (a*a)%p
n//=2
return res
N = 3 * 10**5 + 5
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)
... | res = (res*a)%p
n-=1 | [{"input": "4 2\n10 10 6 14", "output": ["10"]}, {"input": "1 2\n10", "output": ["2"]}] | block_completion_003767 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1... | from math import comb
def bpow(a,n,p):
res = 1
while n:
if n%2:
res = (res*a)%p
n-=1
else:
{{completion}}
return res
N = 3 * 10**5 + 5
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)... | a = (a*a)%p
n//=2 | [{"input": "4 2\n10 10 6 14", "output": ["10"]}, {"input": "1 2\n10", "output": ["2"]}] | block_completion_003768 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1... | from math import comb
def bpow(a,n,p):
res = 1
while n:
if n%2:
{{completion}}
else:
a = (a*a)%p
n//=2
return res
N = 3 * 10**5 + 5
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)
... | res = (res*a)%p
n-=1 | [{"input": "4 2\n10 10 6 14", "output": ["10"]}, {"input": "1 2\n10", "output": ["2"]}] | block_completion_003769 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is participating in a lemper cooking competition. In the competition, Pak Chanek has to cook lempers with $$$N$$$ stoves that are arranged sequentially from stove $$$1$$$ to stove $$$N$$$. Initially, stove $$$i$$$ has a temperature ... | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, data, default=0, func=lambda x, y: x+y):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._... | res_left = self._func(res_left, self.data[start])
start += 1 | [{"input": "7\n2 -1 -1 5 2 -2 9", "output": ["4"]}, {"input": "5\n-1 -2 -3 -4 -5", "output": ["-1"]}] | block_completion_003791 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is participating in a lemper cooking competition. In the competition, Pak Chanek has to cook lempers with $$$N$$$ stoves that are arranged sequentially from stove $$$1$$$ to stove $$$N$$$. Initially, stove $$$i$$$ has a temperature ... | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, data, default=0, func=lambda x, y: x+y):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._... | stop -= 1
res_right = self._func(self.data[stop], res_right) | [{"input": "7\n2 -1 -1 5 2 -2 9", "output": ["4"]}, {"input": "5\n-1 -2 -3 -4 -5", "output": ["-1"]}] | block_completion_003792 | block |
python | Complete the code in python to solve this programming problem:
Description: Kristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times: apply a decrement to each non-zero element of the array, that is, repla... | def solve(a, b):
inf = 2 * 10 ** 6
d, n = inf, len(b)
for i in range(n):
if b[i] > 0:
{{completion}}
# b[i] > a[i]
if d < 0:
print("NO")
return
# All elements of b are 0s
if d == inf:
print("YES")
return
for i in ran... | d = min(d, a[i] - b[i]) | [{"input": "6\n\n4\n\n3 5 4 1\n\n1 3 2 0\n\n3\n\n1 2 1\n\n0 1 0\n\n4\n\n5 3 7 2\n\n1 1 1 1\n\n5\n\n1 2 3 4 5\n\n1 2 3 4 6\n\n1\n\n8\n\n0\n\n1\n\n4\n\n6", "output": ["YES\nYES\nNO\nNO\nYES\nNO"]}] | block_completion_003931 | block |
python | Complete the code in python to solve this programming problem:
Description: Kristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times: apply a decrement to each non-zero element of the array, that is, repla... | def solve(a, b):
inf = 2 * 10 ** 6
d, n = inf, len(b)
for i in range(n):
if b[i] > 0:
d = min(d, a[i] - b[i])
# b[i] > a[i]
if d < 0:
print("NO")
return
# All elements of b are 0s
if d == inf:
print("YES")
return
for... | print("NO")
return | [{"input": "6\n\n4\n\n3 5 4 1\n\n1 3 2 0\n\n3\n\n1 2 1\n\n0 1 0\n\n4\n\n5 3 7 2\n\n1 1 1 1\n\n5\n\n1 2 3 4 5\n\n1 2 3 4 6\n\n1\n\n8\n\n0\n\n1\n\n4\n\n6", "output": ["YES\nYES\nNO\nNO\nYES\nNO"]}] | block_completion_003932 | block |
python | Complete the code in python to solve this programming problem:
Description: An integer array $$$a_1, a_2, \ldots, a_n$$$ is being transformed into an array of lowercase English letters using the following prodecure:While there is at least one number in the array: Choose any number $$$x$$$ from the array $$$a$$$, and... | 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):
n = int(inp1())
a = list(map(int, inp(n)))
s = list(inp1())
d... | ok = not ok
break | [{"input": "7\n\n5\n\n2 3 2 4 1\n\ncacta\n\n1\n\n50\n\na\n\n2\n\n11 22\n\nab\n\n4\n\n1 2 2 1\n\naaab\n\n5\n\n1 2 3 2 1\n\naaaaa\n\n6\n\n1 10 2 9 3 8\n\nazzfdb\n\n7\n\n1 2 3 4 1 1 2\n\nabababb", "output": ["YES\nYES\nYES\nNO\nYES\nYES\nNO"]}] | block_completion_004085 | block |
python | Complete the code in python to solve this programming problem:
Description: You find yourself on an unusual crossroad with a weird traffic light. That traffic light has three possible colors: red (r), yellow (y), green (g). It is known that the traffic light repeats its colors every $$$n$$$ seconds and at the $$$i$$$-... | 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):
n = int(inp1())
c = inp1()
s = inp1()
ret = 0
l = []
la... | last = cur
l.append(('g', i)) | [{"input": "6\n\n5 r\n\nrggry\n\n1 g\n\ng\n\n3 r\n\nrrg\n\n5 y\n\nyrrgy\n\n7 r\n\nrgrgyrg\n\n9 y\n\nrrrgyyygy", "output": ["3\n0\n2\n4\n1\n4"]}] | block_completion_004147 | block |
python | Complete the code in python to solve this programming problem:
Description: You find yourself on an unusual crossroad with a weird traffic light. That traffic light has three possible colors: red (r), yellow (y), green (g). It is known that the traffic light repeats its colors every $$$n$$$ seconds and at the $$$i$$$-... | 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):
n = int(inp1())
c = inp1()
s = inp1()
ret = 0
l = []
la... | first_g = l[i][1] | [{"input": "6\n\n5 r\n\nrggry\n\n1 g\n\ng\n\n3 r\n\nrrg\n\n5 y\n\nyrrgy\n\n7 r\n\nrgrgyrg\n\n9 y\n\nrrrgyyygy", "output": ["3\n0\n2\n4\n1\n4"]}] | block_completion_004148 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ of integers $$$a_1, a_2, \ldots, a_n$$$. Process $$$q$$$ queries of two types: query of the form "0 $$$x_j$$$": add the value $$$x_j$$$ to all even elements of the array $$$a$$$, query of the form "1 $$$x_j$$$": add the v... | from itertools import islice
from sys import stdin
data = iter([int(x) for x in stdin.read().split()[1:]])
res = []
while True:
try:
n = next(data)
except StopIteration:
break
q = next(data)
counts = [0, 0]
sums = [0, 0]
for v in islice(data, n):
counts[v % 2] += 1
... | sums[mod] += to_add | [{"input": "4\n\n1 1\n\n1\n\n1 1\n\n3 3\n\n1 2 4\n\n0 2\n\n1 3\n\n0 5\n\n6 7\n\n1 3 2 4 10 48\n\n1 6\n\n0 5\n\n0 4\n\n0 5\n\n1 3\n\n0 12\n\n0 1\n\n6 7\n\n1000000000 1000000000 1000000000 11 15 17\n\n0 17\n\n1 10000\n\n1 51\n\n0 92\n\n0 53\n\n1 16\n\n0 1", "output": ["2\n11\n14\n29\n80\n100\n100\n100\n118\n190\n196\n300... | block_completion_004172 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ of integers $$$a_1, a_2, \ldots, a_n$$$. Process $$$q$$$ queries of two types: query of the form "0 $$$x_j$$$": add the value $$$x_j$$$ to all even elements of the array $$$a$$$, query of the form "1 $$$x_j$$$": add the v... | from sys import stdin
from collections import deque
lst = list(map(int, 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 = inp1()
for _ in range(t):
n = inp1()
q = inp1()
a = inp(n)
tx = [inp(2) for ... | even = n
odd = 0 | [{"input": "4\n\n1 1\n\n1\n\n1 1\n\n3 3\n\n1 2 4\n\n0 2\n\n1 3\n\n0 5\n\n6 7\n\n1 3 2 4 10 48\n\n1 6\n\n0 5\n\n0 4\n\n0 5\n\n1 3\n\n0 12\n\n0 1\n\n6 7\n\n1000000000 1000000000 1000000000 11 15 17\n\n0 17\n\n1 10000\n\n1 51\n\n0 92\n\n0 53\n\n1 16\n\n0 1", "output": ["2\n11\n14\n29\n80\n100\n100\n100\n118\n190\n196\n300... | block_completion_004173 | block |
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 ... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
prefix = suffix = 0
for i in range(n - 1):
if (d := a[i] - a[i + 1]) > 0:
prefix += d
else:
{{completion}}
print(abs(a[0] - prefix) + prefix + suffix)
| suffix -= d | [{"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"]}] | block_completion_004197 | block |
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 ... | for line in [*open(0)][2::2]:
tot = 0
list = line.split(' ')
list2 = [0] + list
minv = int(list[0])
for val in range(len(list)-1):
diff = int(list2[val+1]) - int(list[val+1])
if (diff >= 0):
{{completion}}
print(tot-minv+abs(minv)+int(list[len(list)-1])) | tot += diff
minv -= diff | [{"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"]}] | block_completion_004198 | block |
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 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
for _ in range(I()):
n=I();a=L();d=[a[0]]
for i in range(1,n):d.append(a[i]-a[i-1])
for i in range(1,n):
if d[i]<=0:{{completion}}... | d[0]+=d[i] | [{"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"]}] | block_completion_004199 | block |
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 ... | for _ in range(int(input())):
input()
a = [int(x) for x in input().split()]
prefix_value = a[0]
suffix_value = 0
steps = 0
for x, y in zip(a, a[1:]):
if x > y:
steps += x - y
prefix_value = y - suffix_value
elif y > x:
{{completion}}
print(... | steps += y - x
suffix_value += y - x | [{"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"]}] | block_completion_004200 | block |
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 ... | from sys import stdin
a = int(stdin.readline())
for t in range(0,a):
b = int(stdin.readline())
c = stdin.readline().split()
count = 0
current = int(c[0])
for u in range(0,b-1):
if int(c[u+1])>int(c[u]):
count+=(int(c[u+1])-int(c[u]))
elif int(c[u+1]) < int(c... | count+=(int(c[u]) - int(c[u+1]))
current = current - (int(c[u]) - int(c[u+1])) | [{"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"]}] | block_completion_004201 | block |
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 ... | t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int,input().split()))
res,r = 0,0
for i in range(n-1):
x = A[i+1]-A[i]
if x>0:
{{completion}}
res+=abs(x)
res+=abs(r-A[n-1])
print(res) | r+=x | [{"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"]}] | block_completion_004202 | block |
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 ... | def solve():
n = int(input())
a = [int(i) for i in input().split()]
dl, dr = 0, 0
for i in range(1, n):
if a[i]-dr >= a[0]-dl:
dr += (a[i]-dr)-(a[0]-dl)
else:
{{completion}}
return dl+dr+abs(a[0]-dl)
for _ in range(int(input())):
print(solve()... | dl += (a[0]-dl)-(a[i]-dr) | [{"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"]}] | block_completion_004203 | block |
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 nex - ori < 0:
{{completion}}
ori = nex
x += 1
ans +=... | temp += abs(nex - ori) | [{"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"]}] | block_completion_004204 | block |
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 x < y:
... | r += y - x | [{"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"]}] | block_completion_004205 | block |
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... | ans += 1
s0 -= 1
s1 += 1 | [{"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"]}] | block_completion_004255 | block |
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... | ans += 1
s0 += 1
s1 -= 1 | [{"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"]}] | block_completion_004256 | block |
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 d[0]<0 and d[1]>0:
{{completion}}
total+... | total+=1
d[0]+=1
d[1]-=1 | [{"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"]}] | block_completion_004257 | block |
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 += 1
bottom -= 1
total += 1 | [{"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"]}] | block_completion_004258 | block |
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 $$... |
import time
def main():
n = int(input())
curr = [[int(x) for x in input().split(" ")] for _ in range(2)]
want = [[int(x) for x in input().split(" ")] for _ in range(2)]
out = 0
s1 = 0
s2 = 0
for x in range(n):
out += abs(s1) + abs(s2)
s1 += curr[0][x]
... | out += abs(s2)
s1 += s2
s2 = 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"]}] | block_completion_004259 | block |
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 (int(mintime) < minval):
print("-1")
else:
{{completion}} | print(math.ceil(tot/int(mintime))) | [{"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"]}] | block_completion_004263 | block |
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()):
{{completion}}
for _ in [0]*int(I()):
t=int(I());print([-1,(p+t-1)//t][t>=m]) | p+=int(v);m=max(m,(p+i)//(i+1)) | [{"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"]}] | block_completion_004264 | block |
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 _ in [0]*int(I()):
{{completion}} | t=int(I());print([-1,(p+t-1)//t][t>=m]) | [{"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"]}] | block_completion_004265 | block |
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();... | answer = -1 | [{"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"]}] | block_completion_004266 | block |
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 k < maxi:
print(-1)
else:
# open x pipe
# time = ceil(sum / x) => x increased =>... | print((tot + k - 1) // k) | [{"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"]}] | block_completion_004267 | block |
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... | div, mod = divmod(s, q)
ans = div + (mod != 0) | [{"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"]}] | block_completion_004268 | block |
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):
{{completion}}
for _ in range(int(input())):
t = int(input())
print((v[-1] - 1) // t + 1 if t >= m else -1)
| m=max((v[i]-1)//(i+1)+1,m) | [{"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"]}] | block_completion_004269 | block |
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 _ in range(int(input())):
{{completion}}
| t = int(input())
print((v[-1] - 1) // t + 1 if t >= m else -1) | [{"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"]}] | block_completion_004270 | block |
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(t<time): print(-1)
else: {{completion}}
pass | print((total+t-1)//t) | [{"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"]}] | block_completion_004271 | block |
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(val > max): {{completion}}
f... | max = val | [{"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"]}] | block_completion_004272 | block |
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... | flag=0;break | [{"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"]}] | block_completion_004307 | block |
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... | flag=0;break | [{"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"]}] | block_completion_004308 | block |
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... | w += 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"]}] | block_completion_004309 | block |
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... | break | [{"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"]}] | block_completion_004310 | block |
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 = "... | flag = False
break | [{"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"]}] | block_completion_004311 | block |
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 = "... | continue | [{"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"]}] | block_completion_004312 | block |
python | Complete the code in python to solve this programming problem:
Description: Lena is a beautiful girl who likes logical puzzles.As a gift for her birthday, Lena got a matrix puzzle!The matrix consists of $$$n$$$ rows and $$$m$$$ columns, and each cell is either black or white. The coordinates $$$(i,j)$$$ denote the cel... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
minr,minc,maxr,maxc=n,m,0,0
l1,l2,l3,l4=n+m,n+m,0,-n-m
b = []
for i in range(n):
r = input().rstrip()
#print('r',r)
#print(list(r))
#print(len(r))
for j, c in enumerate(r):
if c == 'B':
... | madist = max(madist,abs(cr-x)+abs(cc-y)) | [{"input": "5\n3 2\nBW\nWW\nWB\n3 3\nWWB\nWBW\nBWW\n2 3\nBBB\nBBB\n5 5\nBWBWB\nWBWBW\nBWBWB\nWBWBW\nBWBWB\n9 9\nWWWWWWWWW\nWWWWWWWWW\nBWWWWWWWW\nWWWWWWWWW\nWWWWBWWWW\nWWWWWWWWW\nWWWWWWWWW\nWWWWWWWWW\nWWWWWWWWB", "output": ["2 1\n2 2\n1 2\n3 3\n6 5"]}] | block_completion_004377 | block |
python | Complete the code in python to solve this programming problem:
Description: Lena is a beautiful girl who likes logical puzzles.As a gift for her birthday, Lena got a matrix puzzle!The matrix consists of $$$n$$$ rows and $$$m$$$ columns, and each cell is either black or white. The coordinates $$$(i,j)$$$ denote the cel... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
minr,minc,maxr,maxc=n,m,0,0
l1,l2,l3,l4=n+m,n+m,0,-n-m
b = []
for i in range(n):
r = input().rstrip()
#print('r',r)
#print(list(r))
#print(len(r))
for j, c in enumerate(r):
if c == 'B':
... | best = madist
bestr,bestc=cr,cc | [{"input": "5\n3 2\nBW\nWW\nWB\n3 3\nWWB\nWBW\nBWW\n2 3\nBBB\nBBB\n5 5\nBWBWB\nWBWBW\nBWBWB\nWBWBW\nBWBWB\n9 9\nWWWWWWWWW\nWWWWWWWWW\nBWWWWWWWW\nWWWWWWWWW\nWWWWBWWWW\nWWWWWWWWW\nWWWWWWWWW\nWWWWWWWWW\nWWWWWWWWB", "output": ["2 1\n2 2\n1 2\n3 3\n6 5"]}] | block_completion_004378 | block |
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 n-i-1 > 0:
{{completion}}
cn... | heapq.heappush(hp, -(n-i-1)) | [{"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"]}] | block_completion_004395 | block |
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
... | break | [{"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"]}] | block_completion_004396 | block |
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)
... | heappop(to_spread) | [{"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"]}] | block_completion_004397 | block |
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)
... | break | [{"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"]}] | block_completion_004398 | block |
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 = [... | current_max = lives[i]
max_index = i | [{"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"]}] | block_completion_004399 | block |
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([... | c[i] = j - 1 - (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"]}] | block_completion_004400 | block |
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)):
... | l = 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"]}] | block_completion_004401 | block |
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... | heappush(laze, -f) | [{"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"]}] | block_completion_004402 | block |
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... | heappush(laze, -f) | [{"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"]}] | block_completion_004403 | block |
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)... | L = 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"]}] | block_completion_004404 | block |
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 m<n:
{{completion}}
print(ans)
| ans += 1
m *= 2 | [{"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"]}] | block_completion_004419 | block |
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 m<n:{{completion}}
print(r) | r+=min(m,n-m)+1;m*=2 | [{"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"]}] | block_completion_004420 | block |
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 i in L:
try:
count[i]+=1
except:
{{completion}}
m=max(list(count.values()))
print(int(n-m + math.ceil(math.log(n/m,2)))) | count[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"]}] | block_completion_004421 | block |
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 _ in range(t):
{{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) | [{"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"]}] | block_completion_004422 | block |
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 a[i]>a[i-1]:
temp = 1
else:
{{completion}}
... | temp += 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"]}] | block_completion_004423 | block |
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 bb<n:
{{completion}}
print(c) | c+=1
bb*=2 | [{"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"]}] | block_completion_004424 | block |
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(m<n):
{{completion}}
print(ans) | ans+=1
m=2*m | [{"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"]}] | block_completion_004425 | block |
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:
... | break | [{"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"]}] | block_completion_004426 | block |
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 a < n:
{{completion}}
stdout.write(f"{str(a... | a = a + a
ans += 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"]}] | block_completion_004427 | block |
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:
{{completion}}
max_num = max(d.values())
now = max_num
ans = 0
copy = 0
wh... | d[num] = 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"]}] | block_completion_004428 | block |
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 ... | ans += 1
copy = now | [{"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"]}] | block_completion_004429 | block |
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:
{{completion}}
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='') | print(m,2*m,m,1,end=' ') | [{"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"]}] | block_completion_004455 | block |
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 n%4==2:
{{completion}}
else:
print(2,4*m-2,2,1,end=' ')
print(sep='') | print(2*m-1,2*m+1,1,1,end=' ') | [{"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"]}] | block_completion_004456 | block |
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:
{{completion}}
elif n == 6:
a = c = d = 1
b = 3
elif n%4 == 0:
c = d = b = 2
a = n-6
elif n%4 == 1:
d = 1
c = 2
... | a = c = d = 1
b = 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"]}] | block_completion_004457 | block |
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:
{{completion}}
elif n%4 == 0:
c = d = b = 2
a = n-6
elif n%4 == 1:
d = 1
c = 2
... | a = c = d = 1
b = 3 | [{"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"]}] | block_completion_004458 | block |
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:
{{completion}}
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
ans... | ans = [n // 4] * 4 | [{"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"]}] | block_completion_004459 | block |
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 n % 2 == 0:
{{completion}}
else:
a, c, d = 2, 2, 1
b = n - a - c - d
ans = [a, b, c, d]
print(' '... | ans = [(n - 2) // 2 - 1, (n - 2) // 2 + 1, 1, 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"]}] | block_completion_004460 | block |
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:
{{completion}}
elif a1%4==0:
... | a1=a-2
print(a1//2,a1//2+1,1,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"]}] | block_completion_004461 | block |
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)
... | print(a1//4,a1//2,a1//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"]}] | block_completion_004462 | block |
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 (a[i][j] == '#' and a[i-1][j+1] == '#' and a[i-1][j-1] == '#'):
... | x = i
y = j | [{"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#......."... | block_completion_004630 | block |
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 i != 0:
{{completion}}
print(best[0])
| parent = a[i-1]
depth[parent] = max(depth[parent], 1 + depth[i])
best[parent] += best[i] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004724 | block |
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 + ... | S += dp[c]
D = max(D, dp2[c]) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004725 | block |
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):
{{completion}}
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)) | f[a[i]]=max(f[i]+1,f[a[i]]) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004726 | block |
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 i in range(n-1,0,-1):
{{completion}}
print(max(dp[0],f[0]+1)) | dp[i]=max(dp[i],f[i]+1)
dp[a[i]]+=dp[i] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004727 | block |
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):{{completion}}
for i in G(n,0,-1):F[i]=max(F[i],h[i]);F[p[i]]+=F[i]
print(F[1]) | h[p[i]]=max(h[i]+1,h[p[i]]) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004728 | block |
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 i in G(n,0,-1):{{completion}}
print(F[1]) | F[i]=max(F[i],h[i]);F[p[i]]+=F[i] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004729 | block |
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 v in edge[r]:
{{completion}}
print(max(dp[0])) | k = max(dp[v])
dp[r][1] += k
dp[r][0] = max(dp[r][0],dp[v][0]+1) | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | block_completion_004730 | block |
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 ... | dp[total+last][last] += current
dp[total+last][last] %= N | [{"input": "6\n1 1 2 1 4 3", "output": ["7"]}, {"input": "7\n3 5 4 3 7 4 5", "output": ["11"]}] | block_completion_004745 | block |
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 ... | dp[i+x][j+1] += dp[i][j]
dp[i+x][j+1] %= M | [{"input": "6\n1 1 2 1 4 3", "output": ["7"]}, {"input": "7\n3 5 4 3 7 4 5", "output": ["11"]}] | block_completion_004746 | block |
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 j in range(i,40001):{{completion}}
for n in[*open(0)][1:]:print(v[int(n)]%g) | v[j]=v[j]%g+v[j-i] | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004780 | block |
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 pj<=i:
{{completion}}
d[i]=d[i]%int(1e9+7)
for _ in range(int(input())):
print(d[int(input())])
| d[i]+=d[i-pj] | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004781 | block |
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 j in range(i, N):
{{completion}}
def solve():
n = getI... | dp[j] += dp[j-i]
dp[j] %= M | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004782 | block |
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 j in range(i, 40001):
{{completion}}
for _ in range(int(input())):
prin... | dp[j] = (dp[j]+dp[j-i])%int(1e9+7) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004783 | block |
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]:{{completion}}
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)]) | p+=[i] | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004784 | block |
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 j in R(i,m):
{{completion}}
for n in[*open(0)][1:]:print(a[int(n)]) | a[j]+=a[j-i];a[j]%=d | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004785 | block |
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 j >= i:
{{completion}}
a = int(input())
for y in range(a):
b = int(i... | c[j] += (c[j - i]) % ((10 ** 9) + 7) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004786 | block |
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 i in range(x,40001):
{{completion}}
for _ in range(int(input())):
print(d[int(input())])
| d[i]=(d[i]+d[i-x])%(10**9+7) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004787 | block |
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 i+p >= size:
{{completion}}
pm[i+p]+=pm[i]
pm[i+p]%=int(1e9)+7
i+=1
T = int(input(... | break | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004788 | block |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.