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: 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 ... | def rl():
return [int(i) for i in input().split()]
def solve():
[n,x]=rl()
a=rl()
nax=500000+5
ct=[0 for i in range(nax)]
for b in a:
ct[b]+=1
for i in range(x):
if {{completion}}:
return "No"
ct[i+1]+=ct[i]/(i+1)
return "Yes"
print(solve())
| ct[i]%(i+1) | [{"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_005984 | 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+... | print(i)
break | [{"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"]}] | block_completion_001106 | block |
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 = int(input())
mod = 1 << 15
for x in map(int, input().split()):
res = 16
for a in range(15):
for b in range(15):
if (x + a) * (1 << b) % mod == 0:
{{completion}}
print(res)
| res = min(res, a + b) | [{"input": "4\n19 32764 10240 49", "output": ["14 4 4 15"]}] | block_completion_003353 | 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: 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... | for {{completion}}:
a = [int(j) for j in input()]
print("YES" if sum(a[0:3])==sum(a[3:6]) else "NO") | i in range(int(input())) | [{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_007491 | 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
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(input())
G = [[int(x) for x in input()] + [0] for _ in range(2)]
dp = [[0] * 2 for _ in range(N + 1)]
for j in range(2):
dp[N - 1][j] = G[1 - j][N - 1]
for i in range(N - 2, - 1, -1):
... | G[j][i + 1] | [{"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": [... | control_completion_008236 | control_fixed |
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... | (n, q) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
for i in range (1,n):
arr[i] = arr[i] + arr[i-1]
for trial in range(q):
(x, y) = map(int, input().split())
if (x==y):
print (arr[x-1])
else:
{{completion}} | print (arr[x-1] - arr[x-y-1]) | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | block_completion_000523 | 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: This is the hard 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... |
for _ in range(int(input().strip())):
n = int(input().strip())
arr = input()
ans = 0
t = []
for i in range(0, len(arr), 2):
if arr[i] != arr[i + 1]:
ans += 1
else:
{{completion}}
seg = 1
for i in range(0, len(t) - 1):
if t[i] != t... | t.append(arr[i]) | [{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3 2\n0 3\n0 1\n0 1\n3 1"]}] | block_completion_008095 | block |
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 x in map(int, s.split()):
{{completion}}
| print(min(15-i+-x % 2**i for i in range(16))) | [{"input": "4\n19 32764 10240 49", "output": ["14 4 4 15"]}] | block_completion_003354 | 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... | from sys import stdin
t = int(stdin.readline())
for h in range(t):
n = int(stdin.readline())
a = list(map(int,stdin.readline().split(' ')))
b = 0
v = True
for i in range(n):
b += a[i]
if b<0:
v = False
break
elif b==0:
for j ... | v = False
break | [{"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_000425 | 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... | for {{completion}}:
string=tuple(input().strip())
k=len(set(string))
print("NO" if any([string[i]!=string[i%k] for i in range (len(string))]) else "YES")
| _ in range(int(input())) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004715 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: 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... | f=open(0)
R=lambda:map(int,next(f).split())
n,q=R();p=[0]
for w in sorted(R()): p+=p[-1]+w,
for {{completion}}: x, y=R();print(p[n-x+y]-p[n-x])
| _ in " "*q | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | control_completion_000504 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.Consider a number axis. The capital of your empire is initially at $$$0$$$. There are $$$n$$$ unconquered kingdom... | for _ in range(int(input())):
n,a,b=map(int, input().split())
w=[int(x) for x in input().split()]
fb=sum(w)*b
fa=0
ans = fb
cap = 0
cur = n
for x in w:
fb -= x * b
cur -= 1
if {{completion}}:
ans += (x - cap) * a
ans -= (x - cap) * cur * b
cap = x
#print(cap)
print(ans) | (x - cap) * a + fb - (x - cap) * cur * b < fb | [{"input": "4\n5 2 7\n3 5 12 13 21\n5 6 3\n1 5 6 21 30\n2 9 3\n10 15\n11 27182 31415\n16 18 33 98 874 989 4848 20458 34365 38117 72030", "output": ["173\n171\n75\n3298918744"]}] | control_completion_008538 | control_fixed |
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... | for c in [input() for i in range(int(input()))]: {{completion}} | print(('NO', 'YES')[sum(int(p) for p in (c[:3])) == sum(int(p) for p in (c[3:]))]) | [{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}] | block_completion_007622 | 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.... |
n,k=map(int,input().split())
a=[]
d={}
for i in range(n):
a+=[''.join(input().split())]
d[a[-1]]=0
def cal(s,t):
res=""
for i in range(k):
res+=str((9-int(s[i])-int(t[i]))%3)
return res
for i in range(n):
for {{completion}}:
try:
d[cal(a[i],a... | j in range(i) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005229 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You 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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
dd = [0]*(len(a)+5)
add = 0
diff = 0
moves = 0
for key, i in reversed([*enumerate(a)]):
add += diff
i += add
diff += dd[-1]
dd.pop()
if i > 0:
{{completion}}
print(moves)
| K = min(k, key+1)
dd[-K] -= (i+K-1)//K
diff += (i+K-1)//K
moves += (i+K-1)//K
add -= K*((i+K-1)//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_003446 | block |
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())
c=[]
for _ in range(n):
c.append(tuple(map(int,input().split())))
prefix_sum=[[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
temp=0
for j in range(1,n+1):
temp+=c[i-1][j-1]
prefix_sum[i][j]+=prefix_sum[i-1][j]+temp
def get_rectangel_sum(x1,y1,x2,y2):
retu... | dp[i][j]=temp
best_root_for_range[i][j]=root | [{"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_003210 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given an array of length $$$2^n$$$. The elements of the array are numbered from $$$1$$$ to $$$2^n$$$.You have to process $$$q$$$ queries to this array. In the $$$i$$$-th query, you will be given an integer $$$k$$$ ($$$0 \le k \le n-1$$... | import sys
input = lambda: sys.stdin.readline().rstrip()
class Node:
def __init__(self, seg, suf, pref, sum) -> None:
self.best = seg
self.suf = suf
self.pref = pref
self.sum = sum
def merge(a, b):
seg = max(a.best, b.best, a.suf + b.pref)
suf = max(b.suf, b... | i in range((r - l) // 2) | [{"input": "3\n-3 5 -3 2 8 -20 6 -1\n3\n1\n0\n1", "output": ["18\n8\n13"]}] | control_completion_008162 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: On a beach there are $$$n$$$ huts in a perfect line, hut $$$1$$$ being at the left and hut $$$i+1$$$ being $$$100$$$ meters to the right of hut $$$i$$$, for all $$$1 \le i \le n - 1$$$. In hut $$$i$$$ there are $$$p_i$$$ people.There are $$$m$... | N, M = [int(x) for x in input().split()]
hut = [int(x) for x in input().split()]
shop = [int(x) for x in input().split()]
shop = sorted([-1e9] + shop + [1e9])
events = []
j = 0
for i in range(N):
while shop[j] < 100*i:
j += 1
if {{completion}}:
d = min(100*i - shop[j-1], shop[j] - 100*i)
even... | shop[j] != 100 * i | [{"input": "3 1\n2 5 6\n169", "output": ["7"]}, {"input": "4 2\n1 2 7 8\n35 157", "output": ["15"]}, {"input": "4 1\n272203905 348354708 848256926 939404176\n20", "output": ["2136015810"]}, {"input": "3 2\n1 1 1\n300 99", "output": ["2"]}] | control_completion_001129 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: $$$m$$$ chairs are arranged in a circle sequentially. The chairs are numbered from $$$0$$$ to $$$m-1$$$. $$$n$$$ people want to sit in these chairs. The $$$i$$$-th of them wants at least $$$a[i]$$$ empty chairs both on his right and left side.... | for T in range (int(input())) :
n,m = map(int, input().strip().split())
a = sorted(list(map(int,input().strip().split())),reverse=True)
m -= 2*a[0] + 1
cont = 0
for i in range(1,n) :
if {{completion}}: break
m -= a[i] + 1
cont +=1
if cont == n-1 : print('YES')
... | m <= 0 | [{"input": "6\n3 2\n1 1 1\n2 4\n1 1\n2 5\n2 1\n3 8\n1 2 1\n4 12\n1 2 1 3\n4 19\n1 2 1 3", "output": ["NO\nYES\nNO\nYES\nNO\nYES"]}] | control_completion_001003 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: There is a grid, consisting of $$$2$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right.The robot starts in a cell $$$(1, 1)$$$. In ... | def readline():
line = input()
while not line:
line = input()
return line
def main():
t = int(readline())
for _ in range(t):
m = int(readline())
a = [ [], [] ]
a[0] += list(map(int, readline().split()))
a[1] = list(map(int, readline().split()))
h = ... | (i-1) % 4 == 0 | [{"input": "4\n\n3\n\n0 0 1\n\n4 3 2\n\n5\n\n0 4 8 12 16\n\n2 6 10 14 18\n\n4\n\n0 10 10 10\n\n10 10 10 10\n\n2\n\n0 0\n\n0 0", "output": ["5\n19\n17\n3"]}] | control_completion_008132 | control_fixed |
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... | r<n-1 and s[r]!=s[r+1] | [{"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_001183 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is ... | from sys import stdin, stdout
from collections import defaultdict
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
left = 0
right = 0
right_array = []
right_prefix = [0]
answer = 0
second_right = 0
second_right_array = []
second_right_prefix = [0]
while left < n:
if righ... | lower = candidate | [{"input": "4\n2 4 1 4\n3\n2 4\n3 3\n2 1", "output": ["6\n10\n5"]}, {"input": "5\n1 1 3 2 1\n3\n1 3\n2 5\n4 5", "output": ["7\n9\n8"]}] | block_completion_007068 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ consisting of $$$n$$$ integers. You should divide $$$a$$$ into continuous non-empty subarrays (there are $$$2^{n-1}$$$ ways to do that).Let $$$s=a_l+a_{l+1}+\ldots+a_r$$$. The value of a subarray $$$a_l, a_{l+1},... | from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
MOD = 998244353
input = stdin.readline
finp = [int(x) for x in stdin.buffer.read().split()]
def inp(force_list=False):
re = list(map(int, input().split()))
if ... | self.modify(pos, x, p*2 + 1, mid, r) | [{"input": "5\n\n3\n\n1 2 -3\n\n4\n\n0 -2 3 -4\n\n5\n\n-1 -2 3 -1 -1\n\n6\n\n-1 2 -3 4 -5 6\n\n7\n\n1 -1 -1 1 -1 -1 1", "output": ["1\n2\n1\n6\n-1"]}] | block_completion_001050 | block |
python | Complete the code in python to solve this programming problem:
Description: There are $$$n+1$$$ teleporters on a straight line, located in points $$$0$$$, $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, ..., $$$a_n$$$. It's possible to teleport from point $$$x$$$ to point $$$y$$$ if there are teleporters in both of those points, and... | from collections import Counter
n, a, m = int(input()), [*map(int, input().split())], int(input())
def energy(l, t):
x,y = divmod(l, t+1)
return x*x*(t+1-y)+(x+1)*(x+1)*y
def getdiff(l, diff):
lo, hi = 0, l
while lo < hi:
mid = lo + hi >> 1
if energy(l, mid) - energy(l, mid+1) <... | lo = mid + 1 | [{"input": "2\n1 5\n7", "output": ["2"]}, {"input": "2\n1 5\n6", "output": ["3"]}, {"input": "1\n5\n5", "output": ["4"]}, {"input": "1\n1000000000\n1000000043", "output": ["999999978"]}] | block_completion_003462 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = input()
s = int(input(),2)
res = 0
for i in range(100):
{{completion}}
ans = bin(res)[2:]
print(ans) | res = max(res,(s | (s >> i))) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | block_completion_002157 | block |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | import collections
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
data = dict(collections.Counter(map(int, input().split())))
if min(list(data.values())) > 1:
last = 1
for i in data.keys():
print(last + data[i] - 1, end=' ')
... | print(j, end=' ') | [{"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_002398 | block |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | input = __import__('sys').stdin.readline
mapnode = lambda x: int(x)-1
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
u, v = map(mapnode, input().split())
adj[u].append(v)
adj[v].append(u)
# dfs
jump = [[0] * n]
depth = [0] * n
stack = [(0, -1)]
while len(stack) > 0:
... | depth[v] = depth[u] + 1
stack.append((v, u)) | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | block_completion_002280 | 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... | test = int(input())
for i in range(test):
ans = "B"
cnt =0
while cnt < 8 :
t = input()
if t.strip() != '':
cnt +=1
if t == "RRRRRRRR":
{{completion}}
print(ans)
| ans = "R" | [{"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_005800 | block |
python | Complete the code in python to solve this programming problem:
Description: Team Red and Team Blue competed in a competitive FPS. Their match was streamed around the world. They played a series of $$$n$$$ matches.In the end, it turned out Team Red won $$$r$$$ times and Team Blue won $$$b$$$ times. Team Blue was less s... | t = int(input())
for i in range(t):
x = input().split()
r = int(x[1])
b = int(x[2])
x = ""
p = r%(b+1)
q = r//(b+1)
for i in range(p):
{{completion}}
for i in range(b+1-p):
x+= "R"*(q)+"B"
print(x[:-1]) | x += "R"*(q+1)+"B" | [{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}] | block_completion_008717 | 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 < j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff... | from collections import Counter
t=int(input())
while(t!=0):
n=int(input())
s = Counter(input() for x in [1]*n)
cnt = 0
for x in s:
for y in s:
if(x!=y and (x[1]==y[1] or x[0]==y[0])): {{completion}}
print(cnt//2)
t-=1
| cnt += s[x]*s[y] | [{"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"]}] | block_completion_000893 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1, a_2, a_3, \ldots, a_n$$$.You have to answer $$$q$$$ independent queries, each consisting of two integers $$$l$$$ and $$$r$$$. Consider the subarray $$$a[l:r]$$$ $$$=$$$ $$$[a_l, a_{l... | import sys
input = sys.stdin.readline
n,q = map(int,input().split())
a = [0] + list(map(int,input().split()))
cml = a[::1]
for i in range(1, n+1):
a[i] ^= a[i-1]
cml[i] += cml[i-1]
qs = [list(map(int,input().split())) for i in range(q)]
from collections import defaultdict
d = defaultdict(list)
dd = def... | tot == rr-ll or tot == 0 | [{"input": "7 6\n3 0 3 3 1 2 3\n3 4\n4 6\n3 7\n5 6\n1 6\n2 2", "output": ["-1\n1\n1\n-1\n2\n0"]}] | control_completion_001769 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: 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,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
n,m=M();a=L();q=I()
t=[0]*(2*m)
# a is the array of initial values
def build(t,n,a):
for i in range(n):t[i+n]=a[i]
for i in range(n-1,0,-1):t[i]=... | resl=max(resl,t[l]);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"]}] | block_completion_002999 | block |
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... | # read interger t from input.txt and then read t lines
import sys
DEBUG = False
def check(a, b, c):
a = [0] + a
b = [0] + b
c = [0] + c
m_ = [0] * len(a)
m = [0] * len(a)
for i in range(1, len(b)):
m_[b[i]] = i
for i in range(1, len(a)):
m[i] = m_[a[i]]
# print(">>>", a... | c_zeros = False | [{"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 ... | block_completion_006025 | block |
python | Complete the code in python to solve this programming problem:
Description: A triple of points $$$i$$$, $$$j$$$ and $$$k$$$ on a coordinate line is called beautiful if $$$i < j < k$$$ and $$$k - i \le d$$$.You are given a set of points on a coordinate line, initially empty. You have to process queries of three t... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer... | self.push(l >> i) | [{"input": "7 5\n8 5 3 2 1 5 6", "output": ["0\n0\n1\n2\n5\n1\n5"]}] | block_completion_005218 | block |
python | Complete the code in python to solve this programming problem:
Description: Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alpha... | 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()
s = str(inp1())[::-1]
alph = "0abcdefghijk... | s[i] == "0" | [{"input": "9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606", "output": ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"]}] | control_completion_008431 | 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 {{completion}}: break
d[s] = idx + 1
s, r = 0, 0
for idx, i in enumerate(a[::-1]):
s += i
if ... | s > x | [{"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_000790 | 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 ... | for n in [*open(0)][2::2]:
*a,=map(int,n.split());b=len(a);c=a.count(0)
while a:
q=a.pop()
if {{completion}}:
break
print(b+(a==[])*(c==0)-c)
| a.count(q)>0 | [{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}] | control_completion_008021 | 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 ... | import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
N=int(input())
C=list(map(int,input().split()))
ans=[0]*N
k=sum(C)//N
i=N-1
while i>-1 and k>0:
if C[i]==N:
ans[i]=1
k-=1
else:
{{completion}}
... | C[i-k]+=N-i | [{"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"]}] | block_completion_008753 | 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... | input = __import__('sys').stdin.readline
MOD = 998244353
fact = [1]
invfact = [1]
for i in range(1, 101):
fact.append(fact[-1] * i % MOD)
invfact.append(pow(fact[-1], MOD-2, MOD))
def C(n, k):
if k < 0 or k > n:
return 0
return fact[n] * invfact[k] % MOD * invfact[n-k] % MO... | ans -= MOD | [{"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_000546 | block |
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 ... |
for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
Min = 1e18
for l in range(n):
m = a[l]
answer = 1
for i in range(l-1, -1, -1):
answer += (m + a[i]) // a[i]
m = a[i] * ((m + a[i]) // a[i])
if l + 1 < n:
... | answer += (m + a[i]) // a[i]
m = a[i] * ((m + a[i]) // a[i]) | [{"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"]}] | block_completion_000979 | 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... | from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def update(i , t):
global ans
if(i + 1 < n and a[i] == a[i + 1]):
ans += t * (i + 1)
else:
ans += t * (n - i) * (i + 1)
return ans
def answer():
global ans
ans =... | (i >= 0) | [{"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_000077 | 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... | t = int(input())
for i in range (t):
n, m = map(int,input().split())
arr = [[0]*m]*n
for j in range(n):
arr[j] = list(input())
# for h in range(m):
# print(arr[j][h])
for k in range(m):
for l in range(n-1, -1, -1):
if arr[l][k]=='.':
... | arr[f][k]=='*' | [{"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_000838 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.Th... | N=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
ans=-(-B[0]//2)-(-B[1]//2)
for i in range(N-2):
{{completion}}
for i in range(N-1):
score=max(-(-(A[i]+A[i+1])//3),-(-A[i]//2),-(-A[i+1]//2))
ans=min(score,ans)
print(ans) | ans=min(ans,-(-(A[i]+A[i+2])//2)) | [{"input": "5\n20 10 30 10 20", "output": ["10"]}, {"input": "3\n1 8 1", "output": ["1"]}, {"input": "6\n7 6 6 8 5 8", "output": ["4"]}, {"input": "6\n14 3 8 10 15 4", "output": ["4"]}, {"input": "4\n1 100 100 1", "output": ["2"]}, {"input": "3\n40 10 10", "output": ["7"]}] | block_completion_007904 | 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... | arr=[int(i) for i in input().split()]
ans=[]
prices=[int(i) for i in input().split()]
prices.sort(reverse=True)
for i in range(1,arr[0]):
prices[i]=prices[i]+prices[i-1]
for i in range(arr[1]):
xy=[int(i) for i in input().split()]
if{{completion}}:
ans.append(prices[xy[0]-1])
els... | (xy[0]==xy[1]) | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | control_completion_000508 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$.Let $$$A \cup B$$$ be the union of two sets $$$A$$$ ... | import sys
import heapq
from collections import Counter
# sys.setrecursionlimit(10000)
def input_general():
return sys.stdin.readline().rstrip('\r\n')
def input_num():
return int(sys.stdin.readline().rstrip("\r\n"))
def input_multi(x=int):
return map(x, sys.stdin.readline().rstrip("\r\n... | answer = (answer * base) % p | [{"input": "4\n3 5\n4 8\n2 2\n1 9", "output": ["162"]}, {"input": "4\n1 9\n3 5\n4 8\n2 2", "output": ["102"]}] | block_completion_002199 | 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 {{completion}}:
... | x < y | [{"input": "4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5", "output": ["2\n13\n36\n33"]}] | control_completion_004124 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: 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 x in s.split():{{completion}} | print(min(-int(x)%2**i-i+15for i in range(16))) | [{"input": "4\n19 32764 10240 49", "output": ["14 4 4 15"]}] | block_completion_003352 | 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 < j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff... | for i in range(int(input())):
data = [[0 for l in range(11)] for k in range(11)]
for j in range(int(input())):
first, second = input()
data[ord(first)-ord('a')][ord(second)-ord('a')] += 1
answer = 0
for j in range(11):
for k in range(11):
for l in range(11... | j != l | [{"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_000867 | control_fixed |
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... | n,q = map(int,input().split())
graph = [set() for _ in range(n)]
start = [0xffffffff]*n
for _ in range(q):
i,j,x = map(int,input().split())
i -= 1; j -= 1
graph[i].add(j)
graph[j].add(i)
start[i] &= x
start[j] &= x
for i in range(n):
if i in graph[i]:
continue
val = ... | j in graph[i] | [{"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_000017 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $$$n \times m$$$ consisting of characters '.' (empty cell of the desktop) and '*' (an icon).The desktop is called good i... | h, w, q = map(int, input().split())
p = [False] * (h * w)
c = cc = 0
def query(y, x):
global c, cc
i = x*h+y
p[i] = not p[i]
if p[i]:
if i < c:
cc += 1
c += 1
if p[c-1]:
cc += 1
else:
if {{completion}}:
cc -= 1
... | i < c | [{"input": "4 4 8\n..**\n.*..\n*...\n...*\n1 3\n2 3\n3 1\n2 3\n3 4\n4 3\n2 3\n2 2", "output": ["3\n4\n4\n3\n4\n5\n5\n5"]}, {"input": "2 5 5\n*...*\n*****\n1 3\n2 2\n1 3\n1 5\n2 3", "output": ["2\n3\n3\n3\n2"]}] | control_completion_007735 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: On a beach there are $$$n$$$ huts in a perfect line, hut $$$1$$$ being at the left and hut $$$i+1$$$ being $$$100$$$ meters to the right of hut $$$i$$$, for all $$$1 \le i \le n - 1$$$. In hut $$$i$$$ there are $$$p_i$$$ people.There are $$$m$... | from itertools import chain
from sys import stdin
(n, m), population, shops = [[int(x) for x in line.split()] for line in stdin.readlines()]
shops.sort()
shops = chain([float('-inf')], (v / 100 for v in shops), [float('inf')])
shop_left, shop_right = next(shops), next(shops)
hut_left_idx = max_score = score = 0
for h... | score -= population[hut_left_idx]
hut_left_idx += 1 | [{"input": "3 1\n2 5 6\n169", "output": ["7"]}, {"input": "4 2\n1 2 7 8\n35 157", "output": ["15"]}, {"input": "4 1\n272203905 348354708 848256926 939404176\n20", "output": ["2136015810"]}, {"input": "3 2\n1 1 1\n300 99", "output": ["2"]}] | block_completion_001150 | 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{{completion}}: print(-1)
else: print((total+t-1)//t)
pass | (t<time) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004185 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$... | for {{completion}}:p,q,*_,r,s=sorted(map(int,sdr.split()));print(r+s-p-q) | sdr 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_005298 | 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 ... | t = int(input())
for _ in range(t):
n = int(input())
c = list(map(int, input().split()))
a, e, se, s = [], [0]*n, 0, sum(c)
for {{completion}}:
se -= e[i-1]
n1 = s//i
t = 0 if c[i-1] < i + se else 1
a.append(t)
s -= (n1 + (i-1)*t)
e[i-n1-1] += 1... | i in range(n, 0, -1) | [{"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_008599 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Team Red and Team Blue competed in a competitive FPS. Their match was streamed around the world. They played a series of $$$n$$$ matches.In the end, it turned out Team Red won $$$r$$$ times and Team Blue won $$$b$$$ times. Team Blue was less s... | for _ in range(int(input())):
{{completion}} | n,r,b=map(int,input().split())
t=((r-1)//(b+1)+1)
k=t*(b+1)-r
res=('R'*t+'B')*(b+1-k)+('R'*(t-1)+'B')*k
print(res[:-1])
# | [{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}] | block_completion_008710 | 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 ... | b=[0]*500001
l=list(map(int,input("").split()))
n=l[0]
m=l[1]
a=list(map(int,input("").split()))
e=1
for i in a:
b[i]+=1
for i in range(1,l[1]):
if b[i]%(i+1)==0:
b[i+1]+=(b[i]//(i+1))
else:
print("No")
e=0
break
if e==1:
if b[m]!=0 :
print("Yes")... | 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_006097 | 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 ... | last <= min(row_values_pref[i]-total, n-total) | [{"input": "6\n1 1 2 1 4 3", "output": ["7"]}, {"input": "7\n3 5 4 3 7 4 5", "output": ["11"]}] | control_completion_004651 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Once upon a time Mike and Mike decided to come up with an outstanding problem for some stage of ROI (rare olympiad in informatics). One of them came up with a problem prototype but another stole the idea and proposed that problem for another s... | f = open(0)
def R(): return map(int, next(f).split())
n, q = R()
d = {}
i = v = r = 0
for x in R():
r += x
i += 1
d[i] = x
while q:
q -= 1
t, *x = R()
if t & 1:
i, x = x
r += x - d.get(i, v)
d[i] = x
else:
{{completion}}
print(r)
| d = {}
v, = x
r = v * n | [{"input": "5 5\n1 2 3 4 5\n1 1 5\n2 10\n1 5 11\n1 4 1\n2 1", "output": ["19\n50\n51\n42\n5"]}] | block_completion_005606 | 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: 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 ... | t = int(input())
for _ in range(t):
n = int(input())
c = list(map(int, input().split()))
a, e, se, s = [], [0]*n, 0, sum(c)
for i in range(n, 0, -1):
{{completion}}
print(*reversed(a))
| se -= e[i-1]
n1 = s//i
t = 0 if c[i-1] < i + se else 1
a.append(t)
s -= (n1 + (i-1)*t)
e[i-n1-1] += 1
se += 1 | [{"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"]}] | block_completion_008749 | block |
python | Complete the code in python to solve this programming problem:
Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l... | n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(n):
C = [0]*n
for j in range(n-1, -1, -1):
if A[j] == 0:
C[j] = 1
if j+1 < n:
C[j] += C[j+1]
B = A.copy()
s = sum(B)
flag = True
for j in range(n):
... | x = 0 | [{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}] | block_completion_000201 | block |
python | Complete the code in python to solve this programming problem:
Description: Leslie and Leon entered a labyrinth. The labyrinth consists of $$$n$$$ halls and $$$m$$$ one-way passages between them. The halls are numbered from $$$1$$$ to $$$n$$$.Leslie and Leon start their journey in the hall $$$s$$$. Right away, they qu... | def DFS(start):
nodes=set()
stack=[start]
while stack:
parent=stack.pop()
if(not visited[parent]):
nodes.add(parent)
visited[parent]=True
for child in graph[parent]:
if {{completion}}:
stack.append(child)
... | (not visited[child]) | [{"input": "5 5 1\n1 2\n2 3\n1 4\n4 3\n3 5", "output": ["Possible\n3\n1 2 3\n3\n1 4 3"]}, {"input": "5 5 1\n1 2\n2 3\n3 4\n2 5\n5 4", "output": ["Impossible"]}, {"input": "3 3 2\n1 2\n2 3\n3 1", "output": ["Impossible"]}] | control_completion_003114 | 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... | def solve():
n, d = [int(i) for i in input().split(' ')]
power = [int(i) for i in input().split(' ')]
power.sort()
used = 0
w = 0
for i in range(len(power)-1, -1, -1):
min_players = -(d // -power[i])
p = power[i] * min_players
if(p > d):
used... | (p == d) | [{"input": "6 180\n90 80 70 60 50 100", "output": ["2"]}] | control_completion_003664 | control_fixed |
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... | n,q=map(int,input().split())
a=[0]
for x in sorted(map(int,input().split()))[::-1]:a+=a[-1]+x,
for _ in[0]*q:{{completion}}
| x,y=map(int,input().split());print(a[x]-a[x-y]) | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | block_completion_000513 | 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(1, t + 1):
summa = 0
a = int(input())
a6 = a % 10
a5 = (a // 10) % 10
a4 = (a // 100) % 10
a3 = (a // 1000) % 10
a2 = (a // 10000) % 10
a1 = (a // 100000) % 10
if {{completion}}:
print('YES')
else:
print("NO") | a1 + a2 + a3 == a4 + a5 + a6 | [{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_007488 | 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 x in zip(*a):
{{completion}}
| print("".join(x)) | [{"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_000845 | 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 stdin, stdout
from math import floor, ceil, log
input, print = stdin.readline, stdout.write
def main():
n, m = map(int, input().split())
arr = [0] + [int(x) for x in input().split()]
st = construct(arr, m)
for _ in range(int(input())):
x1, y1, x2, y2, k = map(int, input().split())
... | ((y2 - y1) % k != 0 or (x2 - x1) % k != 0) | [{"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_002942 | control_fixed |
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 versions is the constraints on $$$n$$$, $$$k$$$, $$$a_i$$$, and the sum of $$$n$$$ over all test cases. You can make hacks only if both versions of the problem are solved... | 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... | v in s[r] | [{"input": "7\n\n5 2\n\n4 5 6 8 11\n\n5 12\n\n4 5 6 8 11\n\n3 1\n\n2 9 15\n\n7 3\n\n2 3 5 5 6 9 10\n\n6 56\n\n54 286 527 1436 2450 2681\n\n3 95\n\n16 340 2241\n\n2 2\n\n1 3", "output": ["2\n0\n13\n1\n4\n7\n0"]}] | control_completion_003595 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | for _ in range(int(input())):
{{completion}}
| s = input()
c = len(set(s))
print("Yes" if all(len(set(s[i::c])) == 1 for i in range(c)) else "No") | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | block_completion_004801 | block |
python | Complete the code in python to solve this programming problem:
Description: After watching a certain anime before going to sleep, Mark dreams of standing in an old classroom with a blackboard that has a sequence of $$$n$$$ positive integers $$$a_1, a_2,\dots,a_n$$$ on it.Then, professor Koro comes in. He can perform t... | import sys
import os
from io import BytesIO, IOBase
# region fastio
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 ... | res += [1] * (self.sz - i)
break | [{"input": "5 4\n2 2 2 4 5\n2 3\n5 3\n4 1\n1 4", "output": ["6\n5\n4\n5"]}, {"input": "2 1\n200000 1\n2 200000", "output": ["200001"]}] | block_completion_005933 | block |
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{{completion}}:
res.append((xi,yi))
res.sort()
dp = [float("inf")]*(n+3)
dp[0] = 0
dp[n+2] ... | (xi>=0 and yi>=0) | [{"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_001083 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | import itertools
m=0
n = int(input())
v = list(itertools.accumulate(map(int, input().split())))
for i in range(n):
m=max((v[i]-1)//(i+1)+1,m)
for {{completion}}:
t = int(input())
print((v[-1] - 1) // t + 1 if t >= m else -1)
| _ in range(int(input())) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004184 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.Th... | N=int(input())
A=[int(x) for x in input().split()]
B=sorted(A)
ans=-(-B[0]//2)-(-B[1]//2)
for {{completion}}:
ans=min(ans,-(-(A[i]+A[i+2])//2))
for i in range(N-1):
score=max(-(-(A[i]+A[i+1])//3),-(-A[i]//2),-(-A[i+1]//2))
ans=min(score,ans)
print(ans) | i in range(N-2) | [{"input": "5\n20 10 30 10 20", "output": ["10"]}, {"input": "3\n1 8 1", "output": ["1"]}, {"input": "6\n7 6 6 8 5 8", "output": ["4"]}, {"input": "6\n14 3 8 10 15 4", "output": ["4"]}, {"input": "4\n1 100 100 1", "output": ["2"]}, {"input": "3\n40 10 10", "output": ["7"]}] | control_completion_007774 | control_fixed |
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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
dd = [0]*(len(a)+5)
add = 0
diff = 0
moves = 0
for key, i in reversed([*enumerate(a)]):
add += diff
i += add
diff += dd[-1]
dd.pop()
if {{completion}}:
K = min(k, key+1)
dd[-K] -= (i+K-1)//K
diff... | i > 0 | [{"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"]}] | control_completion_003388 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in... | from collections import Counter
for _ in range(int(input())):
n=int(input());
l=list(map(int, input().split()));c = Counter(l);
if any(x == 1 for x in c.values()):
{{completion}}
print(*[i if i!=0 and l[i]==l[i-1] else i+c[l[i]] for i in range(n)]) | print(-1); continue | [{"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_002395 | 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.... | import sys; R = sys.stdin.readline
n,k = map(int,R().split())
deck = [tuple(map(int,R().split())) for _ in range(n)]
dic = {}
for i in range(n): dic[deck[i]] = i
res = [0]*n
for p in range(n-2):
for q in range(p+1,n-1):
last = [0]*k
for j in range(k):
last[j] = deck[p][j] if de... | res[p] += 1; res[q] += 1; res[dic[last]] += 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_005319 | block |
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
n, s = int(input()), input()
def calc(u: int) -> tuple:
if u >= (1 << n):
{{completion}}
t1, t2 = calc(u * 2), calc(u * 2 + 1)
return (t1[0] + t2[0] + (t1[1] != t2[1]),
hash((min(t1[1], t2[1]), max(t1[1], t2[1]), s[u - 1])))
print(pow(2, calc(1)[0],... | return (0, 0) | [{"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"]}] | block_completion_001705 | 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$... | """
take element as "the tail" will use more less operations,
use variables s,cnt and closed,
to avoid the inner iteration(update neighbor k elements every time),
complexity is O(n).
"""
row=lambda:map(int,input().split())
n,k=row()
a=list(row())
closed=[0]*n
s=cnt=res=0
for i in range(n-1,-1,-1):
# p... | i>=th | [{"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"]}] | control_completion_003390 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l... | n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(n):
C = [0]*n
for j in range(n-1, -1, -1):
if A[j] == 0:
C[j] = 1
if j+1 < n:
C[j] += C[j+1]
B = A.copy()
s = sum(B)
flag = True
for j in range(n):
... | j+1 < n | [{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}] | control_completion_000199 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $$$n \times m$$$ consisting of characters '.' (empty cell of the desktop) and '*' (an icon).The desktop is called good i... |
n,m,q = map(int, input().split())
s = [input() for _ in range(n)]
s = [s[j][i] for i in range(m) for j in range(n)]
qrr = [list(map(int, input().split())) for _ in range(q)]
qrr = [n * (q[1] - 1) + q[0] - 1 for q in qrr]
count = s.count('*')
correct = s[:count].count('*')
for q in qrr:
count += 1 if s[q] == ... | correct -= 1 if q < count else 0
correct -= 1 if s[count] == '*' else 0 | [{"input": "4 4 8\n..**\n.*..\n*...\n...*\n1 3\n2 3\n3 1\n2 3\n3 4\n4 3\n2 3\n2 2", "output": ["3\n4\n4\n3\n4\n5\n5\n5"]}, {"input": "2 5 5\n*...*\n*****\n1 3\n2 2\n1 3\n1 5\n2 3", "output": ["2\n3\n3\n3\n2"]}] | block_completion_007866 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the s... | # from __future__ import annotations
import csv
import datetime
import string
import sys
import time
from collections import defaultdict
from contextlib import contextmanager
from typing import List, Optional
def solve() -> None:
s = next_token()
t = next_token()
ls = len(s)
lt = len(t)
is_start = [s[i:i +... | tt = [l[0] + r[0] + 1, r[1]] | [{"input": "8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa", "output": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"]}] | block_completion_008646 | block |
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:
{{completion}}
if (n - i) * val > m:
return inf
if i == n:
return 0... | return inf | [{"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"]}] | block_completion_003581 | 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())]
n=len(a)
for k in 0,1:
for i in range(19):
for j in range(n):
l=j^1<<i
if k^(l<j)and l<n:
{{completion}}
print(*reversed(a))
| a[j]^=a[l] | [{"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_002117 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$ consisting of $$$n$$$ characters. Each character of $$$s$$$ is either 0 or 1.A substring of $$$s$$$ is a contiguous subsequence of its characters.You have to choose two substrings of $$$s$$$ (possibly intersectin... | n = int(input())
s=input()
b=int(s,2)
a=b;
mx=a|b
for i in range(0,7):
a=a>>1
m=a|b
if m>mx:
{{completion}}
st=format(mx ,"b")
print(st) | mx=m | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | block_completion_002156 | 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... | f=open(0)
R=lambda:map(int,next(f).split())
n,q=R();p=[0]
for w in sorted(R()): p+=p[-1]+w,
for _ in " "*q: {{completion}}
| x, y=R();print(p[n-x+y]-p[n-x]) | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | block_completion_000515 | block |
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 ... | from bisect import bisect
b = [-5001, 1400, 1600, 1900]
for i in range(int(input())): {{completion}} | print(f'Division {-bisect(b, int(input()))+5}') | [{"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_000726 | block |
python | Complete the code in python to solve this programming problem:
Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number... | N = 4 * 10**5 + 5
MOD = 10**9 + 7
fact = [1]
invf = [1]
for i in range(1, N):
fact.append(fact[i-1] * i % MOD)
invf.append(pow(fact[-1], MOD-2, MOD))
def C(m, n):
if {{completion}}:
return 0
return fact[m] * invf[n] % MOD * invf[m-n] % MOD
n = int(input())
a = list(map(in... | n < 0 or m < n | [{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}] | control_completion_007310 | control_fixed |
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 ... | x = input()
for i in range(int(x)):
z = input()
if int(z) >= 1900:
print('Division 1')
elif int(z) >= 1600:
print('Division 2')
elif int(z) >= 1400:
{{completion}}
else:
print('Division 4')
| print('Division 3') | [{"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_000732 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$. You have to determine whether it is possible to build the string $$$s$$$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any... | t=int(input())
while(t):
i=0
s=input()
if(len(s)==1):
print("NO")
t=t-1
continue
while(i<len(s)):
if(i==0):
if(s[0:2]=="ab" or s[0:2]=="ba"):
print("NO")
t=t-1
break
if(i>0 and i<len(s)-1):
... | (s[i-1:]=="ba" or s[i-1:]=="ab") | [{"input": "8\n\naaaabbb\n\nbbaaaaabbb\n\naaaaaa\n\nabab\n\na\n\nb\n\naaaab\n\nbbaaa", "output": ["YES\nYES\nYES\nNO\nNO\nNO\nNO\nYES"]}] | control_completion_001643 | control_fixed |
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$$... | R=lambda:map(int,input().split())
n,m=R()
*a,=R()
b=[[0],[0]]
f=max
for x in b:
for {{completion}}:x+=x[-1]+f(0,u-v),
f=min
for _ in[0]*m:s,t=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_002892 | control_fixed |
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... | from sys import stdin
# t = int(stdin.readline().rstrip())
# while t>0:
# t-=1
n,q = map(int,stdin.readline().split())
l = list(map(int,stdin.readline().split()))
l.sort()
for i in range(1,n):
l[i] += l[i-1]
# print(l)
for i in range(q):
x,y = map(int,stdin.readline().split())
actual =... | n-x > 0 | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | control_completion_000505 | 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... | n = int(input())
for i in range(n) :
b = []
j = 0
key = '.'
while(j<8) :
a = input()
if(a != '') :
b.append(a)
j += 1
for j in range(8) :
if(len(set(b[j])) == 1 and b[j][0] == 'R') :
{{completion}}
if(key!= 'R') :
k... | key = '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_005812 | block |
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 {{completion}}:
l = int(input())
print("NO" if any (len(set(x)) == 1 for x in input().split('W') ) else "YES") | _ in range(int(input())) | [{"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"]}] | control_completion_000906 | 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
input = sys.stdin.readline
class Solver1670C:
def __init__(self):
self.n = int(input())
self.a = list(map(int, input().split(' ')))
self.b = list(map(int, input().split(' ')))
self.d = list(map(int, input().split(' ')))
self.pos_a = [0 for _ in rang... | self.been[j] == 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_005923 | 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... | t = int(input())
Ans = [-1]*t
for z in range(t):
n = int(input())
l = input().split('W')
bad = False
for s in l:
b1 = 'R' in s
b2 = 'B' in s
if (b1 ^ b2):
{{completion}}
print("NO" if bad else "YES")
| bad = True | [{"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_000931 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | def dfs(tree,i,h):
if i>=2**(h-1)-1:
return [tree[i],1]
ls,li=dfs(tree,i*2+1,h)
rs,ri=dfs(tree,i*2+2,h)
res=li*ri
if {{completion}}:
res*=2
if ls>rs:
return [tree[i]+rs+ls,res]
else:
return [tree[i]+ls+rs,res]
h=int(input())
tree=input()
prin... | ls!=rs | [{"input": "4\nBAAAAAAAABBABAB", "output": ["16"]}, {"input": "2\nBAA", "output": ["1"]}, {"input": "2\nABA", "output": ["2"]}, {"input": "2\nAAB", "output": ["2"]}, {"input": "2\nAAA", "output": ["1"]}] | control_completion_001667 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$.A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of i... | from __future__ import annotations
import csv
import datetime
import string
import sys
import time
from collections import defaultdict
from contextlib import contextmanager
from typing import List
def solve() -> None:
a = [int(c) % 9 for c in next_token()]
n = len(a)
sa = list(a)
for i in range(1, n):
sa... | res = min(res, (indices[v1][0], indices[v2][0])) | [{"input": "5\n\n1003004\n\n4 1\n\n1 2 1\n\n179572007\n\n4 2\n\n2 7 3\n\n2 7 4\n\n111\n\n2 1\n\n2 2 6\n\n0000\n\n1 2\n\n1 4 0\n\n1 4 1\n\n484\n\n1 5\n\n2 2 0\n\n2 3 7\n\n1 2 5\n\n3 3 8\n\n2 2 6", "output": ["2 4\n1 5\n1 2\n-1 -1\n1 2\n-1 -1\n1 3\n1 3\n-1 -1\n-1 -1\n-1 -1"]}] | block_completion_008664 | 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$$... | (n,m),(*a,),*r=(map(int,s.split())for s in open(0))
b=[[0],[0]]
for x in b:
for u,v in zip([0]+a,a):{{completion}}
max=min
for s,t in r:l=b[s>t];print(l[t]-l[s]) | x+=x[-1]+max(0,u-v), | [{"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"]}] | block_completion_002946 | block |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.