message
stringlengths
2
433k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
113
108k
cluster
float64
12
12
__index_level_0__
int64
226
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ ...
instruction
0
53,225
12
106,450
Tags: bitmasks, combinatorics, math Correct Solution: ``` aas = [] for _ in range(int(input())): d, m = map(int, input().split()) A = [] s = 1 sus = 0 while sus + s <= d: A.append(s) sus += s s *= 2 A.append(d - sum(A)) ans = 1 for x in A: ans *= (x+1) ...
output
1
53,225
12
106,451
Provide tags and a correct Python 2 solution for this coding contest problem. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ ...
instruction
0
53,226
12
106,452
Tags: bitmasks, combinatorics, math Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str...
output
1
53,226
12
106,453
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,235
12
106,470
Tags: constructive algorithms, greedy, math Correct Solution: ``` from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * #from operator import add,mul,sub,xor,truediv,floordiv from functools import * #----------------------------------------...
output
1
53,235
12
106,471
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,236
12
106,472
Tags: constructive algorithms, greedy, math Correct Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key,lru_cache import io, os input = io.BytesIO(os.read(0,os.fstat(0).s...
output
1
53,236
12
106,473
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,237
12
106,474
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby def Golf():*a,=map(int,open(0)) def I():ret...
output
1
53,237
12
106,475
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,238
12
106,476
Tags: constructive algorithms, greedy, math Correct Solution: ``` def check_gk(A, k): N = len(A) for i in range(N-1): if A[i] >= k and A[i+1] >= k: return True for i in range(N-2): if A[i] >= k and A[i+2] >= k: return True return False def answer(b): if...
output
1
53,238
12
106,477
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,239
12
106,478
Tags: constructive algorithms, greedy, math Correct Solution: ``` t = int(input()) out = [] for tt in range(t): n, k = map(int, input().split()) if n == 1: out.append("yes" if int(input()) == k else "no") continue a = [] hasa = False for i in input().split(): x = int(i...
output
1
53,239
12
106,479
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,240
12
106,480
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin, stdout import sys from math import * input = stdin.readline for __ in range(int(input())): n,k=map(int,input().split()) ar=list(map(int,input().split())) if(k not in ar): print("No") elif(n==1): print("Yes") else: ans=...
output
1
53,240
12
106,481
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,241
12
106,482
Tags: constructive algorithms, greedy, math Correct Solution: ``` from sys import stdin input=stdin.buffer.readline T=int(input()) for _ in range(T): n,k = map(int,input().split()) ls = list(map(int,input().split())) if n==1: print("yes" if ls[0]==k else "no"); continue c1,c2=0,0 for i,u in enumerate(l...
output
1
53,241
12
106,483
Provide tags and a correct Python 3 solution for this coding contest problem. Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\...
instruction
0
53,242
12
106,484
Tags: constructive algorithms, greedy, math Correct Solution: ``` printn = lambda x: print(x,end='') import sys input = sys.stdin.readline inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG ...
output
1
53,242
12
106,485
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,271
12
106,542
Tags: greedy, sortings Correct Solution: ``` for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) br=list(map(int,input().split())) li=[] for i in range(n): if(br[i]==0): li.append(ar[i]) li.sort(reverse=True) j=0 for i in range(n): i...
output
1
53,271
12
106,543
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,272
12
106,544
Tags: greedy, sortings Correct Solution: ``` for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) lock = list(map(int, input().split())) b = [] for i in range(n): if lock[i] == 0: b.append(a[i]) b.sort() b=b[::-1] ind = 0 for i in ran...
output
1
53,272
12
106,545
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,273
12
106,546
Tags: greedy, sortings Correct Solution: ``` # 1 import itertools import math import sys from collections import defaultdict def stdinWrapper(): data = '''5 3 1 3 2 0 0 0 4 2 -3 4 -1 1 1 1 1 7 -8 4 -2 -6 4 7 1 1 0 0 0 1 1 0 5 0 1 -4 6 3 0 0 0 1 1 6 -1 7 10 4 -8 -1 1 0 0 0 0 1 ''' for line in da...
output
1
53,273
12
106,547
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,274
12
106,548
Tags: greedy, sortings Correct Solution: ``` import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from bisect import bisect_left as bl, bisect_right as br, insort from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter # from itertools...
output
1
53,274
12
106,549
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,275
12
106,550
Tags: greedy, sortings Correct Solution: ``` for _ in range(int(input())): n=int(input()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) unlock=[] for i in range(len(l1)): if(l2[i]==0): unlock.append(l1[i]) l1[i]="a" unlock.sort() for i in range(n): if(l1[i]=="a"): l1[i]=unlock[...
output
1
53,275
12
106,551
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,276
12
106,552
Tags: greedy, sortings Correct Solution: ``` #------------------------------warmup---------------------------- # ******************************* # * AUTHOR: RAJDEEP GHOSH * # * NICK : Rajdeep2k * # * INSTITUTION: IIEST, SHIBPUR * # ******************************* import os import sys from io impo...
output
1
53,276
12
106,553
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,277
12
106,554
Tags: greedy, sortings Correct Solution: ``` y=lambda:[*map(int,input().split())] r=range for _ in r(int(input())): n=int(input());a=y();l=y();b=[] for i in r(n): if l[i]<1:b+=[a[i]] b.sort() for i in r(n): if l[i]<1:a[i]=b.pop() print(' '.join(map(str,a))) ```
output
1
53,277
12
106,555
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked ...
instruction
0
53,278
12
106,556
Tags: greedy, sortings Correct Solution: ``` I=input for _ in[0]*int(I()): I();*a,=map(int,I().split());b=I()[::2];c=sorted(x for x,y in zip(a,b)if'1'>y);i=k=l=s=0;j=-1 for x in b: if'1'>x:a[i]=c[j];j-=1 i+=1 for x in a:l+=1;s+=x;k=(k,l)[l<0] print(*a) ```
output
1
53,278
12
106,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,279
12
106,558
Yes
output
1
53,279
12
106,559
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,280
12
106,560
Yes
output
1
53,280
12
106,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,281
12
106,562
Yes
output
1
53,281
12
106,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,282
12
106,564
Yes
output
1
53,282
12
106,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,283
12
106,566
No
output
1
53,283
12
106,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,284
12
106,568
No
output
1
53,284
12
106,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,285
12
106,570
No
output
1
53,285
12
106,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a, consisting of n integers. Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in a...
instruction
0
53,286
12
106,572
No
output
1
53,286
12
106,573
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,287
12
106,574
Tags: math Correct Solution: ``` for i in range(int(input())): m = int(input().split()[1]) s = sum(map(int, input().split())) print('NO' if s!=m else 'YES') ```
output
1
53,287
12
106,575
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,288
12
106,576
Tags: math Correct Solution: ``` # import sys # sys.stdin = open('input.txt','r') # sys.stdout = open('output.txt','w') t = int(input()) while t: n,m = map(int,input().split()) arr = list(map(int,input().split())) s = sum(arr) if s == m: print('YES') else: print('NO') t-=1 ```
output
1
53,288
12
106,577
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,289
12
106,578
Tags: math Correct Solution: ``` t=int(input()) for i in range(t): n,m=map(int,input().split()) arr=list(map(int,input().split())) if sum(arr)==m: print("YES") else: print("NO") ```
output
1
53,289
12
106,579
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,290
12
106,580
Tags: math Correct Solution: ``` t = int(input()) for _ in range(t): n,m = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] print("YES" if sum(a) == m else "NO") ```
output
1
53,290
12
106,581
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,291
12
106,582
Tags: math Correct Solution: ``` for _ in range(int(input())): n,m=map(int,input().split()) arr=list(map(int,input().split())) sum1=0 for i in range(1,n+1): for j in range(i,n+1): sum1+=arr[j-1]/j if(round(sum1)==m): print("YES") else: print("NO")...
output
1
53,291
12
106,583
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,292
12
106,584
Tags: math Correct Solution: ``` for _ in range(int(input())): n, m = input().split() m = int(m) a = list(map(int, input().split())) if sum(a) == m: print("YES") else: print("NO") ```
output
1
53,292
12
106,585
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,293
12
106,586
Tags: math Correct Solution: ``` cases = int(input()) for case in range(cases): _, m = input().split() print('YES' if sum(map(int, input().split())) == int(m) else 'NO') ```
output
1
53,293
12
106,587
Provide tags and a correct Python 3 solution for this coding contest problem. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as inser...
instruction
0
53,294
12
106,588
Tags: math Correct Solution: ``` for i in range(int(input())): n,k=list(map(int,input().split())) if sum(list(map(int,input().split())))==k: print("YES") else: print("NO") ```
output
1
53,294
12
106,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,295
12
106,590
Yes
output
1
53,295
12
106,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,296
12
106,592
Yes
output
1
53,296
12
106,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,297
12
106,594
Yes
output
1
53,297
12
106,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,298
12
106,596
Yes
output
1
53,298
12
106,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,299
12
106,598
No
output
1
53,299
12
106,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,300
12
106,600
No
output
1
53,300
12
106,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,301
12
106,602
No
output
1
53,301
12
106,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It i...
instruction
0
53,302
12
106,604
No
output
1
53,302
12
106,605
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,303
12
106,606
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` from collections import defaultdict;mod = 10 ** 9 + 7 for _ in range(int(input())): n = int(input());B = list(map(int, input().split()));dp = defaultdict(int);cur, ans = 0, 0 for i, b in enumerate(B):v = 1 if not i else (ans - dp[cur]) % m...
output
1
53,303
12
106,607
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,304
12
106,608
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` import sys input = sys.stdin.readline from collections import defaultdict for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 dp = defaultdict(int) dp[0] = 1 ans = 1 cur...
output
1
53,304
12
106,609
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,305
12
106,610
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` p=lambda:list(map(int,input().split())) for t in range(p()[0]): N=p()[0] B=p() C=[0]*(N+1) for i in range(N):C[i+1]=C[i]+B[i] S=1 D=dict() D[0]=1 for i in range(1,N):D[C[i]],S=S,(2*S-D.get(C[i],0))%(10**9+7) print(S) ```
output
1
53,305
12
106,611
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,306
12
106,612
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` T = int(input()) for t in range(T): n = int(input()) bb = [int(x) for x in input().split()] sums_bef_offset = {bb[0]: 1} offset = 0 all_sums = 1 base = 1000000007 result = 0 for i in range(1, n): b = bb...
output
1
53,306
12
106,613
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,307
12
106,614
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` import sys import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() def F...
output
1
53,307
12
106,615
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,308
12
106,616
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` p=lambda:list(map(int,input().split())) for t in range(p()[0]): N=p()[0];B=p();C=[0]*(N+1) for i in range(N):C[i+1]=C[i]+B[i] S=1;D=dict();D[0]=1 for i in range(1,N):D[C[i]],S=S,(2*S-D.get(C[i],0))%(10**9+7) print(S) ```
output
1
53,308
12
106,617
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,309
12
106,618
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` import collections import string import math import copy import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buff...
output
1
53,309
12
106,619
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array of integers b_1, b_2, …, b_n. An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true: * b_i = a_i, or * b_i = ∑_{j=1}^{i} a_j. Find the number of ...
instruction
0
53,310
12
106,620
Tags: combinatorics, data structures, dp, sortings Correct Solution: ``` import sys #input=sys.stdin.buffer.readline mod=10**9+7 for t in range(int(input())): N=int(input()) B=list(map(int,input().split())) C=[0]*(N+1) for i in range(N): C[i+1]=C[i]+B[i] ''' DP=[0]*(N+1) DP[0]=1 for i in range(N): ...
output
1
53,310
12
106,621