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 |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 4