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: 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 + ...
ret -= MOD
[{"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_006065
block
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 integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ...
a,b=map(int,input().split()) arr=[0]*500001 for i in map(int,input().split()): arr[i]+=1 for i in range(1,500000): arr[i+1]+=arr[i]//(i+1) arr[i]%=i+1 if sum(arr[:b])==0: print('Yes') else: {{completion}}
print('No')
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006086
block
python
Complete the code in python to solve this programming problem: Description: 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 ...
import sys from collections import Counter input = sys.stdin.readline n, x = map(int, input().split()) a = list(map(int, input().split())) cnt = Counter(a) rest, base = 0, 1 for t in range(x, 0, -1): if t in cnt: {{completion}} rest %= base rest *= t base *= t if n == 0 or bas...
n -= cnt[t] rest += cnt[t] % base
[{"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_006087
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 ...
import sys from collections import Counter input = sys.stdin.readline n, x = map(int, input().split()) a = list(map(int, input().split())) cnt = Counter(a) rest, base = 0, 1 for t in range(x, 0, -1): if t in cnt: n -= cnt[t] rest += cnt[t] % base rest %= base rest *= t bas...
break
[{"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_006088
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 ...
def rl(): return [int(i) for i in input().split()] def solve(): [n,x]=rl() a=rl() nax=500000+5 ct=[0 for i in range(nax)] for b in a: ct[b]+=1 for i in range(x): if ct[i]%(i+1): {{completion}} ct[i+1]+=ct[i]/(i+1) return "Yes" print(solve())
return "No"
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006089
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 ...
# your code goes here if __name__ == '__main__': n, x = map(int, input('').split(' ')) a = list(map(int, input('').split(' '))) cnt = [0] * (x+2) for w in a: cnt[w] += 1 for i in range(x): while cnt[i] > i: {{completion}} print('No' if sum(cnt[:x]) else 'Yes')
cnt[i] -= (i+1) cnt[i+1] += 1
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006090
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 ...
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 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]: cnt += 1 a.pop() if cnt < k + 1: {{completion}} for i in range(cnt // (k + ...
return ('Yes' if k >= x else 'No' )
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006092
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 s[i] % (i+1) == 0: s[i+1] += s[i]//(i+1) else: {{completion}} else: print('Yes')
print('NO') break
[{"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_006093
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 ...
ex = [0] arr = [0] for i in range(1): a = list(map(int, input().split())) ex = a[1] b = list(map(int, input().split())) arr = b for i in range(1): dp = [0]*ex for a in arr: dp[a-1]+=1 for m in range(len(dp)-1): while dp[m]>=m+2: {{completion}} ...
dp[m] = dp[m] - m - 2 dp[m+1]+=1
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006094
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=map(int,input().split()) s={i:0 for i in range(1,x+1)} def f(x,a): s[x]=s[x]+a an=map(int,input().split()) for b in an: f(b,1) l=1 i=1 while i < x: if s[i]%(i+1)==0: f(i+1,s[i]//(i+1)) i+=1 else: {{completion}} print(['no','yes'][l])
l=0 break
[{"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_006095
block
python
Complete the code in python to solve this programming problem: Description: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ...
b=[0]*500001 l=list(map(int,input("").split())) n=l[0] m=l[1] a=list(map(int,input("").split())) e=1 for i in a: b[i]+=1 for i in range(1,l[1]): if b[i]%(i+1)==0: b[i+1]+=(b[i]//(i+1)) else: {{completion}} if e==1: if b[m]!=0 : print("Yes") else: prin...
print("No") e=0 break
[{"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_006096
block
python
Complete the code in python to solve this programming problem: Description: You are given an integer $$$x$$$ and an array of integers $$$a_1, a_2, \ldots, a_n$$$. You have to determine if the number $$$a_1! + a_2! + \ldots + a_n!$$$ is divisible by $$$x!$$$.Here $$$k!$$$ is a factorial of $$$k$$$ — the product of all ...
b=[0]*500001 l=list(map(int,input("").split())) n=l[0] m=l[1] a=list(map(int,input("").split())) e=1 for i in a: b[i]+=1 for i in range(1,l[1]): if b[i]%(i+1)==0: b[i+1]+=(b[i]//(i+1)) else: print("No") e=0 break if e==1: if b[m]!=0 : print("Yes")...
print("No")
[{"input": "6 4\n3 2 2 2 3 3", "output": ["Yes"]}, {"input": "8 3\n3 2 2 2 2 2 1 1", "output": ["Yes"]}, {"input": "7 8\n7 7 7 7 7 7 7", "output": ["No"]}, {"input": "10 5\n4 3 2 1 4 3 2 4 3 4", "output": ["No"]}, {"input": "2 500000\n499999 499999", "output": ["No"]}]
block_completion_006097
block
python
Complete the code in python to solve this programming problem: Description: You have been invited as a production process optimization specialist to some very large company. The company has $$$n$$$ machines at its factory, standing one behind another in the production chain. Each machine can be described in one of the...
from bisect import bisect import sys input = sys.stdin.readline n, b, p, m = map(int, input().split()) adds = [] curr = [] mults = [] i = 0 for _ in range(n): t, v = input().split() v = int(v) if t == '*': if v == 1: continue curr.sort() a...
continue
[{"input": "3 2 1 3\n* 2\n+ 1\n+ 1", "output": ["6"]}, {"input": "4 2 2 2\n* 2\n+ 1\n* 3\n+ 2", "output": ["21"]}, {"input": "8 2 1 1\n* 2\n+ 1\n* 4\n+ 1\n+ 1\n+ 1\n* 5\n+ 3", "output": ["240"]}]
block_completion_006115
block
python
Complete the code in python to solve this programming problem: Description: You have been invited as a production process optimization specialist to some very large company. The company has $$$n$$$ machines at its factory, standing one behind another in the production chain. Each machine can be described in one of the...
from bisect import bisect import sys input = sys.stdin.readline n, b, p, m = map(int, input().split()) adds = [] curr = [] mults = [] i = 0 for _ in range(n): t, v = input().split() v = int(v) if t == '*': if v == 1: continue curr.sort() a...
seg_mult.append(seg_mult[-1])
[{"input": "3 2 1 3\n* 2\n+ 1\n+ 1", "output": ["6"]}, {"input": "4 2 2 2\n* 2\n+ 1\n* 3\n+ 2", "output": ["21"]}, {"input": "8 2 1 1\n* 2\n+ 1\n* 4\n+ 1\n+ 1\n+ 1\n* 5\n+ 3", "output": ["240"]}]
block_completion_006116
block
python
Complete the code in python to solve this programming problem: Description: Everyone was happy coding, until suddenly a power shortage happened and the best competitive programming site went down. Fortunately, a system administrator bought some new equipment recently, including some UPSs. Thus there are some servers t...
n, m = map(int, input().split()) def modmul(a, b, c = 0): return (a * b + c) % m half = [0, 0, 1] + [0] * (3 * n) pref = [0, 0, 1] + [0] * (3 * n) good = [-1, 1] bad = [-1, 0] for i in range(2, n + 1): nb = 0 for j in range(1, i): prev = i - 2 * j - 1 if prev < 0: ...
continue
[{"input": "2 100", "output": ["1"]}, {"input": "3 10", "output": ["2"]}, {"input": "4 3271890", "output": ["4"]}, {"input": "17 123456", "output": ["32347"]}]
block_completion_006450
block
python
Complete the code in python to solve this programming problem: Description: We call an array $$$a$$$ of length $$$n$$$ fancy if for each $$$1 &lt; i \le n$$$ it holds that $$$a_i = a_{i-1} + 1$$$.Let's call $$$f(p)$$$ applied to a permutation$$$^\dagger$$$ of length $$$n$$$ as the minimum number of subarrays it can be...
n, m = map(int, input().split()) def modmul(a, b, c = 0): return (a * b + c) % m comb = [[1]] for i in range(2010): prev = comb[-1] nex = [1] for i in range(i): nex.append((prev[i] + prev[i + 1]) % m) nex.append(1) comb.append(nex) fact = [1] for i in range(1, 3000): ...
out[base][sq + 1] += ct
[{"input": "4 666012\n1 3 4 2", "output": ["1 0 1 1"]}, {"input": "3 10\n3 2 1", "output": ["1 2 2"]}, {"input": "7 1000000000\n7 2 1 3 5 4 6", "output": ["1 6 40 201 705 1635 1854"]}, {"input": "10 11\n10 9 8 7 6 5 4 3 2 1", "output": ["1 9 9 0 1 5 5 0 1 0"]}]
block_completion_006456
block
python
Complete the code in python to solve this programming problem: Description: We call an array $$$a$$$ of length $$$n$$$ fancy if for each $$$1 &lt; i \le n$$$ it holds that $$$a_i = a_{i-1} + 1$$$.Let's call $$$f(p)$$$ applied to a permutation$$$^\dagger$$$ of length $$$n$$$ as the minimum number of subarrays it can be...
n, m = map(int, input().split()) def modmul(a, b, c = 0): return (a * b + c) % m comb = [[1]] for i in range(2010): prev = comb[-1] nex = [1] for i in range(i): nex.append((prev[i] + prev[i + 1]) % m) nex.append(1) comb.append(nex) fact = [1] for i in range(1, 3000): ...
diff[d] += 1
[{"input": "4 666012\n1 3 4 2", "output": ["1 0 1 1"]}, {"input": "3 10\n3 2 1", "output": ["1 2 2"]}, {"input": "7 1000000000\n7 2 1 3 5 4 6", "output": ["1 6 40 201 705 1635 1854"]}, {"input": "10 11\n10 9 8 7 6 5 4 3 2 1", "output": ["1 9 9 0 1 5 5 0 1 0"]}]
block_completion_006457
block
python
Complete the code in python to solve this programming problem: Description: You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times: select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the va...
# Problem - https://codeforces.com/contest/1714/problem/E # Editorial - https://codeforces.com/blog/entry/105549 # Tags - brute force, math, number theory, *1400 import sys import typing # Read stdin and remove newline elements stdin = [line.strip() for line in sys.stdin.readlines() if line != '\n'] stdin_co...
has_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: You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times: select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the va...
# Problem - https://codeforces.com/contest/1714/problem/E # Editorial - https://codeforces.com/blog/entry/105549 # Tags - brute force, math, number theory, *1400 import sys import typing # Read stdin and remove newline elements stdin = [line.strip() for line in sys.stdin.readlines() if line != '\n'] stdin_co...
has_0 = True
[{"input": "10\n\n2\n\n6 11\n\n3\n\n2 18 22\n\n5\n\n5 10 5 10 5\n\n4\n\n1 2 4 8\n\n2\n\n4 5\n\n3\n\n93 96 102\n\n2\n\n40 6\n\n2\n\n50 30\n\n2\n\n22 44\n\n2\n\n1 5", "output": ["Yes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\nYes\nNo"]}]
block_completion_006708
block
python
Complete the code in python to solve this programming problem: Description: You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The weight of the $$$i$$$-th edge is $$$i$$$.Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:vis := an array of length n...
input = __import__('sys').stdin.readline class DisjointSetUnion(object): def __init__(self, n): self.n = n self.par = [i for i in range(n)] def find(self, x): toupdate = [] while x != self.par[x]: {{completion}} for u in toupdate: ...
toupdate.append(x) x = self.par[x]
[{"input": "5 5\n1 2\n3 5\n1 3\n3 2\n4 2", "output": ["01111"]}, {"input": "10 11\n1 2\n2 5\n3 4\n4 2\n8 1\n4 5\n10 5\n9 5\n8 2\n5 7\n4 6", "output": ["0011111011"]}]
block_completion_006772
block
python
Complete the code in python to solve this programming problem: Description: You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The weight of the $$$i$$$-th edge is $$$i$$$.Here is a wrong algorithm of finding a minimum spanning tree (MST) of a graph:vis := an array of length n...
input = __import__('sys').stdin.readline class DisjointSetUnion(object): def __init__(self, n): self.n = n self.par = [i for i in range(n)] def find(self, x): toupdate = [] while x != self.par[x]: toupdate.append(x) x = self.par[x] ...
self.par[u] = x
[{"input": "5 5\n1 2\n3 5\n1 3\n3 2\n4 2", "output": ["01111"]}, {"input": "10 11\n1 2\n2 5\n3 4\n4 2\n8 1\n4 5\n10 5\n9 5\n8 2\n5 7\n4 6", "output": ["0011111011"]}]
block_completion_006773
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. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
import sys tokens = (token for token in sys.stdin.read().split()) N = int(next(tokens)) for i in range(N): Q = int(next(tokens)) arr = [] count = 0 for i in range(Q): arr.append(int(next(tokens))) i = 0 j = len(arr) - 1 while True: while True: if arr[i] == 1 or i == j: break e...
i+=1
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
block_completion_006955
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. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
import sys tokens = (token for token in sys.stdin.read().split()) N = int(next(tokens)) for i in range(N): Q = int(next(tokens)) arr = [] count = 0 for i in range(Q): arr.append(int(next(tokens))) i = 0 j = len(arr) - 1 while True: while True: if arr[i] == 1 or i == j: break e...
j-=1
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
block_completion_006956
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. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
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() a = deque(inp(n)) ret = 0 sm = sum(a) ...
continue
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
block_completion_006957
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. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
import sys tokens = (token for token in sys.stdin.read().split()) N = int(next(tokens)) for i in range(N): Q = int(next(tokens)) arr = [] count = 0 for i in range(Q): arr.append(int(next(tokens))) i = 0 j = len(arr) - 1 while True: while True: if arr[i] == 1 or i == j: break e...
i+=1
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
block_completion_006958
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. You can do the following operation: choose two indices $$$1 \le i , j \le n$$$, $$$i \ne j$$$, add $$$a_{i}$$$ to $$$a_{j}$$$, remove $$$a_{i}$$$ from $$$a$$$. No...
import sys tokens = (token for token in sys.stdin.read().split()) N = int(next(tokens)) for i in range(N): Q = int(next(tokens)) arr = [] count = 0 for i in range(Q): arr.append(int(next(tokens))) i = 0 j = len(arr) - 1 while True: while True: if arr[i] == 1 or i == j: break e...
j-=1
[{"input": "4\n\n8\n\n0 0 1 1 1 1 1 1\n\n5\n\n1 0 0 1 1\n\n2\n\n1 0\n\n11\n\n1 1 0 0 1 0 0 1 1 1 0", "output": ["0\n1\n1\n3"]}]
block_completion_006959
block
python
Complete the code in python to solve this programming problem: Description: You have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones and an integer $$$k$$$. In one operation you can do one of the following: Select $$$2$$$ consecutive elements of $$$a$$$ and replace them with their minimum (that is...
from sys import stdin from collections import deque lst = list(map(int, stdin.read().split())) _s = 0 def inp(n=1): {{completion}} def inp1(): return inp()[0] t = inp1() for _ in range(t): n = inp1() k = inp1() a = set(inp(n)) print("YES" if 1 in a else "NO")
global _s ret = lst[_s:_s + n] _s += n return ret
[{"input": "7\n\n3 2\n\n0 1 0\n\n5 3\n\n1 0 1 1 0\n\n2 2\n\n1 1\n\n4 4\n\n0 0 0 0\n\n6 3\n\n0 0 1 0 0 1\n\n7 5\n\n1 1 1 1 1 1 1\n\n5 3\n\n0 0 1 0 0", "output": ["YES\nYES\nYES\nNO\nYES\nYES\nYES"]}]
block_completion_006994
block
python
Complete the code in python to solve this programming problem: Description: You 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: You have an array $$$a$$$ consisting of $$$n$$$ positive integers and you have to handle $$$q$$$ queries of the following types: $$$1$$$ $$$i$$$ $$$x$$$: change $$$a_{i}$$$ to $$$x$$$, $$$2$$$ $$$l$$$ $$$r$$$ $$$k$$$: check if the number of ...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.bu...
ans[i] = "NO"
[{"input": "10 8\n1234 2 3 3 2 1 1 2 3 4\n2 1 6 2\n1 1 1\n2 1 6 2\n2 1 9 2\n1 10 5\n2 1 9 3\n1 3 5\n2 3 10 2", "output": ["NO\nYES\nNO\nYES\nYES"]}]
block_completion_007029
block
python
Complete the code in python to solve this programming problem: Description: You have an array $$$a$$$ consisting of $$$n$$$ positive integers and you have to handle $$$q$$$ queries of the following types: $$$1$$$ $$$i$$$ $$$x$$$: change $$$a_{i}$$$ to $$$x$$$, $$$2$$$ $$$l$$$ $$$r$$$ $$$k$$$: check if the number of ...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.bu...
continue
[{"input": "10 8\n1234 2 3 3 2 1 1 2 3 4\n2 1 6 2\n1 1 1\n2 1 6 2\n2 1 9 2\n1 10 5\n2 1 9 3\n1 3 5\n2 3 10 2", "output": ["NO\nYES\nNO\nYES\nYES"]}]
block_completion_007030
block
python
Complete the code in python to solve this programming problem: Description: This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is ...
import sys input = sys.stdin.readline inf = float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s = getStr() if split: s = s.split() return map(int, s) # t = getInt() t = 1 def solve(): n = getInt() a = list(getList(...
l = max(f[keys[it-1]], u+1-v) ans += calc(l, f[keys[it]]-1, P)
[{"input": "4\n2 4 1 4\n3\n2 4\n3 3\n2 1", "output": ["6\n10\n5"]}, {"input": "5\n1 1 3 2 1\n3\n1 3\n2 5\n4 5", "output": ["7\n9\n8"]}]
block_completion_007066
block
python
Complete the code in python to solve this programming problem: Description: This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is ...
import sys input = sys.stdin.readline inf = float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s = getStr() if split: s = s.split() return map(int, s) # t = getInt() t = 1 def solve(): n = getInt() a = list(getList(...
j += 1
[{"input": "4\n2 4 1 4\n3\n2 4\n3 3\n2 1", "output": ["6\n10\n5"]}, {"input": "5\n1 1 3 2 1\n3\n1 3\n2 5\n4 5", "output": ["7\n9\n8"]}]
block_completion_007067
block
python
Complete the code in python to solve this programming problem: Description: This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is ...
from sys import stdin, stdout from collections import defaultdict n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] left = 0 right = 0 right_array = [] right_prefix = [0] answer = 0 second_right = 0 second_right_array = [] second_right_prefix = [0] while left < n: if righ...
lower = candidate
[{"input": "4\n2 4 1 4\n3\n2 4\n3 3\n2 1", "output": ["6\n10\n5"]}, {"input": "5\n1 1 3 2 1\n3\n1 3\n2 5\n4 5", "output": ["7\n9\n8"]}]
block_completion_007068
block
python
Complete the code in python to solve this programming problem: Description: This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is ...
from sys import stdin, stdout from collections import defaultdict n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] left = 0 right = 0 right_array = [] right_prefix = [0] answer = 0 second_right = 0 second_right_array = [] second_right_prefix = [0] while left < n: if righ...
upper = candidate
[{"input": "4\n2 4 1 4\n3\n2 4\n3 3\n2 1", "output": ["6\n10\n5"]}, {"input": "5\n1 1 3 2 1\n3\n1 3\n2 5\n4 5", "output": ["7\n9\n8"]}]
block_completion_007069
block
python
Complete the code in python to solve this programming problem: Description: Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it:A square table of size $$$n \times n$$$, where $$$n$$$ is a multiple of $$$k$$$, is called good if only the characters '.' and...
import sys if __name__ == "__main__": input_arr = sys.stdin.read().split() tc = int(input_arr[0]) pos = 1 for case in range(tc): n, k, r, c = list(map(int, input_arr[pos:pos + 4])) pos += 4 mat = [["." for _ in range(n)] for j in range(n)] r = r - 1 c ...
mat[(r+ll*k) % n][c % n] = 'X' mat[r][(c + ll*k) % n] = 'X'
[{"input": "3\n\n3 3 3 2\n\n2 1 1 2\n\n6 3 4 2", "output": ["X..\n..X\n.X.\nXX\nXX\n.X..X.\nX..X..\n..X..X\n.X..X.\nX..X..\n..X..X"]}]
block_completion_007166
block
python
Complete the code in python to solve this programming problem: Description: Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it:A square table of size $$$n \times n$$$, where $$$n$$$ is a multiple of $$$k$$$, is called good if only the characters '.' and...
import sys if __name__ == "__main__": input_arr = sys.stdin.read().split() tc = int(input_arr[0]) pos = 1 for case in range(tc): n, k, r, c = list(map(int, input_arr[pos:pos + 4])) pos += 4 mat = [["." for _ in range(n)] for j in range(n)] r = r - 1 c ...
print(j, end="")
[{"input": "3\n\n3 3 3 2\n\n2 1 1 2\n\n6 3 4 2", "output": ["X..\n..X\n.X.\nXX\nXX\n.X..X.\nX..X..\n..X..X\n.X..X.\nX..X..\n..X..X"]}]
block_completion_007167
block
python
Complete the code in python to solve this programming problem: Description: You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.Today you need to check a copy of a dialog between a client and a technical support manager. Acc...
import fileinput def f(n): i = 0 while i<len(n): if n[i] == "Q": found = False for j in range(i,len(n)): if n[j] == "A": {{completion}} if not found: print("NO") return i += 1 ...
n = n[:j] + n[j+1:] found = True break
[{"input": "5\n\n4\n\nQQAA\n\n4\n\nQQAQ\n\n3\n\nQAA\n\n1\n\nQ\n\n14\n\nQAQQAQAAQQQAAA", "output": ["Yes\nNo\nYes\nNo\nYes"]}]
block_completion_007322
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
n,x,d,m,f=int(input()),0,0,10**9+7,[1] for i in range(1,9**6):{{completion}} for z in map(int,input().split()):d+=f[z+x]*pow(f[x+1]*f[z-1],-1,m)*(z>0);x+=1 print(d%m)
f.append(f[-1]*i%m)
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007437
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
n,x,d,m,f=int(input()),0,0,10**9+7,[1] for i in range(1,9**6):f.append(f[-1]*i%m) for z in map(int,input().split()):{{completion}} print(d%m)
d+=f[z+x]*pow(f[x+1]*f[z-1],-1,m)*(z>0);x+=1
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007438
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
from math import gcd mod=1_000_000_007 maxn=400_100 fac=[1]*maxn for i in range(2,maxn): fac[i]=(fac[i-1]*i)%mod def inv(b,m): return pow(b, m - 2, m) n=int(input()) a=list(map(int,input().split())) o=0 for i in range(n+1): if a[i]==0: {{completion}} c=fac[a[i]+i]*inv(fac[i+1]*fac[a[i]-1],mod...
break
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007439
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
N = 4 * 10**5 + 5 MOD = 10**9 + 7 fact = [1] invf = [1] for i in range(1, N): fact.append(fact[i-1] * i % MOD) invf.append(pow(fact[-1], MOD-2, MOD)) def C(m, n): if n < 0 or m < n: {{completion}} return fact[m] * invf[n] % MOD * invf[m-n] % MOD n = int(input()) a = list(...
return 0
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007440
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 n = int(input()) a = [int(x) for x in input().split()] fac = [1] for i in range(8 * 10 ** 5 - 1): fac.append((fac[-1] * (i + 1)) % MOD) ans = 0 for i in range(n + 1): if a[i] != 0: {{completion}} print(int(ans % MOD))
ans = (ans + fac[a[i] + i] * pow((fac[i + 1] * fac[a[i] - 1]), -1, MOD))
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007441
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
n,x,d,m,f=int(input()),0,0,10**9+7,[1] for i in range(1,9**6): {{completion}} for z in list(map(int,input().split())): d+=f[z+x]*pow(f[x+1]*f[z-1],m-2,m)*(z!=0) x+=1 print(d%m)
f.append(f[-1]*i%m)
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007442
block
python
Complete the code in python to solve this programming problem: Description: We say an infinite sequence $$$a_{0}, a_{1}, a_2, \ldots$$$ is non-increasing if and only if for all $$$i\ge 0$$$, $$$a_i \ge a_{i+1}$$$.There is an infinite right and down grid. The upper-left cell has coordinates $$$(0,0)$$$. Rows are number...
n,x,d,m,f=int(input()),0,0,10**9+7,[1] for i in range(1,9**6): f.append(f[-1]*i%m) for z in list(map(int,input().split())): {{completion}} print(d%m)
d+=f[z+x]*pow(f[x+1]*f[z-1],m-2,m)*(z!=0) x+=1
[{"input": "2\n2 2 0", "output": ["5"]}, {"input": "10\n12 11 8 8 6 6 6 5 3 2 1", "output": ["2596"]}]
block_completion_007443
block
python
Complete the code in python to solve this programming problem: Description: Mainak has a convex polygon $$$\mathcal P$$$ with $$$n$$$ vertices labelled as $$$A_1, A_2, \ldots, A_n$$$ in a counter-clockwise fashion. The coordinates of the $$$i$$$-th point $$$A_i$$$ are given by $$$(x_i, y_i)$$$, where $$$x_i$$$ and $$$...
import math pi = 3.14159265358979323846264338327950288419716939937510 eps, sq2 = 1e-13, math.sqrt(2) x, y = [], [] n = 0 def binary_find(la, lb, ra, rb, cy, fy, alpha_1, alpha_2, ab): while math.fabs(cy - fy) > eps: mid_y = cy / 2.0 + fy / 2.0 la = lb = 0.0 ra, rb = pi - alpha...
la = mid_a
[{"input": "4\n4 5\n4 1\n7 1\n7 5", "output": ["1.17809724510"]}, {"input": "5\n-3 3\n3 1\n4 2\n-1 9\n-2 9", "output": ["1.07823651333"]}]
block_completion_007521
block
python
Complete the code in python to solve this programming problem: Description: Mainak has a convex polygon $$$\mathcal P$$$ with $$$n$$$ vertices labelled as $$$A_1, A_2, \ldots, A_n$$$ in a counter-clockwise fashion. The coordinates of the $$$i$$$-th point $$$A_i$$$ are given by $$$(x_i, y_i)$$$, where $$$x_i$$$ and $$$...
import math pi = 3.14159265358979323846264338327950288419716939937510 eps, sq2 = 1e-13, math.sqrt(2) x, y = [], [] n = 0 def binary_find(la, lb, ra, rb, cy, fy, alpha_1, alpha_2, ab): while math.fabs(cy - fy) > eps: mid_y = cy / 2.0 + fy / 2.0 la = lb = 0.0 ra, rb = pi - alpha...
ra = mid_a
[{"input": "4\n4 5\n4 1\n7 1\n7 5", "output": ["1.17809724510"]}, {"input": "5\n-3 3\n3 1\n4 2\n-1 9\n-2 9", "output": ["1.07823651333"]}]
block_completion_007522
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
for _ in range(int(input())): {{completion}}
p = list(map(int, input())) print('YES' if sum(p[:3]) == sum(p[3:]) else 'NO')
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007619
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
for _ in [*open(0)][1:]:{{completion}}
print('yes' if int(_[0]) + int(_[1]) + int(_[2]) == int(_[3]) + int(_[4]) + int(_[5]) else 'NO')
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007620
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
t = int(input()) for i in range(1, t + 1): summa = 0 a = int(input()) a6 = a % 10 a5 = (a // 10) % 10 a4 = (a // 100) % 10 a3 = (a // 1000) % 10 a2 = (a // 10000) % 10 a1 = (a // 100000) % 10 if a1 + a2 + a3 == a4 + a5 + a6: print('YES') else: {{completion}}
print("NO")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007621
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
for c in [input() for i in range(int(input()))]: {{completion}}
print(('NO', 'YES')[sum(int(p) for p in (c[:3])) == sum(int(p) for p in (c[3:]))])
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007622
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
import sys def main(): s = sys.stdin.read().strip().split('\n')[1:] r = [] for i in s: {{completion}} return r print(*main(), sep='\n')
nums = list(map(int, i)) r.append(('NO', 'YES')[sum(nums[:3]) == sum(nums[3:])])
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007623
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
for i in range(int(input())): {{completion}}
a = [int(j) for j in input()] print("YES" if sum(a[0:3])==sum(a[3:6]) else "NO")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007624
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
t = int(input("")) for i in range(t): ticket = input("") if int(ticket[0])+int(ticket[1])+int(ticket[2]) == int(ticket[3])+int(ticket[4])+int(ticket[5]): print("YES") else: {{completion}}
print("NO")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007625
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
s = int(input()) r = [] for i in range(s): a = int(input()) if a // 100000 + a // 10000 % 10 + a // 1000 % 10 == a // 100 % 10 + a % 10 + a // 10 % 10: print("YES", end=" ") else: {{completion}}
print("NO", end=" ")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007626
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
n=input() for i in range(int(n)): sumf=0 suml=0 s = input() for x in range(0,3): sumf += int(s[x]) for x in range(3,6): suml += int(s[x]) if sumf== suml: print('YES') else: {{completion}}
print('NO')
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007627
block
python
Complete the code in python to solve this programming problem: Description: A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading ze...
for t in range(int(input())): {{completion}}
n = list(map(int, list(input()))) print("YES" if n[0]+n[1]+n[2]==n[3]+n[4]+n[5] else "NO")
[{"input": "5\n213132\n973894\n045207\n000000\n055776", "output": ["YES\nNO\nYES\nYES\nNO"]}]
block_completion_007628
block
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()) def solve(): n, m = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n): for j in range(m): temp = -A[i][j] for x in range(n): # i - j == x - y => y = x - i + j y = x - i + j if 0 <= y <...
temp += A[x][y]
[{"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_007687
block
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()) def solve(): n, m = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in range(n): for j in range(m): temp = -A[i][j] for x in range(n): # i - j == x - y => y = x - i + j y = x - i + j if 0 <= y <...
temp += A[x][y]
[{"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_007688
block
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...
k,o=lambda:map(int,input().split()),range for f in o(*k()): n,m=k();a=[[*k()]for t in o(n)];l=[0]*(m+n);r=l[:] for i in o(n): for j in o(m):{{completion}} print(max(l[i-j+m-1]+r[i+j]-a[i][j]for i in o(n)for j in o(m)))
b=a[i][j];l[i-j+m-1]+=b;r[i+j]+=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"]}]
block_completion_007689
block
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 b in range(B)...
left_index = a + b right_index = a + B - 1 - b left[left_index] += nums[a][b] right[right_index] += nums[a][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"]}]
block_completion_007690
block
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 b in range(B)...
left_index = a + b right_index = a + B - 1 - b d = left[left_index] + right[right_index] - nums[a][b] damage = max(d, damage)
[{"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_007691
block
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...
import sys sm_row = [-1, +1, -1, +1] sm_column = [-1, +1, +1, -1] for _ in range(int(sys.stdin.readline())): n, m = map(int, sys.stdin.readline().split()) t = [] maximum = 0 for i in range(n): t.append(list(map(int, sys.stdin.readline().split()))) for row in range(n): for c...
summa += t[new_row][new_column] new_row += sm_row[i] new_column += sm_column[i]
[{"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_007692
block
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: 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): u[i+j] += a[i][j] v[i-j] += a[i][j] for i in rang...
a[i][j] = u[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_007694
block
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...
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,m=M();l=[L() for i in range(n)];ans=0 for i in range(n): for j in range(m): s=l[i][j] ...
s+=l[p][q];p-=1;q-=1
[{"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_007695
block
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...
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,m=M();l=[L() for i in range(n)];ans=0 for i in range(n): for j in range(m): s=l[i][j] ...
s+=l[p][q];p-=1;q+=1
[{"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_007696
block
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=eval(input()) for i in range(t): ans=-1 temp=[int(x) for x in input().split()] n,m=temp[0],temp[1] # n*m check=[] for j in range(n): temp=[int(x) for x in input().split()] check.append(temp) dic_l={} dic_r={} for x in range(n): for y in range(m...
dic_l[x+y]+=check[x][y]
[{"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_007697
block
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=eval(input()) for i in range(t): ans=-1 temp=[int(x) for x in input().split()] n,m=temp[0],temp[1] # n*m check=[] for j in range(n): temp=[int(x) for x in input().split()] check.append(temp) dic_l={} dic_r={} for x in range(n): for y in range(m...
dic_r[y-x]+=check[x][y]
[{"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_007698
block
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...
def calc(x, y): ans = 0 x1, y1 = x, y while x1 > 0 and y1 > 0: ans += field[y1 - 1][x1 - 1] x1 -= 1 y1 -= 1 # print("OK", x1, y1) x1, y1 = x, y x1 += 1 y1 += 1 while x1 <= m and y1 <= n: ans += field[y1 - 1][x1 - 1] x1 += 1 y1...
max_sum = max(max_sum, calc(x + 1, y + 1))
[{"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_007699
block
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...
I,R=lambda:map(int,input().split()),range for _ in R(*I()): n,m=I();a=[[*I()] for _ in R(n)];l=[0]*(m+n);r=l[:] for i in R(n): for j in R(m): {{completion}} print(max(l[i-j+m-1]+r[i+j]-a[i][j] for i in R(n) for j in R(m)))
b=a[i][j];l[i-j+m-1]+=b;r[i+j]+=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"]}]
block_completion_007700
block
python
Complete the code in python to solve this programming problem: Description: Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bisho...
t=int(input()) for p in range(t): n,m=map(int,input().split()) c=[] b=[] s=0 for i in range(n): a=list(map(int,input().split())) b+=[a] for k in range(n): for l in range(m): for v in range(min(l,k)+1): {{completion}} fo...
s+=b[k-v][l-v]
[{"input": "4\n4 4\n1 2 2 1\n2 4 2 4\n2 2 3 1\n2 4 2 4\n2 1\n1\n0\n3 3\n1 1 1\n1 1 1\n1 1 1\n3 3\n0 1 1\n1 0 1\n1 1 0", "output": ["20\n1\n5\n3"]}]
block_completion_007701
block
python
Complete the code in python to solve this programming problem: Description: Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bisho...
t=int(input()) for p in range(t): n,m=map(int,input().split()) c=[] b=[] s=0 for i in range(n): a=list(map(int,input().split())) b+=[a] for k in range(n): for l in range(m): for v in range(min(l,k)+1): s+=b[k-v][l-v] fo...
s+=b[k+w][l+w]
[{"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_007702
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...
h, w, q = map(int, input().split()) p = [False] * (h * w) c = cc = 0 def query(y, x): global c, cc i = x*h+y p[i] = not p[i] if p[i]: if i < c: cc += 1 c += 1 if p[c-1]: cc += 1 else: if i < c: {{completion}} ...
cc -= 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_007861
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...
h, w, q = map(int, input().split()) p = [False] * (h * w) c = cc = 0 def query(y, x): global c, cc i = x*h+y p[i] = not p[i] if p[i]: if i < c: cc += 1 c += 1 if p[c-1]: cc += 1 else: if i < c: cc -= 1 ...
cc -= 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_007862
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,...
a[i]^=1 l+=i<k l+=a[k] k+=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_007863
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_007864
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: Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $$$n \times m$$$ consisting of characters '.' (empty cell of the desktop) and '*' (an icon).The desktop is called good i...
n,m,q = map(int, input().split()) s = [input() for _ in range(n)] s = [s[j][i] for i in range(m) for j in range(n)] qrr = [list(map(int, input().split())) for _ in range(q)] qrr = [n * (q[1] - 1) + q[0] - 1 for q in qrr] count = s.count('*') correct = s[:count].count('*') for q in qrr: count += 1 if s[q] == ...
correct -= 1 if q < count else 0 correct -= 1 if s[count] == '*' else 0
[{"input": "4 4 8\n..**\n.*..\n*...\n...*\n1 3\n2 3\n3 1\n2 3\n3 4\n4 3\n2 3\n2 2", "output": ["3\n4\n4\n3\n4\n5\n5\n5"]}, {"input": "2 5 5\n*...*\n*****\n1 3\n2 2\n1 3\n1 5\n2 3", "output": ["2\n3\n3\n3\n2"]}]
block_completion_007866
block
python
Complete the code in python to solve this programming problem: Description: 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 itertools import chain I=lambda:map(int,input().split()) n,m,q=I() g0=[list(input()) for _ in range(n)] g=list(chain.from_iterable(zip(*g0))) tot=g.count('*') inner=g[:tot].count('*') for _ in range(q): i,j=I() p=(j-1)*n+i-1 if g[p]=='*': tot-=1 #"tide fall" if g[tot]=='*':inner-=1...
inner+=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_007867
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 itertools import chain I=lambda:map(int,input().split()) n,m,q=I() g0=[list(input()) for _ in range(n)] g=list(chain.from_iterable(zip(*g0))) tot=g.count('*') inner=g[:tot].count('*') for _ in range(q): i,j=I() p=(j-1)*n+i-1 if g[p]=='*': tot-=1 #"tide fall" if g[tot]=='*':inner-=1...
inner+=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_007868
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: 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 def solve(): # n = int(sys.stdin.readline().strip()) n, m, q = [int(x) for x in sys.stdin.readline().strip().split()] a = [] m = [0] * (m * n) for y in range(n): s = sys.stdin.readline().strip() for x, c in enumerate(s): if c == '*': a.append...
correct -= 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_007870
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 def solve(): # n = int(sys.stdin.readline().strip()) n, m, q = [int(x) for x in sys.stdin.readline().strip().split()] a = [] m = [0] * (m * n) for y in range(n): s = sys.stdin.readline().strip() for x, c in enumerate(s): if c == '*': a.append...
correct -= 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_007871
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
from collections import deque n,m=[int(x) for x in input().split()] g=[[] for _ in range(n)] indeg=[0]*n outdeg=[0]*n tpdeg=[0]*n for _ in range(m): v,u=[int(x) for x in input().split()] v-=1 u-=1 g[v].append(u) outdeg[v]+=1 indeg[u]+=1 tpdeg[u]+=1 q=deque(i for i in ...
f[v]=max(f[v],f[u]+1)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007888
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
from collections import deque n,m=[int(x) for x in input().split()] g=[[] for _ in range(n)] indeg=[0]*n outdeg=[0]*n tpdeg=[0]*n for _ in range(m): v,u=[int(x) for x in input().split()] v-=1 u-=1 g[v].append(u) outdeg[v]+=1 indeg[u]+=1 tpdeg[u]+=1 q=deque(i for i in ...
q.append(v)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007889
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
def iint(): return int(input().strip()) def iints(): return map(int, input().strip().split(" ")) def arr(): return list(input().strip().split(" ")) def arri(): return list(iints()) n,m = iints() class Graph: def __init__(self, n): self.adj = [[] for _ in range(n)] self.ins = [0...
order[b] = x b += 1
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007890
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
def iint(): return int(input().strip()) def iints(): return map(int, input().strip().split(" ")) def arr(): return list(input().strip().split(" ")) def arri(): return list(iints()) n,m = iints() class Graph: def __init__(self, n): self.adj = [[] for _ in range(n)] self.ins = [0...
dp[x] = max(dp[x], 1 + dp[cur])
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007891
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
import sys from collections import deque n, m = map(int, sys.stdin.readline().split()) inv = [0] * (n + 1) outv = [0] * (n + 1) graph = [[] for _ in range(n + 1)] reverse = [[] for _ in range(n + 1)] for _ in range(m): v, u = map(int, sys.stdin.readline().split()) graph[v].append(u) reverse[u].a...
res = max(res, dp[nxt])
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007892
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
import sys input = sys.stdin.readline import math for _ in range(1): n, m = map(int, input().split()) g = [[] for i in range(n)] deg = [0] * n in_deg = [0] * n out_deg = [0] * n for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 g[x]....
order.append(to)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007893
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
import sys input = sys.stdin.readline import math for _ in range(1): n, m = map(int, input().split()) g = [[] for i in range(n)] deg = [0] * n in_deg = [0] * n out_deg = [0] * n for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 g[x]....
dp[j] = max(dp[j], dp[i] + 1)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007894
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
from collections import deque I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n)] din,dout,dcur=[0]*n,[0]*n,[0]*n for _ in range(m): u,v=I() u,v=u-1,v-1 g[u].append(v) dout[u]+=1;din[v]+=1;dcur[v]+=1 q=deque([i for i,d in enumerate(din) if d==0]) f=[1]*n while q: u=q.popleft() ...
f[v]=max(f[v],f[u]+1)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007895
block
python
Complete the code in python to solve this programming problem: Description: You are given a directed acyclic graph, consisting of $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered from $$$1$$$ to $$$n$$$. There are no multiple edges and self-loops.Let $$$\mathit{in}_v$$$ be the number of incoming edges (in...
from collections import deque I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n)] din,dout,dcur=[0]*n,[0]*n,[0]*n for _ in range(m): u,v=I() u,v=u-1,v-1 g[u].append(v) dout[u]+=1;din[v]+=1;dcur[v]+=1 q=deque([i for i,d in enumerate(din) if d==0]) f=[1]*n while q: u=q.popleft() ...
q.append(v)
[{"input": "3 3\n1 2\n2 3\n1 3", "output": ["2"]}, {"input": "5 0", "output": ["1"]}, {"input": "7 8\n7 1\n1 3\n6 2\n2 3\n7 2\n2 4\n7 3\n6 3", "output": ["3"]}]
block_completion_007896
block
python
Complete the code in python to solve this programming problem: Description: Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.Th...
N=int(input()) A=[int(x) for x in input().split()] B=sorted(A) ans=-(-B[0]//2)-(-B[1]//2) for i in range(N-2): {{completion}} for i in range(N-1): score=max(-(-(A[i]+A[i+1])//3),-(-A[i]//2),-(-A[i+1]//2)) ans=min(score,ans) print(ans)
ans=min(ans,-(-(A[i]+A[i+2])//2))
[{"input": "5\n20 10 30 10 20", "output": ["10"]}, {"input": "3\n1 8 1", "output": ["1"]}, {"input": "6\n7 6 6 8 5 8", "output": ["4"]}, {"input": "6\n14 3 8 10 15 4", "output": ["4"]}, {"input": "4\n1 100 100 1", "output": ["2"]}, {"input": "3\n40 10 10", "output": ["7"]}]
block_completion_007904
block
python
Complete the code in python to solve this programming problem: Description: Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.Th...
N=int(input()) A=[int(x) for x in input().split()] B=sorted(A) ans=-(-B[0]//2)-(-B[1]//2) for i in range(N-2): ans=min(ans,-(-(A[i]+A[i+2])//2)) for i in range(N-1): {{completion}} print(ans)
score=max(-(-(A[i]+A[i+1])//3),-(-A[i]//2),-(-A[i+1]//2)) ans=min(score,ans)
[{"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_007905
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...
def onagr(x, y): x, y = max(x, y), min(x, y) if x >= 2 * y: res = (x + 1) // 2 else: res = x - y + (2 * y - x) // 3 * 2 + (2 * y - x) % 3 return res def onagr1(x, y): return min(x, y) + (abs(x - y) + 1) // 2 n = int(input()) m1, m2, *a = list(map(int, input().split(...
m2 = k
[{"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_007906
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,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353 n=I();a=L() b=sorted(a)[:2] ans=math.ceil(b[0]/2)+math.ceil(b[1]/2) for i in range(n-2): ans=min(ans,math.ceil((a[i]+a[i+2])/2)) for i in range(n...
ans=min(ans,math.ceil((4*y-2*x)/3)+x-y)
[{"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_007907
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=int(input()) arr=list(map(int,input().split())) ans=float("inf") y=sorted(arr) ans = ((y[0]+1)//2) + ((y[1]+1)//2) for i in range(len(arr)-1): ans=min(ans,max((arr[i]+1)//2,(arr[i+1]+1)//2,(arr[i]+arr[i+1]+2)//3)) for i in range(len(arr)-2): if arr[i]<=arr[i+2]: ans = min(ans,arr[i]+...
ans = min(ans,arr[i+2]+(arr[i]-arr[i+2]+1)//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_007908
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 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 ...
ans = min(ans, (x + 1) // 2 + (y + 1) // 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_007909
block