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 a positive integer $$$n$$$. Let's call some positive integer $$$a$$$ without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express $$$n$$$ as a sum ... | import sys
input = sys.stdin.readline
s = []
c = [1]
for y in range(1,40005):
if str(y) == (str(y))[::-1]:
s.append(y)
c.append(0)
for i in s:
for j in range(1,40005):
if j >= i:
{{completion}}
a = int(input())
for y in range(a):
b = int(i... | c[j] += (c[j - i]) % ((10 ** 9) + 7) | [{"input": "2\n5\n12", "output": ["7\n74"]}] | block_completion_004786 | block |
python | Complete the code in python to solve this programming problem:
Description: Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following: Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$). Let $$$c$$$ ... | def ev(x):
k = 0
while x%2 == 0:
x//=2
k+=1
return x+k
p,q = [int(i) for i in input().split()]
t = 1
s = 1
sum = 0
while True:
ss = s + (t+1)//2
if ss > p:
m = (p-s+1)
sum += m*t
break
sum += t*((t+1)//2)
s = ss
t += 1
mx = t-2*m... | x-ded <= tt | [{"input": "6 3\n1\n4\n5", "output": ["17\n1\n3\n4"]}, {"input": "1 0", "output": ["1"]}] | control_completion_003692 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe... | import sys
import collections
inf=float('inf')
mod=10**5+7
input = lambda: sys.stdin.readline().rstrip()
inpnm = lambda: map(int,input().split())
inparr = lambda: [int(i) for i in input().split()]
inpint = lambda: int(input())
# for case in range(inpint()):
n,m=inpnm()
arr=inparr()
res=[1]
cnt=0
se=1
t=1
... | i!=n-1 and arr[i+1]!=arr[i] | [{"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_000084 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree, consisting of $$$n$$$ vertices. Each edge has an integer value written on it.Let $$$f(v, u)$$$ be the number of values that appear exactly once on the edges of a simple path between vertices $$$v$$$ and $$$u$$$.Calculate ... |
##########################
def tree_search(n,G,s,func1,func2,func3):
seen = [0] * (n + 1) # 場合によっては外に出す
ind = [0] * (n + 1) ##
search=[s]
while search:
now=search[-1]
if seen[now]==0 and func1!=0:func1(now)
seen[now]=1
if len(G[now])>ind[now]:
next=G[n... | func3!=0 | [{"input": "3\n1 2 1\n1 3 2", "output": ["4"]}, {"input": "3\n1 2 2\n1 3 2", "output": ["2"]}, {"input": "5\n1 4 4\n1 2 3\n3 4 4\n4 5 5", "output": ["14"]}, {"input": "2\n2 1 1", "output": ["1"]}, {"input": "10\n10 2 3\n3 8 8\n4 8 9\n5 8 5\n3 10 7\n7 8 2\n5 6 6\n9 3 4\n1 6 3", "output": ["120"]}] | control_completion_001877 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start wate... | # by the authority of GOD author: Kritarth Sharma #
import sys
from collections import defaultdict,deque,Counter
from bisect import bisect_left
import math
input=sys.stdin.readline
def inp():
l=list(map(int,input().split()))
return l
for _ in range(int(input())):
n,=inp()
l=inp(... | x+=(i-l[j])//2
y+=(i-l[j])%2 | [{"input": "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4", "output": ["4\n3\n16"]}] | block_completion_003423 | 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())):
n= int(input())
a = dict()
b = dict()
c = dict()
ans = 0
for j in range(n):
d,e = str(input())
try:
ans += a[d]
a[d] += 1
except KeyError:
a[d] = 1
try:
ans += b[e]
... | b[e] = 1 | [{"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_000892 | 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... | def random(st):
n = 8
st = int(st, 2)
MAX = st
for t in range(n):
{{completion}}
return bin(MAX)[2:]
N = input()
b = input()
print(random(b))
| MAX = max((st >> t) | st, MAX) | [{"input": "5\n11010", "output": ["11111"]}, {"input": "7\n1110010", "output": ["1111110"]}, {"input": "4\n0000", "output": ["0"]}] | block_completion_002161 | block |
python | Complete the code in python to solve this programming problem:
Description: Monocarp is going to host a party for his friends. He prepared $$$n$$$ dishes and is about to serve them. First, he has to add some powdered pepper to each of them — otherwise, the dishes will be pretty tasteless.The $$$i$$$-th dish has two va... | import math
import sys
input = sys.stdin.readline
class Dish:
def __init__(self):
self.a=0
self.b=0
def exgcd(a,b):
if b:
x,y=exgcd(b,a%b)
return y,x-a//b*y
return 1,0
n=int(input())
dish=[Dish() for i in range(n)]
val=[0 for i in range(n+5)]
for i in range(n):
dish[i].a,dish[i].b=... | print(val[a*gcdAB*(x1+kmin*b)]) | [{"input": "3\n5 10\n100 50\n2 2\n4\n2 3\n1 1\n3 2\n2 2", "output": ["62\n112\n107\n-1"]}, {"input": "10\n3 1\n2 3\n1 1\n2 1\n6 3\n1 4\n4 3\n1 3\n5 3\n5 4\n10\n8 10\n9 3\n1 4\n2 5\n8 3\n3 5\n1 6\n7 2\n6 7\n3 1", "output": ["26\n-1\n36\n30\n-1\n26\n34\n26\n-1\n36"]}] | block_completion_005537 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$... | # get testcase input
t = int(input())
result = ""
while t:
t -= 1
n = int(input())
aux = int(n/2 if n%2==0 else n/2+1)
if n == 1:
result += "1\n1 2\n"
continue
result += str(aux) + "\n"
for i in range(aux):
{{completion}}
print(result[:-1]) | result += str(2+3*i) + ' ' + str(3+3*(n-i-1)) + "\n" | [{"input": "2\n1\n2", "output": ["1\n1 2\n1\n2 6"]}] | block_completion_001833 | block |
python | Complete the code in python to solve this programming problem:
Description: A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Ch... | from heapq import *
for _ in range(int(input())):
n = int(input())
pp = list(map(int, input().split()))
sibs = [[] for _ in range(n+1)]
for i,p in enumerate(pp, 2):
sibs[p].append(i)
child_infected = [False] * (n+1)
isibs = sorted(range(1, n+1), key=lambda x:len(sibs[x]), reverse=True)
... | to_spread and to_spread[0][0] <= turn | [{"input": "5\n7\n1 1 1 2 2 4\n5\n5 5 1 4\n2\n1\n3\n3 1\n6\n1 1 1 1 1", "output": ["4\n4\n2\n3\n4"]}] | control_completion_004308 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: 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... | import sys,os,io
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = sys.stdin.readline
for _ in range (int(input())):
c = [int(i) for i in input().split()]
s = list(input().strip())
if s.count('A') != c[0] + c[2] + c[3] or s.count('B') != c[1] + c[2] + c[3]:
print("NO")
... | extra += cnt - 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"]}] | block_completion_001214 | block |
python | Complete the code in python to solve this programming problem:
Description: This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only o... | def func(s):
curr=s[0]
c=0
count=0
for i in s:
if i==curr:
c+=1
elif c%2==0:
{{completion}}
else:
curr=i
c=2
count+=1
return count
for i in range(int(input())):
n=int(input())
print(func(inp... | c=1
curr=i
continue | [{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}] | block_completion_008122 | 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 {{completion}}:x+=x[-1]+max(0,u-v),
max=min
for s,t in r:l=b[s>t];print(l[t]-l[s]) | u,v in zip([0]+a,a) | [{"input": "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2", "output": ["2\n10\n0\n7\n3\n1"]}] | control_completion_002895 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | import sys
class LCA:
def __init__(self, g, root=0):
self.g = g
self.root = root
n = len(g)
self.logn = (n - 1).bit_length()
self.depth = [None] * n
self.parent = [[None] * self.logn for _ in range(n)]
self._dfs()
self._doubling()
def _dfs(self)... | self.depth[v] is None | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002245 | 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$$... | n,m=map(int,input().split())
c=[int(i) for i in input().split()]
f=[0]*n
g=[0]*n
for i in range(1,n):
f[i]=f[i-1]+max(0,c[i-1]-c[i])
g[-i-1]=g[-i]+max(0,c[-i]-c[-i-1])
for i in range(m):
x,y=map(int,input().split())
if {{completion}}:
print(f[y-1]-f[x-1])
else:
print(g[y-1]-g[x-1]) | x<y | [{"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_002891 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ... | def factorial_divisibility(n, x, a: list):
a.sort()
a.reverse()
while True:
k = a[-1]
a.pop()
cnt = 1
while len(a) > 0 and k == a[-1]:
{{completion}}
if cnt < k + 1:
return ('Yes' if k >= x else 'No' )
for i in range(cnt //... | cnt += 1
a.pop() | [{"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_006091 | 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... |
#############################
#############
cnb_max=10**5
mod=998244353
#############
kai=[1]*(cnb_max+1)
rkai=[1]*(cnb_max+1)
for i in range(cnb_max):
kai[i+1]=kai[i]*(i+1)%mod
rkai[cnb_max]=pow(kai[cnb_max],mod-2,mod)
for i in range(cnb_max):
rkai[cnb_max-1-i]=rkai[cnb_max-i]*(cnb_max-i)%mod
def cnb(x,... | flag=0 | [{"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_000548 | block |
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... | import sys
lines = list(map(str.strip, sys.stdin.readlines()))
def cum_sum(nums):
curr = 0
result = [0]*len(nums)
for {{completion}}:
curr += num
result[idx] = curr
return result
for i in range(1, len(lines), 2):
n, a, b = map(int, lines[i].split(" "))
nums = [0] +... | idx, num in enumerate(nums) | [{"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_008535 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe... | for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
tot = a[0]
for i in range(1, n):
if tot < 0:
break
elif tot == 0:
if a[i] != 0:
{{completion}}
else:
tot += a[i]
else:
... | 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_000424 | 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... |
inp = [*open(0)]
for s in inp[2::2]:
s = s.strip()
res = 0
mseg = 1
prebit = None
for i in range(len(s) // 2):
if s[2*i] != s[2*i+1]:
res += 1
else:
if prebit is None:
prebit = s[2*i]
else:
{{complet... | mseg += 1 if s[2*i] != prebit else 0
prebit = s[2*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_008094 | block |
python | Complete the code in python to solve this programming problem:
Description: Monocarp is going to host a party for his friends. He prepared $$$n$$$ dishes and is about to serve them. First, he has to add some powdered pepper to each of them — otherwise, the dishes will be pretty tasteless.The $$$i$$$-th dish has two va... | import math
import sys
input = sys.stdin.readline
class Dish:
def __init__(self):
self.a=0
self.b=0
def exgcd(a,b):
if b:
x,y=exgcd(b,a%b)
return y,x-a//b*y
return 1,0
n=int(input())
dish=[Dish() for i in range(n)]
val=[0 for i in range(n+5)]
for i in range(n):
dish[i].a,dish[i].b=... | k=(maxW/a/gcdAB-x1)/b
print(max(val[a*gcdAB*(x1+math.ceil(k)*b)],val[a*gcdAB*(x1+math.floor(k)*b)])) | [{"input": "3\n5 10\n100 50\n2 2\n4\n2 3\n1 1\n3 2\n2 2", "output": ["62\n112\n107\n-1"]}, {"input": "10\n3 1\n2 3\n1 1\n2 1\n6 3\n1 4\n4 3\n1 3\n5 3\n5 4\n10\n8 10\n9 3\n1 4\n2 5\n8 3\n3 5\n1 6\n7 2\n6 7\n3 1", "output": ["26\n-1\n36\n30\n-1\n26\n34\n26\n-1\n36"]}] | block_completion_005538 | block |
python | Complete the code in python to solve this programming problem:
Description: Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees.There ... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
prefix = suffix = 0
for i in range(n - 1):
if (d := a[i] - a[i + 1]) > 0:
prefix += d
else:
{{completion}}
print(abs(a[0] - prefix) + prefix + suffix)
| suffix -= d | [{"input": "4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5", "output": ["2\n13\n36\n33"]}] | block_completion_004197 | block |
python | Complete the code in python to solve this programming problem:
Description: 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... | import math
n = int(input())
s = list(int(i) for i in input().split())
min1 = 10000000
for i in range(n-1):
a, b = (s[i], s[i+1]) if s[i] < s[i+1] else (s[i + 1], s[i])
if b > a * 2:
min1 = min(min1, math.ceil(b/2))
else:
{{completion}}
for i in range(n-2):
a, b = ((s[i], s[i ... | min1 = min(min1, math.ceil((a + b) / 3)) | [{"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_007911 | 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... | # trans rights
N = int(input())
N = 2 ** N
S = input()
U = [0] * N
cnt = 0
for i in range(N - 2, -1, -1):
a = 2 * i + 1
b = 2 * i + 2
if b >= N:
{{completion}}
if U[a] != U[b]:
cnt += 1
U[i] = ord(S[i]) + 331 * min(U[a], U[b]) + 3331 * max(U[a], U[b]) + min(U[a], U[b]) *... | U[i] = ord(S[i])
continue | [{"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_001709 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is equal to $$$a_i$$$.Recall that a simple path is a path that visits each vertex at most once. Let the weight of the path be... | import sys
from types import GeneratorType
from collections import defaultdict
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if {{completion}}:
... | type(to) is GeneratorType | [{"input": "6\n3 2 1 3 2 1\n4 5\n3 4\n1 4\n2 1\n6 1", "output": ["2"]}, {"input": "4\n2 1 1 1\n1 2\n1 3\n1 4", "output": ["0"]}, {"input": "5\n2 2 2 2 2\n1 2\n2 3\n3 4\n4 5", "output": ["2"]}] | control_completion_002988 | control_fixed |
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())):
n = int(input())
l = [[], []]
for {{completion}}:
l[x==y].append(int(x))
print(len(l[0]), sum(map(lambda x : x[0] ^ x[1], zip(l[1], l[1][1:]))) + 1) | x, y in zip(*[iter(input())]*2) | [{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3 2\n0 3\n0 1\n0 1\n3 1"]}] | control_completion_007953 | 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... | from sys import stdin
t = int(input())
lines = stdin.read().split()
j = 0
for num in range(t):
for i in range(8):
if lines[i + j].count('R') == 8:
{{completion}}
else:
print('B')
j += 8 | print('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_005809 | block |
python | Complete the code in python to solve this programming problem:
Description: You find yourself on an unusual crossroad with a weird traffic light. That traffic light has three possible colors: red (r), yellow (y), green (g). It is known that the traffic light repeats its colors every $$$n$$$ seconds and at the $$$i$$$-... | from sys import stdin
from collections import deque
lst = stdin.read().split()
_s = 0
def inp(n=1):
global _s
ret = lst[_s:_s + n]
_s += n
return ret
def inp1():
return inp()[0]
t = int(inp1())
for _ in range(t):
n = int(inp1())
c = inp1()
s = inp1()
ret = 0
l = []
la... | last = cur
l.append(('g', i)) | [{"input": "6\n\n5 r\n\nrggry\n\n1 g\n\ng\n\n3 r\n\nrrg\n\n5 y\n\nyrrgy\n\n7 r\n\nrgrgyrg\n\n9 y\n\nrrrgyyygy", "output": ["3\n0\n2\n4\n1\n4"]}] | block_completion_004147 | block |
python | Complete the code in python to solve this programming problem:
Description: You have a square chessboard of size $$$n \times n$$$. Rows are numbered from top to bottom with numbers from $$$1$$$ to $$$n$$$, and columns — from left to right with numbers from $$$1$$$ to $$$n$$$. So, each cell is denoted with pair of inte... | import math
from collections import defaultdict, deque, Counter
from sys import stdin
inf = int(1e18)
input = stdin.readline
#fenwick Tree
#D V ARAVIND
def add(ft, i, v):
while i < len(ft):
ft[i] += v
i += i&(-i)
def get(ft, i):
s = 0
while (i > 0):
s = s + ft[i]
... | print("NO") | [{"input": "8 10\n1 2 4\n3 6 2 7 2\n1 3 2\n3 6 2 7 2\n1 4 3\n3 2 6 4 8\n2 4 3\n3 2 6 4 8\n1 4 8\n3 2 6 4 8", "output": ["No\nYes\nYes\nNo\nYes"]}] | block_completion_005577 | block |
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... | import sys
n, m, k = map(int, sys.stdin.readline().split())
board = [list(sys.stdin.readline().strip()) for _ in range(n)]
cnt = 0
for i in range(n):
for j in range(m):
cnt += board[i][j] == '*'
clean = 0
q, r = divmod(cnt, n)
for j in range(q):
for i in range(n):
clean += board[i... | clean -= 1 | [{"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_007865 | 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... | from collections import defaultdict, deque, Counter
import sys
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools impo... | self.depth[v] == -1 | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002239 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | from math import ceil
r = range;i = lambda: int(input());s = lambda: input().split()
for _ in r(1):
n = i();v = list(map(int,s()))
dp = [];sum = 0;max = 0
for _ in r(n):
sum += v[_];val = ceil(sum/(_+1))
dp += val, #comma --> tuple element
if{{completion}}: max = val
for... | (val > max) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | control_completion_004186 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: 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... | c=input()
for _ in range(int(c)):
b=input().split()
a=[]
for i in range(int(b[0])):
a.append(list(input()))
for i in range(int(b[1])):
count=0
row=int(b[0])-1
for j in range(int(b[0])):
if a[row][i]=='.':
count+=1
elif {... | a[row][i]=='o' | [{"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_000832 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = [int(x) - 1 for x in input().split()]
G[u].append(v)
G[v].append(u)
# build a tree with ... | par[v] = u
depth[v] = depth[u] + 1
q.append(v) | [{"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_002261 | block |
python | Complete the code in python to solve this programming problem:
Description: This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected gra... | 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
from collections import deque
n=I();adj=[[] for i in range(n)]
for i in range(n-1):
p,q=M()
adj[p-1].append(q-1)
adj[q-1].append(p-1)
p=... | d[i-1]>m | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002215 | 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=map(int,input().split())
p=list(map(int,input().split()))
x=sorted(list(map(int,input().split())))
s=sum(p[:-(-(x[0])//100)])
for i in range(len(x)-1):
if x[i]//100+1>=n:
break
num=int(((x[i+1]-x[i])/2)//(100)+1)
l=x[i]//100+1
r=-(-(x[i+1])//100)
r=min(r,n)
prefs=0
if ... | prefs=sum(p[l:l+num])
s=max(s,prefs) | [{"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_001152 | 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 ... | word != 0 | [{"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"]}] | control_completion_005831 | 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... | def read():
return int(input())
def readline():
return list(map(int,input().split()))
def solve():
n=read()
arr=readline()
ans,cur=0,0
a,suma=-1,0
b,sumb=n,0
while True:
if a>=b: break
elif suma>sumb:
b-=1
sumb+=arr[b]
... | suma<sumb | [{"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_000795 | control_fixed |
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... | I=input
for _ in [0]*int(I()):
I();p,z,zero=0,1,0
for v in I().split():
p+=int(v)
if zero and p>0:z=0;break
if {{completion}}:zero=True
if p<0:z=0;break
print(['NO','YES'][zero and z]) | p==0 | [{"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"]}] | control_completion_000418 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: During their training for the ICPC competitions, team "Jee You See" stumbled upon a very basic counting problem. After many "Wrong answer" verdicts, they finally decided to give up and destroy turn-off the PC. Now they want your help in up-sol... | import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
N = 10000
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
fact[i] = fact[i - 1] * i % MOD
invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)
for i in range(N - 2, -1, -1):
invfact[i] = invfact[i + ... | break | [{"input": "3 1 5 1", "output": ["13"]}, {"input": "4 1 3 2", "output": ["4"]}, {"input": "2 1 100000 15629", "output": ["49152"]}, {"input": "100 56 89 66", "output": ["981727503"]}] | block_completion_006066 | 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 ... | from math import ceil
n=int(input())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(len(a)):
t=[0]*n
temp=0
j=i-1
prev =0
while {{completion}}:
x=(ceil((prev+1)/a[j]))
temp+=x
prev=(a[j]*x)
j-=1
k=i+1
prev=0
while k<... | j>=0 | [{"input": "5\n1 2 3 4 5", "output": ["4"]}, {"input": "7\n1 2 1 2 1 2 1", "output": ["10"]}, {"input": "8\n1 8 2 7 3 6 4 5", "output": ["16"]}] | control_completion_000962 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a rooted tree of $$$2^n - 1$$$ vertices. Every vertex of this tree has either $$$0$$$ children, or $$$2$$$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children... | mod=998244353
cnt=0
n=int(input())
s=input()
import random
q=random.randint(10**9,2*10**9)
p=random.randint(10**9,2*10**9)
r=10**9+7
a=[-1]
for i in s:
if i=='A':
a.append(p)
else:
{{completion}}
for i in range(2**(n-1)-1,0,-1):
if a[2*i]!=a[2*i+1]:
cnt+=1
a[i]=a[i]^(2*a[2*i]+2*a[2*i+1])
a[i]%=... | a.append(q) | [{"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_001704 | block |
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())
z=[] # 2d
a=[] # 1d
c=0 # count icons
ans=0
for i in range(n):
z.append(list(input()))
for i in range(m):
for j in range(n):
if z[j][i]=="*":
a.append(1)
c+=1
else:
a.append(0)
ans=c
for i in range(c):
if a[i]... | ans-=1 | [{"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_007869 | block |
python | Complete the code in python to solve this programming problem:
Description: There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i... | import sys
from array import array
input = lambda: sys.stdin.buffer.readline().decode().strip()
inp = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp(dtype) for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
de... | i + (1 << j) - 1 < self.n | [{"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_002944 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bisho... | # auther: codeCell
for _ in range(int(input())):
n,m=map(int,input().split())
a = [ [*map(int, input().split())] for _ in range(n)]
u = [0]*(n+m-1)
v = [0]*(n+m-1)
for i in range(n):
for j in range(m):
{{completion}}
for i in range(n):
for j in range(m):
... | u[i+j] += a[i][j]
v[i-j] += a[i][j] | [{"input": "4\n4 4\n1 2 2 1\n2 4 2 4\n2 2 3 1\n2 4 2 4\n2 1\n1\n0\n3 3\n1 1 1\n1 1 1\n1 1 1\n3 3\n0 1 1\n1 0 1\n1 1 0", "output": ["20\n1\n5\n3"]}] | block_completion_007693 | 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 {{completion}}:
ans += 1
else:
t.append(arr[i])
seg = 1
for i in range(0, len(t) - 1):
if t[i] != t[i +... | arr[i] != arr[i + 1] | [{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3 2\n0 3\n0 1\n0 1\n3 1"]}] | control_completion_007950 | control_fixed |
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 = sys.stdin.readline
def seg(start, end):
if start == end:
{{completion}}
mid = (start + end) // 2
l = seg(start, mid)
r = seg(mid + 1, end)
result = []
for i in range((end - start + 1) // 2):
lb, ls, lp, lS = l[i]
rb, rs, rp, rS = r[i]
... | val = max(arr[start], 0)
return [(val, val, val, arr[start])] | [{"input": "3\n-3 5 -3 2 8 -20 6 -1\n3\n1\n0\n1", "output": ["18\n8\n13"]}] | block_completion_008315 | 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... | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
def ff(gap, ints):
sml = gap // ints
bigcount = gap % ints
return bigcount * (sml + 1) ** 2 + (ints - bigcount) * sml ** 2
... | big = mid | [{"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_003463 | block |
python | Complete the code in python to solve this programming problem:
Description: The robot is placed in the top left corner of a grid, consisting of $$$n$$$ rows and $$$m$$$ columns, in a cell $$$(1, 1)$$$.In one step, it can move into a cell, adjacent by a side to the current one: $$$(x, y) \rightarrow (x, y + 1)$$$; $... | import sys
ls = []
for l in sys.stdin:
lst = l.rstrip('\n')
if len(lst) > 0:
{{completion}}
for l in ls:
sys.stderr.write(l + ('\n'))
sys.stderr.write("-- output --\n")
def ins(u, mn, mx):
return u[0] >= mn[0] and u[1] >= mn[1] and u[0] <= mx[0] and u[1] <= mx[1]
def clmp(x,... | ls.append(lst) | [{"input": "3\n\n2 3 1 3 0\n\n2 3 1 3 1\n\n5 5 3 4 1", "output": ["3\n-1\n8"]}] | block_completion_002786 | block |
python | Complete the code in python to solve this programming problem:
Description: Monocarp is going to host a party for his friends. He prepared $$$n$$$ dishes and is about to serve them. First, he has to add some powdered pepper to each of them — otherwise, the dishes will be pretty tasteless.The $$$i$$$-th dish has two va... | from collections import *
from itertools import *
from functools import *
import math,sys
input = sys.stdin.buffer.readline
n = int(input())
AB = [tuple(map(int,input().split())) for _ in range(n)]
M = int(input())
XY = [tuple(map(int,input().split())) for _ in range(M)]
ans = []
from math import gcd
d... | ng = mid | [{"input": "3\n5 10\n100 50\n2 2\n4\n2 3\n1 1\n3 2\n2 2", "output": ["62\n112\n107\n-1"]}, {"input": "10\n3 1\n2 3\n1 1\n2 1\n6 3\n1 4\n4 3\n1 3\n5 3\n5 4\n10\n8 10\n9 3\n1 4\n2 5\n8 3\n3 5\n1 6\n7 2\n6 7\n3 1", "output": ["26\n-1\n36\n30\n-1\n26\n34\n26\n-1\n36"]}] | block_completion_005535 | block |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek is participating in a lemper cooking competition. In the competition, Pak Chanek has to cook lempers with $$$N$$$ stoves that are arranged sequentially from stove $$$1$$$ to stove $$$N$$$. Initially, stove $$$i$$$ has a temperature ... | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, data, default=0, func=lambda x, y: x+y):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._... | res_left = self._func(res_left, self.data[start])
start += 1 | [{"input": "7\n2 -1 -1 5 2 -2 9", "output": ["4"]}, {"input": "5\n-1 -2 -3 -4 -5", "output": ["-1"]}] | block_completion_003791 | block |
python | Complete the code in python to solve this programming problem:
Description: 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 _ in range(int(input())):
{{completion}}
| input()
a, b, *_, c, d = sorted(map(int, input().split()))
print(c+d-a-b) | [{"input": "4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8", "output": ["9\n297\n0\n14"]}] | block_completion_005388 | 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 ... | word != 0 | [{"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"]}] | control_completion_005832 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a... | from sys import stdin, stderr
def debug(*args, **kwargs):
print(*args, file=stderr, **kwargs)
_, volumes, _, *queries = stdin.readlines()
volumes = map(int, volumes.split())
queries = map(int, queries)
s = t_min = 0
for i, v in enumerate(volumes, 1):
s += v
div, mod = divmod(s, i)
t_min = max(t_min... | div, mod = divmod(s, q)
ans = div + (mod != 0) | [{"input": "5\n4 1 5 4 1\n6\n1\n6\n2\n3\n4\n5", "output": ["-1\n3\n-1\n-1\n4\n3"]}, {"input": "5\n4 4 4 4 4\n6\n1\n3\n6\n5\n2\n4", "output": ["-1\n-1\n4\n4\n-1\n5"]}] | block_completion_004268 | block |
python | Complete the code in python to solve this programming problem:
Description: You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.... |
n,k=map(int,input().split())
a=[]
d={}
for i in range(n):
a+=[''.join(input().split())]
d[a[-1]]=0
def cal(s,t):
res=""
for {{completion}}:
res+=str((9-int(s[i])-int(t[i]))%3)
return res
for i in range(n):
for j in range(i):
try:
d[cal(a[i],a... | i in range(k) | [{"input": "8 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n1 0 0 0\n2 2 0 0", "output": ["1"]}, {"input": "7 4\n0 0 0 0\n0 0 0 1\n0 0 0 2\n0 0 1 0\n0 0 2 0\n0 1 0 0\n0 2 0 0", "output": ["3"]}, {"input": "9 2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2", "output": ["54"]}, {"input": "20 4\n0 2 0 0\n0 2 2 2... | control_completion_005228 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de... | input = __import__('sys').stdin.readline
n = int(input())
a = list(map(int, input().split())) + [n+1]
cache = {}
def check(i, u, d):
keys = []
j = i
while j+1 <= n:
key = (j, u, d)
v = cache.get(key, -1)
if v != -1:
j = v
break
... | d = min(d, a[j]) | [{"input": "3\n2 3 1", "output": ["6"]}, {"input": "6\n4 5 2 6 1 3", "output": ["19"]}, {"input": "10\n7 10 1 8 3 9 2 4 6 5", "output": ["39"]}] | block_completion_000488 | block |
python | Complete the code in python to solve this programming problem:
Description: Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bi... | t = int(input())
for test in range(t):
a = []
while len(a) != 8:
s = input()
if (len(s) == 8):
a.append(s)
x = 0
y = 0
for i in range(1, 7):
for j in range(1, 7):
if (a[i][j] == '#' and a[i-1][j+1] == '#' and a[i-1][j-1] == '#'):
... | x = i
y = j | [{"input": "3\n\n\n\n\n.....#..\n\n#...#...\n\n.#.#....\n\n..#.....\n\n.#.#....\n\n#...#...\n\n.....#..\n\n......#.\n\n\n\n\n#.#.....\n\n.#......\n\n#.#.....\n\n...#....\n\n....#...\n\n.....#..\n\n......#.\n\n.......#\n\n\n\n\n.#.....#\n\n..#...#.\n\n...#.#..\n\n....#...\n\n...#.#..\n\n..#...#.\n\n.#.....#\n\n#......."... | block_completion_004630 | block |
python | Complete the code in python to solve this programming problem:
Description: You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pix... | import sys
if __name__ == "__main__":
input_arr = sys.stdin.read().split()
tc = int(input_arr[0])
pos = 1
for case in range(tc):
a1, a2 = input_arr[pos:pos + 2]
char = []
for i in a1:
char.append(i)
for j in a2:
char.append(j)
... | l == 3 | [{"input": "5\n\nrb\n\nbr\n\ncc\n\nwb\n\naa\n\naa\n\nab\n\ncd\n\nyy\n\nxx", "output": ["1\n2\n0\n3\n1"]}] | control_completion_002660 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, and an array $$$b$$$, with length $$$n$$$. Initially $$$b_i=0$$$ for each $$$1 \leq i \leq n$$$.In one move you can choose an integer $$$i$$$ ($$$1 \leq i \leq n$$$), and ... | import math
n = int(input())
a = list(map(int, input().split(' '))) # numbers w/ ws
c = None
d = 0
for i in range(len(a)):
p = 0
t = 0
for k in a[i+1:]:
d = math.ceil((t+1)/k)
t = k*d
p += d
t = 0
for {{completion}}:
d = math.ceil((t+1)/k)
t = k*d
p += d
if c == None or p < c:
c ... | k in reversed(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"]}] | control_completion_000968 | 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... | import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
x, y = sorted(arr)[:2]
ans = (x + 1) // 2 + (y + 1) // 2
for i in range(n - 2):
x, y = arr[i], arr[i + 2]
if (x % 2 == 1) and (y % 2 == 1):
x -= 1
y -= 1
ans = min(ans, (x + 1) // 2 ... | res = y - x
x -= res
y -= 2 * res
tmp = x // 3
res += 2 * tmp
x -= 3 * tmp
ans = min(ans, res + x) | [{"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_007910 | block |
python | Complete the code in python to solve this programming problem:
Description: There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i... | import sys, collections, math, itertools
input = lambda: sys.stdin.readline().strip()
ints = lambda: list(map(int, input().split()))
Int = lambda: int(input())
n, m = ints()
a = ints()
s = int(m ** .5 + 1)
maxs = [max(a[i:i + s]) for i in range(0, m, s)]
for i in range(Int()):
ys, xs, yf, xf, k = ints()
... | not yes | [{"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_002939 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $$$5$$$ players in one team for each match). There are $$$N$$$ candidate players in the competition that will be t... | import math
enemy_power=int(input().split()[1])
team=[int(i) for i in input().split()]
team.sort()
days=0
while len(team)>0:
num=enemy_power//team[-1]+1
if len(team)<num:
break;
else:
{{completion}}
print(days) | del team[-1]
del team[0:num-1]
days+=1 | [{"input": "6 180\n90 80 70 60 50 100", "output": ["2"]}] | block_completion_003724 | 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... | answer += data[j][k]*data[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"]}] | block_completion_000884 | 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... | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
for _ in range(I()):
n=I();a=L();b=L();d=L();l=[]
for i in range(n):l.append([a[i],b[i],d[i]])
l.sort(key=lambda x:x[0]);s=set();ans=1
... | break | [{"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_006032 | block |
python | Complete the code in python to solve this programming problem:
Description: Alina has discovered a weird language, which contains only $$$4$$$ words: $$$\texttt{A}$$$, $$$\texttt{B}$$$, $$$\texttt{AB}$$$, $$$\texttt{BA}$$$. It also turned out that there are no spaces in this language: a sentence is written by just con... | for _ in range(int(input())):
a,b,ab,ba=map(int,input().split());s=input()
if s.count('A')!=a+ab+ba:print('NO');continue
stack=[[1,s[0]]]
for i in range(1,len(s)):
if stack[-1][1]!=s[i]:
x=stack.pop()
stack.append([x[0]+1,s[i]])
else: stack.append([1,s[i]]... | trash+=(val//2-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"]}] | block_completion_001213 | block |
python | Complete the code in python to solve this programming problem:
Description: You have a sequence of $$$n$$$ colored blocks. The color of the $$$i$$$-th block is $$$c_i$$$, an integer between $$$1$$$ and $$$n$$$.You will place the blocks down in sequence on an infinite coordinate grid in the following way. Initially, ... | 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... | i % 2 == 0 | [{"input": "6\n\n7\n\n1 2 3 1 2 3 1\n\n6\n\n4 2 2 2 4 4\n\n1\n\n1\n\n5\n\n5 4 5 3 5\n\n6\n\n3 3 3 1 3 3\n\n8\n\n1 2 3 4 4 3 2 1", "output": ["3 2 2 0 0 0 0 \n0 3 0 2 0 0 \n1 \n0 0 1 1 1 \n1 0 4 0 0 0 \n2 2 2 2 0 0 0 0"]}] | control_completion_003617 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a string $$$s$$$, consisting of lowercase Latin letters.You are asked $$$q$$$ queries about it: given another string $$$t$$$, consisting of lowercase Latin letters, perform the following steps: concatenate $$$s$$$ and $$$t$$$; ... | def get_next(j, k, nxt, p):
while p[j] != '$':
if k == -1 or p[j] == p[k]:
j += 1
k += 1
if p[j] == p[k]:
nxt[j] = nxt[k]
else:
{{completion}}
else:
k = nxt[k]
return j, k, nxt
def solve()... | nxt[j] = k | [{"input": "aba\n6\ncaba\naba\nbababa\naaaa\nb\nforces", "output": ["0 1 2 3 \n1 2 3 \n2 3 4 5 6 7 \n1 1 1 1 \n2 \n0 0 0 0 0 0"]}, {"input": "aacba\n4\naaca\ncbbb\naab\nccaca", "output": ["2 2 3 1 \n0 0 0 0 \n2 2 0 \n0 0 1 0 1"]}] | block_completion_002698 | 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... | import sys
input=sys.stdin.readline
I = lambda : list(map(int,input().split()))
t,=I()
for _ in range(t):
n, = I()
l = I()
pos = 0
if sum(l)!=0 or l[-1]>0:
pos=1
else:
pref = l[0]
seen = 0
if pref<0:
pos=1
if pref==0:
seen = 1
for i in range(1,n):
pref+=l[i]
if pref<0:
... | seen | [{"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"]}] | control_completion_000427 | control_fixed |
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... | import collections
def caminho(parent, sala):
resp = []
while sala is not None:
resp.append(sala)
sala = parent[sala]
return list(reversed(resp))
def solve(grafo, total, inicio):
if len(grafo[inicio]) < 2:
return
globalParent = collections.defaultdict(lambda: None)
for sala1 in gr... | currentParent[x] = y
fila.append(x) | [{"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"]}] | block_completion_003160 | 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... | for t in range(int(input())):
n=int(input())
x=list(map(int,input().split()))
g={}
if n==1:
print(-1)
else:
for i in range(n-1):
if not((x[i]==x[i+1] or x[i]==x[i-1]) and ( x[-1]==x[-2])):
print(-1)
break
g[x[i]]=[]
... | print(j[q-1],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_002399 | 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 ... | k = 0
a = int(input())
for x in range(1, a+1):
b = int(input())
if 1900<= b:
d = 1
elif 1600 <= b <= 1899:
d = 2
elif 1400 <= b <= 1599:
{{completion}}
elif b <= 1399:
d = 4
print('Division', d) | d = 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_000734 | 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 (not visited[child]):
{{completion}}
... | stack.append(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"]}] | block_completion_003165 | block |
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... | from sys import stdin
rln=stdin.buffer.readline
rl=lambda:rln().rstrip(b'\r\n').rstrip(b'\n')
ri=lambda:int(rln())
rif=lambda:[*map(int,rln().split())]
rt=lambda:rl().decode()
rtf=lambda:rln().decode().split()
inf=float('inf')
dir4=[(-1,0),(0,1),(1,0),(0,-1)]
dir8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,... | x in range(n) | [{"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_007737 | control_fixed |
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 ... | word != 0 | [{"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"]}] | control_completion_005834 | control_fixed |
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... | import re
import sys
exit=sys.exit
from bisect import *
from collections import *
ddict=defaultdict
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
rb=lambda:list(map(int,rl()))
rfs=lambda... | path.append(x)
x=vis[x][j] | [{"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"]}] | block_completion_003163 | 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=map(int,input().split())
world=['x']+list(map(int,input().split()))
L1=[0]
L2=[0]
for i in range(1,n):
L1.append(L1[i-1]+max(world[i]-world[i+1],0))
L2.append(L2[i-1]+max(world[i+1]-world[i],0))
for i in range(m):
s,t=map(int,input().split())
if {{completion}}:
print(L1[t-1]-L1[s-1... | s<t | [{"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_002893 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: One day Masha was walking in the park and found a graph under a tree... Surprised? Did you think that this problem would have some logical and reasoned story? No way! So, the problem...Masha has an oriented graph which $$$i$$$-th vertex contai... | import sys
input = sys.stdin.readline
def solve():
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for i in range(m):
u, v = map(int, input().split())
graph[u-1].append(v-1)
lo, hi = min(arr), max(arr)+1
while lo < hi:
... | continue | [{"input": "6 7 4\n1 10 2 3 4 5\n1 2\n1 3\n3 4\n4 5\n5 6\n6 2\n2 5", "output": ["4"]}, {"input": "6 7 100\n1 10 2 3 4 5\n1 2\n1 3\n3 4\n4 5\n5 6\n6 2\n2 5", "output": ["10"]}, {"input": "2 1 5\n1 1\n1 2", "output": ["-1"]}, {"input": "1 0 1\n1000000000", "output": ["1000000000"]}] | block_completion_005668 | 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... | """
author: Manoj
inp_start
5 5
1 2 3 4 5
3 2
4 2
3 1
2 1
2 2
inp_end
"""
n, m = list(map(int, input().split()))
li = list(map(int, input().split()))
ans = int((n*(n+1))/2)
for i in range(1, n):
if li[i]!=li[i-1]:
ans += i*(n-i)
al = []
for tc in range(m):
i, x = list(map(int, input().spl... | ans-=i*(n-i) | [{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}] | block_completion_000083 | block |
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... | len(indices[v1]) > 1 | [{"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"]}] | control_completion_008511 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elemen... | from collections import Counter
for _ in range(int(input())):
n = int(input())
m = max(Counter(input().split()).values())
ans = n-m
while m<n:
{{completion}}
print(ans)
| ans += 1
m *= 2 | [{"input": "6\n1\n1789\n6\n0 1 3 3 7 0\n2\n-1000000000 1000000000\n4\n4 3 2 1\n5\n2 5 7 6 3\n7\n1 1 1 1 1 1 1", "output": ["0\n6\n2\n5\n7\n0"]}] | block_completion_004419 | block |
python | Complete the code in python to solve this programming problem:
Description: Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees.There ... | import sys
T = int(sys.stdin.readline())
for t in range(T):
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().strip().split(' ')]
l, r = 0, 0
for i in range(len(a) - 1):
x, y = a[i], a[i+1]
if x > y:
l += x - y
elif x < y:
... | r += y - x | [{"input": "4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5", "output": ["2\n13\n36\n33"]}] | block_completion_004205 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ... | n , x = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
s = [0] * (x+1)
for i in l:
s[i] += 1
for i in range(1,x):
if {{completion}}:
s[i+1] += s[i]//(i+1)
else:
print('NO')
break
else:
print('Yes') | s[i] % (i+1) == 0 | [{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}] | control_completion_005988 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies o... | n = int(input())
for i in range(n):
str1 = input()
set_char = set(str1)
req = len(set_char)
prev = dict()
truth = True
ind = 0
for i1 in str1:
if{{completion}}:
truth = False
break
prev[i1] = ind
ind += 1
print(truth and 'YES' or 'NO') | ( i1 in prev and ind - prev[i1] != req) | [{"input": "5\naba\nabb\nabc\naaaaa\nabcba", "output": ["YES\nNO\nYES\nYES\nNO"]}] | control_completion_004714 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Pak Chanek has $$$n$$$ blank heart-shaped cards. Card $$$1$$$ is attached directly to the wall while each of the other cards is hanging onto exactly one other card by a piece of string. Specifically, card $$$i$$$ ($$$i > 1$$$) is hanging on... | n = int(input())
a = [*map(lambda x:int(x)-1,input().split())]
edge = [[] for _ in range(n)]
for i,p in enumerate(a,1): edge[p] += i,
dp = [[1,0] for _ in range(n)]
for r in range(n-1,-1,-1):
for {{completion}}:
k = max(dp[v])
dp[r][1] += k
dp[r][0] = max(dp[r][0],dp[v][0]+1)
pr... | v in edge[r] | [{"input": "6\n1 2 1 4 2", "output": ["4"]}, {"input": "2\n1", "output": ["2"]}] | control_completion_004638 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bisho... | T = int(input())
for tc in range(T):
(A, B) = map(int, input().split(' '))
nums = []
for i in range(A):
nums.append([int(x) for x in input().split()])
C = A + B - 1
left = [0 for _ in range(C)]
right = [0 for _ in range(C)]
for a in range(A):
for {{completion}... | b in range(B) | [{"input": "4\n4 4\n1 2 2 1\n2 4 2 4\n2 2 3 1\n2 4 2 4\n2 1\n1\n0\n3 3\n1 1 1\n1 1 1\n1 1 1\n3 3\n0 1 1\n1 0 1\n1 1 0", "output": ["20\n1\n5\n3"]}] | control_completion_007557 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and the $$$i$$$-th string and the $$$j$$$-th string diff... | for ii in range(int(input())):
n=int(input())
a=[]
co=0
x=set()
for jj in range(n):
a.append(input())
for jj in range(n):
mul=1
if jj not in x:
for kk in range(jj+1,n):
if a[jj][0]!=a[kk][0] and a[jj][1]==a[kk][1]:
co+=mul
elif {{completion}}:
co+=mul
elif a[jj][0]==a... | a[jj][0]==a[kk][0] and a[jj][1]!=a[kk][1] | [{"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_000871 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times: select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the va... | # Problem - https://codeforces.com/contest/1714/problem/E
# Editorial - https://codeforces.com/blog/entry/105549
# Tags - brute force, math, number theory, *1400
import sys
import typing
# Read stdin and remove newline elements
stdin = [line.strip() for line in sys.stdin.readlines() if line != '\n']
stdin_co... | has_2 = True | [{"input": "10\n\n2\n\n6 11\n\n3\n\n2 18 22\n\n5\n\n5 10 5 10 5\n\n4\n\n1 2 4 8\n\n2\n\n4 5\n\n3\n\n93 96 102\n\n2\n\n40 6\n\n2\n\n50 30\n\n2\n\n22 44\n\n2\n\n1 5", "output": ["Yes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\nYes\nNo"]}] | block_completion_006707 | block |
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 i in range(int(input())):
n = int(input())
s = input().split()
if s.count("0"):
print(n-s.count("0"))
else:
for i in s:
if {{completion}}:
print(n)
break
else:
print(n+1) | s.count(i)>1 | [{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}] | control_completion_008025 | control_fixed |
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_005935 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(... | # import io,os
# read = io.BytesIO(os.read(0, os.fstat(0).st_size))
# I = lambda: [*map(int, read.readline().split())]
import sys
I=lambda:[*map(int,sys.stdin.readline().split())]
M = 10 ** 9 + 7
n, k = I()
binomk = [0] * k
binomk.append(1)
for i in range(k + 1, n + 1):
binomk.append(binomk[-1] * i *... | boi in neighbors[guy] | [{"input": "3 2\n1 2\n1 3", "output": ["25"]}, {"input": "7 2\n1 2\n2 3\n2 4\n1 5\n4 6\n4 7", "output": ["849"]}] | control_completion_002442 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: While searching for the pizza, baby Hosssam came across two permutations $$$a$$$ and $$$b$$$ of length $$$n$$$.Recall that a permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For exampl... |
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
b = list(map(int,sys.stdin.readline().split()))
c = list(map(int,sys.stdin.readline().split()))
count = 0
L = [0] * (n+1)
for i in range(0,n):
... | count += 1 | [{"input": "9\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n2 0 1 0 0 0 0\n1\n1\n1\n0\n6\n1 5 2 4 6 3\n6 5 3 1 4 2\n6 0 0 0 0 0\n8\n1 6 4 7 2 3 8 5\n3 2 8 1 4 5 6 7\n1 0 0 7 0 3 0 5\n10\n1 8 6 2 4 7 9 3 10 5\n1 9 2 3 4 10 8 6 7 5\n1 9 2 3 4 10 8 6 7 5\n7\n1 2 3 4 5 6 7\n2 3 1 7 6 5 4\n0 0 0 0 0 0 0\n5\n1 2 3 4 5\n1 2 3 4 5\n0 0 0 ... | block_completion_006026 | block |
python | Complete the code in python to solve this programming problem:
Description: You have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones and an integer $$$k$$$. In one operation you can do one of the following: Select $$$2$$$ consecutive elements of $$$a$$$ and replace them with their minimum (that is... | from sys import stdin
from collections import deque
lst = list(map(int, stdin.read().split()))
_s = 0
def inp(n=1):
global _s
ret = lst[_s:_s + n]
_s += n
return ret
def inp1():
{{completion}}
t = inp1()
for _ in range(t):
n = inp1()
k = inp1()
a = set(inp(n))
print("YES" i... | return inp()[0] | [{"input": "7\n\n3 2\n\n0 1 0\n\n5 3\n\n1 0 1 1 0\n\n2 2\n\n1 1\n\n4 4\n\n0 0 0 0\n\n6 3\n\n0 0 1 0 0 1\n\n7 5\n\n1 1 1 1 1 1 1\n\n5 3\n\n0 0 1 0 0", "output": ["YES\nYES\nYES\nNO\nYES\nYES\nYES"]}] | block_completion_006995 | block |
python | Complete the code in python to solve this programming problem:
Description: There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start wate... | def solve(m,a):
ev=od=0
for i in a:
ev += (m-i)//2; od += (m-i)%2
if(od>=ev):
{{completion}}
ev = (ev-od)*2
return od*2 + ev//3*2 + ev%3
I = lambda: map(int,input().split())
t,=I()
for _ in [1]*t:
n, = I()
b = [*I()]
mx = max(b)
print(min(solve(mx,b),s... | return od*2-(od!=ev) | [{"input": "3\n3\n1 2 4\n5\n4 4 3 5 5\n7\n2 5 4 8 3 7 4", "output": ["4\n3\n16"]}] | block_completion_003422 | 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... | input = __import__('sys').stdin.readline
def solve():
n = int(input())
allzeros = False
total = 0
for x in map(int, input().split()):
total += x
if {{completion}}:
print('No')
return
allzeros = allzeros or total == 0
print('YES' if tot... | total < 0 or total != 0 and allzeros | [{"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"]}] | control_completion_000426 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, and an array $$$b$$$, with length $$$n$$$. Initially $$$b_i=0$$$ for each $$$1 \leq i \leq n$$$.In one move you can choose an integer $$$i$$$ ($$$1 \leq i \leq n$$$), and ... |
n=int(input())
a=list(map(int,input().split()))
b=[int(0) for _ in range(n)]
m=1e18
for i in range(n):
c=0
p=0
for {{completion}}:
p+=a[j]-p%a[j]
c+=p//a[j]
p=0
for j in range(i-1,-1,-1):
p+=a[j]-p%a[j]
c+=p//a[j]
m=min(m,c)
print(m)
| j in range(i+1,len(b)) | [{"input": "5\n1 2 3 4 5", "output": ["4"]}, {"input": "7\n1 2 1 2 1 2 1", "output": ["10"]}, {"input": "8\n1 8 2 7 3 6 4 5", "output": ["16"]}] | control_completion_000970 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: This is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected grap... | from collections import deque;import math
import sys;I=sys.stdin.readline;R=lambda:map(lambda x:int(x)-1,input().split())
n=int(I());g=[[] for _ in range(n)]
for _ in [0]*(n-1):
u,v=R();g[u].append(v);g[v].append(u)
h=math.ceil(math.log2(n))
fa=[[-1]*(h+1) for _ in range(n)];dep=[0]*n
q=deque([0])
while q:
... | v!=fa[u][0] | [{"input": "5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4", "output": ["YES\nNO\nYES\nNO\nYES"]}, {"input": "5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1", "output": ["YES\nNO\nYES\nYES"]}] | control_completion_002241 | control_fixed |
python | Complete the code in python to solve this programming problem:
Description: You are given a positive integer $$$n$$$. You have to find $$$4$$$ positive integers $$$a, b, c, d$$$ such that $$$a + b + c + d = n$$$, and $$$\gcd(a, b) = \operatorname{lcm}(c, d)$$$.If there are several possible answers you can output any ... | for _ in range(int(input())):
a=int(input())
if a%4==0:
print(a//4,a//4,a//4,a//4)
else:
if a%2==1:
a1=(a-1)
if a1%3==0:
print(a1//3,a1//3,a1//3,1)
elif a1%4!=0:
{{completion}}
elif a1%4==0:
... | a1=a-2
print(a1//2,a1//2+1,1,1) | [{"input": "5\n4\n7\n8\n9\n10", "output": ["1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1"]}] | block_completion_004461 | block |
python | Complete the code in python to solve this programming problem:
Description: You are given 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 sdr in[*open(0)][2::2]:{{completion}} | p,q,*_,r,s=sorted(map(int,sdr.split()));print(r+s-p-q) | [{"input": "4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8", "output": ["9\n297\n0\n14"]}] | block_completion_005387 | block |
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... | n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
x, c, s, b = 0, 0, sum(a), [1]*(n)
for i in range(q):
k = list(map(int, input().split()))
if k[0]==1:
j = k[1]-1
if {{completion}}:
s = s-a[j]+k[2]
else:
s = s-x+k[2]
... | b[j]>c | [{"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"]}] | control_completion_005516 | 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... | import sys
n, p = map(int, sys.stdin.readline().split())
l = map(int, sys.stdin.readline().split())
l = sorted(l, reverse=True)
for i in range(n-1, 0, -1):
l[i-1] += l[i]
for _ in range(p):
xi, yi = map(int, sys.stdin.readline().split())
a = n-xi
b = a+yi
if a == 0:
print(... | print(l[-b]-l[-a]) | [{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}] | block_completion_000520 | block |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.