message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive). In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content? Here the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order. For both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content. Since the answer can be tremendous, print the number modulo 10^9+7. Constraints * 1 \leq N, M \leq 2 \times 10^3 * The length of S is N. * The length of T is M. * 1 \leq S_i, T_i \leq 10^5 * All values in input are integers. Input Input is given from Standard Input in the following format: N M S_1 S_2 ... S_{N-1} S_{N} T_1 T_2 ... T_{M-1} T_{M} Output Print the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7. Examples Input 2 2 1 3 3 1 Output 3 Input 2 2 1 1 1 1 Output 6 Input 4 4 3 4 5 6 3 4 5 6 Output 16 Input 10 9 9 6 5 7 5 9 8 5 6 7 8 6 8 5 5 7 9 9 7 Output 191 Input 20 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 846527861 Submitted Solution: ``` # Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- L = input().rstrip() lenL = len(L) mod = 10**9+7 dp0 = [0]*(lenL+1) # dp0[i] : 上からi桁目まで L と一致する (A,B) の場合の数 dp1 = [0]*(lenL+1) # dp1[i] : 上からi桁目までで L と一致しない (A,B) の場合の数 dp0[0] = 1 for i,l in enumerate(L, 1): # 現在の桁が 0 の時 if l=="0": dp0[i] = dp0[i-1] # (0,0) のみ dp1[i] = dp1[i-1]*3 # (0,0), (0,1), (1,0) の3通り # 現在の桁が 1 の時 else: dp0[i] = dp0[i-1]*2 # (0,1), (1,0) dp1[i] = dp0[i-1] + dp1[i-1]*3 # (i-1)桁まで一致している場合, (0,0) のみ # (i-1)桁まで一致していない場合, (0,0), (0,1), (1,0) の3通り dp0[i] %= mod dp1[i] %= mod print((dp0[-1] + dp1[-1]) % mod) ```
instruction
0
28,079
5
56,158
No
output
1
28,079
5
56,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` N,M = map(int,input().split()) A = list(map(int,input().split())) from collections import defaultdict r = defaultdict(lambda:0) s = 0 for i in range(N): s += A[i] s %= M r[s] += 1 ans = r[0] for s in r: ans += (r[s]*(r[s]-1))//2 print(ans) ```
instruction
0
28,104
5
56,208
Yes
output
1
28,104
5
56,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` from collections import Counter N,M = list(map(int,input().split())) A = list(map(int,input().split())) sum = [0]*(N+1) for i in range(N): sum[i+1] = (sum[i] + A[i])%M C = Counter(sum) ans = 0 for k,v in C.items(): ans += v*(v-1)//2 print(ans) ```
instruction
0
28,106
5
56,212
Yes
output
1
28,106
5
56,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` from collections import defaultdict N,M=map(int,input().split()) A=list(map(int,input().split())) B=[0]*(N+1) C=defaultdict(int) C[0]+=1 for i in range(N): B[i+1]=(B[i]+A[i])%M C[B[i+1]]+=1 ans=0 for i in C.values(): ans+=i*(i-1)//2 print(ans) ```
instruction
0
28,107
5
56,214
Yes
output
1
28,107
5
56,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` N,M = map(int,input().split) A = list(map(int,input().split)) R = [A[0]%M] for i in range(1,N): R.append((R[-1]+A[i])%M) k = set(R) dic = {i:0 for i in k} for item in R: dic[item]+=1 #print(dic) ans = dic[0]*(dic[0]+1)/2 for i in k: if i !=0 : ans += dic[i]*(dic[i]-1)/2 print(int(ans)) ```
instruction
0
28,108
5
56,216
No
output
1
28,108
5
56,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` # encoding: utf-8 N, M = list(map(int, input().split())) # TLE # Amod = [A for A in map(lambda x: int(x) % M , input().split())] # ans = 0 # for l in range(len(Amod)): # acm = 0 # for r in range(l, len(Amod)): # acm = (acm + Amod[r]) % M # if acm == 0: ans += 1 for i, A in enumerate(map(int, input().split())): if i == 0: Asym = [A % M] else: Asym.append((Asym[-1] + A) % M) print(Asym) ans = Asym.count(0) for sym in set(Asym): # print(sym, Asym.count(sym), ans) cnt = Asym.count(sym) ans += int(cnt * (cnt - 1) / 2) print(ans) ```
instruction
0
28,109
5
56,218
No
output
1
28,109
5
56,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` import sys,math,itertools input=sys.stdin.readline if __name__ == '__main__': N,M=list(map(int,input().split())) A=list(map(int,input().split())) B=[0]+A B=list(itertools.accumulate(B)) count=0 mods={} for b in B: c=b%M if c in mods.keys(): mods[c]+=1 else: mods[c]=1 for v in mods.values(): count+=(v*(v-1))//2 print(count) ```
instruction
0
28,111
5
56,222
No
output
1
28,111
5
56,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input 6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2 Output 17 Submitted Solution: ``` n,m=map(int,input().split()) a=[0]*(n+1); b=[int(input()) for _ in range(m)] for x in b[::-1]: if a[x]==0:a[x]=1;print(x) [print(i)for i in range(1,n+1)if a[i]==0] ```
instruction
0
28,210
5
56,420
No
output
1
28,210
5
56,421
Provide a correct Python 3 solution for this coding contest problem. Example Input acmicpc tsukuba Output No
instruction
0
28,215
5
56,430
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: s = S() t = S() l = len(t) def f(s): i = 0 for c in s: while i < l and t[i] != c: i += 1 if i == l: return False i += 1 return True if f(s[0::2]) or f(s[1::2]): rr.append('Yes') else: rr.append('No') break return '\n'.join(map(str, rr)) print(main()) ```
output
1
28,215
5
56,431
Provide a correct Python 3 solution for this coding contest problem. Example Input acmicpc tsukuba Output No
instruction
0
28,216
5
56,432
"Correct Solution: ``` def f(s,t): j=0;i=0 while i<len(t) and j<len(s): if t[i]==s[j]:j+=2 i+=1 return j>=len(s) I=input s=I() t=I() print(['No','Yes'][f(s,t) or f(s[1:],t)]) ```
output
1
28,216
5
56,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` t = int(input()) for i in range(0, t): n = int(input()) a = [int(x) for x in input().split()] count = 0 for i in a: if i%2 == 1: count +=1 if count == n: print("Yes") else: print("No") ```
instruction
0
28,514
5
57,028
Yes
output
1
28,514
5
57,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` def func(n,vals): ec=0 oc=0 for i in vals: if i%2==0: ec=ec+1 else: oc=oc+1 if ec==n and oc==n: return "Yes" else: return "No" t=int(input(" ")) for t in range(0,t): n = int(input(" ")) vals = list(map(int, input(" ").split())) res=func(n,vals) print(res) ```
instruction
0
28,515
5
57,030
Yes
output
1
28,515
5
57,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` for i in range(int(input())): n,even,odd=int(input()),0,0 l=list(map(int,input().split())) for x in l: if x % 2 ==0: even += 1 else: odd += 1 if even==odd: print("Yes") else: print("No") ```
instruction
0
28,516
5
57,032
Yes
output
1
28,516
5
57,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` a=int(input()) for i in range(0,a): b=int(input()) arr = list(map(int, input().split())) if b>2: print('No') else: s = 0 s1 = 0 for i in range(len(arr)): if arr[i]%2==0: s=s+1 else: s1=s1+1 if s==s1: print('Yes') else: print('No') ```
instruction
0
28,518
5
57,036
No
output
1
28,518
5
57,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` for _ in range(int(input())): n = int(input()) n_even = sum(v in '02468' for v in input().split()) print(('No', 'Yes')[n_even == n]) ```
instruction
0
28,519
5
57,038
No
output
1
28,519
5
57,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset (i. e. a set that can contain multiple equal integers) containing 2n integers. Determine if you can split it into exactly n pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by 2, the remainder is 1). Input The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 100) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer n (1≤ n≤ 100). The second line of each test case contains 2n integers a_1,a_2,..., a_{2n} (0≤ a_i≤ 100) — the numbers in the set. Output For each test case, print "Yes" if it can be split into exactly n pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case. Example Input 5 2 2 3 4 5 3 2 3 4 5 5 5 1 2 4 1 2 3 4 1 5 3 2 6 7 3 4 Output Yes No No Yes No Note In the first test case, a possible way of splitting the set is (2,3), (4,5). In the second, third and fifth test case, we can prove that there isn't any possible way. In the fourth test case, a possible way of splitting the set is (2,3). Submitted Solution: ``` for _ in range(int(input())): print("No" if (eval(f"{input()}+{input().replace(' ', '+')}")) % 2 else "Yes") ```
instruction
0
28,521
5
57,042
No
output
1
28,521
5
57,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x, y = map(int, input().split() ) n = int(input() ) p = [y-x, x, y, y-x] print((p[n % 3] * (-1) ** ((n-1)//3 & 1) + int(1e9+7)) % int(1e9+7)) ```
instruction
0
28,604
5
57,208
Yes
output
1
28,604
5
57,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` import math t = input() s = input() temp = t.split() List = [int(i) for i in temp] f1 = List[0] f2 = List[1] f3 = f2 - f1 f4 = -f1 f5 = -f2 f6 = -f3 n = int(s) x = math.pow(10,9) + 7 modulus = n%6 if modulus == 1: fn = f1 elif modulus == 2: fn = f2 elif modulus == 3: fn = f3 elif modulus == 4: fn = f4 elif modulus == 5: fn = f5 elif modulus == 0: fn = f6 print(int(fn%x)) ```
instruction
0
28,605
5
57,210
Yes
output
1
28,605
5
57,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x, y = map(int, input().split()) n = int(input()) l = [x,y,0,0,0,0] for i in range (2, 6): l[i] = l[i-1] - l[i-2] print(l[(n-1)%6]%1000000007) ```
instruction
0
28,606
5
57,212
Yes
output
1
28,606
5
57,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x,y=map(int,input().split()) n=int(input()) M=1000000007 f0=x-y if n%3==0: ans=f0 elif n%3==1: ans=x else: ans=y if (n//3)%2==0: print((ans)%M) else: print((ans*-1)%M) ```
instruction
0
28,607
5
57,214
Yes
output
1
28,607
5
57,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x = -1 % 1000000007 temparr = input() temparr = temparr.split() f1 = int(temparr[0]) % 1000000007 f2 = int(temparr[1]) % 1000000007 n = int( input() ) nn = 2 if n == 1: print(f1) elif n == 2: print(f2) else: while True: f3 = (f2 - f1 ) % 1000000007 nn += 1 if nn == n : print(f3) break f1 = f2 f3 = f2 ```
instruction
0
28,608
5
57,216
No
output
1
28,608
5
57,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x, y = [int(i) for i in input().split()] n = int(input()) z= y-x f = [x, y, z, -x, -y, -z] print(f[n%6]%1000000007) ```
instruction
0
28,609
5
57,218
No
output
1
28,609
5
57,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x,y=[int(x) for x in input().split()] n=int(input()) mod=1000000007 if n%3==1: print(x%mod) elif n%3==2: print(y%mod) else: print((y-x)%mod) ```
instruction
0
28,610
5
57,220
No
output
1
28,610
5
57,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jzzhu has invented a kind of sequences, they meet the following property: <image> You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109). Output Output a single integer representing fn modulo 1000000007 (109 + 7). Examples Input 2 3 3 Output 1 Input 0 -1 2 Output 1000000006 Note In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1. In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). Submitted Solution: ``` x, y = map(int, input().split()) n = int(input()) a = [x, y, y-x, y-x, -x, -y, x-y] print(a[(n-1)%6] % 1000000007) ```
instruction
0
28,611
5
57,222
No
output
1
28,611
5
57,223
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,796
5
57,592
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` import sys,os,io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline q = int(input()) s = [] l = 0 sl = 0 for _ in range (q): a = [int(i) for i in input().split()] if len(a)==2: s.append(a[1]) res = (sl + s[-1])/(l+1) while(l<len(s) and (sl+s[l]+s[-1])/(l+2)< res): sl += s[l] l+=1 res = (sl + s[-1])/(l+1) if len(a)==1: print("{0:.8f}". format(s[-1]-res)) ```
output
1
28,796
5
57,593
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,797
5
57,594
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` from sys import stdin def mean(p): return (c[p] + a[-1]) / (p + 2) def check(p): return mean(p) >= a[p] def binSearch(a, b): left, right = a - 1, b + 1 while right - left > 1: mid = (left + right) // 2 if check(mid): left = mid else: right = mid return left all_in = stdin.readlines() Q = int(all_in[0]) zapr = list(map(lambda x: tuple(map(int, x.split())), all_in[1:])) a, c = [zapr[0][1]], [zapr[0][1]] ans = list() for el in zapr[1:]: if el[0] == 1: a.append(el[1]) c.append(c[-1] + el[1]) elif el[0] == 2: b = binSearch(0, len(a) - 1) ans.append(a[-1] - mean(b)) else: exit(100500) print('\n'.join(map(str, ans))) ```
output
1
28,797
5
57,595
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,798
5
57,596
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` from sys import stdin def mean(p): return (c[p]+a[-1])/(p+2) def check(p): return mean(p)>=a[p] def binary(a,b): low,high = a-1,b+1 while high-low>1: mid = (low+high)//2 if check(mid): low = mid else: high = mid return low all = stdin.readlines() q = int(all[0]) za = list(map(lambda x: tuple(map(int,x.split())),all[1:])) a,c = [za[0][1]],[za[0][1]] ans = [] for i in za[1:]: if i[0] == 1: a.append(i[1]) c.append(i[1]+c[-1]) else: k = binary(0,len(a)-1) ans.append(a[-1]-mean(k)) print('\n'.join(map(str,ans))) ```
output
1
28,798
5
57,597
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,799
5
57,598
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): q = int(input()) x = int(input().split()[1]) su,poi,nums,ans = 0,0,[x],0 for _ in range(q-1): a = input() if a[0] == '1': x = int(a.split()[1]) nums.append(x) while poi != len(nums)-1: if (su+x+nums[poi])*(poi+1) < (su+x)*(poi+2): su += nums[poi] poi += 1 else: break ans = max(ans,nums[-1]-(su+nums[-1])/(poi+1)) else: print(ans) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
output
1
28,799
5
57,599
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,800
5
57,600
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` q=int(input()) s=input().split() a=[int(s[1])] sum1=a[0] pos=-1 mean=sum1 fin='' for i in range(q-1): n=len(a) s=input().split() if(s[0]=='1'): a.append(int(s[1])) sum1+=(a[-1]-a[-2]) mean=sum1/(pos+2) n=len(a) #print(sum1,pos,i+1) while(pos<n-2 and a[pos+1]<mean): pos+=1 sum1+=a[pos] mean=sum1/(pos+2) #print(sum1,pos,i+1) else: #print(sum1,pos) fin+=str(a[-1]-mean) + '\n' print(fin) ```
output
1
28,800
5
57,601
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,802
5
57,604
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` import sys def input(): return sys.stdin.buffer.readline() Q = int(input()) stack = [] pos = 0 query = [tuple(map(int, input().split())) for i in range(Q)] S = 0 for que in query: command = que[0] if command == 1: stack.append(que[1]) continue last_number = stack[-1] while pos < len(stack) and (pos + 2)*(last_number + S) > (pos + 1)*(last_number + S + stack[pos]): S += stack[pos] pos += 1 print(last_number - (last_number + S)/(pos + 1)) continue ```
output
1
28,802
5
57,605
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000
instruction
0
28,803
5
57,606
Tags: binary search, greedy, ternary search, two pointers Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a * a + b * b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key,a1): left = 0 right = n - 1 count = 0 while (left <= right): mid = ((right + left)// 2) # Check if middle element is # less than or equal to key if (Fraction((a1[mid]+l[-1]),(mid+1))>=arr[mid]): count = mid left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) # If mid element is greater than # k update leftGreater and r if (arr[m] > k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n=int(input()) l=[] a1=[] a1.append(0) for i in range(n): a=input() if len(a)!=1: l.append(int(a[2:])) a1.append(l[-1]+a1[-1]) else: #print(l) if len(l)==1: print(0) continue elif len(l)==2: print((l[-1]-l[0])/2) continue avg=Fraction(l[-1]+l[0],2) t=binarySearchCount(l,len(l),avg,a1)+1 avg=Fraction((l[-1]+a1[t]),(t+1)) #print(avg) print(float(l[-1]-avg)) ```
output
1
28,803
5
57,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` import sys s, left_index, sub_sum, subset = [], -1, 0, 1 input() for line in sys.stdin: inp = list(map(int, line.split())) if inp[0] == 2: sub_sum += s[-1] for j in range(left_index + 1, len(s)): if s[j] <= sub_sum / subset: sub_sum += s[j] subset += 1 left_index += 1 else: break print(s[-1] - sub_sum / subset) sub_sum -= s[-1] else: s.append(inp[1]) ```
instruction
0
28,804
5
57,608
Yes
output
1
28,804
5
57,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def main(): a = [] j, su = 0, 0 for _ in range(int(input())): b = list(map(int, input().split())) if b[0] == 1: a.append(b[1]) while j < len(a) - 1 and (a[-1] + su) * (j + 2) > (a[-1] + su + a[j]) * (j + 1): su += a[j] j += 1 else: print(a[-1] - (a[-1] + su) / (j + 1)) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
28,805
5
57,610
Yes
output
1
28,805
5
57,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` import sys import math from collections import defaultdict #n=int(sys.stdin.readline().split()) arr=[] q=int(sys.stdin.readline()) a,b=map(int,sys.stdin.readline().split()) l,r=0,0 mean=b num=1 arr.append(b) for _ in range(1,q): lis=list(map(int,sys.stdin.readline().split())) if lis[0]==1: b=lis[1] arr.append(b) if len(arr)==2: newmean=(arr[0]+arr[1])/2 r+=1 mean=newmean num=2 continue newmean=(mean*num-arr[r]+arr[r+1])/num r+=1 mean=newmean while l+1<r and (mean*num+arr[l+1])/(num+1)<=mean: mean=(mean*num+arr[l+1])/(num+1) l+=1 num+=1 else: #print(arr,'arr',mean,'mean') print(arr[r]-mean) ```
instruction
0
28,806
5
57,612
Yes
output
1
28,806
5
57,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` import sys input = sys.stdin.readline Q = int(input()) a = [] sm = [] def best(): mx = a[-1] n = len(a) l, r = 0, n-2 ret = mx while l <= r: mid = (l + r) // 2 s = sm[mid] + mx c = mid + 2 avg = s / c if a[mid] > avg: r = mid - 1 else: ret = avg l = mid + 1 return ret for _ in range(Q): inp = [int(i) for i in input().split()] if len(inp) == 2: x = inp[1] a.append(x) sm.append((sm[-1] if sm else 0) + x) else: mx = a[-1] avg = best() ans = mx - avg print(ans) ```
instruction
0
28,807
5
57,614
Yes
output
1
28,807
5
57,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` a = int(input()) s = [] l = 1 f = list(map(int, input().split())) mean = 0 if f[0] == 1: s.append(f[1]) mean = s[0] for i in range(a - 1): f = list(map(int, input().split())) if f[0] == 1: s.append(f[1]) else: if len(s) > 1: while (l + 1) <= len(s) - 1: if s[l] < mean: mean = (mean * (l + 1) + s[l]) / (l + 2) l += 1 print("{:.10f}".format(s[-1] - mean)) else: print("{:.10f}".format(0)) ```
instruction
0
28,808
5
57,616
No
output
1
28,808
5
57,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` from bisect import bisect_left as bi def fu(a,n): b=a[0]+a[-1] d=set([0,n-1]) c=2 while 1>0: e=bi(a,b/c) if a[e]==b/c: e-=1 e-=1 if e in d: break else: d.add(c-1) b+=a[c-1] c+=1 return a[-1]-b/c import sys input=sys.stdin.readline n=int(input()) b=0 c=0 a=[] for i in range(n): d=list(map(int,input().split())) if d[0]==1: a.append(d[1]) c+=1 if c!=1: b=fu(a,c) else: print(b) ```
instruction
0
28,809
5
57,618
No
output
1
28,809
5
57,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` s = [] left_index = -1 sub_sum = 0 for i in range(int(input())): inp = list(map(int, input().split())) if inp[0] == 2: sub_sum += s[-1] subset = left_index + 2 i = left_index for i in range(min(left_index + 1, len(s) - 1), len(s)): if s[i] <= sub_sum / subset: sub_sum += s[i] subset += 1 left_index = i else: break print(s[-1] - sub_sum / subset) sub_sum -= s[-1] if inp[0] == 1: s.append(inp[1]) ```
instruction
0
28,810
5
57,620
No
output
1
28,810
5
57,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to S, the newly added integer is not less than any number in it. 2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>. Input The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries. Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given. It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes. Output Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>. Examples Input 6 1 3 2 1 4 2 1 8 2 Output 0.0000000000 0.5000000000 3.0000000000 Input 4 1 1 1 4 1 5 2 Output 2.0000000000 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a * a + b * b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] <= key): # At least (mid + 1) elements are there # whose values are less than # or equal to key count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) # If mid element is greater than # k update leftGreater and r if (arr[m] > k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n=int(input()) l=[] a1=[] a1.append(0) for i in range(n): a=input() if len(a)==3: l.append(int(a[-1])) a1.append(l[-1]+a1[-1]) else: if len(l)==1: print(0) continue elif len(l)==2: print((l[-1]-l[0])/2) continue avg=Fraction(l[-1]+l[0],2) t=binarySearchCount(l,len(l),avg) avg=(l[-1]+a1[t])/(t+1) print(l[-1]-avg) ```
instruction
0
28,811
5
57,622
No
output
1
28,811
5
57,623
Provide a correct Python 3 solution for this coding contest problem. Problem Given $ N $ a pair of non-negative integers $ (a_i, b_i) $ and non-negative integers $ A $, $ B $. I want to do as many of the following operations as possible. * $ | a_i --b_i | \ leq A $ or $ B \ leq | a_i --b_i | \ leq Take out and delete the element $ i $ that satisfies 2A $ * $ | (a_i + a_j)-(b_i + b_j) | \ leq A $ or $ B \ leq | (a_i + a_j)-(b_i + b_j) | Extract and delete the pair of j $ ($ i \ neq j $) Find the maximum number of operations. Constraints The input satisfies the following conditions. * $ 1 \ leq N \ leq 800 $ * $ 0 \ leq A, B \ leq 10 ^ 5 $ * $ 0 \ leq a_i, b_i \ leq 10 ^ 5 $ * $ A \ leq B $ and $ B \ leq 2A $ Input The input is given in the following format. $ N $ $ A $ $ B $ $ a_1 $ $ b_1 $ $ a_2 $ $ b_2 $ ... $ a_N $ $ b_N $ All inputs are given as integers. $ N $, $ A $, $ B $ are given on the first line, separated by blanks. The $ i $ th pair $ a_i $ and $ b_i $ ($ 1 \ leq i \ leq N $) are given in the second and subsequent $ N $ lines, separated by blanks. Output Output the maximum number of operations on one line. Examples Input 5 3 5 7 2 13 1 1 1 2 9 2 4 Output 4 Input 10 7 12 34 70 36 0 12 50 76 46 33 45 61 21 0 1 24 3 98 41 23 84 Output 5
instruction
0
29,066
5
58,132
"Correct Solution: ``` N, A, B = map(int, input().split()) P = [] Q = [] ans = 0 for i in range(N): a, b = map(int, input().split()) v = abs(a-b) if v <= A or B <= v <= 2*A: ans += 1 continue if a > b: P.append(a-b) else: Q.append(a-b) import collections class Dinic: def __init__(self, n): self.n = n self.g = [[] for i in range(n)] def add_edge(self, fr, to, cap): self.g[fr].append([to, cap, len(self.g[to])]) self.g[to].append([fr, 0, len(self.g[fr])-1]) def add_multi_edge(self, v1, v2, cap1, cap2): self.g[v1].append([v2, cap1, len(self.g[v2])]) self.g[v2].append([v1, cap2, len(self.g[v1])-1]) def bfs(self, s): level = [-1]*self.n deq = collections.deque() level[s] = 0 deq.append(s) while deq: v = deq.popleft() for e in self.g[v]: if e[1]>0 and level[e[0]]<0: level[e[0]] = level[v] + 1 deq.append(e[0]) self.level = level def dfs(self, v, t, f): if v==t: return f es = self.g[v] level = self.level for i in range(self.it[v], len(self.g[v])): e = es[i] if e[1]>0 and level[v]<level[e[0]]: d = self.dfs(e[0], t, min(f, e[1])) if d>0: e[1] -= d self.g[e[0]][e[2]][1] += d self.it[v] = i return d self.it[v] = len(self.g[v]) return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t]<0: break self.it = [0]*self.n while True: f = self.dfs(s, t, 10**9+7) if f>0: flow += f else: break return flow dinic = Dinic(2+len(P)+len(Q)) LP = len(P) for i in range(len(P)): dinic.add_edge(0, 2+i, 1) for j in range(len(Q)): dinic.add_edge(2+LP+j, 1, 1) for i, p in enumerate(P): for j, q in enumerate(Q): v = abs(p+q) if v <= A or B <= v <= 2*A: dinic.add_edge(2+i, 2+LP+j, 1) ans += dinic.max_flow(0, 1) print(ans) ```
output
1
29,066
5
58,133
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,067
5
58,134
"Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) dp = [[False]*(44000) for i in range(n+1)] dp[0][0] = True for i in range(n): for j in range(max(a)*n+1): dp[i+1][j] |= dp[i][j] if j-a[i] >=0:dp[i+1][j] |= dp[i][j-a[i]] for i in range(q): if dp[n][m[i]]:print('yes') else:print('no') ```
output
1
29,067
5
58,135
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,068
5
58,136
"Correct Solution: ``` n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) N = int(2**n) d = [] for i in range(N): b = "{:0{}b}".format(i, n) d.append(sum(A[j] for j in range(n) if b[j] == '1')) #print(b) for i in range(q): if m[i] in d: print("yes") else: print("no") ```
output
1
29,068
5
58,137
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,069
5
58,138
"Correct Solution: ``` n = int(input()) A = list(map(int,input().split())) q = int(input()) M = list(map(int,input().split())) s = set() for i in range(2**n): tmp = 0 for j in range(n): if i >> j & 1: tmp += A[j] s.add(tmp) for i in range(q): if M[i] in s: print('yes') else: print('no') ```
output
1
29,069
5
58,139
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,070
5
58,140
"Correct Solution: ``` a = int(input()) comb_num = list(map(int, input().split())) b = int(input()) ans_num = list(map(int, input().split())) gen = 1 for i in comb_num: gen = gen<<i|gen for j in ans_num: if gen>>j&1: print('yes') else: print('no') ```
output
1
29,070
5
58,141
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,071
5
58,142
"Correct Solution: ``` #coding:utf-8 #1_5_A from itertools import combinations n = int(input()) A = list(map(int, input().split())) q = int(input()) ms = list(map(int, input().split())) numbers = set() for i in range(1, n+1): for com in combinations(A, i): numbers.add(sum(com)) for m in ms: if m in numbers: print("yes") else: print("no") ```
output
1
29,071
5
58,143
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,072
5
58,144
"Correct Solution: ``` from itertools import combinations import bisect n = int(input()) *A, = map(int, input().split()) q = int(input()) *M, = map(int, input().split()) S = set() for i in range(1, n + 1): for c in combinations(A, i): S.add(sum(c)) for m in M: if m in S: print('yes') else: print('no') ```
output
1
29,072
5
58,145
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,073
5
58,146
"Correct Solution: ``` def solve(m,ans): global L,S if m == len(L): S.add(ans) else: solve(m+1,ans+L[m]) solve(m+1,ans) n = int(input()) S = set([]) L = list(map(int,input().split())) q = int(input()) solve(0,0) for i in map(int,input().split()): if i in S: print("yes") else: print("no") ```
output
1
29,073
5
58,147
Provide a correct Python 3 solution for this coding contest problem. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no
instruction
0
29,074
5
58,148
"Correct Solution: ``` from itertools import combinations, chain n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) S = list(map(sum, chain.from_iterable(combinations(A, r) for r in range(n)))) ans = map(lambda y: 'yes' if y else 'no', map(lambda x: x in S, m)) print('\n'.join(ans)) ```
output
1
29,074
5
58,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no Submitted Solution: ``` from itertools import combinations n = int(input()) a_array = [int(x) for x in input().split()] q = int(input()) m_array = [int(x) for x in input().split()] array = [] for j in range(n + 1): x = combinations(a_array, j) for y in x: array.append(sum(y)) for m in m_array: print("yes" if m in array else "no") ```
instruction
0
29,075
5
58,150
Yes
output
1
29,075
5
58,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2]. <image> Constraints * n ≤ 20 * q ≤ 200 * 1 ≤ elements in A ≤ 2000 * 1 ≤ Mi ≤ 2000 Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given. Output For each question Mi, print yes or no. Example Input 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 Output no no yes yes yes yes no no Submitted Solution: ``` N=int(input()) L=list(map(int,input().split())) B=1 for i in range(N): B=B|B<<L[i] BI=list(str(bin(B))) BI=BI[2:] SB=BI[::-1] #print(SB) Q=int(input()) A=list(map(int,input().split())) for i in range(Q): if A[i]>=len(SB): print("no") elif SB[A[i]]=="1": print("yes") else: print("no") ```
instruction
0
29,076
5
58,152
Yes
output
1
29,076
5
58,153