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: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys input = sys.stdin.readline def bit(w, b): if w & (1 << b): return 1 return 0 class DSU: def __init__(self, n): self.n = n self.parent = [i for i in range(self.n)] self.SZ = [1 for _ in range(self.n)] def root(self, node): if self...
self.bit_i_0[j].merge(u, v)
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008769
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys from sys import stdin def uf_find(n,p): ufl = [] while p[n] != n: ufl.append(n) n = p[n] for i in ufl: p[i] = n return n def uf_union(a,b,p,rank,flags): ap = uf_find(a,p) bp = uf_find(b,p) if ap == bp: return True ...
p[ap] = bp flags[bp] = flags[ap] or flags[bp]
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008770
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
import sys from sys import stdin def uf_find(n,p): ufl = [] while p[n] != n: ufl.append(n) n = p[n] for i in ufl: p[i] = n return n def uf_union(a,b,p,rank,flags): ap = uf_find(a,p) bp = uf_find(b,p) if ap == bp: return True ...
p[bp] = ap flags[ap] = flags[ap] or flags[bp] rank[ap] += 1
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008771
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) class dsu: def __init__(self , n): self.p = [0]*(n + 1) self.rank = [0]*(n + 1) for i in range(1 , n + 1): self.p[i] = i def find(self , node): if(self.p...
ans = 1 break
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008772
block
python
Complete the code in python to solve this programming problem: Description: There is an undirected, connected graph with $$$n$$$ vertices and $$$m$$$ weighted edges. A walk from vertex $$$u$$$ to vertex $$$v$$$ is defined as a sequence of vertices $$$p_1,p_2,\ldots,p_k$$$ (which are not necessarily distinct) starting ...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) class dsu: def __init__(self , n): self.p = [0]*(n + 1) self.rank = [0]*(n + 1) for i in range(1 , n + 1): self.p[i] = i def find(self , node): if(self.p...
d[i].union(u , v)
[{"input": "6 7\n1 2 1\n2 3 3\n3 1 5\n4 5 2\n5 6 4\n6 4 6\n3 4 1\n3\n1 5\n1 2\n5 3", "output": ["2\n0\n1"]}, {"input": "9 8\n1 2 5\n2 3 11\n3 4 10\n3 5 10\n5 6 2\n5 7 1\n7 8 5\n7 9 5\n10\n5 7\n2 5\n7 1\n6 4\n5 2\n7 6\n4 1\n6 2\n4 7\n2 8", "output": ["0\n0\n2\n0\n0\n2\n1\n0\n1\n1"]}]
block_completion_008773
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 {{completion}}: continue val =...
i in graph[i]
[{"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"]}]
control_completion_000016
control_fixed
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 = ...
j in graph[i]
[{"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"]}]
control_completion_000017
control_fixed
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[...
j != i
[{"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"]}]
control_completion_000018
control_fixed
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...
i == j or mask & ans[j] == 0
[{"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"]}]
control_completion_000019
control_fixed
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...
b == a
[{"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"]}]
control_completion_000020
control_fixed
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): ...
j, x in qs[i]
[{"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"]}]
control_completion_000021
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) def update(i , t): global ans if(i + 1 < n and a[i] == a[i + 1]): ans += t * (i + 1) else: ans += t * (n - i) * (i + 1) return ans def answer(): global ans ans =...
(i >= 0)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000077
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
from sys import stdin input = stdin.readline inp = lambda : list(map(int,input().split())) def update(i , t): global ans if(i + 1 < n and a[i] == a[i + 1]): ans += t * (i + 1) else: ans += t * (n - i) * (i + 1) return ans def answer(): global ans ans =...
(i >= 0)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000078
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys 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 {{completion}}: ans += (a[i] != a[i + 1]) * (n - (i + 1) + 1) * i while(m): i, x = map(int, input().split()) ans -= (a[i] != a[i - 1]) * (n ...
i in range(1, n + 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"]}]
control_completion_000079
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys 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{{completion}}: i, x = map(int, input().split()) ans -= (a[i] !...
(m)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000080
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import 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...
a[ix] != a[ix-1] == x
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000081
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import 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...
a[ix] != a[ix+1] == x
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000082
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys import collections inf=float('inf') mod=10**5+7 input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int,input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) # for case in range(inpint()): n,m=inpnm() arr=inparr() res=[1] cnt=0 se=1 t=1 ...
i!=0 and arr[i-1]!=arr[i]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000083
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys import collections inf=float('inf') mod=10**5+7 input = lambda: sys.stdin.readline().rstrip() inpnm = lambda: map(int,input().split()) inparr = lambda: [int(i) for i in input().split()] inpint = lambda: int(input()) # for case in range(inpint()): n,m=inpnm() arr=inparr() res=[1] cnt=0 se=1 t=1 ...
i!=n-1 and arr[i+1]!=arr[i]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000084
control_fixed
python
Complete the code in python to solve this programming problem: Description: 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...
i, x in enumerate(arr)
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000085
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
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...
line in INPUT[2:]
[{"input": "5 5\n1 2 3 4 5\n3 2\n4 2\n3 1\n2 1\n2 2", "output": ["29\n23\n35\n25\n35"]}]
control_completion_000086
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
""" 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...
li[i]!=li[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"]}]
control_completion_000087
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
""" 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...
x!=li[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"]}]
control_completion_000088
control_fixed
python
Complete the code in python to solve this programming problem: Description: Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.The awesomeness of an array is the minimum number of blocks of consecutive identical numbe...
import sys 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 {{completion}}: awr[i]+=awr[i-1]+(i-1) else: awr[i]+=awr[i-1] awr[i]+=1 awe=sum(awr) for _ in range(q): i...
arr[i]!=arr[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"]}]
control_completion_000089
control_fixed
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[v] + cost < dist[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"]}]
control_completion_000113
control_fixed
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)]:...
u, cost in G[v]
[{"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"]}]
control_completion_000114
control_fixed
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 {{completion}}: ind+=[i] a[i]=k 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] ...
a[i]==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"]}]
control_completion_000196
control_fixed
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 {{completion}}: l0=p0[j]-p0[i];r0=p0[-1]-l0 l,r=max(-l0*k, -s-r...
j in range(i+1,n)
[{"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"]}]
control_completion_000197
control_fixed
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 ...
not intersect(m1 + m3, b1 + b3, -m2, b2)
[{"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"]}]
control_completion_000198
control_fixed
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): ...
j+1 < n
[{"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"]}]
control_completion_000199
control_fixed
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): ...
B[j] < -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"]}]
control_completion_000200
control_fixed
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 {{completion}}: dp1[i] += dp[i] dp = [x % MOD...
(k & i) == 0
[{"input": "101", "output": ["12"]}, {"input": "1110", "output": ["780"]}, {"input": "11011111101010010", "output": ["141427753"]}]
control_completion_000274
control_fixed
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{{completion}}: dp1[i]+=dp[i] dp=[x%MOD for x in dp1] n=int(s,base=2)+1 p...
(k&i)==0
[{"input": "101", "output": ["12"]}, {"input": "1110", "output": ["780"]}, {"input": "11011111101010010", "output": ["141427753"]}]
control_completion_000275
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
I=input for _ in [0]*int(I()): I();p,z,zero=0,1,0 for v in I().split(): p+=int(v) if {{completion}}:z=0;break if p==0:zero=True if p<0:z=0;break print(['NO','YES'][zero and z])
zero and p>0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000417
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
I=input for _ in [0]*int(I()): I();p,z,zero=0,1,0 for v in I().split(): p+=int(v) if zero and p>0:z=0;break if {{completion}}:zero=True if p<0:z=0;break print(['NO','YES'][zero and z])
p==0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000418
control_fixed
python
Complete the code in python to solve this programming problem: Description: 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] ...
f
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000419
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) tot = a[0] for i in range(1, n): if tot < 0: break elif tot == 0: if {{completion}}: break else: tot += a[i] else: if t...
a[i] != 0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000420
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
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 ...
a[j] != 0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000421
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in [0]*int(input()): input() n = list(map(int,input().split())) s,f,m = 0,0,0 for i in n: s+=i if {{completion}}:m = 1;break if s==0:f=1 if f and s>0:m=1;break print("YNEOS"[(m or not f)::2])
s<0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000422
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for _ in [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 {{completion}}:f=1 if f and s>0:m=1;break print("YNEOS"[(m or not f)::2])
s==0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000423
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
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 {{completion}}: ok = False break if x == 0 ...
x < 0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000424
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
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 {{completion}}: ...
x == 0 and v != 0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000425
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
input = __import__('sys').stdin.readline def solve(): n = int(input()) allzeros = False total = 0 for x in map(int, input().split()): total += x if {{completion}}: print('No') return allzeros = allzeros or total == 0 print('YES' if tot...
total < 0 or total != 0 and allzeros
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000426
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
import sys input=sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() for _ in range(t): n, = I() l = I() pos = 0 if sum(l)!=0 or l[-1]>0: pos=1 else: pref = l[0] seen = 0 if pref<0: pos=1 if pref==0: seen = 1 for i in range(1,n): pref+=l[i] if pref<0: ...
seen
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000427
control_fixed
python
Complete the code in python to solve this programming problem: Description: 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 {{completion}}: ...
a[i]==0
[{"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0", "output": ["No\nYes\nNo\nNo\nYes\nYes\nYes"]}]
control_completion_000428
control_fixed
python
Complete the code in python to solve this programming problem: Description: We have an array of length $$$n$$$. Initially, each element is equal to $$$0$$$ and there is a pointer located on the first element.We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointe...
for 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 {{completion}}: k=0 break ...
g<=c[-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"]}]
control_completion_000429
control_fixed
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...
dist + d[v] < dists[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"]}]
control_completion_000462
control_fixed
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 {{completion}}:d[v]=d[u]+o...
d[u]+out[v]<d[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"]}]
control_completion_000463
control_fixed
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
[{"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"]}]
control_completion_000464
control_fixed
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[v] + nadj[u] + 1 < cost[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"]}]
control_completion_000465
control_fixed
python
Complete the code in python to solve this programming problem: Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de...
input = __import__('sys').stdin.readline n = int(input()) a = list(map(int, input().split())) + [n+1] 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: ...
a[j] > a[j+1]
[{"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"]}]
control_completion_000478
control_fixed
python
Complete the code in python to solve this programming problem: Description: Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the de...
input = __import__('sys').stdin.readline n = int(input()) a = list(map(int, input().split())) + [n+1] cache = {} def check(i, u, d): keys = [] j = i while j+1 <= n: key = (j, u, d) v = cache.get(key, -1) if v != -1: j = v break ...
a[j] > a[j+1]
[{"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"]}]
control_completion_000479
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
#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 {{completion}}: x,y=R();print(p[x]-p[x-y])
_ in range(q)
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000498
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n, q = [int(x) for x in input().split()] prices = [int(price) for price in input().split(" ")] prices.sort(reverse=True) for {{completion}}: prices[i] += prices[i-1] 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] ...
i in range(1, len(prices))
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000499
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n, q = [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 {{completion}}: # 5 5 3 2 1 # 5 10 13 15 16 x, y = [int(x) for x in input().split()] l = 0 if x == y els...
q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000500
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n,q=map(int,input().split()) a=[0] for {{completion}}:a+=a[-1]+x, for _ in[0]*q:x,y=map(int,input().split());print(a[x]-a[x-y])
x in sorted(map(int,input().split()))[::-1]
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000501
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
n,q=map(int,input().split()) a=[0] for x in sorted(map(int,input().split()))[::-1]:a+=a[-1]+x, for {{completion}}:x,y=map(int,input().split());print(a[x]-a[x-y])
_ in[0]*q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000502
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
f=open(0) R=lambda:map(int,next(f).split()) n,q=R();p=[0] for {{completion}}: p+=p[-1]+w, for _ in " "*q: x, y=R();print(p[n-x+y]-p[n-x])
w in sorted(R())
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000503
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
f=open(0) R=lambda:map(int,next(f).split()) n,q=R();p=[0] for w in sorted(R()): p+=p[-1]+w, for {{completion}}: x, y=R();print(p[n-x+y]-p[n-x])
_ in " "*q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000504
control_fixed
python
Complete the code in python to solve this programming problem: Description: 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 =...
n-x > 0
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000505
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
Y=lambda:map(int,input().split()) O=[];n,q=Y();p=sorted(Y())[::-1];s=[0] for {{completion}}:s+=[s[-1]+i] for _ in[0]*q:x,y=Y();O+=[str(s[x]-s[x-y])] print('\n'.join(O))
i in p
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000506
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
Y=lambda:map(int,input().split()) O=[];n,q=Y();p=sorted(Y())[::-1];s=[0] for i in p:s+=[s[-1]+i] for {{completion}}:x,y=Y();O+=[str(s[x]-s[x-y])] print('\n'.join(O))
_ in[0]*q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000507
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
arr=[int(i) for i in input().split()] ans=[] prices=[int(i) for i in input().split()] prices.sort(reverse=True) for i in range(1,arr[0]): prices[i]=prices[i]+prices[i-1] for i in range(arr[1]): xy=[int(i) for i in input().split()] if{{completion}}: ans.append(prices[xy[0]-1]) els...
(xy[0]==xy[1])
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000508
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
import sys n, p = map(int, sys.stdin.readline().split()) l = map(int, sys.stdin.readline().split()) l = sorted(l, reverse=True) for i in range(n-1, 0, -1): l[i-1] += l[i] for _ in range(p): xi, yi = map(int, sys.stdin.readline().split()) a = n-xi b = a+yi if {{completion}}: ...
a == 0
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000509
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
## cf does not have numpy so with lists r=open(0) g=lambda:map(int,next(r).split()) n,q=g() a=[0] for {{completion}}:a+=a[-1]+x, for b in[0]*q:x,y=g();print(a[x]-a[x-y])
x in sorted(g())[::-1]
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000510
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
## cf does not have numpy so with lists r=open(0) g=lambda:map(int,next(r).split()) n,q=g() a=[0] for x in sorted(g())[::-1]:a+=a[-1]+x, for {{completion}}:x,y=g();print(a[x]-a[x-y])
b in[0]*q
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000511
control_fixed
python
Complete the code in python to solve this programming problem: Description: The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet dec...
(n, q) = map(int, input().split()) arr = list(map(int, input().split())) arr.sort(reverse=True) for i in range (1,n): arr[i] = arr[i] + arr[i-1] for trial in range(q): (x, y) = map(int, input().split()) if {{completion}}: print (arr[x-1]) else: print (arr[x-1] - arr[x-y-1])
(x==y)
[{"input": "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3", "output": ["8\n5\n6"]}]
control_completion_000512
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
from collections import deque def solve(): n = int(input()) MOD = 998244353 arr = [list(map(int, input().split())) for i in range(n)] dis = [[10**9]*n for i in range(n)] for i in range(n): for j in range(n): if i != j: dis[i][j] = abs(arr[i][0]-arr[j][0...
v[y] == 0
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000530
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
from collections import deque def solve(): n = int(input()) MOD = 998244353 arr = [list(map(int, input().split())) for i in range(n)] dis = [[10**9]*n for i in range(n)] for i in range(n): for j in range(n): if i != j: dis[i][j] = abs(arr[i][0]-arr[j][0...
x != y and adj[x][y] == 0
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000531
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
from math import perm, comb import sys input = sys.stdin.readline M = 998244353 n = int(input()) x, y = [0]*n, [0]*n for i in range(n): x[i], y[i] = map(int, input().split()) # print(x, y) dist = [[] for _ in range(n)] for i in range(n): for j in range(n): dist[i].append(abs(x[i] - ...
dist[i][j] == mindist[i]
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000532
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
input = __import__('sys').stdin.readline MOD = 998244353 fact = [1] invfact = [1] for i in range(1, 101): fact.append(fact[-1] * i % MOD) invfact.append(pow(fact[-1], MOD-2, MOD)) def C(n, k): if k < 0 or k > n: return 0 return fact[n] * invfact[k] % MOD * invfact[n-k] % MO...
not seen[w] and dist[v][w] == min_dist[v]
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000533
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
############################# ############# cnb_max=10**5 mod=998244353 ############# kai=[1]*(cnb_max+1) rkai=[1]*(cnb_max+1) for i in range(cnb_max): kai[i+1]=kai[i]*(i+1)%mod rkai[cnb_max]=pow(kai[cnb_max],mod-2,mod) for i in range(cnb_max): rkai[cnb_max-1-i]=rkai[cnb_max-i]*(cnb_max-i)%mod def cnb(x,...
i==j
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000534
control_fixed
python
Complete the code in python to solve this programming problem: Description: You are given $$$n$$$ points on the plane, the coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. No two points have the same coordinates.The distance between points $$$i$$$ and $$$j$$$ is defined as $$$d(i,j) = |x_i - x_j| + |y_i - y_j...
############################# ############# cnb_max=10**5 mod=998244353 ############# kai=[1]*(cnb_max+1) rkai=[1]*(cnb_max+1) for i in range(cnb_max): kai[i+1]=kai[i]*(i+1)%mod rkai[cnb_max]=pow(kai[cnb_max],mod-2,mod) for i in range(cnb_max): rkai[cnb_max-1-i]=rkai[cnb_max-i]*(cnb_max-i)%mod def cnb(x,...
i in nod
[{"input": "3\n1 0\n3 0\n2 1", "output": ["9"]}, {"input": "5\n1 2\n2 4\n3 4\n4 4\n1 3", "output": ["240"]}, {"input": "4\n1 0\n3 0\n2 1\n2 0", "output": ["24"]}]
control_completion_000535
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
for {{completion}}: r = int(input()) print('Division', 4 - sum(r >= p for p in (1400, 1600, 1900)))
_ in range(int(input()))
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000710
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
for {{completion}}:r=int(n)/100;print('Division',1+(r<19)+(r<16)+(r<14))
n in[*open(0)][1:]
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000711
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
from bisect import bisect b = [-5001, 1400, 1600, 1900] for {{completion}}: print(f'Division {-bisect(b, int(input()))+5}')
i in range(int(input()))
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000712
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
n=int(input()) while n: num=int(input()) if num>=1900:print("Division 1") elif {{completion}}:print("Division 2") elif num>=1400:print("Division 3") else:print("Division 4") n-=1
num>=1600
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000713
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
n=int(input()) while n: num=int(input()) if num>=1900:print("Division 1") elif num>=1600:print("Division 2") elif {{completion}}:print("Division 3") else:print("Division 4") n-=1
num>=1400
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000714
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
def div(n): return 1 if n >= 1900 else 2 if n >= 1600 else 3 if n >= 1400 else 4 for {{completion}}: print(f'Division {div(int(input()))}')
_ in range(int(input()))
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000715
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
x = input() for i in range(int(x)): z = input() if int(z) >= 1900: print('Division 1') elif {{completion}}: print('Division 2') elif int(z) >= 1400: print('Division 3') else: print('Division 4')
int(z) >= 1600
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000716
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
x = input() for i in range(int(x)): z = input() if int(z) >= 1900: print('Division 1') elif int(z) >= 1600: print('Division 2') elif {{completion}}: print('Division 3') else: print('Division 4')
int(z) >= 1400
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000717
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
k = 0 a = int(input()) for x in range(1, a+1): b = int(input()) if 1900<= b: d = 1 elif {{completion}}: d = 2 elif 1400 <= b <= 1599: d = 3 elif b <= 1399: d = 4 print('Division', d)
1600 <= b <= 1899
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000718
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
k = 0 a = int(input()) for x in range(1, a+1): b = int(input()) if 1900<= b: d = 1 elif 1600 <= b <= 1899: d = 2 elif {{completion}}: d = 3 elif b <= 1399: d = 4 print('Division', d)
1400 <= b <= 1599
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000719
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
t = int(input()) while t > 0: n = int(input()) if n >= 1900: print("Division",1) elif {{completion}}: print("Division", 2) elif n >= 1400 and n < 1600: print("Division", 3) else: print("Division",4) t -= 1
n >= 1600 and n <1900
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000720
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
t = int(input()) while t > 0: n = int(input()) if n >= 1900: print("Division",1) elif n >= 1600 and n <1900: print("Division", 2) elif {{completion}}: print("Division", 3) else: print("Division",4) t -= 1
n >= 1400 and n < 1600
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000721
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
x=int(input("")) for i in range (x): c=int(input("")) if c<=1399: print(" Division 4") elif {{completion}}: print(" Division 3") elif 1600<=c<=1899: print(" Division 2") else : print(" Division 1")
1400<=c<=1599
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000722
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
x=int(input("")) for i in range (x): c=int(input("")) if c<=1399: print(" Division 4") elif 1400<=c<=1599: print(" Division 3") elif {{completion}}: print(" Division 2") else : print(" Division 1")
1600<=c<=1899
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000723
control_fixed
python
Complete the code in python to solve this programming problem: Description: Codeforces separates its users into $$$4$$$ divisions by their rating: For Division 1: $$$1900 \leq \mathrm{rating}$$$ For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$ For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$ For ...
''' How pros write B) ''' for {{completion}}: x = int(input()) print("Division 4" if x < 1400 else "Division 3" if x < 1600 else "Division 2" if x < 1900 else "Division 1")
i in range(int(input()))
[{"input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300", "output": ["Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1"]}]
control_completion_000724
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
from collections import deque for _ in range(int(input())): n = int(input()) l = deque(map(int, input().split())) a, b = 0, 0 ans = 0 cur = 0 while l: cur+=1 if {{completion}}: b += l.pop() else: a += l.popleft() if a==b: ...
a>=b
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000779
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
from collections import deque for _ in range(int(input())): n = int(input()) l = deque(map(int, input().split())) a, b = 0, 0 ans = 0 cur = 0 while l: cur+=1 if a>=b: b += l.pop() else: a += l.popleft() if {{completion}}: ...
a==b
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000780
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
for n in[*open(0)][2::2]: n=[*map(int,n.split())] a,b,l,f=[0]*4;r=len(n)-1 while l<=r: if a<=b: a+=n[l] l+=1 elif {{completion}}: b+=n[r] r-=1 if a==b: f=len(n)-r+l-1 print(f)
b<a
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000781
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
from bisect import * from itertools import * t = int(input()) for _ in range(t): n = int(input()) w = list(map(int, input().split())) aw = list(accumulate(w)) bw = list(accumulate(w[::-1])) mx = 0 for i, a in enumerate(aw): c = bisect_left(bw, a, hi=len(bw)-i-2) if {{completion}}: mx = max(mx, (i+1)+(c+1)...
a==bw[c] and i<(len(bw)-c-1)
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000782
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
def solve(): n=int(input()) a=[*map(int,input().split())] b=a[:] for i in range(n-1):a[i+1]+=a[i] for i in range(n-1,0,-1):b[i-1]+=b[i] l,r=0,n-1 sol=0 while r-l>=1: if {{completion}}:sol=l+n-r+1;l+=1 if a[l]<b[r]:l+=1 else:r-=1 return sol for _ in [0]*int(input()):print(solve())
a[l]==b[r]
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000783
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
def solve(): n=int(input()) a=[*map(int,input().split())] b=a[:] for i in range(n-1):a[i+1]+=a[i] for i in range(n-1,0,-1):b[i-1]+=b[i] l,r=0,n-1 sol=0 while r-l>=1: if a[l]==b[r]:sol=l+n-r+1;l+=1 if {{completion}}:l+=1 else:r-=1 return sol for _ in [0]*int(input()):print(solve())
a[l]<b[r]
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000784
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
I=lambda:[int(i) for i in input().split()] for _ in range(I()[0]): n=I()[0] l=I() l2=[] s1,s2=0,0 p1,p2=0,n-1 while (p1-1<=p2): if {{completion}}: l2.append(p1 + n-1-p2); s1+=l[p1]; p1+=1 if s1 < s2: s1+=l[p1]; p1+=1 if s2 < s1: s2+=l[p2]; p2-=1 print(l2[-1])
s1 == s2
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000785
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
I=lambda:[int(i) for i in input().split()] for _ in range(I()[0]): n=I()[0] l=I() l2=[] s1,s2=0,0 p1,p2=0,n-1 while (p1-1<=p2): if s1 == s2: l2.append(p1 + n-1-p2); s1+=l[p1]; p1+=1 if {{completion}}: s1+=l[p1]; p1+=1 if s2 < s1: s2+=l[p2]; p2-=1 print(l2[-1])
s1 < s2
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000786
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
import math as m i = input() inp = [] for a in range(0,int(i)): inp += [[input(), input()]] def maxx(arr): if arr == []: return 0 else: return max(arr) for s in inp: n = int(s[0]) arr = [int(x) for x in s[1].split()] i = 0 j = n-1 lsum = arr[i] rsum = arr[j] ...
rsum < lsum
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000787
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
for t in range(int(input())): n=int(input()) l1=list(map(int,input().split())) l=0 h=n-1 ans=0 a=0 b=0 while(l<=h): if{{completion}}: b=b+l1[h] h=h-1 else: a=a+l1[l] l=l+1 if(a==b): ans=l+...
(a>b)
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000788
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
for t in range(int(input())): n=int(input()) l1=list(map(int,input().split())) l=0 h=n-1 ans=0 a=0 b=0 while(l<=h): if(a>b): b=b+l1[h] h=h-1 else: a=a+l1[l] l=l+1 if{{completion}}: ans=l+n...
(a==b)
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000789
control_fixed
python
Complete the code in python to solve this programming problem: Description: There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip c...
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] x = sum(a) // 2 s, d = 0, {} for idx, i in enumerate(a): s += i if {{completion}}: break d[s] = idx + 1 s, r = 0, 0 for idx, i in enumerate(a[::-1]): s += i if ...
s > x
[{"input": "4\n3\n10 20 10\n6\n2 1 4 2 4 1\n5\n1 2 4 8 16\n9\n7 3 20 5 15 1 11 8 10", "output": ["2\n6\n0\n7"]}]
control_completion_000790
control_fixed