Dataset Viewer
Auto-converted to Parquet Duplicate
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: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
n,q = map(int,input().split()) graph = [set() for _ in range(n)] start = [0xffffffff]*n for _ in range(q): i,j,x = map(int,input().split()) i -= 1; j -= 1 graph[i].add(j) graph[j].add(i) start[i] &= x start[j] &= x for i in range(n): if i in graph[i]: {{completion}} ...
continue
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000016
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
n,q = map(int,input().split()) graph = [set() for _ in range(n)] start = [0xffffffff]*n for _ in range(q): i,j,x = map(int,input().split()) i -= 1; j -= 1 graph[i].add(j) graph[j].add(i) start[i] &= x start[j] &= x for i in range(n): if i in graph[i]: continue val = ...
val &= start[j]
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000017
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
import sys n, Q = list(map(int, sys.stdin.readline().strip().split())) m = [0] * n M = [2 ** 30 - 1] * n L = [[] for i in range (0, n)] for q in range (0, Q): i, j, x = list(map(int, sys.stdin.readline().strip().split())) i -= 1 j -= 1 M[i] &= x M[j] &= x L[i].append((j, x)) L[...
m[i] = x
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000018
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
from sys import stdin, stdout input, print = stdin.buffer.readline, stdout.write n, T = [int(x) for x in input().split()] ans = [(1<<31)-1] * n from collections import defaultdict R = defaultdict(list) for _ in range(T): a,b, x = [int(_a) for _a in input().split()] a -= 1 b -= 1 a,b = min(a,b), max...
can_remove = False break
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000019
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
n,q = map(int, input().split()) adj = [list() for i in range(n+1)] val = [-1]*(n+1) for _ in range(q): i,j,x=map(int, input().split()) val[i] &= x val[j] &= x adj[i].append(j) adj[j].append(i) # print(*val[1:], sep=" ") # print(*adj, sep="\n") for a in range(1, n+1): if val[a] == -1: va...
t = 0 break
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000020
block
python
Complete the code in python to solve this programming problem: Description: The Narrator has an integer array $$$a$$$ of length $$$n$$$, but he will only tell you the size $$$n$$$ and $$$q$$$ statements, each of them being three integers $$$i, j, x$$$, which means that $$$a_i \mid a_j = x$$$, where $$$|$$$ denotes the...
n, q = map(int, input().strip().split()) qs = [[] for _ in range(n)] refers_self = [False for _ in range(n)] for _ in range(q): i, j, x = map(int, input().strip().split()) if i==j: refers_self[i-1] = True qs[i-1].append((j-1, x)) qs[j-1].append((i-1, x)) a = [] for i in range(n): ...
ans = ans & x
[{"input": "4 3\n1 2 3\n1 3 2\n4 1 2", "output": ["0 3 2 2"]}, {"input": "1 0", "output": ["0"]}, {"input": "2 1\n1 1 1073741823", "output": ["1073741823 0"]}]
block_completion_000021
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) def update(i , t): global ans if(i + 1 < n and a[i] == a[i + 1]): ans += t * (i + 1) else: ans += t * (n - i) * (i + 1) return ans def answer(): global ans ans =...
update(i - 1 , -1)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000074
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) def update(i , t): global ans if(i + 1 < n and a[i] == a[i + 1]): ans += t * (i + 1) else: ans += t * (n - i) * (i + 1) return ans def answer(): global ans ans =...
update(i - 1 , 1)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000075
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) a.insert(0, 0) a.append(0) ans = 0 for i in range(1, n + 1): {{completion}} while(m): i, x = map(int, input().split()) ans -= (a[i] != a[i - 1]) * (n - i + 1) * (i - 1) ans -...
ans += (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000076
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) a.insert(0, 0) a.append(0) ans = 0 for i in range(1, n + 1): ans += (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i while(m): {{completion}}
i, x = map(int, input().split()) ans -= (a[i] != a[i - 1]) * (n - i + 1) * (i - 1) ans -= (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i a[i] = x ans += (a[i] != a[i - 1]) * (n - i + 1) * (i - 1) ans += (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i print(ans + n * (n + 1) // 2) m -= 1
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000077
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import time, sys n, m = [int(i) for i in sys.stdin.readline().split()] a = [int(i) for i in sys.stdin.readline().split()] t1 = time.time() w = [(i+1)*(n-i-1) for i in range(n-1)] c = sum([w[i] if a[i+1] != a[i] else 0 for i in range(n-1)]) for _ in range(m): ix, x = [int(i) for i in sys.stdin.readline().sp...
c -= w[ix-1]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000078
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import time, sys n, m = [int(i) for i in sys.stdin.readline().split()] a = [int(i) for i in sys.stdin.readline().split()] t1 = time.time() w = [(i+1)*(n-i-1) for i in range(n-1)] c = sum([w[i] if a[i+1] != a[i] else 0 for i in range(n-1)]) for _ in range(m): ix, x = [int(i) for i in sys.stdin.readline().sp...
c -= w[ix]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000079
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys import collections inf=float('inf') mod=10**5+7 input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int,input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) # for case in range(inpint()): n,m=inpnm() arr=inparr() res=[1] cnt=0 se=1 t=1 ...
se+=1 t=res[-1] res.append(res[-1]+se+cnt)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000080
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
def update_awesomeness(arr, i, x, curr_aws): {{completion}} INPUT = [*open(0)] n, m = map(int, INPUT[0].split()) arr = list(map(int, INPUT[1].split())) tar = [0] * n aws = (n * (n + 1)) // 2 for i, x in enumerate(arr): aws = update_awesomeness(tar, i, x, aws) for line in INPUT[2:]: i, x ...
left_edit = (x != arr[i - 1]) - (arr[i] != arr[i - 1]) if i != 0 else 0 right_edit = (x != arr[i + 1]) - (arr[i] != arr[i + 1]) if i != n - 1 else 0 arr[i] = x return curr_aws + left_edit * i * (n - i) + right_edit * (i + 1) * (n - i - 1)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000081
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
def update_awesomeness(arr, i, x, curr_aws): left_edit = (x != arr[i - 1]) - (arr[i] != arr[i - 1]) if i != 0 else 0 right_edit = (x != arr[i + 1]) - (arr[i] != arr[i + 1]) if i != n - 1 else 0 arr[i] = x return curr_aws + left_edit * i * (n - i) + right_edit * (i + 1) * (n - i - 1) INPUT = [*o...
aws = update_awesomeness(tar, i, x, aws)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000082
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
""" author: Manoj inp_start 5 5 1 2 3 4 5 3 2 4 2 3 1 2 1 2 2 inp_end """ n, m = list(map(int, input().split())) li = list(map(int, input().split())) ans = int((n*(n+1))/2) for i in range(1, n): if li[i]!=li[i-1]: ans += i*(n-i) al = [] for tc in range(m): i, x = list(map(int, input().spl...
ans-=i*(n-i)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000083
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
""" author: Manoj inp_start 5 5 1 2 3 4 5 3 2 4 2 3 1 2 1 2 2 inp_end """ n, m = list(map(int, input().split())) li = list(map(int, input().split())) ans = int((n*(n+1))/2) for i in range(1, n): if li[i]!=li[i-1]: ans += i*(n-i) al = [] for tc in range(m): i, x = list(map(int, input().spl...
ans+=i*(n-i)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000084
block
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys input=lambda:sys.stdin.readline().rstrip() n,q=map(int,input().split()) arr=[0]+[*map(int,input().split())]+[0] awe=0 awr=[0]*(n+1) for i in range(1,n+1): if arr[i]!=arr[i-1]: awr[i]+=awr[i-1]+(i-1) else: {{completion}} awr[i]+=1 awe=sum(awr) for _ in range(q): i...
awr[i]+=awr[i-1]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
block_completion_000085
block
python
Complete the code in python to solve this programming problem: Description: Stanley lives in a country that consists of $$$n$$$ cities (he lives in city $$$1$$$). There are bidirectional roads between some of the cities, and you know how long it takes to ride through each of them. Additionally, there is a flight betwe...
import sys input=sys.stdin.readline #文字列入力はするな!! ######################################## from heapq import heappush, heappop B=10**5+10 def dijkstra( G, dist, INF=10**11): """ https://tjkendev.github.io/procon-library/python/graph/dijkstra.html O((|E|+|V|)log|V|) V: 頂点数 G[v] = [(nod, cost)]:...
dist[u] = dist[v] + cost heappush(hp, dist[u]*B+u)
[{"input": "3 1 2\n1 3 1", "output": ["0 1 1"]}, {"input": "4 3 1\n1 2 3\n2 4 5\n3 4 7", "output": ["0 1 4 6"]}, {"input": "2 1 1\n2 1 893746473", "output": ["0 1"]}, {"input": "5 5 2\n2 1 33\n1 5 93\n5 3 48\n2 3 21\n4 2 1", "output": ["0 1 2 2 3"]}]
block_completion_000108
block
python
Complete the code in python to solve this programming problem: Description: Stanley lives in a country that consists of $$$n$$$ cities (he lives in city $$$1$$$). There are bidirectional roads between some of the cities, and you know how long it takes to ride through each of them. Additionally, there is a flight betwe...
import sys input=sys.stdin.readline #文字列入力はするな!! ######################################## from heapq import heappush, heappop B=10**5+10 def dijkstra( G, dist, INF=10**11): """ https://tjkendev.github.io/procon-library/python/graph/dijkstra.html O((|E|+|V|)log|V|) V: 頂点数 G[v] = [(nod, cost)]:...
continue
[{"input": "3 1 2\n1 3 1", "output": ["0 1 1"]}, {"input": "4 3 1\n1 2 3\n2 4 5\n3 4 7", "output": ["0 1 4 6"]}, {"input": "2 1 1\n2 1 893746473", "output": ["0 1"]}, {"input": "5 5 2\n2 1 33\n1 5 93\n5 3 48\n2 3 21\n4 2 1", "output": ["0 1 2 2 3"]}]
block_completion_000109
block
python
Complete the code in python to solve this programming problem: Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l...
n,k=map(int,input().split()) l=list(map(int,input().split())) ans=-2 b=l.count(0) for y in range(n): a=l[y:]+l[:y] ind=[] s=0 for i in range(n): if a[i]==0: {{completion}} s+=a[i] while s>0 and len(ind)>0: a[ind[-1]]=max(k-s,-k) s+=(-k+a[ind[-1]]) ind=ind[:-1] s=0 f=0 ...
ind+=[i] a[i]=k
[{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}]
block_completion_000198
block
python
Complete the code in python to solve this programming problem: Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l...
R=lambda:map(int,input().split()) n,k=R();n+=1 a=[0]+[*R()] p0,p=[0]*n,[0]*n for i in range(1,n): p0[i]=p0[i-1]+int(a[i]==0) p[i]=p[i-1]+a[i] s=p[-1] if p0[-1]*k<abs(s): res=-1 else: res=0 for i in range(n): for j in range(i+1,n): {{completion}} print(res)
l0=p0[j]-p0[i];r0=p0[-1]-l0 l,r=max(-l0*k, -s-r0*k),min(l0*k, -s+r0*k) v=p[j]-p[i] res=max(res, 1+abs(v+l), 1+abs(v+r))
[{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}]
block_completion_000199
block
python
Complete the code in python to solve this programming problem: Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l...
import sys input = sys.stdin.readline def ProGamerMove(): n, k = map(int, input().split()) a = list(map(int, input().split())) zeros = a.count(0) sm = sum(a) s1, s2 = 0, 0 c1, c2 = 0, 0 res = -2 def intersect(m1, b1, m2, b2): l1, r1 = m1 - b1 * k, m1 + b1 * k l2, r2 = m2 - b2 * k, m2 + b2 * k return not ...
continue
[{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}]
block_completion_000200
block
python
Complete the code in python to solve this programming problem: Description: You are walking with your dog, and now you are at the promenade. The promenade can be represented as an infinite line. Initially, you are in the point $$$0$$$ with your dog. You decided to give some freedom to your dog, so you untied her and l...
n, k = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(n): C = [0]*n for j in range(n-1, -1, -1): if A[j] == 0: C[j] = 1 if j+1 < n: C[j] += C[j+1] B = A.copy() s = sum(B) flag = True for j in range(n): ...
x = 0
[{"input": "3 2\n5 0 -4", "output": ["6"]}, {"input": "6 4\n1 -2 0 3 -4 5", "output": ["7"]}, {"input": "3 1000000000\n0 0 0", "output": ["1000000001"]}, {"input": "5 9\n-7 -3 8 12 0", "output": ["-1"]}, {"input": "5 3\n-1 0 3 3 0", "output": ["7"]}, {"input": "5 4\n0 2 0 3 0", "output": ["9"]}]
block_completion_000201
block
python
Complete the code in python to solve this programming problem: Description: You are given a positive integer $$$n$$$. Since $$$n$$$ may be very large, you are given its binary representation.You should compute the number of triples $$$(a,b,c)$$$ with $$$0 \leq a,b,c \leq n$$$ such that $$$a \oplus b$$$, $$$b \oplus c$...
MOD = 998244353 TRANS = [6, 3, 7, 4, 1, 0] s = input().strip() dp = [0] * 7 + [1] for c in map(int, s): dp1 = [0] * 8 for i in range(8): for k in TRANS: if c: dp1[k & i] += dp[i] elif (k & i) == 0: {{completion}} dp = [x % MOD fo...
dp1[i] += dp[i]
[{"input": "101", "output": ["12"]}, {"input": "1110", "output": ["780"]}, {"input": "11011111101010010", "output": ["141427753"]}]
block_completion_000281
block
python
Complete the code in python to solve this programming problem: Description: You are given a positive integer $$$n$$$. Since $$$n$$$ may be very large, you are given its binary representation.You should compute the number of triples $$$(a,b,c)$$$ with $$$0 \leq a,b,c \leq n$$$ such that $$$a \oplus b$$$, $$$b \oplus c$...
MOD=998244353 TRANS=[6,3,7,4,1,0] s=input().strip() dp=[0]*7+[1] for c in map(int,s): dp1=[0]*8 for i in range(8): for k in TRANS: if c: dp1[k&i]+=dp[i] elif(k&i)==0: {{completion}} dp=[x%MOD for x in dp1] n=int(s,base=2)+1 print(...
dp1[i]+=dp[i]
[{"input": "101", "output": ["12"]}, {"input": "1110", "output": ["780"]}, {"input": "11011111101010010", "output": ["141427753"]}]
block_completion_000282
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
I=input for _ in [0]*int(I()): I();p,z,zero=0,1,0 for v in I().split(): p+=int(v) if zero and p>0:{{completion}} if p==0:zero=True if p<0:z=0;break print(['NO','YES'][zero and z])
z=0;break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000421
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
I=input for _ in [0]*int(I()): I();p,z,zero=0,1,0 for v in I().split(): p+=int(v) if zero and p>0:z=0;break if p==0:{{completion}} if p<0:z=0;break print(['NO','YES'][zero and z])
zero=True
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000422
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
import sys input = lambda : sys.stdin.readline().rstrip() dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] def solve(): n = int(input()) arr = list(map(int, input().split())) if sum(arr)!=0: return 0 psum = 0 f = 0 for i in range(len(arr)): psum += arr[i] ...
return 0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000423
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) tot = a[0] for i in range(1, n): if tot < 0: break elif tot == 0: if a[i] != 0: {{completion}} else: tot += a[i] else: ...
break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000424
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
from sys import stdin t = int(stdin.readline()) for h in range(t): n = int(stdin.readline()) a = list(map(int,stdin.readline().split(' '))) b = 0 v = True for i in range(n): b += a[i] if b<0: v = False break elif b==0: for j ...
v = False break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000425
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in [0]*int(input()): input() n = list(map(int,input().split())) s,f,m = 0,0,0 for i in n: s+=i if s<0:{{completion}} if s==0:f=1 if f and s>0:m=1;break print("YNEOS"[(m or not f)::2])
m = 1;break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000426
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in [0]*int(input()): input() n = list(map(int,input().split())) s,f,m = 0,0,0 for i in n: s+=i if s<0:m = 1;break if s==0:{{completion}} if f and s>0:m=1;break print("YNEOS"[(m or not f)::2])
f=1
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000427
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
if __name__ == '__main__': t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] x = a[0] ok = True for v in a[1:]: if x < 0: {{completion}} if x == 0 and v != 0: ...
ok = False break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000428
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
if __name__ == '__main__': t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] x = a[0] ok = True for v in a[1:]: if x < 0: ok = False break if x == 0 and v != ...
ok = False break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000429
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
input = __import__('sys').stdin.readline def solve(): n = int(input()) allzeros = False total = 0 for x in map(int, input().split()): total += x if total < 0 or total != 0 and allzeros: {{completion}} allzeros = allzeros or total == 0 print('YES' i...
print('No') return
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000430
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
import sys input=sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() for _ in range(t): n, = I() l = I() pos = 0 if sum(l)!=0 or l[-1]>0: pos=1 else: pref = l[0] seen = 0 if pref<0: pos=1 if pref==0: seen = 1 for i in range(1,n): pref+=l[i] if pref<0: ...
pos=1 break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000431
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) i=n-1 while(a[i]==0 and i!=0): i-=1 while(i>0): if a[i]>=0: print("NO") break a[i-1]+=a[i] i-=1 else: if a[i]==0: print("...
print("NO")
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000432
block
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for i in range(int(input())): n=int(input()) c=[int(j) for j in input().split()] k=1 if [0]*n==c: print('Yes') else: g=0 while c[-1]==0: c.pop() while len(c)-1: if g<=c[-1]: {{completion}} g=g-c.pop() ...
k=0 break
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
block_completion_000433
block
python
Complete the code in python to solve this programming problem: Description: AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and...
import heapq as hq INF = 1001001001 N, M = map(int, input().split()) G = [[] for _ in range(N)] d = [0] * N for _ in range(M): U, V = map(int, input().split()) G[V - 1].append(U - 1) d[U - 1] += 1 dists = [INF] * N dists[N - 1] = 0 queue = [(0, N - 1)] while queue: dist, V = hq.heappop(qu...
dists[v] = dist + d[v] hq.heappush(queue, (dist + d[v], v))
[{"input": "2 1\n1 2", "output": ["1"]}, {"input": "4 4\n1 2\n1 4\n2 4\n1 4", "output": ["2"]}, {"input": "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1", "output": ["4"]}]
block_completion_000469
block
python
Complete the code in python to solve this programming problem: Description: AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and...
from heapq import*;I=input;R=lambda:map(int,I().split()) n,m=R();g,q,vis=[[] for _ in range(n)],[(0,n-1)],[0]*n d,out=[m+1]*n,[0]*n;d[-1]=0 for _ in range(m):u,v=R();u,v=u-1,v-1;g[v].append(u);out[u]+=1 while q: _,u=heappop(q) if vis[u]:continue vis[u]=1 for v in g[u]: if d[u]+out[v]<d[v]:{{complet...
d[v]=d[u]+out[v];heappush(q,(d[v],v))
[{"input": "2 1\n1 2", "output": ["1"]}, {"input": "4 4\n1 2\n1 4\n2 4\n1 4", "output": ["2"]}, {"input": "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1", "output": ["4"]}]
block_completion_000470
block
python
Complete the code in python to solve this programming problem: Description: AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and...
import sys input=sys.stdin.readline #文字列入力はするな!! from heapq import * n,m=map(int,input().split()) root=[[] for i in range(n+2)] rootinv=[[] for i in range(n+2)] no=[0]*(n+2) for i in range(m): u,v=map(int,input().split()) root[u].append(v) rootinv[v].append(u) no[u]+=1 dp=[10**18]*(n+3) dp[n]=0 hp=[...
dp[y]=dp[x]+cost heappush(hp,(dp[y],y))
[{"input": "2 1\n1 2", "output": ["1"]}, {"input": "4 4\n1 2\n1 4\n2 4\n1 4", "output": ["2"]}, {"input": "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1", "output": ["4"]}]
block_completion_000471
block
python
Complete the code in python to solve this programming problem: Description: AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and...
import sys, heapq input=sys.stdin.readline n,m=map(int,input().split()) iadj=[{} for _ in range(n)] # inverted road nadj=[0]*n dist=[n+1]*n cost=[float("inf")]*n visit=[0]*n for _ in range(m): v,u=map(int,input().split()) v-=1 u-=1 pi=iadj[u].setdefault(v,0) iadj[u][v]=1+pi # road...
cost[u]=cost[v]+nadj[u] + 1 heapq.heappush(q, (cost[u], u))
[{"input": "2 1\n1 2", "output": ["1"]}, {"input": "4 4\n1 2\n1 4\n2 4\n1 4", "output": ["2"]}, {"input": "5 7\n1 2\n2 3\n3 5\n1 4\n4 3\n4 5\n3 1", "output": ["4"]}]
block_completion_000472
block
python
Complete the code in python to solve this programming problem: Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de...
input = __import__('sys').stdin.readline n = int(input()) a = list(map(int, input().split())) + [n+1] ans = 0 cache = {} for i in range(n): u = 0 d = n+1 keys = [] j = i while j+1 <= n: key = (j, u, d) v = cache.get(key, -1) if v != -1: ...
d = min(d, a[j])
[{"input": "3\n2 3 1", "output": ["6"]}, {"input": "6\n4 5 2 6 1 3", "output": ["19"]}, {"input": "10\n7 10 1 8 3 9 2 4 6 5", "output": ["39"]}]
block_completion_000487
block
python
Complete the code in python to solve this programming problem: Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de...
input = __import__('sys').stdin.readline n = int(input()) a = list(map(int, input().split())) + [n+1] cache = {} def check(i, u, d): keys = [] j = i while j+1 <= n: key = (j, u, d) v = cache.get(key, -1) if v != -1: j = v break ...
d = min(d, a[j])
[{"input": "3\n2 3 1", "output": ["6"]}, {"input": "6\n4 5 2 6 1 3", "output": ["19"]}, {"input": "10\n7 10 1 8 3 9 2 4 6 5", "output": ["39"]}]
block_completion_000488
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
#from niumeng from itertools import accumulate I=input;R=lambda:map(int,I().split()) n,q=R();a=sorted(R())[::-1];p=[0]+list(accumulate(a)) for _ in range(q): {{completion}}
x,y=R();print(p[x]-p[x-y])
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000509
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n, q = [int(x) for x in input().split()] prices = [int(price) for price in input().split(" ")] prices.sort(reverse=True) for i in range(1, len(prices)): {{completion}} while q: # 5 5 3 2 1 # 5 10 13 15 16 x, y = [int(x) for x in input().split()] l = 0 if x == y else prices[x - y - 1] ...
prices[i] += prices[i-1]
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000510
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n, q = [int(x) for x in input().split()] prices = [int(price) for price in input().split(" ")] prices.sort(reverse=True) for i in range(1, len(prices)): prices[i] += prices[i-1] while q: # 5 5 3 2 1 # 5 10 13 15 16 {{completion}}
x, y = [int(x) for x in input().split()] l = 0 if x == y else prices[x - y - 1] print(prices[x-1] - l) q -= 1
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000511
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n,q=map(int,input().split()) a=[0] for x in sorted(map(int,input().split()))[::-1]:{{completion}} for _ in[0]*q:x,y=map(int,input().split());print(a[x]-a[x-y])
a+=a[-1]+x,
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000512
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n,q=map(int,input().split()) a=[0] for x in sorted(map(int,input().split()))[::-1]:a+=a[-1]+x, for _ in[0]*q:{{completion}}
x,y=map(int,input().split());print(a[x]-a[x-y])
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000513
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
f=open(0) R=lambda:map(int,next(f).split()) n,q=R();p=[0] for w in sorted(R()): {{completion}} for _ in " "*q: x, y=R();print(p[n-x+y]-p[n-x])
p+=p[-1]+w,
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000514
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
f=open(0) R=lambda:map(int,next(f).split()) n,q=R();p=[0] for w in sorted(R()): p+=p[-1]+w, for _ in " "*q: {{completion}}
x, y=R();print(p[n-x+y]-p[n-x])
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000515
block
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
from sys import stdin # t = int(stdin.readline().rstrip()) # while t>0: # t-=1 n,q = map(int,stdin.readline().split()) l = list(map(int,stdin.readline().split())) l.sort() for i in range(1,n): l[i] += l[i-1] # print(l) for i in range(q): x,y = map(int,stdin.readline().split()) actual =...
val -= l[n-x-1]
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
block_completion_000516
block
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
11
Free AI Image Generator No sign-up. Instant results. Open Now