lang
stringclasses
1 value
prompt
stringlengths
1.38k
11.3k
eval_prompt
stringlengths
39
8.09k
ground_truth
stringlengths
3
196
unit_tests
stringlengths
44
873
task_id
stringlengths
23
25
split
stringclasses
2 values
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
def div(n): {{completion}} for _ in range(int(input())): print(f'Division {div(int(input()))}')
return 1 if n >= 1900 else 2 if n >= 1600 else 3 if n >= 1400 else 4
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
block_completion_000729
block
python
Complete the code in python to solve this programming problem: Description: One day Masha was walking in the park and found a graph under a tree... Surprised? Did you think that this problem would have some logical and reasoned story? No way! So, the problem...Masha has an oriented graph which $$$i$$$-th vertex contai...
import sys input = sys.stdin.readline def solve(): n, m, k = map(int, input().split()) arr = list(map(int, input().split())) graph = [[] for _ in range(n)] for i in range(m): u, v = map(int, input().split()) graph[u-1].append(v-1) lo, hi = min(arr), max(arr)+1 while lo < hi: ...
continue
[{"input": "6 7 4\n1 10 2 3 4 5\n1 2\n1 3\n3 4\n4 5\n5 6\n6 2\n2 5", "output": ["4"]}, {"input": "6 7 100\n1 10 2 3 4 5\n1 2\n1 3\n3 4\n4 5\n5 6\n6 2\n2 5", "output": ["10"]}, {"input": "2 1 5\n1 1\n1 2", "output": ["-1"]}, {"input": "1 0 1\n1000000000", "output": ["1000000000"]}]
block_completion_005667
block
python
Complete the code in python to solve this programming problem: Description: This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only o...
t=int(input("")) for z in range(t): n=int(input("")) a=input("") s=[] for i in range(0,len(a)-1,2): {{completion}} b=s.count('10') c=s.count('01') print(b+c)
ab=a[i]+a[i+1] s.append(ab)
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008121
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 < 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: There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start wate...
from bisect import bisect t = int(input().strip()) def solve(o, t): if t - o > 1: d = (t - o) // 3 + ((t - o) % 3 == 2) o, t = o + 2 * d, t - d return (o + (t > o)) * 2 - (o > t) out = [] for _ in range(t): n = int(input().strip()) h = list(map(int, input().strip().spli...
e += (mx - x + 1) % 2 o += (mx - x) % 2 t += (mx - x) // 2
[{"input": "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4", "output": ["4\n3\n16"]}]
block_completion_003417
block
python
Complete the code in python to solve this programming problem: Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de...
input = __import__('sys').stdin.readline n = int(input()) a = list(map(int, input().split())) + [n+1] ans = 0 cache = {} for i in range(n): u = 0 d = n+1 keys = [] j = i while j+1 <= n: key = (j, u, d) v = cache.get(key, -1) if v != -1: ...
d = min(d, a[j])
[{"input": "3\n2 3 1", "output": ["6"]}, {"input": "6\n4 5 2 6 1 3", "output": ["19"]}, {"input": "10\n7 10 1 8 3 9 2 4 6 5", "output": ["39"]}]
block_completion_000487
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{{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: There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start wate...
for ii in range(int(input())): n=int(input()) a = list(map(int, input().split())) m=max(a) ans=float("inf") for jj in range(m,m+4): x,y=0,0 for {{completion}}: x+=(jj-kk)%2 y+=(jj-kk)//2 ans=min(max(((x+y*2)//3*2)+(x+y*2)%3,x*2-1),ans) print(ans)
kk in a
[{"input": "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4", "output": ["4\n3\n16"]}]
control_completion_003368
control_fixed
python
Complete the code in python to solve this programming problem: Description: Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i &lt; j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff...
for i in range(int(input())): n= int(input()) a = dict() b = dict() c = dict() ans = 0 for j in range(n): d,e = str(input()) try: ans += a[d] a[d] += 1 except KeyError: a[d] = 1 try: ans += b[e] ...
d+e not in c
[{"input": "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk", "output": ["5\n6\n0\n6"]}]
control_completion_000874
control_fixed
python
Complete the code in python to solve this programming problem: Description: While searching for the pizza, baby Hosssam came across two permutations $$$a$$$ and $$$b$$$ of length $$$n$$$.Recall that a permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For exampl...
import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) a = list(map(int,sys.stdin.readline().split())) b = list(map(int,sys.stdin.readline().split())) c = list(map(int,sys.stdin.readline().split())) count = 0 L = [0] * (n+1) for i in range(0,n): ...
xcount >= 1
[{"input": "9\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n2 0 1 0 0 0 0\n1\n1\n1\n0\n6\n1 5 2 4 6 3\n6 5 3 1 4 2\n6 0 0 0 0 0\n8\n1 6 4 7 2 3 8 5\n3 2 8 1 4 5 6 7\n1 0 0 7 0 3 0 5\n10\n1 8 6 2 4 7 9 3 10 5\n1 9 2 3 4 10 8 6 7 5\n1 9 2 3 4 10 8 6 7 5\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n0 0 0 0 0 0 0\n5\n1 2 3 4 5\n1 2 3 4 5\n0 0 0 ...
control_completion_005921
control_fixed
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$n$$$ rows and $$$m$$$ columns, and three types of cells: An empty cell, denoted with '.'. A stone, denoted with '*'. An obstacle, denoted with the lowercase Latin letter 'o'. All stones fall down until they meet the...
def res(s): a=s.split('o');t='' for i in a:t+=i.count('*')*'*'+i.count('.')*'.'+'o' return t[:-1] for _ in[0]*int(input()): n,m=map(int,input().split()) a=[[*input()] for x in[0]*n] b=[] for i in range(m):b+=res(''.join([a[~j][i] for j in range(n)])), for i in range(n): for j in range(m):{{complet...
print(b[j][~i],end='')
[{"input": "3\n6 10\n.*.*....*.\n.*.......*\n...o....o.\n.*.*....*.\n..........\n.o......o*\n2 9\n...***ooo\n.*o.*o.*o\n5 5\n*****\n*....\n*****\n....*\n*****", "output": ["..........\n...*....*.\n.*.o....o.\n.*........\n.*......**\n.o.*....o*\n\n....**ooo\n.*o**o.*o\n\n.....\n*...*\n*****\n*****\n*****"]}]
block_completion_000847
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: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ...
a,b=map(int,input().split()) arr=[0]*500001 for i in map(int,input().split()): arr[i]+=1 for i in range(1,500000): arr[i+1]+=arr[i]//(i+1) arr[i]%=i+1 if sum(arr[:b])==0: print('Yes') else: {{completion}}
print('No')
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006086
block
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$n$$$ rows and $$$m$$$ columns, and three types of cells: An empty cell, denoted with '.'. A stone, denoted with '*'. An obstacle, denoted with the lowercase Latin letter 'o'. All stones fall down until they meet the...
I=lambda:map(int,input().split()) for _ in range(int(input())): n,m=I() a=[input() for _ in range(n)] at=[''.join(col).split('o') for col in zip(*a)] f=lambda s:''.join(sorted(s,reverse=True)) at=['o'.join(map(f, col)) for col in at] for row in zip(*at): {{completion}}
print(''.join(row))
[{"input": "3\n6 10\n.*.*....*.\n.*.......*\n...o....o.\n.*.*....*.\n..........\n.o......o*\n2 9\n...***ooo\n.*o.*o.*o\n5 5\n*****\n*....\n*****\n....*\n*****", "output": ["..........\n...*....*.\n.*.o....o.\n.*........\n.*......**\n.o.*....o*\n\n....**ooo\n.*o**o.*o\n\n.....\n*...*\n*****\n*****\n*****"]}]
block_completion_000853
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
t = int(input("")) for i in range(t): ticket = input("") if int(ticket[0])+int(ticket[1])+int(ticket[2]) == int(ticket[3])+int(ticket[4])+int(ticket[5]): print("YES") else: {{completion}}
print("NO")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007625
block
python
Complete the code in python to solve this programming problem: Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E...
case=int(input()) for i in range(case): n,m = (int(v) for v in input().split()) tmp=0 for j in range(n): list1 = [int(v) for v in input().split()] value = 0 for k in range(m): value += list1[k]*(k+1) if j==0: tmp = value else: if value > tmp: print(str(j+...
value < tmp
[{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ...
control_completion_002577
control_fixed
python
Complete the code in python to solve this programming problem: Description: Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same. In...
import sys if __name__ == "__main__": input_arr = sys.stdin.read().split() tc = int(input_arr[0]) pos = 1 for i in range(tc): n, row1, row2 = input_arr[pos:pos + 3] row1n, row2n = [], [] for k,j in zip(row1, row2): if k == "G": k = "B" ...
j = "B"
[{"input": "6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG", "output": ["YES\nNO\nYES\nNO\nYES\nYES"]}]
block_completion_008471
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
Y=lambda:map(int,input().split()) O=[];n,q=Y();p=sorted(Y())[::-1];s=[0] for i in p:s+=[s[-1]+i] for {{completion}}:x,y=Y();O+=[str(s[x]-s[x-y])] print('\n'.join(O))
_ in[0]*q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000507
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 &gt; 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: The derby between Milan and Inter is happening soon, and you have been chosen as the assistant referee for the match, also known as linesman. Your task is to move along the touch-line, namely the side of the field, always looking very carefull...
from bisect import bisect_right,bisect_left n,v = map(int,input().split()) t = [*map(int,input().split())] a = [*map(int,input().split())] res = [] for i in range(n): xi,yi = t[i]*v+a[i],t[i]*v-a[i] if(xi>=0 and yi>=0): res.append((xi,yi)) res.sort() dp = [float("inf")]*(n+3) dp[0] = 0 dp[n+...
(dp[i]!=float("inf"))
[{"input": "3 2\n5 10 15\n7 17 29", "output": ["2"]}, {"input": "5 1\n5 7 8 11 13\n3 3 -2 -2 4", "output": ["3"]}, {"input": "1 2\n3\n7", "output": ["0"]}]
control_completion_001084
control_fixed
python
Complete the code in python to solve this programming problem: Description: Suppose you have an integer $$$v$$$. In one operation, you can: either set $$$v = (v + 1) \bmod 32768$$$ or set $$$v = (2 \cdot v) \bmod 32768$$$. You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of oper...
n,s=open(0) for {{completion}}:print(min(-x%2**i-i+15for i in range(16)))
x in map(int,s.split())
[{"input": "4\n19 32764 10240 49", "output": ["14 4 4 15"]}]
control_completion_003302
control_fixed
python
Complete the code in python to solve this programming problem: Description: Consider an array $$$a$$$ of $$$n$$$ positive integers.You may perform the following operation: select two indices $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$), then decrease all elements $$$a_l, a_{l + 1}, \dots, a_r$$$ by $$$1$$$. L...
import sys tokens = ''.join(sys.stdin.readlines()).split()[::-1] def next(): return tokens.pop() def nextInt(): return int(next()) def nextFloat(): return float(next()) def getIntArray(n): return [nextInt() for _ in range(n)] def getFloatArray(n): return [nextFloat() for _ in range(n)] def getStringArray(n): r...
tc in range(testcaseCount)
[{"input": "3\n\n4\n\n2 3 5 4\n\n3\n\n1 2 3\n\n4\n\n3 1 3 2", "output": ["YES\nYES\nNO"]}]
control_completion_001993
control_fixed
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
for s in[*open(0)][2::2]: c=[*map(int,s.split())] a=[1 if x else 0 for x in c]+[1] for {{completion}}: a[x+i-i*a[i]]=0 print(*a[:-1])
i,x in enumerate(c)
[{"input": "5\n4\n2 4 2 4\n7\n0 3 4 2 3 2 7\n3\n0 0 0\n4\n0 0 0 4\n3\n1 2 3", "output": ["1 1 0 1 \n0 1 1 0 0 0 1 \n0 0 0 \n0 0 0 1 \n1 0 1"]}]
control_completion_008596
control_fixed
python
Complete the code in python to solve this programming problem: Description: A row of $$$n$$$ cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as $$$\color{blue}{\te...
for _ in range(int(input())) : {{completion}}
l = int(input()) print("NO" if any (len(set(x)) == 1 for x in input().split('W') ) else "YES")
[{"input": "12\n5\nBRBBW\n1\nB\n2\nWB\n2\nRW\n3\nBRB\n3\nRBB\n7\nWWWWWWW\n9\nRBWBWRRBW\n10\nBRBRBRBRRB\n12\nBBBRWWRRRWBR\n10\nBRBRBRBRBW\n5\nRBWBW", "output": ["YES\nNO\nNO\nNO\nYES\nYES\nYES\nNO\nYES\nNO\nYES\nNO"]}]
block_completion_000924
block
python
Complete the code in python to solve this programming problem: Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E...
case=int(input()) for i in range(case): n,m = (int(v) for v in input().split()) tmp=0 for j in range(n): list1 = [int(v) for v in input().split()] value = 0 for k in range(m): value += list1[k]*(k+1) if j==0: tmp = value else: if value > tmp: print(str(j+...
pass
[{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ...
block_completion_002630
block
python
Complete the code in python to solve this programming problem: Description: You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times: select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the va...
# Problem - https://codeforces.com/contest/1714/problem/E # Editorial - https://codeforces.com/blog/entry/105549 # Tags - brute force, math, number theory, *1400 import sys import typing # Read stdin and remove newline elements stdin = [line.strip() for line in sys.stdin.readlines() if line != '\n'] stdin_co...
has_0 = True
[{"input": "10\n\n2\n\n6 11\n\n3\n\n2 18 22\n\n5\n\n5 10 5 10 5\n\n4\n\n1 2 4 8\n\n2\n\n4 5\n\n3\n\n93 96 102\n\n2\n\n40 6\n\n2\n\n50 30\n\n2\n\n22 44\n\n2\n\n1 5", "output": ["Yes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\nYes\nNo"]}]
block_completion_006708
block
python
Complete the code in python to solve this programming problem: Description: On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the ce...
for _ in range(int(input())): met = [] res = [] judge = True i = 0 while i < 8: tmp = input() met.append(tmp) if tmp != '': i += 1 if {{completion}}: print("R") judge = False if judge: print("B") # f...
tmp == "R" * 8 and judge
[{"input": "4\n\n\n\n\n....B...\n\n....B...\n\n....B...\n\nRRRRRRRR\n\n....B...\n\n....B...\n\n....B...\n\n....B...\n\n\n\n\nRRRRRRRB\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nRRRRRRRB\n\n\n\n\nRRRRRRBB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\...
control_completion_005709
control_fixed
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
n, k = map(int, input().split()) answer = [0] * (n + 1) dp = [1] + [0] * n MIN = 0 while MIN + k <= n: mod = [0 for _ in range(k)] for {{completion}}: dp[i], mod[i % k] = mod[i % k], dp[i] + mod[i % k] mod[i % k] %= 998244353 answer[i] += dp[i] answer[i] %= 998244353 ...
i in range(MIN, n + 1)
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
control_completion_008069
control_fixed
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 ...
i[1] % 2 != 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...
control_completion_004093
control_fixed
python
Complete the code in python to solve this programming problem: Description: Nastya baked $$$m$$$ pancakes and spread them on $$$n$$$ dishes. The dishes are in a row and numbered from left to right. She put $$$a_i$$$ pancakes on the dish with the index $$$i$$$.Seeing the dishes, Vlad decided to bring order to the stack...
from functools import cache from math import inf from itertools import accumulate def solve(A, m): n = len(A) A.reverse() @cache def dp(i, val, balance): if abs(balance) > m: return inf if {{completion}}: return inf if i == n: return 0 if bal...
(n - i) * val > m
[{"input": "6 19\n5 3 2 3 3 3", "output": ["2"]}, {"input": "3 6\n3 2 1", "output": ["0"]}, {"input": "3 6\n2 1 3", "output": ["1"]}, {"input": "6 19\n3 4 3 3 5 1", "output": ["3"]}, {"input": "10 1\n0 0 0 0 0 0 0 0 0 1", "output": ["9"]}]
control_completion_003521
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 &gt; 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: You have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones and an integer $$$k$$$. In one operation you can do one of the following: Select $$$2$$$ consecutive elements of $$$a$$$ and replace them with their minimum (that is...
from sys import stdin from collections import deque lst = list(map(int, stdin.read().split())) _s = 0 def inp(n=1): {{completion}} def inp1(): return inp()[0] t = inp1() for _ in range(t): n = inp1() k = inp1() a = set(inp(n)) print("YES" if 1 in a else "NO")
global _s ret = lst[_s:_s + n] _s += n return ret
[{"input": "7\n\n3 2\n\n0 1 0\n\n5 3\n\n1 0 1 1 0\n\n2 2\n\n1 1\n\n4 4\n\n0 0 0 0\n\n6 3\n\n0 0 1 0 0 1\n\n7 5\n\n1 1 1 1 1 1 1\n\n5 3\n\n0 0 1 0 0", "output": ["YES\nYES\nYES\nNO\nYES\nYES\nYES"]}]
block_completion_006994
block
python
Complete the code in python to solve this programming problem: Description: You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to...
import sys tokens = ''.join(sys.stdin.readlines()).split()[::-1] def next(): return tokens.pop() def nextInt(): return int(next()) def nextFloat(): return float(next()) def getIntArray(n): return [nextInt() for _ in range(n)] def getFloatArray(n): return [nextFloat() for _ in range(n)] def getStringArray(n): r...
continue
[{"input": "5\n\n1 1\n\n1\n\n1 2\n\n1 -1\n\n1 4\n\n1 -1 1 -1\n\n3 4\n\n1 -1 -1 -1\n\n-1 1 1 -1\n\n1 1 1 -1\n\n3 4\n\n1 -1 1 1\n\n-1 1 -1 1\n\n1 -1 1 1", "output": ["NO\nYES\nYES\nYES\nNO"]}]
block_completion_002517
block
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(s[i] != s[i - d]): {{completion}} else: print("Yes") t -= 1
print("No") break
[{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_004807
block
python
Complete the code in python to solve this programming problem: Description: There is an array $$$a$$$ of length $$$n$$$. You may perform the following operation any number of times: Choose two indices $$$l$$$ and $$$r$$$ where $$$1 \le l &lt; r \le n$$$ and $$$a_l = a_r$$$. Then, set $$$a[l \ldots r] = [a_{l+1}, a_{l...
import sys sys.setrecursionlimit(10000) def read_line(f): while True: s=f.readline().strip() if s: return s def read_list(f): return [int(x) for x in read_line(f).split()] def read_tuple(f): return tuple(read_list(f)) def load_single_case(f): read_line(f) ...
return False
[{"input": "5\n\n5\n\n1 2 3 3 2\n\n1 3 3 2 2\n\n5\n\n1 2 4 2 1\n\n4 2 2 1 1\n\n5\n\n2 4 5 5 2\n\n2 2 4 5 5\n\n3\n\n1 2 3\n\n1 2 3\n\n3\n\n1 1 2\n\n2 1 1", "output": ["YES\nYES\nNO\nYES\nNO"]}]
block_completion_008013
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys input = sys.stdin.readline class DSU: def __init__(self, n): self.UF = list(range(n)) self.sz = [0]*n def find(self, u): UF = self.UF if UF[u]!=u: UF[u] = self.find(UF[u]) return UF[u] def union(self,u,v): UF = self...
DSUs[k].find(u) == DSUs[k].find(v)
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
control_completion_008616
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children...
def dfs(tree,i,h): if {{completion}}: return [tree[i],1] ls,li=dfs(tree,i*2+1,h) rs,ri=dfs(tree,i*2+2,h) res=li*ri if ls!=rs: res*=2 if ls>rs: return [tree[i]+rs+ls,res] else: return [tree[i]+ls+rs,res] h=int(input()) tree=input() print(dfs(t...
i>=2**(h-1)-1
[{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}]
control_completion_001666
control_fixed
python
Complete the code in python to solve this programming problem: Description: Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of ...
import sys input = sys.stdin.readline def getInts(): return map(int, input().split()) def solve(): input() a = [*getInts()] if {{completion}}: print(len(a) - a.count(0)) else: s = set(a) print(len(a) + (len(a) == len(s))) for _ in range(int(input())): solve()
0 in a
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
control_completion_008026
control_fixed
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: Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i &lt; j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff...
from collections import defaultdict ak = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"] t = int(input()) for _ in range(t): count = 0 d = defaultdict(int) n = int(input()) for i in range(n): s = input() for c in ak: if c != s[0]: if d[c +...
d[s[0] + c] > 0
[{"input": "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk", "output": ["5\n6\n0\n6"]}]
control_completion_000870
control_fixed
python
Complete the code in python to solve this programming problem: Description: There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i...
input = __import__('sys').stdin.readline log2s = [0, 0] for i in range(2, 200005): log2s.append(log2s[i // 2] + 1) n, m = map(int, input().split()) sparse = [[0] + list(map(int, input().split()))] for j in range(20): sparse.append([max(sparse[j][min(i + (1 << j), m)], sparse[j][i]) for i in range...
h -= k
[{"input": "11 10\n9 0 0 10 3 4 8 11 10 8\n6\n1 2 1 3 1\n1 2 1 3 2\n4 3 4 5 2\n5 3 11 5 3\n5 3 11 5 2\n11 9 9 10 1", "output": ["YES\nNO\nNO\nNO\nYES\nYES"]}]
block_completion_002998
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in [0]*int(input()): input() n = list(map(int,input().split())) s,f,m = 0,0,0 for i in n: s+=i if s<0:m = 1;break if s==0:{{completion}} if f and s>0:m=1;break print("YNEOS"[(m or not f)::2])
f=1
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000427
block
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$r$$$ rows and $$$c$$$ columns, where the square on the $$$i$$$-th row and $$$j$$$-th column has an integer $$$a_{i, j}$$$ written on it. Initially, all elements are set to $$$0$$$. We are allowed to do the following ope...
# import io,os # read = io.BytesIO(os.read(0, os.fstat(0).st_size)) # I = lambda: [*map(int, read.readline().split())] import sys I=lambda:[*map(int,sys.stdin.readline().split())] M = 998244353 r, c = I() rows = [] for i in range(r): rows.append([*input()]) if r % 2 == 0 and c % 2 == 0: blanks = 0 fo...
seen[v] = 1 component.append(v)
[{"input": "3 3\n?10\n1??\n010", "output": ["1"]}, {"input": "2 3\n000\n001", "output": ["0"]}, {"input": "1 1\n?", "output": ["2"]}, {"input": "6 9\n1101011?0\n001101?00\n101000110\n001011010\n0101?01??\n00?1000?0", "output": ["8"]}]
block_completion_008069
block
python
Complete the code in python to solve this programming problem: Description: You have a square chessboard of size $$$n \times n$$$. Rows are numbered from top to bottom with numbers from $$$1$$$ to $$$n$$$, and columns — from left to right with numbers from $$$1$$$ to $$$n$$$. So, each cell is denoted with pair of inte...
import sys input=sys.stdin.readline R=lambda:map(int,input().split()) n,m=R();r,c,tr,tc=[0]*(n+1),[0]*(n+1),[0]*(n+1),[0]*(n+1) def A(t,i,v): while i<=n:t[i]+=v;i+=i&(-i) def Q(t,i): s=0 while i:s+=t[i];i-=i&(-i) return s for _ in range(m): v=[*R()];op,x,y=v[:3] if op==1: r[x]+=1;c[y]+=1 ...
A(tr,x,-1)
[{"input": "8 10\n1 2 4\n3 6 2 7 2\n1 3 2\n3 6 2 7 2\n1 4 3\n3 2 6 4 8\n2 4 3\n3 2 6 4 8\n1 4 8\n3 2 6 4 8", "output": ["No\nYes\nYes\nNo\nYes"]}]
block_completion_005571
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: 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 &gt; 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: There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i...
from sys import setrecursionlimit, stdin readline = stdin.readline # def I(): return int(readline()) # def ST(): return readline()[:-1] # def LI(): return list(map(int, readline().split())) def solve(): N, m = map(int, readline().split()) A = [0] + list(map(int, readline().split())) n = len(A) num = 1...
l & 1
[{"input": "11 10\n9 0 0 10 3 4 8 11 10 8\n6\n1 2 1 3 1\n1 2 1 3 2\n4 3 4 5 2\n5 3 11 5 3\n5 3 11 5 2\n11 9 9 10 1", "output": ["YES\nNO\nNO\nNO\nYES\nYES"]}]
control_completion_002945
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
from collections import deque I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n)] din,dout,dcur=[0]*n,[0]*n,[0]*n for _ in range(m): u,v=I() u,v=u-1,v-1 g[u].append(v) dout[u]+=1;din[v]+=1;dcur[v]+=1 q=deque([i for i,d in enumerate(din) if d==0]) f=[1]*n while q: u=q.popleft() ...
q.append(v)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007896
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) a.insert(0, 0) a.append(0) ans = 0 for {{completion}}: ans += (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i while(m): i, x = map(int, input().split()) ans -= (a[i] != a[i - 1]) * (n ...
i in range(1, n + 1)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000079
control_fixed
python
Complete the code in python to solve this programming problem: Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap...
import sys class LCA: def __init__(self, g, root=0): self.g = g self.root = root n = len(g) self.logn = (n - 1).bit_length() self.depth = [None] * n self.parent = [[None] * self.logn for _ in range(n)] self._dfs() self._doubling() def _dfs(self)...
p[i + 1] = self.parent[p[i]][i]
[{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}]
block_completion_002289
block
python
Complete the code in python to solve this programming problem: Description: Today, like every year at SWERC, the $$$n^2$$$ contestants have gathered outside the venue to take a drone photo. Jennifer, the social media manager for the event, has arranged them into an $$$n\times n$$$ square. Being very good at her job, s...
import sys import random input = sys.stdin.buffer.readline read = sys.stdin.buffer.read N = int(input()) As = [list(map(int, input().split())) for _ in range(N)] # N = 1500 # As = list(range(1, N ** 2 + 1)) # random.shuffle(As) # As = [As[i * N:(i + 1) * N] for i in range(N)] ijs = [0] * (N ** 2) for i in range(N):...
j in range(N)
[{"input": "2\n1 3\n4 2", "output": ["0"]}, {"input": "2\n3 2\n4 1", "output": ["1"]}, {"input": "3\n9 2 4\n1 5 3\n7 8 6", "output": ["6"]}]
control_completion_001072
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, and an array $$$b$$$, with length $$$n$$$. Initially $$$b_i=0$$$ for each $$$1 \leq i \leq n$$$.In one move you can choose an integer $$$i$$$ ($$$1 \leq i \leq n$$$), and ...
from math import ceil n=int(input()) a=list(map(int,input().split())) ans=float("inf") for i in range(len(a)): t=[0]*n temp=0 j=i-1 prev =0 while j>=0: x=(ceil((prev+1)/a[j])) temp+=x prev=(a[j]*x) j-=1 k=i+1 prev=0 while {{completion...
k<len(a)
[{"input": "5\n1 2 3 4 5", "output": ["4"]}, {"input": "7\n1 2 1 2 1 2 1", "output": ["10"]}, {"input": "8\n1 8 2 7 3 6 4 5", "output": ["16"]}]
control_completion_000963
control_fixed
python
Complete the code in python to solve this programming problem: Description: You found a map of a weirdly shaped labyrinth. The map is a grid, consisting of $$$n$$$ rows and $$$n$$$ columns. The rows of the grid are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns of the grid are numbered from $$$1$$$ t...
import sys input = sys.stdin.readline N = int(input()) logN = (N - 2).bit_length() door = [] for _ in range(N - 1): _, a, b, _ = map(int, input().split()) door.append([a - 1, b - 1]) # door = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)] dist = [[[-1] * 4 for _ in range(logN)] for ...
dist[i][j][fr << 1 | to] = min( dist[i][j - 1][fr << 1] + dist[i + k][j - 1][to], dist[i][j - 1][fr << 1 | 1] + dist[i + k][j - 1][2 | to] )
[{"input": "2\n1 1 1 1\n10\n1 1 1 1\n1 1 1 2\n1 1 2 1\n1 1 2 2\n1 2 1 2\n1 2 2 1\n1 2 2 2\n2 1 2 1\n2 1 2 2\n2 2 2 2", "output": ["0\n1\n1\n2\n0\n2\n1\n0\n1\n0"]}, {"input": "4\n1 1 1 1\n2 1 2 2\n3 2 1 3\n5\n2 4 4 3\n4 4 3 3\n1 2 3 3\n2 2 4 4\n1 4 2 3", "output": ["3\n4\n3\n6\n2"]}]
block_completion_001953
block
python
Complete the code in python to solve this programming problem: Description: You are beta testing the new secret Terraria update. This update will add quests to the game!Simply, the world map can be represented as an array of length $$$n$$$, where the $$$i$$$-th column of the world has height $$$a_i$$$.There are $$$m$$...
_,(*a,),*r=(map(int,s.split())for s in open(0)) b=[[0],[0]] for x in b: for {{completion}}:x+=x[-1]+max(0,u-v), max=min for s,t in r:l=b[s>t];print(l[t]-l[s])
u,v in zip([0]+a,a)
[{"input": "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2", "output": ["2\n10\n0\n7\n3\n1"]}]
control_completion_002890
control_fixed
python
Complete the code in python to solve this programming problem: Description: On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the ce...
t=int(input()) for p in range(t): l=[] c=0 a=['R','R','R','R','R','R','R','R'] while(len(l)<8): s=input() if {{completion}}: l.append([*s]) for i in range(8): if l[i]==a: c=1 break print("B" if c!=1 else "R")
len(s)==8
[{"input": "4\n\n\n\n\n....B...\n\n....B...\n\n....B...\n\nRRRRRRRR\n\n....B...\n\n....B...\n\n....B...\n\n....B...\n\n\n\n\nRRRRRRRB\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nRRRRRRRB\n\n\n\n\nRRRRRRBB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\...
control_completion_005703
control_fixed
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...
import sys,math n,team=map(int,sys.stdin.readline().split()) arr=sorted(map(int,sys.stdin.readline().split()),reverse=True) # print(arr) all=n+1 count=0 for i in range(n): sub=int(math.floor(team/arr[i])+1) all-=sub if {{completion}}: count+=1 else:break print(count)
all>0
[{"input": "6 180\n90 80 70 60 50 100", "output": ["2"]}]
control_completion_003666
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given a board with $$$n$$$ rows and $$$n$$$ columns, numbered from $$$1$$$ to $$$n$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$.A half-queen attacks cells in the same row, same column, and...
import sys input = sys.stdin.readline n = int(input()) ans = [] if n <= 2: k = 1 ans.append(" ".join(map(str, (1, 1)))) elif n == 3: k = 2 ans.append(" ".join(map(str, (1, 1)))) ans.append(" ".join(map(str, (1, 2)))) else: for i in range(100000, -1, -1): if 3 * i + 2 <= n:...
x = i break
[{"input": "1", "output": ["1\n1 1"]}, {"input": "2", "output": ["1\n1 1"]}, {"input": "3", "output": ["2\n1 1\n1 2"]}]
block_completion_001073
block
python
Complete the code in python to solve this programming problem: Description: There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i...
import math import sys input = sys.stdin.buffer.readline y, x_ = input().split() block = [int(x) for x in input().split()] list2 = [[0] *20 for i in range( len(block))] for a in range(len(block)): list2[a][0] = block[a] z, x = 0, 1 while (1 << x) <= len(block): z = 0 while (z + (1 << x...
print("NO")
[{"input": "11 10\n9 0 0 10 3 4 8 11 10 8\n6\n1 2 1 3 1\n1 2 1 3 2\n4 3 4 5 2\n5 3 11 5 3\n5 3 11 5 2\n11 9 9 10 1", "output": ["YES\nNO\nNO\nNO\nYES\nYES"]}]
block_completion_002991
block
python
Complete the code in python to solve this programming problem: Description: You are given an array $$$a_1, a_2, \dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, \dots, b_n$$$: Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-ne...
import sys from math import ceil ls = [] for l in sys.stdin: lst = l.rstrip('\n') if len(lst) > 0: ls.append(lst) for l in ls: sys.stderr.write(l + ('\n')) sys.stderr.write("-- output --\n") def at_least(L, x): for i in range(len(L)): if L[i] >= x: return...
b[n-i-2] < a[n-i-1]
[{"input": "4\n\n3\n\n2 3 5\n\n7 11 13\n\n1\n\n1000\n\n5000\n\n4\n\n1 2 3 4\n\n1 2 3 4\n\n4\n\n10 20 30 40\n\n22 33 33 55", "output": ["5 4 2\n11 10 8\n4000\n4000\n0 0 0 0\n0 0 0 0\n12 2 3 15\n23 13 3 15"]}]
control_completion_002703
control_fixed
python
Complete the code in python to solve this programming problem: Description: Julia's $$$n$$$ friends want to organize a startup in a new country they moved to. They assigned each other numbers from 1 to $$$n$$$ according to the jobs they have, from the most front-end tasks to the most back-end ones. They also estimated...
n = int(input().strip()) S = [[0 for i in range(n)] for j in range(n)] for i in range(n): for j, c in enumerate(map(int, input().strip().split())): S[i][j] = c for i in range(n): for j in range(n): if i > 0 and j > 0: S[i][j] += S[i][j-1] + S[i-1][j] - S[i-1][j-1] ...
S[i][j] += S[i][j-1]
[{"input": "4\n0 566 1 0\n566 0 239 30\n1 239 0 1\n0 30 1 0", "output": ["2 4 2 0"]}]
block_completion_003209
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)...
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: Inflation has occurred in Berlandia, so the store needs to change the price of goods.The current price of good $$$n$$$ is given. It is allowed to increase the price of the good by $$$k$$$ times, with $$$1 \le k \le m$$$, k is an integer. Outpu...
from sys import stdin, stderr data = [int(x) for x in stdin.read().split()[1:]] ns, ms = data[::2], data[1::2] output = [] for n, m in zip(ns, ms): # n = 2 ** a * 5 ** b * c a = b = 0 c = n while c % 2 == 0: a += 1 c //= 2 while c % 5 == 0: b += 1 c //= 5 t = 1...
t *= 2 a += 1
[{"input": "10\n\n6 11\n\n5 43\n\n13 5\n\n4 16\n\n10050 12345\n\n2 6\n\n4 30\n\n25 10\n\n2 81\n\n1 7", "output": ["60\n200\n65\n60\n120600000\n10\n100\n200\n100\n7"]}]
block_completion_001335
block
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 &lt; n$$...
for s in[*open(0)][2::2]:{{completion}}
a,b,*_,c,d=sorted(map(int,s.split()));print(c+d-a-b)
[{"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"]}]
block_completion_005385
block
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
from math import perm, comb import sys input = sys.stdin.readline M = 998244353 n = int(input()) x, y = [0]*n, [0]*n for i in range(n): x[i], y[i] = map(int, input().split()) # print(x, y) dist = [[] for _ in range(n)] for i in range(n): for j in range(n): dist[i].append(abs(x[i] - ...
nbr[i].append(j)
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
block_completion_000544
block
python
Complete the code in python to solve this programming problem: Description: Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i &lt; j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff...
t=int(input()) for i in range(t): n=int(input()) result=0 dic1={} dic2={} dic3={} for i in range(n): S=input() if {{completion}}: result+=dic1[S[0]] dic1[S[0]]+=1 else: dic1[S[0]]=1 if S[1] in dic2: result+=dic2[S[1]] dic2[S[1]]+=1 else: ...
S[0] in dic1
[{"input": "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk", "output": ["5\n6\n0\n6"]}]
control_completion_000872
control_fixed
python
Complete the code in python to solve this programming problem: Description: Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i &lt; j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff...
from collections import Counter from itertools import islice from sys import stdin LETTERS = 'abcdefghijk' data = (line.strip() for line in stdin.readlines()[1:]) res = [] for line in data: n = int(line) s = 0 ctr = Counter() for ab in islice(data, n): a, b = ab ctr[ab] += 1 f...
l != a
[{"input": "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk", "output": ["5\n6\n0\n6"]}]
control_completion_000865
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start wate...
from bisect import bisect t = int(input().strip()) def solve(o, t): if t - o > 1: d = (t - o) // 3 + ((t - o) % 3 == 2) o, t = o + 2 * d, t - d return (o + (t > o)) * 2 - (o > t) out = [] for _ in range(t): n = int(input().strip()) h = list(map(int, input().strip().spli...
x in h
[{"input": "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4", "output": ["4\n3\n16"]}]
control_completion_003362
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The weight of the $$$i$$$-th edge is $$$i$$$.Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:vis := an array of length n...
input = __import__('sys').stdin.readline class DisjointSetUnion(object): def __init__(self, n): self.n = n self.par = [i for i in range(n)] def find(self, x): toupdate = [] while x != self.par[x]: {{completion}} for u in toupdate: ...
toupdate.append(x) x = self.par[x]
[{"input": "5 5\n1 2\n3 5\n1 3\n3 2\n4 2", "output": ["01111"]}, {"input": "10 11\n1 2\n2 5\n3 4\n4 2\n8 1\n4 5\n10 5\n9 5\n8 2\n5 7\n4 6", "output": ["0011111011"]}]
block_completion_006772
block
python
Complete the code in python to solve this programming problem: Description: Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, \dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way:Initially, $$$c_i = b$$$ for every $$$1 \le i \le n$$$. E...
input = __import__('sys').stdin.readline def solve(): n, m = map(int, input().split()) mx = (0, -1) mn = (10**18, -1) for i in range(n): current, total = 0, 0 for x in map(int, input().split()): {{completion}} mx = max(mx, (total, i)) ...
current += x total += current
[{"input": "7\n3 9\n0 1 2 0 0 2 1 1 0\n0 1 1 1 2 0 0 2 0\n0 1 2 0 0 1 2 1 0\n3 7\n25 15 20 15 25 20 20\n26 14 20 14 26 20 20\n25 15 20 15 20 20 25\n3 9\n25 15 20 15 25 20 20 20 20\n26 14 20 14 26 20 20 20 20\n25 15 20 15 25 15 20 20 25\n3 11\n25 15 20 15 25 20 20 20 20 20 20\n26 14 20 14 26 20 20 20 20 20 20\n25 15 20 ...
block_completion_002631
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import time, sys n, m = [int(i) for i in sys.stdin.readline().split()] a = [int(i) for i in sys.stdin.readline().split()] t1 = time.time() w = [(i+1)*(n-i-1) for i in range(n-1)] c = sum([w[i] if a[i+1] != a[i] else 0 for i in range(n-1)]) for _ in range(m): ix, x = [int(i) for i in sys.stdin.readline().sp...
a[ix] != a[ix+1] == x
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000082
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children...
mod=998244353 cnt=0 n=int(input()) s=input() import random q=random.randint(10**9,2*10**9) p=random.randint(10**9,2*10**9) r=10**9+7 a=[-1] for i in s: if i=='A': a.append(p) else: a.append(q) for i in range(2**(n-1)-1,0,-1): if {{completion}}: cnt+=1 a[i]=a[i]^(2*a[2*i]+2*a[2*i+1]) a[i]%=r ...
a[2*i]!=a[2*i+1]
[{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}]
control_completion_001664
control_fixed
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
n,k=map(int,input().split());M=998244353 f,z=[1]+[0]*n,[0]*(n+1);l=0 while l<=n-k: s=[0]*k for {{completion}}: j=i%k s[j],f[i],z[i]=(s[j]+f[i])%M,s[j],(z[i]+s[j])%M l+=k;k+=1 print(*z[1:])
i in range(l,n+1)
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
control_completion_008076
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$...
from sys import stdin t = int(stdin.readline().strip()) for i in range(t): n = int(stdin.readline().strip()) b = list('ban'*n) if n==1: print(1) print(1, 2) else: z = n*3-1 print(n//2+n%2) for i3 in range(n//2+n%2): for i2 in range(n*3): ...
c = b[z] b[z] = 'a' b[i2] = c print(min(i2+1, z+1), max(i2+1, z+1)) z-=3 break
[{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}]
block_completion_001831
block
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 j in range(i + 1, len(cards)): {{completion}} print(sum(x * (x ...
counter[cards_lookup.get(tuple(x if x == y else ((x + 1) ^ (y + 1)) - 1 for x, y in zip(cards[i], cards[j])), -1)] += 1
[{"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...
block_completion_005315
block
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 &lt; 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
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: You are given two arrays: an array $$$a$$$ consisting of $$$n$$$ zeros and an array $$$b$$$ consisting of $$$n$$$ integers.You can apply the following operation to the array $$$a$$$ an arbitrary number of times: choose some subsegment of $$$a$...
n,k = map(int, input().split()) bb = list(map(int, input().split())) ans = 0 sofar = 0 sumprog = 0 timeq = [] for ib,b in enumerate(bb[::-1]): kk = min(k, n-ib) time = (max(0,b-sofar)+kk-1)//kk ans += time timeq.append(time) sumprog += time if ib >= k: {{completion}} sofar += kk*time...
sumprog -= timeq[ib-k]
[{"input": "3 3\n5 4 6", "output": ["5"]}, {"input": "6 3\n1 2 3 2 2 3", "output": ["3"]}, {"input": "6 3\n1 2 4 1 2 3", "output": ["3"]}, {"input": "7 3\n50 17 81 25 42 39 96", "output": ["92"]}]
block_completion_003443
block
python
Complete the code in python to solve this programming problem: Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra...
def solve(): n = int(input()) g = [[] for _ in range(n)] for _ in range(n-1): u, v = [int(t) for t in input().split()] u -= 1 v -= 1 g[u].append(v) g[v].append(u) q = int(input()) for _ in range(q): input() S = [int(t)-1 for t i...
depth[nei] == -1
[{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}]
control_completion_002216
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ...
n,x=map(int,input().split()) s={i:0 for i in range(1,x+1)} def f(x,a): s[x]=s[x]+a an=map(int,input().split()) for b in an: f(b,1) l=1 i=1 while i < x: if {{completion}}: f(i+1,s[i]//(i+1)) i+=1 else: l=0 break print(['no','yes'][l])
s[i]%(i+1)==0
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
control_completion_005990
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 ...
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: 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: Alina has discovered a weird language, which contains only $$$4$$$ words: $$$\texttt{A}$$$, $$$\texttt{B}$$$, $$$\texttt{AB}$$$, $$$\texttt{BA}$$$. It also turned out that there are no spaces in this language: a sentence is written by just con...
def canmake(s,a,b,c,d): anum = s.count('A') bnum = s.count('B') cnum = s.count('AB') dnum = s.count('BA') if cnum < c or dnum < d or anum != a + c + d or bnum != b + c + d: return False n=len(s) ans=0 abls=[] bals=[] l=0 while l<n: while...
s[l]== s[r]=='B'
[{"input": "8\n1 0 0 0\nB\n0 0 1 0\nAB\n1 1 0 1\nABAB\n1 0 1 1\nABAAB\n1 1 2 2\nBAABBABBAA\n1 1 2 3\nABABABBAABAB\n2 3 5 4\nAABAABBABAAABABBABBBABB\n1 3 3 10\nBBABABABABBBABABABABABABAABABA", "output": ["NO\nYES\nYES\nYES\nYES\nYES\nNO\nYES"]}]
control_completion_001184
control_fixed
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$n$$$ rows and $$$m$$$ columns, and three types of cells: An empty cell, denoted with '.'. A stone, denoted with '*'. An obstacle, denoted with the lowercase Latin letter 'o'. All stones fall down until they meet the...
for _ in range(int(input())): n, _ = map(int, input().split()) a = map("".join, zip(*(input() for _ in range(n)))) a = ("o".join("".join(sorted(y, reverse=True)) for y in x.split("o")) for x in a) for {{completion}}: print("".join(x))
x in zip(*a)
[{"input": "3\n6 10\n.*.*....*.\n.*.......*\n...o....o.\n.*.*....*.\n..........\n.o......o*\n2 9\n...***ooo\n.*o.*o.*o\n5 5\n*****\n*....\n*****\n....*\n*****", "output": ["..........\n...*....*.\n.*.o....o.\n.*........\n.*......**\n.o.*....o*\n\n....**ooo\n.*o**o.*o\n\n.....\n*...*\n*****\n*****\n*****"]}]
control_completion_000829
control_fixed
python
Complete the code in python to solve this programming problem: Description: On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the ce...
for _ in range(int(input())): l=[] ans="B" while len(l)!=8: l.append(input()) if len(l[-1])<8: l.pop() for row in l: if row.count('R')==8: {{completion}} print(ans)
ans='R' break
[{"input": "4\n\n\n\n\n....B...\n\n....B...\n\n....B...\n\nRRRRRRRR\n\n....B...\n\n....B...\n\n....B...\n\n....B...\n\n\n\n\nRRRRRRRB\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nB......B\n\nRRRRRRRB\n\n\n\n\nRRRRRRBB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\n\nRRRRRRBB\n\n.B.B..BB\n\n.B.B..BB\...
block_completion_005804
block
python
Complete the code in python to solve this programming problem: Description: You are given two arrays $$$a$$$ and $$$b$$$, consisting of $$$n$$$ integers each.Let's define a function $$$f(a, b)$$$ as follows: let's define an array $$$c$$$ of size $$$n$$$, where $$$c_i = a_i \oplus b_i$$$ ($$$\oplus$$$ denotes bitwise...
import sys from itertools import permutations, combinations ls = [] for l in sys.stdin: lst = l.rstrip('\n') if len(lst) > 0: ls.append(lst) def solve(n, a, b): ps = [((list(range(n))), (list(range(n))))] res = (1<<30) - 1 for k in range(30, -1, -1): next_ps ...
a1.append(pai)
[{"input": "3\n\n5\n\n1 0 0 3 3\n\n2 3 2 1 0\n\n3\n\n1 1 1\n\n0 0 3\n\n8\n\n0 1 2 3 4 5 6 7\n\n7 6 5 4 3 2 1 0", "output": ["2\n0\n7"]}]
block_completion_002743
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
from sys import stdin, stdout input, print = stdin.buffer.readline, stdout.write n, T = [int(x) for x in input().split()] ans = [(1<<31)-1] * n from collections import defaultdict R = defaultdict(list) for _ in range(T): a,b, x = [int(_a) for _a in input().split()] a -= 1 b -= 1 a,b = min(a,b), max...
i == j or mask & ans[j] == 0
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
control_completion_000019
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 &lt; j &lt; 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: While searching for the pizza, baby Hosssam came across two permutations $$$a$$$ and $$$b$$$ of length $$$n$$$.Recall that a permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For exampl...
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();b=L();d=L();l=[] for i in range(n):l.append([a[i],b[i],d[i]]) l.sort(key=lambda x:x[0]);s=set();ans=1 ...
l[cur][2]!=0 or l[cur][1]==l[cur][0]
[{"input": "9\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n2 0 1 0 0 0 0\n1\n1\n1\n0\n6\n1 5 2 4 6 3\n6 5 3 1 4 2\n6 0 0 0 0 0\n8\n1 6 4 7 2 3 8 5\n3 2 8 1 4 5 6 7\n1 0 0 7 0 3 0 5\n10\n1 8 6 2 4 7 9 3 10 5\n1 9 2 3 4 10 8 6 7 5\n1 9 2 3 4 10 8 6 7 5\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n0 0 0 0 0 0 0\n5\n1 2 3 4 5\n1 2 3 4 5\n0 0 0 ...
control_completion_005927
control_fixed
python
Complete the code in python to solve this programming problem: Description: You have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
import sys tokens = (token for token in sys.stdin.read().split()) N = int(next(tokens)) for i in range(N): Q = int(next(tokens)) arr = [] count = 0 for i in range(Q): arr.append(int(next(tokens))) i = 0 j = len(arr) - 1 while True: while True: if arr[i] == 1 or i == j: break e...
arr[j] == 0 or j == i
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
control_completion_006842
control_fixed
python
Complete the code in python to solve this programming problem: Description: Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bisho...
t=int(input()) for p in range(t): n,m=map(int,input().split()) c=[] b=[] s=0 for i in range(n): a=list(map(int,input().split())) b+=[a] for k in range(n): for l in range(m): for v in range(min(l,k)+1): {{completion}} fo...
s+=b[k-v][l-v]
[{"input": "4\n4 4\n1 2 2 1\n2 4 2 4\n2 2 3 1\n2 4 2 4\n2 1\n1\n0\n3 3\n1 1 1\n1 1 1\n1 1 1\n3 3\n0 1 1\n1 0 1\n1 1 0", "output": ["20\n1\n5\n3"]}]
block_completion_007701
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 &gt; 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: AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and...
import heapq as hq INF = 1001001001 N, M = map(int, input().split()) G = [[] for _ in range(N)] d = [0] * N for _ in range(M): U, V = map(int, input().split()) G[V - 1].append(U - 1) d[U - 1] += 1 dists = [INF] * N dists[N - 1] = 0 queue = [(0, N - 1)] while queue: dist, V = hq.heappop(qu...
dist + d[v] < dists[v]
[{"input": "2 1\n1 2", "output": ["1"]}, {"input": "4 4\n1 2\n1 4\n2 4\n1 4", "output": ["2"]}, {"input": "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1", "output": ["4"]}]
control_completion_000462
control_fixed
python
Complete the code in python to solve this programming problem: Description: You have an array $$$a$$$ consisting of $$$n$$$ positive integers and you have to handle $$$q$$$ queries of the following types: $$$1$$$ $$$i$$$ $$$x$$$: change $$$a_{i}$$$ to $$$x$$$, $$$2$$$ $$$l$$$ $$$r$$$ $$$k$$$: check if the number of ...
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.bu...
continue
[{"input": "10 8\n1234 2 3 3 2 1 1 2 3 4\n2 1 6 2\n1 1 1\n2 1 6 2\n2 1 9 2\n1 10 5\n2 1 9 3\n1 3 5\n2 3 10 2", "output": ["NO\nYES\nNO\nYES\nYES"]}]
block_completion_007030
block
python
Complete the code in python to solve this programming problem: Description: My orzlers, we can optimize this problem from $$$O(S^3)$$$ to $$$O\left(T^\frac{5}{9}\right)$$$!— Spyofgame, founder of Orzlim religionA long time ago, Spyofgame invented the famous array $$$a$$$ ($$$1$$$-indexed) of length $$$n$$$ that contai...
a=[*map(int,[*open(0)][1].split())] for k in 0,1: for i in range(19): z=1<<i for j in range(len(a)): if {{completion}}:a[j-k*z]^=a[j+k*z-z] print(*reversed(a))
j&z
[{"input": "3\n0 2 1", "output": ["1 2 3"]}, {"input": "1\n199633", "output": ["199633"]}, {"input": "10\n346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607", "output": ["725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365...
control_completion_002076
control_fixed
python
Complete the code in python to solve this programming problem: Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in...
import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) x=tuple(map(int,input().split())) if n==1: print(-1) continue ans=[-1]*n extra=[] visited=[False]*n for i in range(n-1,-1,-1): if i!=0 and x[i]==x[i-1]: ans[i]=i ...
print(-1) break
[{"input": "2\n5\n1 1 1 1 1\n6\n3 6 8 13 15 21", "output": ["5 1 2 3 4 \n-1"]}]
block_completion_002401
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 {{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: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] x = sum(a) // 2 s, d = 0, {} for idx, i in enumerate(a): s += i if s > x: break d[s] = idx + 1 s, r = 0, 0 for idx, i in enumerate(a[::-1]): s += i if {{complet...
s in d
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000791
control_fixed
python
Complete the code in python to solve this programming problem: Description: Consider a hallway, which can be represented as the matrix with $$$2$$$ rows and $$$n$$$ columns. Let's denote the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$. The distance between the cells $$$(i_1...
import sys inf = float('inf') mod = 998244353 input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int, input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) n=inpint() s=[] for i in range(2): s.append([i for i in list(input())]+['0','0']) #pri...
f[min(i+2,n)][j^1]=max(f[min(i+2,n)][j^1],f[i][j]+1+int(s[j^1][i+1])+int(s[j^1][i+2]))
[{"input": "2\n01\n11", "output": ["2"]}, {"input": "2\n01\n01", "output": ["2"]}, {"input": "4\n0101\n1011", "output": ["4"]}, {"input": "4\n0000\n0000", "output": ["0"]}, {"input": "5\n00011\n10101", "output": ["4"]}, {"input": "6\n011111\n111111", "output": ["8"]}, {"input": "10\n0101001010\n1010100110", "output": [...
block_completion_008393
block
python
Complete the code in python to solve this programming problem: Description: My orzlers, we can optimize this problem from $$$O(S^3)$$$ to $$$O\left(T^\frac{5}{9}\right)$$$!— Spyofgame, founder of Orzlim religionA long time ago, Spyofgame invented the famous array $$$a$$$ ($$$1$$$-indexed) of length $$$n$$$ that contai...
a=[*map(int,[*open(0)][1].split())] for k in 0,1: for i in range(19): z=1<<i for j in range(len(a)): if j&z:{{completion}} print(*reversed(a))
a[j-k*z]^=a[j+k*z-z]
[{"input": "3\n0 2 1", "output": ["1 2 3"]}, {"input": "1\n199633", "output": ["199633"]}, {"input": "10\n346484077 532933626 858787727 369947090 299437981 416813461 865836801 141384800 157794568 691345607", "output": ["725081944 922153789 481174947 427448285 516570428 509717938 855104873 280317429 281091129 1050390365...
block_completion_002116
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 {{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