lang
stringclasses
1 value
prompt
stringlengths
1.38k
11.3k
eval_prompt
stringlengths
37
8.09k
ground_truth
stringlengths
1
328
unit_tests
stringclasses
145 values
task_id
stringlengths
23
25
split
stringclasses
2 values
python
Complete the code in python to solve this programming problem: Description: 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: 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: 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...
from math import ceil def cal(a,b): if a>b: a,b=b,a if a>b//2: return ceil((a+b)/3) else: {{completion}} def cal2(a,b,c): if a%2==1 or c%2==1: return a//2+c//2+1 return a//2+b//2 n=int(input()) l=list(map(int,input().split())) t=sorted(l) ans=...
return ceil(b/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_007912
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...
N, A = int(input()), list(map(int, input().split())) c = 1000000 for i in range(N-2): prev = c c = min(c, max(A[i], A[i+2])) if A[i]%2 == A[i+2]%2 == 1: c=min(c, (A[i]//2)+(A[i+2]//2)+1) for i in range(N-1): x = min(A[i], A[i+1]) y = A[i]+A[i+1]-x if min(A[i], A[i+1]) <= (max(A[i], ...
c = min(c, (A[i]+A[i+1]+2)//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_007913
block
python
Complete the code in python to solve this programming problem: Description: There is an array $$$a$$$ of length $$$n$$$. You may perform the following operation any number of times: Choose two indices $$$l$$$ and $$$r$$$ where $$$1 \le l &lt; r \le n$$$ and $$$a_l = a_r$$$. Then, set $$$a[l \ldots r] = [a_{l+1}, a_{l...
import sys sys.setrecursionlimit(10000) def read_line(f): while True: s=f.readline().strip() if s: return s def read_list(f): return [int(x) for x in read_line(f).split()] def read_tuple(f): return tuple(read_list(f)) def load_single_case(f): read_line(f) ...
return False
[{"input": "5\n\n5\n\n1 2 3 3 2\n\n1 3 3 2 2\n\n5\n\n1 2 4 2 1\n\n4 2 2 1 1\n\n5\n\n2 4 5 5 2\n\n2 2 4 5 5\n\n3\n\n1 2 3\n\n1 2 3\n\n3\n\n1 1 2\n\n2 1 1", "output": ["YES\nYES\nNO\nYES\nNO"]}]
block_completion_008013
block
python
Complete the code in python to solve this programming problem: Description: There is an array $$$a$$$ of length $$$n$$$. You may perform the following operation any number of times: Choose two indices $$$l$$$ and $$$r$$$ where $$$1 \le l &lt; r \le n$$$ and $$$a_l = a_r$$$. Then, set $$$a[l \ldots r] = [a_{l+1}, a_{l...
import sys sys.setrecursionlimit(10000) def read_line(f): while True: s=f.readline().strip() if s: return s def read_list(f): return [int(x) for x in read_line(f).split()] def read_tuple(f): return tuple(read_list(f)) def load_single_case(f): read_line(f) ...
used[prv]=used.get(prv,0)+1
[{"input": "5\n\n5\n\n1 2 3 3 2\n\n1 3 3 2 2\n\n5\n\n1 2 4 2 1\n\n4 2 2 1 1\n\n5\n\n2 4 5 5 2\n\n2 2 4 5 5\n\n3\n\n1 2 3\n\n1 2 3\n\n3\n\n1 1 2\n\n2 1 1", "output": ["YES\nYES\nNO\nYES\nNO"]}]
block_completion_008014
block
python
Complete the code in python to solve this programming problem: Description: There is an array $$$a$$$ of length $$$n$$$. You may perform the following operation any number of times: Choose two indices $$$l$$$ and $$$r$$$ where $$$1 \le l &lt; r \le n$$$ and $$$a_l = a_r$$$. Then, set $$$a[l \ldots r] = [a_{l+1}, a_{l...
import sys sys.setrecursionlimit(10000) def read_line(f): while True: s=f.readline().strip() if s: return s def read_list(f): return [int(x) for x in read_line(f).split()] def read_tuple(f): return tuple(read_list(f)) def load_single_case(f): read_line(f) ...
return False
[{"input": "5\n\n5\n\n1 2 3 3 2\n\n1 3 3 2 2\n\n5\n\n1 2 4 2 1\n\n4 2 2 1 1\n\n5\n\n2 4 5 5 2\n\n2 2 4 5 5\n\n3\n\n1 2 3\n\n1 2 3\n\n3\n\n1 1 2\n\n2 1 1", "output": ["YES\nYES\nNO\nYES\nNO"]}]
block_completion_008015
block
python
Complete the code in python to solve this programming problem: Description: There is an array $$$a$$$ of length $$$n$$$. You may perform the following operation any number of times: Choose two indices $$$l$$$ and $$$r$$$ where $$$1 \le l &lt; r \le n$$$ and $$$a_l = a_r$$$. Then, set $$$a[l \ldots r] = [a_{l+1}, a_{l...
import sys sys.setrecursionlimit(10000) def read_line(f): while True: s=f.readline().strip() if s: return s def read_list(f): return [int(x) for x in read_line(f).split()] def read_tuple(f): return tuple(read_list(f)) def load_single_case(f): read_line(f) ...
used[prv]=used.get(prv,0)+1
[{"input": "5\n\n5\n\n1 2 3 3 2\n\n1 3 3 2 2\n\n5\n\n1 2 4 2 1\n\n4 2 2 1 1\n\n5\n\n2 4 5 5 2\n\n2 2 4 5 5\n\n3\n\n1 2 3\n\n1 2 3\n\n3\n\n1 1 2\n\n2 1 1", "output": ["YES\nYES\nNO\nYES\nNO"]}]
block_completion_008016
block
python
Complete the code in python to solve this programming problem: Description: You have a binary string $$$a$$$ of length $$$n$$$ consisting only of digits $$$0$$$ and $$$1$$$. You are given $$$q$$$ queries. In the $$$i$$$-th query, you are given two indices $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$. Let $$...
import sys;input=sys.stdin.readline I=lambda:map(int,input().split()) n, q = I() s = input() pre0,pre1 = [0]*n,[0]*n for i in range(1,n): c1,c2=s[i-1],s[i] pre0[i],pre1[i] = pre0[i-1],pre1[i-1] if c1 == c2 == '0':pre0[i]+=1 elif c1 == c2 == '1':{{completion}} for _ in range(q): l,r=I() print(m...
pre1[i]+=1
[{"input": "5 3\n11011\n2 4\n1 5\n3 5", "output": ["1\n3\n2"]}, {"input": "10 3\n1001110110\n1 10\n2 5\n5 10", "output": ["4\n2\n3"]}]
block_completion_008033
block
python
Complete the code in python to solve this programming problem: Description: You have a binary string $$$a$$$ of length $$$n$$$ consisting only of digits $$$0$$$ and $$$1$$$. You are given $$$q$$$ queries. In the $$$i$$$-th query, you are given two indices $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$. Let $$...
# 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())] n, q = I() s = input() ones = [0, 0] zeroes = [0, 0] for i in range(1, n): if s[i] == s[i - 1] == '0': zeroes.append(zeroe...
zeroes.append(zeroes[-1])
[{"input": "5 3\n11011\n2 4\n1 5\n3 5", "output": ["1\n3\n2"]}, {"input": "10 3\n1001110110\n1 10\n2 5\n5 10", "output": ["4\n2\n3"]}]
block_completion_008034
block
python
Complete the code in python to solve this programming problem: Description: You have a binary string $$$a$$$ of length $$$n$$$ consisting only of digits $$$0$$$ and $$$1$$$. You are given $$$q$$$ queries. In the $$$i$$$-th query, you are given two indices $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$. Let $$...
# 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())] n, q = I() s = input() ones = [0, 0] zeroes = [0, 0] for i in range(1, n): if s[i] == s[i - 1] == '0': zeroes.append(zeroe...
ones.append(ones[-1])
[{"input": "5 3\n11011\n2 4\n1 5\n3 5", "output": ["1\n3\n2"]}, {"input": "10 3\n1001110110\n1 10\n2 5\n5 10", "output": ["4\n2\n3"]}]
block_completion_008035
block
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$r$$$ rows and $$$c$$$ columns, where the square on the $$$i$$$-th row and $$$j$$$-th column has an integer $$$a_{i, j}$$$ written on it. Initially, all elements are set to $$$0$$$. We are allowed to do the following ope...
# import io,os # read = io.BytesIO(os.read(0, os.fstat(0).st_size)) # I = lambda: [*map(int, read.readline().split())] import sys I=lambda:[*map(int,sys.stdin.readline().split())] M = 998244353 r, c = I() rows = [] for i in range(r): rows.append([*input()]) if r % 2 == 0 and c % 2 == 0: blanks = 0 fo...
seen[v] = 1 component.append(v)
[{"input": "3 3\n?10\n1??\n010", "output": ["1"]}, {"input": "2 3\n000\n001", "output": ["0"]}, {"input": "1 1\n?", "output": ["2"]}, {"input": "6 9\n1101011?0\n001101?00\n101000110\n001011010\n0101?01??\n00?1000?0", "output": ["8"]}]
block_completion_008069
block
python
Complete the code in python to solve this programming problem: Description: There is a grid with $$$r$$$ rows and $$$c$$$ columns, where the square on the $$$i$$$-th row and $$$j$$$-th column has an integer $$$a_{i, j}$$$ written on it. Initially, all elements are set to $$$0$$$. We are allowed to do the following ope...
# import io,os # read = io.BytesIO(os.read(0, os.fstat(0).st_size)) # I = lambda: [*map(int, read.readline().split())] import sys I=lambda:[*map(int,sys.stdin.readline().split())] M = 998244353 r, c = I() rows = [] for i in range(r): rows.append([*input()]) if r % 2 == 0 and c % 2 == 0: blanks = 0 fo...
ones.append(y) zeroes.append(0)
[{"input": "3 3\n?10\n1??\n010", "output": ["1"]}, {"input": "2 3\n000\n001", "output": ["0"]}, {"input": "1 1\n?", "output": ["2"]}, {"input": "6 9\n1101011?0\n001101?00\n101000110\n001011010\n0101?01??\n00?1000?0", "output": ["8"]}]
block_completion_008070
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())): n = int(input()) a = b = 0 c = '-' for x, y in zip(*[iter(input())]*2): if x != y: a += 1 else: {{completion}} print(a, max(1, b))
b += x != c c = x
[{"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_008093
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: 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: 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...
import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) s=input() x,y,Lf=0,0,-1 for i in range(0,n,2): if(s[i]!=s[i+1]): x+=1 else: if(Lf!=s[i]): {{completion}} Lf=s[i] print(x,max(y,1))
y+=1
[{"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_008096
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())): n = int(input()) l = [[], []] for x, y in zip(*[iter(input())]*2): {{completion}} print(len(l[0]), sum(map(lambda x : x[0] ^ x[1], zip(l[1], l[1][1:]))) + 1)
l[x==y].append(int(x))
[{"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_008097
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...
def solve(s): res = 0 seg = 0 prev = -1 allDiff = True for i in range(1,len(s),2): if s[i] == s[i-1]: allDiff = False if prev != s[i]: {{completion}} prev = s[i] else: res += 1 if allDiff: seg += 1 print(res,seg) if __name__ == "__main__": t = int(input()) while t: n= int...
seg += 1
[{"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_008098
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...
for _ in range(int(input())): {{completion}}
n,s=int(input()),input() print(sum([1 for i in range(1,n,2) if s[i]!=s[i-1]]))
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008119
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...
import re for s in[*open(0)][2::2]: i=p=r=0 for t in re.findall('0+|1+',s): i+=1 if len(t)&1: if p:r+=i-p;p=0 else:{{completion}} print(r)
p=i
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008120
block
python
Complete the code in python to solve this programming problem: Description: This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only o...
t=int(input("")) for z in range(t): n=int(input("")) a=input("") s=[] for i in range(0,len(a)-1,2): {{completion}} b=s.count('10') c=s.count('01') print(b+c)
ab=a[i]+a[i+1] s.append(ab)
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008121
block
python
Complete the code in python to solve this programming problem: Description: 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: 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: c=1 curr=i continue else: {{completion}} return count for i in range(int(input())): n=int(input()) print(func(inp...
curr=i c=2 count+=1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008123
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...
for _ in range(int(input())): input() inp, count = input(), 0 for i in range(0, len(inp), 2): if (inp[i] != inp[i+1]): {{completion}} print(count)
count += 1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008124
block
python
Complete the code in python to solve this programming problem: Description: This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only o...
t = int(input()) for _ in range(t): _, s = input(), input() res, i, c = 0, 0, 0 while i < len(s): d = s[i] while i < len(s) and s[i] == d: {{completion}} c = c & 1 res += 1 if c else 0 print(res)
c += 1 i += 1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008125
block
python
Complete the code in python to solve this programming problem: Description: This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only o...
t=int(input()) for i in range (t): n=int(input()) a=input() count=0 for k in range(n//2): if(a[2*k]!=a[2*k+1]): {{completion}} print(count)
count+=1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008126
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...
from itertools import groupby t = int(input()) while t: t-=1 n = int(input()) s = input() o = [len("".join(g))&1 for _,g in groupby(s)] l = -1 res = 0 for i, o_ in enumerate(o): if o_: if l == -1: l = i else: {{completion}} ...
res += i-l l = -1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008127
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...
n=int(input("")) t=0 while(t<n): t+=1 length=int(input("")) s=input("") count=0 for i in range(1, length, 2): if s[i]!=s[i-1]: {{completion}} print(count)
count+=1
[{"input": "5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110", "output": ["3\n0\n0\n0\n3"]}]
block_completion_008128
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 t in range(int(input())): {{completion}}
n = int(input()); a = [*map(int,input().split())] print(n+(-a.count(0) or len(set(a))==n))
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008165
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 n in [*open(0)][2::2]: *a,=map(int,n.split());b=len(a);c=a.count(0) while a: q=a.pop() if a.count(q)>0: {{completion}} print(b+(a==[])*(c==0)-c)
break
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008166
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 ...
def solve(): {{completion}} T=int(input()) for i in range(T): print(solve())
N=int(input()) A=sorted(list(map(int,input().split()))) return sum([i>0 for i in A])+all([i>0 for i in A])*all([A[i]<A[i+1] for i in range(N-1)])
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008167
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 ...
def solve(): N=int(input()) A=sorted(list(map(int,input().split()))) return sum([i>0 for i in A])+all([i>0 for i in A])*all([A[i]<A[i+1] for i in range(N-1)]) T=int(input()) for i in range(T): {{completion}}
print(solve())
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008168
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 ...
t=int(input()) for _ in range(t): n=int(input()) ar=list(map(int,input().split())) z=[0]*110 for x in range(n): z[ar[x]]+=1 eq=False for x in range(110): if z[x]>1: {{completion}} if z[0]>0: print(n-z[0]) elif eq: print(n) e...
eq=True
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008169
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 j in range(int(input())): h = int(input()) a = list(map(int,input().split())) if 0 in a: print(h - a.count(0)) else: if len(set(a)) < len(a): print(len(a)) else: {{completion}}
print(len(a)+1)
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008170
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 s.count(i)>1: {{completion}} else: print(n+1)
print(n) break
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008171
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 ...
import sys input = sys.stdin.readline def getInts(): return map(int, input().split()) def solve(): input() a = [*getInts()] if 0 in a: print(len(a) - a.count(0)) else: {{completion}} for _ in range(int(input())): solve()
s = set(a) print(len(a) + (len(a) == len(s)))
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008172
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 ...
test=int(input()) while test: test-=1 n=int(input()) arr=[int(x) for x in input().split()] zero=0 s=set(arr) for i in arr: if i==0: {{completion}} if zero: print(n-zero) elif len(s)==n: print(n+1) else: print(n)
zero+=1
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008173
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 _ in[0]*int(input()): {{completion}}
n=int(input()) a=[*map(int,input().split())] print(n-a.count(0)+(0 not in a and len(a)==len(set(a))))
[{"input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0", "output": ["4\n3\n2"]}]
block_completion_008174
block
python
Complete the code in python to solve this programming problem: Description: You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$...
import sys def diff_ops(arr): result = True for i in range(1, len(arr)): {{completion}} return result if __name__ == "__main__": input_arr = list(map(int, sys.stdin.read().split())) len_input = len(input_arr) n = input_arr[0] test_cases = [] pos = 1 while pos ...
result = result and arr[i] % arr[0] == 0
[{"input": "4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3", "output": ["YES\nYES\nYES\nNO"]}]
block_completion_008175
block
python
Complete the code in python to solve this programming problem: Description: You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero): choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$...
import sys def diff_ops(arr): result = True for i in range(1, len(arr)): result = result and arr[i] % arr[0] == 0 return result if __name__ == "__main__": input_arr = list(map(int, sys.stdin.read().split())) len_input = len(input_arr) n = input_arr[0] test_cases = [] ...
case_len = input_arr[pos] test_cases.append(input_arr[pos + 1: pos + 1 + case_len]) pos += case_len + 1
[{"input": "4\n\n2\n\n5 10\n\n3\n\n1 2 3\n\n4\n\n1 1 1 1\n\n9\n\n9 9 8 2 4 4 3 5 3", "output": ["YES\nYES\nYES\nNO"]}]
block_completion_008176
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
n, k = map(int, input().split()) answer = [0] * (n + 1) dp = [1] + [0] * n MIN = 0 while MIN + k <= n: mod = [0 for _ in range(k)] for i in range(MIN, n + 1): {{completion}} MIN += k k += 1 print(*answer[1:])
dp[i], mod[i % k] = mod[i % k], dp[i] + mod[i % k] mod[i % k] %= 998244353 answer[i] += dp[i] answer[i] %= 998244353
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008218
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
import copy n, k = list(map(int, input().split(' '))) dp = [0]*(n+1) for i in range(k, n+1, k): dp[i] = 1 # print(list(range(n+1))) # print(dp, k) ans = copy.copy(dp) dp2 = [0]*(n+1) for s in range(2,n): # will be sqrt(n) really ks = k + s - 1 first = (ks * (ks+1) // 2) - ((k-1) * k // 2) if first ...
break
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008219
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
import copy n, k = list(map(int, input().split(' '))) dp = [0]*(n+1) for i in range(k, n+1, k): dp[i] = 1 # print(list(range(n+1))) # print(dp, k) ans = copy.copy(dp) dp2 = [0]*(n+1) for s in range(2,n): # will be sqrt(n) really ks = k + s - 1 first = (ks * (ks+1) // 2) - ((k-1) * k // 2) if first ...
dp2[i] = (dp2[i-ks] + dp[i-ks]) % 998244353
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008220
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
import sys inf=float('inf') mod=998244353 #input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int,input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) def main(): n,k=inpnm() N=n+1 f1=[0]*N res=[0]*N f1[0]=1 i=1 ...
f2[j]=(f1[j-step]+f2[j-step])%mod res[j]=(res[j]+f2[j])%mod
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008221
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
import sys inf=float('inf') mod=998244353 #input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int,input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) def main(): n,k=inpnm() N=n+1 f1=[0]*N res=[0]*N f1[0]=1 i=1 ...
f1[j]=f2[j]
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008222
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
t=1 mod=998244353 while t: t-=1 n,k=[int(x) for x in input().split()] dp=[0 for x in range(n+1)] ans=[0 for x in range(n+1)] for i in range(k,n+1,k): dp[i]+=1 ans[i]=dp[i] while True: k+=1 shift=False for i in reversed(range(n+1)): ...
shift=True
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008223
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
MOD, MAXN = 998244353, 10**5 * 2 N, K = map(int, input().split()) ans, dp = [0] * (MAXN + 10), [0] * (MAXN + 10) dp[0] = 1 s = 0 for i in range(701): if s > N: {{completion}} new_dp = [0] * (MAXN + 10) for j in range(s + i + K, N + 1): new_dp[j] = (new_dp[j - i - K] + dp[j - i - K]...
break
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008224
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
MOD, MAXN = 998244353, 10**5 * 2 N, K = map(int, input().split()) ans, dp = [0] * (MAXN + 10), [0] * (MAXN + 10) dp[0] = 1 s = 0 for i in range(701): if s > N: break new_dp = [0] * (MAXN + 10) for j in range(s + i + K, N + 1): {{completion}} dp = new_dp s += i + K print(...
new_dp[j] = (new_dp[j - i - K] + dp[j - i - K]) % MOD ans[j] = (ans[j] + new_dp[j]) % MOD
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008225
block
python
Complete the code in python to solve this programming problem: Description: There is a chip on the coordinate line. Initially, the chip is located at the point $$$0$$$. You can perform any number of moves; each move increases the coordinate of the chip by some positive integer (which is called the length of the move)....
n,k=map(int,input().split());M=998244353 f,z=[1]+[0]*n,[0]*(n+1);l=0 while l<=n-k: s=[0]*k for i in range(l,n+1): {{completion}} l+=k;k+=1 print(*z[1:])
j=i%k s[j],f[i],z[i]=(s[j]+f[i])%M,s[j],(z[i]+s[j])%M
[{"input": "8 1", "output": ["1 1 2 2 3 4 5 6"]}, {"input": "10 2", "output": ["0 1 0 1 1 1 1 2 2 2"]}]
block_completion_008226
block
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 = ...
pos = (pos[0], pos[1]+1)
[{"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"]}]
block_completion_008286
block
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 = ...
pos = (pos[0]-1, pos[1])
[{"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"]}]
block_completion_008287
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 = 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: 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: val = max(arr[start], 0) return [(val, val, val, arr[start])] 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] result.append((max(lb, rb, ls + rp), max(rs, rS + ls), max(lp, lS + rp), lS + rS))
[{"input": "3\n-3 5 -3 2 8 -20 6 -1\n3\n1\n0\n1", "output": ["18\n8\n13"]}]
block_completion_008316
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...
ans.append(merge(vl[i], vr[i]))
[{"input": "3\n-3 5 -3 2 8 -20 6 -1\n3\n1\n0\n1", "output": ["18\n8\n13"]}]
block_completion_008317
block
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)] # number of 1 cells robot will clean when it arrives at cell (j, i) from the left for j in range(2): ...
dp[i][j] = max(dp[i][j], 1 + G[1 - j][i + 1] + G[1 - j][i + 2] + dp[i + 2][1 - j])
[{"input": "2\n01\n11", "output": ["2"]}, {"input": "2\n01\n01", "output": ["2"]}, {"input": "4\n0101\n1011", "output": ["4"]}, {"input": "4\n0000\n0000", "output": ["0"]}, {"input": "5\n00011\n10101", "output": ["4"]}, {"input": "6\n011111\n111111", "output": ["8"]}, {"input": "10\n0101001010\n1010100110", "output": [...
block_completion_008392
block
python
Complete the code in python to solve this programming problem: Description: Consider a hallway, which can be represented as the matrix with $$$2$$$ rows and $$$n$$$ columns. Let's denote the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$. The distance between the cells $$$(i_1...
import sys inf = float('inf') mod = 998244353 input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int, input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) n=inpint() s=[] for i in range(2): s.append([i for i in list(input())]+['0','0']) #pri...
f[min(i+2,n)][j^1]=max(f[min(i+2,n)][j^1],f[i][j]+1+int(s[j^1][i+1])+int(s[j^1][i+2]))
[{"input": "2\n01\n11", "output": ["2"]}, {"input": "2\n01\n01", "output": ["2"]}, {"input": "4\n0101\n1011", "output": ["4"]}, {"input": "4\n0000\n0000", "output": ["0"]}, {"input": "5\n00011\n10101", "output": ["4"]}, {"input": "6\n011111\n111111", "output": ["8"]}, {"input": "10\n0101001010\n1010100110", "output": [...
block_completion_008393
block
python
Complete the code in python to solve this programming problem: Description: 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): ...
dp[i][j] = max(dp[i][j], 1 + G[1 - j][i + 1] + dp[i + 1][1 - j])
[{"input": "2\n01\n11", "output": ["2"]}, {"input": "2\n01\n01", "output": ["2"]}, {"input": "4\n0101\n1011", "output": ["4"]}, {"input": "4\n0000\n0000", "output": ["0"]}, {"input": "5\n00011\n10101", "output": ["4"]}, {"input": "6\n011111\n111111", "output": ["8"]}, {"input": "10\n0101001010\n1010100110", "output": [...
block_completion_008394
block
python
Complete the code in python to solve this programming problem: Description: Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same. In...
import sys if __name__ == "__main__": input_arr = sys.stdin.read().split() tc = int(input_arr[0]) pos = 1 for i in range(tc): n, row1, row2 = input_arr[pos:pos + 3] row1n, row2n = [], [] for k,j in zip(row1, row2): if k == "G": {{completion...
k = "B"
[{"input": "6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG", "output": ["YES\nNO\nYES\nNO\nYES\nYES"]}]
block_completion_008470
block
python
Complete the code in python to solve this programming problem: Description: Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same. In...
import sys if __name__ == "__main__": input_arr = sys.stdin.read().split() tc = int(input_arr[0]) pos = 1 for i in range(tc): n, row1, row2 = input_arr[pos:pos + 3] row1n, row2n = [], [] for k,j in zip(row1, row2): if k == "G": k = "B" ...
j = "B"
[{"input": "6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG", "output": ["YES\nNO\nYES\nNO\nYES\nYES"]}]
block_completion_008471
block
python
Complete the code in python to solve this programming problem: Description: 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...
import sys if __name__ == "__main__": input_arr = list(map(int, sys.stdin.read().split())) n = input_arr[0] pos = 1 for i in range(n): n, code = input_arr[pos:pos+2] code_str = str(code) result = [] j = n-1 while j >= 0: if j >= 2: ...
result.append(chr(int(code_str[j])+96)) j -= 1
[{"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"]}]
block_completion_008584
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...
d.appendleft(int(s[i])) i += 1
[{"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"]}]
block_completion_008585
block
python
Complete the code in python to solve this programming problem: Description: Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently ...
import sys def calculate(x, y1, y2): x = int(x) y1 = int(y1) y2 = int(y2) diff1 = abs(x - 1) diff2 = abs(y1-y2) if y2 == 1 else abs(y1-y2)+y2-1 if diff1 < diff2: return 1 elif diff2 < diff1: return 2 else: return 3 if __name__ == "__main__": ...
print(calculate(input[0], input[1], input[2]))
[{"input": "3\n\n1 2 3\n\n3 1 2\n\n3 2 1", "output": ["1\n3\n2"]}]
block_completion_008602
block
python
Complete the code in python to solve this programming problem: Description: You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the s...
# from __future__ import annotations import csv import datetime import string import sys import time from collections import defaultdict from contextlib import contextmanager from typing import List, Optional def solve() -> None: s = next_token() t = next_token() ls = len(s) lt = len(t) is_start = [s[i:i +...
tt[1] = tt[1] + r[1]
[{"input": "8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa", "output": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"]}]
block_completion_008645
block
python
Complete the code in python to solve this programming problem: Description: You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the s...
# from __future__ import annotations import csv import datetime import string import sys import time from collections import defaultdict from contextlib import contextmanager from typing import List, Optional def solve() -> None: s = next_token() t = next_token() ls = len(s) lt = len(t) is_start = [s[i:i +...
tt = [l[0] + r[0] + 1, r[1]]
[{"input": "8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa", "output": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"]}]
block_completion_008646
block
python
Complete the code in python to solve this programming problem: Description: You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the s...
# from __future__ import annotations import csv import datetime import string import sys import time from collections import defaultdict from contextlib import contextmanager from typing import List, Optional def solve() -> None: s = next_token() t = next_token() ls = len(s) lt = len(t) is_start = [s[i:i +...
tt[1] = tt[1] + r[1]
[{"input": "8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa", "output": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"]}]
block_completion_008647
block
python
Complete the code in python to solve this programming problem: Description: You are given two non-empty strings $$$s$$$ and $$$t$$$, consisting of Latin letters.In one move, you can choose an occurrence of the string $$$t$$$ in the string $$$s$$$ and replace it with dots.Your task is to remove all occurrences of the s...
# from __future__ import annotations import csv import datetime import string import sys import time from collections import defaultdict from contextlib import contextmanager from typing import List, Optional def solve() -> None: s = next_token() t = next_token() ls = len(s) lt = len(t) is_start = [s[i:i +...
tt = [l[0] + r[0] + 1, r[1]]
[{"input": "8\n\nabababacababa\n\naba\n\nddddddd\n\ndddd\n\nxyzxyz\n\nxyz\n\nabc\n\nabcd\n\nabacaba\n\nabaca\n\nabc\n\ndef\n\naaaaaaaa\n\na\n\naaaaaaaa\n\naa", "output": ["2 2\n1 4\n2 1\n0 1\n1 1\n0 1\n8 1\n3 6"]}]
block_completion_008648
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...
res = min(res, (indices[v1][0], indices[v2][0]))
[{"input": "5\n\n1003004\n\n4 1\n\n1 2 1\n\n179572007\n\n4 2\n\n2 7 3\n\n2 7 4\n\n111\n\n2 1\n\n2 2 6\n\n0000\n\n1 2\n\n1 4 0\n\n1 4 1\n\n484\n\n1 5\n\n2 2 0\n\n2 3 7\n\n1 2 5\n\n3 3 8\n\n2 2 6", "output": ["2 4\n1 5\n1 2\n-1 -1\n1 2\n-1 -1\n1 3\n1 3\n-1 -1\n-1 -1\n-1 -1"]}]
block_completion_008664
block
python
Complete the code in python to solve this programming problem: Description: Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$.A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of i...
from __future__ import annotations import csv import datetime import string import sys import time from collections import defaultdict from contextlib import contextmanager from typing import List def solve() -> None: a = [int(c) % 9 for c in next_token()] n = len(a) sa = list(a) for i in range(1, n): sa...
res = min(res, tuple(indices[v1][:2]))
[{"input": "5\n\n1003004\n\n4 1\n\n1 2 1\n\n179572007\n\n4 2\n\n2 7 3\n\n2 7 4\n\n111\n\n2 1\n\n2 2 6\n\n0000\n\n1 2\n\n1 4 0\n\n1 4 1\n\n484\n\n1 5\n\n2 2 0\n\n2 3 7\n\n1 2 5\n\n3 3 8\n\n2 2 6", "output": ["2 4\n1 5\n1 2\n-1 -1\n1 2\n-1 -1\n1 3\n1 3\n-1 -1\n-1 -1\n-1 -1"]}]
block_completion_008665
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...
# from collections import Counter """ standing at point i, why choose to jump to a point j? if jump: a*(j-i) + cost(j,n) if not jump(ie. start from i): every unconquered kingdom require the distance j-i be conqured, totally n-j times, -> (j-i)*b*(n-j) + cost(j,n) compare the two equations: when a < b*(n-j)...
res+=a*d pos=i
[{"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"]}]
block_completion_008687
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 idx, num in enumerate(nums): {{completion}} return result for i in range(1, len(lines), 2): n, a, b = map(int, lines[i].split(" ")) nums = [0] + list(map(in...
curr += num result[idx] = curr
[{"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"]}]
block_completion_008688
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 idx, num in enumerate(nums): curr += num result[idx] = curr return result for i in range(1, len(lines), 2): n, a, b = map(int, lines[i].split(" ")) ...
curr = a*nums[f]+b*(cumulative[-1] - cumulative[f] - (n-f-1)*nums[f]) smallest = min(curr, smallest)
[{"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"]}]
block_completion_008689
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...
#Name: Codeforces Round #782 (Div. 4) #Code: #Rating: 00 #Date: 14/06/2022 #Author: auros25 #Done: #sys.stdin.readline().strip() #sys.stdout.write(+"\n") import sys #import bisect for lol in range(int(sys.stdin.readline().strip())): n, a, b = list(map(int, sys.stdin.readline().strip(...
c=a+b ## v=c*x[n-k-1] ## w=k*b*x[n-k-1] ## u= sum(x[n-k:])*b #print(v, w, u) #print(v-w+u) sys.stdout.write( str( c*x[n-k-1] + b*(sum(x[n-k:])-x[n-k-1]*k)) +"\n")
[{"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"]}]
block_completion_008690
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...
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 (x - cap) * a + fb - (x - cap) * cur * b < fb: {{completion}} #print(cap) print(ans)
ans += (x - cap) * a ans -= (x - cap) * cur * b cap = x
[{"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"]}]
block_completion_008691
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...
t = int(input()) for i in range(t): li = input().split() n = int(li[0]) a = int(li[1]) b = int(li[2]) x = input().split() ans = 0 now = 0 for j in range(n): ans += b*(int(x[j])-now) if a < b*(n-j-1): {{completion}} print(ans)
ans += a*(int(x[j])-now) now = int(x[j])
[{"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"]}]
block_completion_008692
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...
def solve(): n,a,b=map(int,input().split()) xs=list(map(int,input().split())) cum=0 ans=sum(xs)*b for i in range(n): {{completion}} print(ans) for _ in range(int(input())): solve()
x=xs[-i-1] ans=min(ans,x*(a+b)+(cum-x*i)*b) cum+=x
[{"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"]}]
block_completion_008693
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 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())] t, = I() for _ in range(t): n, a, b = I() x = [0] + I() suffixes = [0] for i in range(n - 1, -1, -1): {{completion}} ...
move = x[i + 1] - x[i] tot = suffixes[-1] + len(suffixes) * move * b suffixes.append(tot)
[{"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"]}]
block_completion_008694
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 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())] t, = I() for _ in range(t): n, a, b = I() x = [0] + I() suffixes = [0] for i in range(n - 1, -1, -1): move = x[i + 1] -...
best = min(best, x[i] * (b + a) + suffixes[i])
[{"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"]}]
block_completion_008695
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...
def f(ar,a,b): ans=0 c=0 n=len(ar) for id,i in enumerate(ar): d=i-c ans+=d*b if d*a<(n-id-1)*(d)*b: {{completion}} return ans r=lambda :map(int,input().strip().split()) for _ in range(int(input())): n,a,b=r() ar=list(r()) print(f(ar,a,b...
ans+=d*a c=i
[{"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"]}]
block_completion_008696
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...
for s in[*open(0)][1:]:{{completion}}
n,r,b=map(int,s.split());b+=1;c=r//b*'R'+'B';print((r%b*('R'+c)+n*c)[:n])
[{"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_008709
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...
for _ in range(int(input())): {{completion}}
n,r,b=map(int,input().split()) t=((r-1)//(b+1)+1) k=t*(b+1)-r res=('R'*t+'B')*(b+1-k)+('R'*(t-1)+'B')*k print(res[:-1]) #
[{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}]
block_completion_008710
block
python
Complete the code in python to solve this programming problem: Description: 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...
tc=int(input()) for _ in range(tc): {{completion}}
n,a,b=map(int,input().split());b+=1 print((('R'*(a//b+1)+'B')*(a%b)+('R'*(a//b)+'B')*(b-a%b))[:-1])
[{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}]
block_completion_008711
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...
def solve(): n, r, b = list(map(int, input().split(" "))) d = r // (b+1) rem = r%(b+1) s = '' for i in range(b): if(rem > 0): {{completion}} s += 'R'*d + 'B' s += 'R'*d s+='R'*rem print(s) for t in range(int(input())): solve()
s += 'R' rem-= 1
[{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}]
block_completion_008712
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...
for n in[*open(0)][1:]:{{completion}}
n,r,b=map(int,n.split());b+=1;n=r//b*'R';print((r%b*(n+'RB')+(b-r%b)*(n+'B'))[:-1])
[{"input": "3\n7 4 3\n6 5 1\n19 13 6", "output": ["RBRBRBR\nRRRBRR\nRRBRRBRRBRRBRRBRRBR"]}, {"input": "6\n3 2 1\n10 6 4\n11 6 5\n10 9 1\n10 8 2\n11 9 2", "output": ["RBR\nRRBRBRBRBR\nRBRBRBRBRBR\nRRRRRBRRRR\nRRRBRRRBRR\nRRRBRRRBRRR"]}]
block_completion_008713
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(0,t): {{completion}}
n,r,b=map(int,input().split()) eq=r//(b+1) rem=r%(b+1) print(rem*((eq+1)*"R"+"B")+(b-rem)*(eq*("R")+"B")+eq*"R")
[{"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_008714
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...
for t in range(int(input())): n,r,b = map(int,input().split()) s = [] while r and b: s.append("R") s.append("B") r-=1 b-=1 s.append("R") r-=1 j = 0 while r: s[j]+='R' r-=1 j+=2 if j>=len(s): {{complet...
j=0
[{"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_008715
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...
for l in [*open(0)][1:]: {{completion}}
n,r,b=map(int,l.split()) b+=1 c=(r//b)*'R'+'B' print(((r%b)*('R'+c)+n*c)[:n])
[{"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_008716
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: 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): x += "R"*(q+1)+"B" for i in range(b+1-p): {{completion}} print(x[:-1])
x+= "R"*(q)+"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_008718
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
for s in[*open(0)][2::2]: c=[*map(int,s.split())] a=[1 if x else 0 for x in c]+[1] for i,x in enumerate(c): {{completion}} print(*a[:-1])
a[x+i-i*a[i]]=0
[{"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_008746
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
import sys def solve(): n = int(input()) num = list(map(int , input().split())) ret = [1]*n for i in range(n): j = num[i] if j == 0 or ret[i] == 0: {{completion}} if j < n: ret[j] = 0 print(*ret) for _ in range(int(input())): ...
j += 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_008747
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
import sys def solve(): n = int(input()) num = list(map(int , input().split())) ret = [1]*n for i in range(n): j = num[i] if j == 0 or ret[i] == 0: j += i if j < n: {{completion}} print(*ret) for _ in range(int(input())): s...
ret[j] = 0
[{"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_008748
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
t = int(input()) for _ in range(t): n = int(input()) c = list(map(int, input().split())) a, e, se, s = [], [0]*n, 0, sum(c) for i in range(n, 0, -1): {{completion}} print(*reversed(a))
se -= e[i-1] n1 = s//i t = 0 if c[i-1] < i + se else 1 a.append(t) s -= (n1 + (i-1)*t) e[i-n1-1] += 1 se += 1
[{"input": "5\n4\n2 4 2 4\n7\n0 3 4 2 3 2 7\n3\n0 0 0\n4\n0 0 0 4\n3\n1 2 3", "output": ["1 1 0 1 \n0 1 1 0 0 0 1 \n0 0 0 \n0 0 0 1 \n1 0 1"]}]
block_completion_008749
block
python
Complete the code in python to solve this programming problem: Description: 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 ...
from sys import stdin,stderr def rl(): return [int(w) for w in stdin.readline().split()] t, = rl() for _ in range(t): n, = rl() c = rl() a = [1] * n for i in range(n): j = c[i] if j == 0 or a[i] == 0: {{completion}} if j < n: a[j] = 0 ...
j += 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_008750
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
from sys import stdin,stderr def rl(): return [int(w) for w in stdin.readline().split()] t, = rl() for _ in range(t): n, = rl() c = rl() a = [1] * n for i in range(n): j = c[i] if j == 0 or a[i] == 0: j += i if j < n: {{completion}} ...
a[j] = 0
[{"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_008751
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
for _ in range(int(input())): n=int(input()) C=list(map(int,input().split())) z=sum(C)//n d=[0]*(n+1) ans=[] for i in range(n-1,-1,-1): d[i]+=d[i+1] d[i]-=1 d[i-z]+=1 if z and C[i]+d[i]==i: ans.append(1) z-=1 else: ...
ans.append(0)
[{"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_008752
block
python
Complete the code in python to solve this programming problem: Description: Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing ...
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: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys input = sys.stdin.readline class DSU: def __init__(self, n): self.UF = list(range(n)) self.sz = [0]*n def find(self, u): UF = self.UF if UF[u]!=u: UF[u] = self.find(UF[u]) return UF[u] def union(self,u,v): UF = self...
sz[pv] += 1 UF[pu] = pv
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008766
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys input = sys.stdin.readline class DSU: def __init__(self, n): self.UF = list(range(n)) self.sz = [0]*n def find(self, u): UF = self.UF if UF[u]!=u: {{completion}} return UF[u] def union(self,u,v): UF = self.UF ...
UF[u] = self.find(UF[u])
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008767
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys input = sys.stdin.readline def bit(w, b): if w & (1 << b): return 1 return 0 class DSU: def __init__(self, n): self.n = n self.parent = [i for i in range(self.n)] self.SZ = [1 for _ in range(self.n)] def root(self, node): if self...
self.bit_i[j].merge(u, v)
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008768
block