message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3
instruction
0
43,832
24
87,664
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) s = list(map(int, input().split())) t = sum(s)/k if sum(s) % k != 0: print("No") else: answ = [] summ = 0 kk = 0 m = True for el in s: summ += el kk += 1 if summ == t: answ.append(str(kk)) summ = 0 kk = 0 elif summ > t: m = False break if m: print("Yes") print(" ".join(answ)) else: print("No") ```
output
1
43,832
24
87,665
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3
instruction
0
43,833
24
87,666
Tags: implementation Correct Solution: ``` def read(): return list(map(int, input().split())) def solve(n, k, A): if sum(A) % k != 0 : print('No') return target = sum(A) // k ans, elems, sm = [], 0, 0 for num in A: sm += num elems += 1 if sm > target: print('No') return if sm == target: ans.append(elems) elems, sm = 0, 0 print('Yes') print(' '.join(map(str, ans))) n, k = read() A = read() solve(n, k, A) ```
output
1
43,833
24
87,667
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3
instruction
0
43,834
24
87,668
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) t = 0 p = 0 i = 0 res = [] poss = True if s % k != 0: print("No") else: while i != n: if t + a[i] <= s // k: t += a[i] p += 1 else: poss = False break if t == s // k: res.append(p) t = 0 p = 0 i += 1 if t != 0: poss = False if poss: print("Yes") print(' '.join(map(str, res))) else: print("No") ```
output
1
43,834
24
87,669
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3
instruction
0
43,835
24
87,670
Tags: implementation Correct Solution: ``` n,k=map(int,input().split()) arr=list(map(int,input().split())) ansarr=[] m=0 su=0 ans=0 s=sum(arr) le=s//k; if(s%k!=0): print('No') exit(0) else: for i in range(n): su+=arr[m] m+=1 ans+=1 if(su==le): ansarr.append(ans) ans=0 su=0 elif(su>le): print('No') exit(0) print('Yes') print(*ansarr) ```
output
1
43,835
24
87,671
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3
instruction
0
43,836
24
87,672
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) s = [int(x) for x in input().split()] su = sum(s) flag = 1 if(su%k != 0): print('No') else: v = su // k s1 = [] a = 0 cou = 0 for i in range(n): cou += 1 a += s[i] if(a > v): print('No') flag = 0 break elif(a < v): continue elif(a == v): a = 0 s1.append(cou) cou = 0 if(a != 0): s1.append((su) // v) if(flag): print("Yes") print(*s1) ```
output
1
43,836
24
87,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` import sys n, k = tuple(int(i) for i in sys.stdin.readline().split()) a = tuple(int(i) for i in sys.stdin.readline().split()) assert len(a) == n def solve(n, k, a): q, r = divmod(sum(a), k) if r > 0: return s = [] i = 0 while i < n: total = 0 count = 0 while i < n: total += a[i] count += 1 i += 1 if total == q: break if total > q: return s.append(count) return s r = solve(n, k, a) if r is None: print("No") else: print("Yes") print(" ".join(str(i) for i in r)) ```
instruction
0
43,837
24
87,674
Yes
output
1
43,837
24
87,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` n,k=[int(s) for s in input().split()] s=[0 for i in range(k)] a=[int(s) for s in input().split()] b=[0 for i in range(n)] b[0]=a[0] def check(): for i in range(1,n): b[i]=b[i-1]+a[i] cnt=0 if(b[n-1]%k!=0): print('No') return m=b[n-1]/k for j in range(0,n): if b[j]%m==0: s[cnt]=j cnt+=1 #print(s) if(cnt>=k): print('Yes') for i in range(k): if i==0: print(s[i]+1,end=" ") else: print(s[i]-s[i-1],end=" ") return else: print('No') return check() ```
instruction
0
43,838
24
87,676
Yes
output
1
43,838
24
87,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` n, k = map(int, input().split()) l = list(map(int, input().split())) ans = [] f = 0 tmp = 0 c = 0 average = sum(l)//k for i in l: tmp += i c += 1 if(tmp == average): ans.append(c);tmp = c = 0 elif(tmp > average): f = 1; break if f == 1 or len(ans)!=k or average != sum(l)/k: print("No") else: print("Yes") for i in ans: print(i,end = ' ') ```
instruction
0
43,839
24
87,678
Yes
output
1
43,839
24
87,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## n,k=ris() a=ris() s=sum(a) if s%k: print('No') exit() m=s//k ans=[] cnt=cur=0 for x in a: cur+=x if cur>m: print('No') exit() cnt+=1 if cur==m: ans.append(cnt) cnt=cur=0 print('Yes') print(*ans) ```
instruction
0
43,840
24
87,680
Yes
output
1
43,840
24
87,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` temp = input().split(' ') n = int(temp[0]) k = int(temp[1]) temp = input().split(' ') mas = [] sum = 0 for i in range(n): mas.append(int(temp[i])) for i in range(n): sum += mas[i] d = 0 if sum%k: print('NO') exit(0) else: d = sum/k rez = [] rez.append(0) temp = 0 for i in range(n): temp += mas[i] if (temp == d): temp = 0 rez.append(i+1) if (temp > d): print('NO') exit(0) print("YES") for i in range(1, len(rez)): print(rez[i] - rez[i-1], end = ' ') ```
instruction
0
43,841
24
87,682
No
output
1
43,841
24
87,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` n, k = map(int,input().split()) a = list(map(int,input().split())) tmp = sum(a)/k if tmp != int(tmp): print("NO") exit() ans = 0 cnt = 0 res = [] for i in a: ans+=i cnt+=1 if ans > tmp: print('NO') exit() if ans == tmp: res.append(cnt) cnt = 0 ans = 0 print('YES') print(*res) ```
instruction
0
43,842
24
87,684
No
output
1
43,842
24
87,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` def main(): n, k = (int(x) for x in input().split()) l = [int(x) for x in input().split()] s = sum(l) if s % k: print('No') return 0 q = s / k m = [0 for i in range(k)] c_m = 0 c_s = 0 for i in range(n): if c_s < q: m[c_m] += 1 c_s += l[i] elif c_s == q: c_m += 1 c_s = l[i] m[c_m] += 1 else: print('No') return 0 print('Yes') print(*m) main() ```
instruction
0
43,843
24
87,686
No
output
1
43,843
24
87,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exactly k (1 ≀ k ≀ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then: * s_1+s_2+...+s_k=n (s_i>0), * the first post contains the videos: 1, 2, ..., s_1; * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2; * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3; * ... * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^4), where a_i is the duration of the i-th video. Output If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". Examples Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 Submitted Solution: ``` n,k=list(map(int, input().split())) a=list(map(int, input().split())) if sum(a)%k==0: s=sum(a)//k i=0 b=[0] t=True while i<n: while sum(a[b[-1]:i])<s and i<n: i+=1 if sum(a[b[-1]:i])!=s: print("NO") t=False break else: b.append(i) if t: print("Yes") c=[b[x]-b[x-1] for x in range(1,len(b))] print(' '.join(list(map(str, c)))) else: print("No") ```
instruction
0
43,844
24
87,688
No
output
1
43,844
24
87,689
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,365
24
88,730
Tags: implementation, strings Correct Solution: ``` import string m = int(input()) word = input() words = set() stars = set() let = {a for a in string.ascii_lowercase} for i in range(0, len(word)): if word[i] == '*': stars.add(i) else: words.add(word[i]) n = int(input()) tse = set() for i in range(0, n): st = input() for j in stars: tse.add(st[j]) flag = True j = 0 while j < m and (st[j] == word[j] or j in stars): j += 1 if len(tse.intersection(words)) != 0 or j != m: tse.clear() continue let = let.intersection(tse) tse.clear() if len(stars) == 0: print(0) else: print(len(let)) ```
output
1
44,365
24
88,731
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,366
24
88,732
Tags: implementation, strings Correct Solution: ``` import math import re import string def ria(): return [int(i) for i in input().split()] def ri(): return int(input()) def rfa(): return [float(i) for i in input().split()] eps = 1e-9 def is_equal(a, b): return abs(a - b) <= eps def distance(p0, p1): return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2) N = ri() hid = input() mpk = {} totalKek = 0 for n, i in enumerate(string.ascii_lowercase): mpk[i] = 1 << n totalKek |= mpk[i] M = ri() revealed = 0 for i in hid: if i != '*': revealed |= mpk[i] isAny = False for i in range(M): t = input() isAny=True bad = False hidBit = 0 for n, j in enumerate(t): if hid[n] != '*': if hid[n] != t[n]: bad = True continue hidBit |= mpk[j] if hidBit & revealed != 0 or bad: continue totalKek &= hidBit if isAny: print(str(bin(totalKek)).count('1')) else: exit(-1) ```
output
1
44,366
24
88,733
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,367
24
88,734
Tags: implementation, strings Correct Solution: ``` def is_good_guess(guess, original_string, pos_not_reveal, pos_reveal, reveal): for i in pos_not_reveal: if guess[i] in reveal: return False for i in pos_reveal: if guess[i] != original_string[i]: return False return True n = int(input()) l2 = list(input()) reveal = [] pos_reveal = [] pos_not_reveal = [] for i in range(n): if l2[i] != '*': pos_reveal.append(i) reveal.append(l2[i]) else: pos_not_reveal.append(i) reveal = set(reveal) m = int(input()) option = set('abcdefghijklmnopqrstuvwxyz') for i in range(m): guess = list(input()) guess_char = set(guess) if is_good_guess(guess,l2,pos_not_reveal,pos_reveal,reveal): option = (guess_char - reveal) & option print(len(option)) ```
output
1
44,367
24
88,735
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,368
24
88,736
Tags: implementation, strings Correct Solution: ``` import re n = int(input()) a = input() r = { i: 1 for i in a if i != '*' } r = ''.join(r) regex = f'([^{r}_])' regex = re.sub('\*', regex, a) regex = re.compile(regex) m = int(input()) mx = 0 dx = {} for i in range(m): s = input() d = regex.match(s) if d: mx += 1 rx = {} for j in d.groups(): rx[j] = 1 for j in rx: dx[j] = dx.get(j, 0) + 1 res = 0 for i in dx: if dx[i] == mx: res += 1 print(res) ```
output
1
44,368
24
88,737
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,369
24
88,738
Tags: implementation, strings Correct Solution: ``` import sys from collections import defaultdict def filter_letters(revealed_letters, all_words): used_char = set() for letter in revealed_letters: used_char.add(letter) unknown_letters = defaultdict(int) unknown_indices = [] known_indices = [] matching_words = [] valid_words = [] # get the indices of '*' for index, letter in enumerate(revealed_letters): if letter == '*': unknown_indices.append(index) else: known_indices.append(index) #find all words that match the revealed words for word in all_words: is_valid = True for i in known_indices: if word[i] != revealed_letters[i]: is_valid = False break if is_valid: matching_words.append(word) for word in matching_words: missing_letters = set() is_valid = True for i in unknown_indices: if word[i] in used_char: is_valid = False break else: missing_letters.add(word[i]) if is_valid: valid_words.append(word) for letter in missing_letters: unknown_letters[letter] += 1 return (unknown_letters, valid_words) count = 0 possible_words = [] filtered_words = [] for line in sys.stdin: if count == 0: len_word = int(line) elif count == 1: revealed_letters = line elif count == 2: num_possible_words = int(line) else: possible_words.append(line) count += 1 unknown_letters, valid_words = filter_letters(revealed_letters, possible_words) num_required = len(valid_words) count = 0 for key in unknown_letters: if unknown_letters[key] == num_required: count += 1 print(count) ```
output
1
44,369
24
88,739
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,370
24
88,740
Tags: implementation, strings Correct Solution: ``` n = int(input()) word = input() ast = word.count('*') mas = [i for i in range(n) if word[i] == '*'] mas1 = [i for i in range(n) if word[i] != '*'] st = {word[i] for i in mas1} m = int(input()) Mas = list() for i in range(m): temp = input() f = True for j in mas1: if temp[j] != word[j]: f = False break if f: t = [temp[k] for k in mas if temp[k] not in st] if len(t) == ast: Mas.append(set(t)) ans = set() for el in Mas: ans |= el count = 0 for i in ans: f = True for j in Mas: if i not in j and len(j) > 0: f = False break if f: count += 1 print(count) ```
output
1
44,370
24
88,741
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,371
24
88,742
Tags: implementation, strings Correct Solution: ``` I = input n, s = int(I()), I() J, K = set(), set() for i in range(n): if s[i] == '*': J.add(i) else: K.add(i) L, S = set('abcdefghijklmnopqrstuvwxyz'), set(s) for _ in range(int(input())): w = I() if all(s[k] == w[k] for k in K): W = {w[i] for i in J} if not (S & W): L &= W print(len(L)) ```
output
1
44,371
24
88,743
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
instruction
0
44,372
24
88,744
Tags: implementation, strings Correct Solution: ``` n=int(input()) s=input().strip() m=int(input()) l=[] l1=[] lmain=[] for i in range(26): l.append(0) lmain.append(0) for i in s: if (i!='*'): lmain[ord(i)-97]=1 for i in range(m): s1=input().strip() f=0 for j in range(n): if (s[j]=='*' and lmain[ord(s1[j])-97]==1): f=1 break elif (s[j]!='*'): if (s1[j]!=s[j]): f=1 break if (f==0): l1.append(s1) length=len(l1) for i in range(length): l2=[] s1=l1[i] for j in range(26): l2.append(0) for j in range(n): if (s[j]=='*'): if (l2[ord(s1[j])-97]!=1): l[ord(s1[j])-97]+=1 l2[ord(s1[j])-97]=1 print (l.count(length)) ```
output
1
44,372
24
88,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` alf = "abcdefghijklmnopqrstuvwxyz" n = int(input()) s = str(input()) m = int(input()) a = [] for _ in range(m): a.append(input()) used = set(s) - {'*'} idx = [] for i in range(n): if s[i]=='*': idx.append(i) excp = set(alf) - used temp = set() #print(*excp) #print(*idx) for i in a: if all(i[j] == s[j] for j in range(n) if not j in idx): t = set(i[k] for k in idx) if t & used == temp: excp &= t else: continue print(len(excp)) #print(*excp) ```
instruction
0
44,373
24
88,746
Yes
output
1
44,373
24
88,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` def f(t): for i in range(n): if s[i] != '*' and s[i] != t[i]: return 0 if s[i] == '*': if t[i] in fam: return 0 return 1 n = int(input()) s = input() fam = set(s) m = int(input()) a = [input() for i in range(m)] flag = 0 ans = set() for t in a: if f(t): cur = set(t[i] for i in range(n) if s[i] == '*') if not flag: flag = 1 ans = cur else: ans &= cur print(len(ans)) ```
instruction
0
44,374
24
88,748
Yes
output
1
44,374
24
88,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` n = int(input()) s = input() m = int(input()) l = [] cnt_ = [] cnt = [] for i in range(n): if s[i]=='*': cnt_.append(i) else: cnt.append(i) for x in range(m): flag = True st = input() for j in cnt_: if st[j] in s: flag = False else: for j in cnt: if st[j]!=s[j]: flag =False if flag: l.append(st) g = [[] for i in range(len(l))] for i in range(len(l)): for j in cnt_: g[i].append(l[i][j]) for i in range(len(g)): g[i] = list(set(g[i])) ans = 0 for ch in g[0]: for li in g: if ch not in li: break else: ans = ans+1 print(ans) ```
instruction
0
44,375
24
88,750
Yes
output
1
44,375
24
88,751
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` #python 3.5.2 n = int(input()) kataawal = input() pos = [] posmuncul = [] muncul = set() for i,x in zip(range(n),kataawal): if (x == '*'): pos.append(i) else: muncul.add(x) posmuncul.append(i) m = int(input()) belum = [] for i in range(m): kata = input() yay = set() cancel = False for x in posmuncul: if (kata[x] != kataawal[x]): cancel = True break if (not cancel): for x in pos: if (kata[x] in muncul): cancel = True break else: yay.add(kata[x]) if (not cancel): belum.append(yay) if (len(belum) > 1): hoo = belum[0] for sett in belum[1:]: hoo = hoo.intersection(sett) print(len(hoo)) elif(len(belum) == 0): print(0) else: print(len(belum[0])) ```
instruction
0
44,376
24
88,752
Yes
output
1
44,376
24
88,753
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` j = i = count = ans = 0 n = int(input()) word = input() m = int(input()) ws = {} ls = [] for i in range(m): ws[i] = input() for j in word: ws[i] = ws[i].replace(j, "") #print(ws[i]) for j in ws[0]: for i in range(m-1): if j in ws[i+1]: count += 1 if (count == m - 1) and (count > 0): ans += 1 count = 0 print(ans) ```
instruction
0
44,377
24
88,754
No
output
1
44,377
24
88,755
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` n = int(input()) s = input() oc = s.count('*') m = int(input()) k = m a = [0 for i in range(27)] t = [] for i in range(m): p = input() q = '' for i in range(len(s)): if s[i] == '*' : q = q+p[i] p = q if oc != len(p): k-=1 continue r = p for j in range(len(p)): a[ord(p[j]) - ord('a')] += 1 p = p.replace(p[j], chr(ord('a')+26)) t.append(r) jav = 0 if k <= 0: print(0) else: for i in range(26): #print(str(i) + " " +str(a[k])) if(k > 0 and a[i] == k): jav += 1 for j in range(len(t)): t[j] = t[j].replace(chr(ord('a')+i), "") if(len(t[j])==0): k-=1 #print(chr(i+ord('a')) + str(a[i])) print(jav) ```
instruction
0
44,378
24
88,756
No
output
1
44,378
24
88,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` n=int(input()) s=list(input()) dis=[] ind=[] for i in range(n): if(s[i]!='*'): dis.append(s[i]) else: ind.append(i) di=set(dis) c=[] m=int(input()) for i in range(m): t=list(input()) q=[] for j in ind: q.append(t[j]) q=set(q) q=q-di if(len(q)!=0): c.append(q) ss=c[0] l=len(c) for i in range(1,l): ss=ss.intersection(c[i]) print(len(ss)) ```
instruction
0
44,379
24
88,758
No
output
1
44,379
24
88,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. Input The first line contains one integer n (1 ≀ n ≀ 50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer m (1 ≀ m ≀ 1000) β€” the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β€” n-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed. Output Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. Examples Input 4 a**d 2 abcd acbd Output 2 Input 5 lo*er 2 lover loser Output 0 Input 3 a*a 2 aaa aba Output 1 Note In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. Submitted Solution: ``` n = int(input()) word = input() _word = word words = [] m = int(input()) exist = [] stars = [] for i in word: if i =='*': stars+=[word.find('*')] word = word[:word.find('*')]+word[word.find('*')+1:] cur = input() print(stars) for i in stars: if cur[i] not in exist and cur[i] not in _word: exist += [cur[i]] for j in range(m-1): cur = input() wrd = '' for i in cur: if i not in _word: wrd += i for i in exist: if i not in wrd: exist.remove(i) print(len(exist)) ```
instruction
0
44,380
24
88,760
No
output
1
44,380
24
88,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a chessboard of size n Γ— m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected. Input The first line contains four integers n, m, k and q (1 ≀ n, m ≀ 100 000, 1 ≀ k, q ≀ 200 000) β€” the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≀ x ≀ n, 1 ≀ y ≀ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≀ x1 ≀ x2 ≀ n, 1 ≀ y1 ≀ y2 ≀ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≀ x ≀ x2, y1 ≀ y ≀ y2. Strategically important areas can intersect of coincide. Output Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise. Examples Input 4 3 3 3 1 1 3 2 2 3 2 3 2 3 2 1 3 3 1 2 2 3 Output YES YES NO Note Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook. Submitted Solution: ``` n,m,k,q=input().split() n=int(n) m=int(m) k=int(k) q=int(q) rook=[] rookarea=[] for i in range(k): p,r=input().split() rook.append([int(p),int(r)]) a=[] strarea=[] for i in range(q): w,x,y,z=input().split() w=int(w) x=int(x) y=int(y) z=int(z) a=[] for n in range(y-w+1): for m in range(z-x+1): a.append([w+n,x+m]) strarea.append(a) for j in rook: b=j[0] c=j[1] if j in strarea[i]: for t in range(w,y+1): if [t,c] in strarea[i]: strarea[i].remove([t,c]) for t in range(x,z+1): if [b,t] in strarea[i]: strarea[i].remove([b,t]) for i in strarea: if(i==[]): print("Yes") else: print("No") ```
instruction
0
45,750
24
91,500
No
output
1
45,750
24
91,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a chessboard of size n Γ— m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected. Input The first line contains four integers n, m, k and q (1 ≀ n, m ≀ 100 000, 1 ≀ k, q ≀ 200 000) β€” the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≀ x ≀ n, 1 ≀ y ≀ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≀ x1 ≀ x2 ≀ n, 1 ≀ y1 ≀ y2 ≀ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≀ x ≀ x2, y1 ≀ y ≀ y2. Strategically important areas can intersect of coincide. Output Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise. Examples Input 4 3 3 3 1 1 3 2 2 3 2 3 2 3 2 1 3 3 1 2 2 3 Output YES YES NO Note Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook. Submitted Solution: ``` n,m,k,q=(int(x) for x in input().split()) coord=[] otvet='' for i in range(k): coord.append([int(z) for z in input().split()]) for i in range(q): x_coord=[] y_coord=[] x1,y1,x2,y2=(int(z) for z in input().split()) for elem in coord: if elem[0]>=x1 and elem[0]<=x2 and elem[1]>=y1 and elem[1]<=y2: x_coord.append(elem[0]) y_coord.append(elem[1]) flag=True if len(x_coord)<(x2-x1+1) and len(y_coord)<(y2-y1+1): flag=False if flag: for j in range(x1,x2+1): if not j in x_coord: flag=False break if not flag: for j in range(y1,y2+1): if not j in y_coord: flag=False break if flag: otvet+='YES\n' else: otvet+='NO\n' print(otvet) ```
instruction
0
45,751
24
91,502
No
output
1
45,751
24
91,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a chessboard of size n Γ— m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected. Input The first line contains four integers n, m, k and q (1 ≀ n, m ≀ 100 000, 1 ≀ k, q ≀ 200 000) β€” the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≀ x ≀ n, 1 ≀ y ≀ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≀ x1 ≀ x2 ≀ n, 1 ≀ y1 ≀ y2 ≀ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≀ x ≀ x2, y1 ≀ y ≀ y2. Strategically important areas can intersect of coincide. Output Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise. Examples Input 4 3 3 3 1 1 3 2 2 3 2 3 2 3 2 1 3 3 1 2 2 3 Output YES YES NO Note Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook. Submitted Solution: ``` n,m,k,q=input().split() n=int(n) m=int(m) k=int(k) q=int(q) rook=[] rookarea=[] for i in range(k): p,r=input().split() rook.append([int(p),int(r)]) a=[] for j in range(1,n+1): a.append([int(p),j]) for j in range(1,m+1): a.append([j,int(r)]) rookarea.append(a) strarea=[] for i in range(q): w,x,y,z=input().split() w=int(w) x=int(x) y=int(y) z=int(z) a=[] for n in range(y-w+1): for m in range(z-x+1): a.append([w+n,x+m]) strarea.append(a) for i in range(len(strarea)): for j in range(len(rook)): if rook[j] in strarea[i]: for l in rookarea[j]: if l in strarea[i]: strarea[i].remove(l) for i in strarea: if(i==[]): print("Yes") else: print("No") ```
instruction
0
45,752
24
91,504
No
output
1
45,752
24
91,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a chessboard of size n Γ— m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ​​the board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected. Input The first line contains four integers n, m, k and q (1 ≀ n, m ≀ 100 000, 1 ≀ k, q ≀ 200 000) β€” the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 ≀ x ≀ n, 1 ≀ y ≀ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 ≀ x1 ≀ x2 ≀ n, 1 ≀ y1 ≀ y2 ≀ m). The corresponding rectangle area consists of cells (x, y), for which x1 ≀ x ≀ x2, y1 ≀ y ≀ y2. Strategically important areas can intersect of coincide. Output Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise. Examples Input 4 3 3 3 1 1 3 2 2 3 2 3 2 3 2 1 3 3 1 2 2 3 Output YES YES NO Note Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook. Submitted Solution: ``` n,m,k,q=(int(x) for x in input().split()) coord=[] otvet='' for i in range(k): coord.append([int(z) for z in input().split()]) for i in range(q): bzz=[] x_coord=[] y_coord=[] ys=[] x1,y1,x2,y2=(int(z) for z in input().split()) for elem in coord: if elem[0]>=x1 and elem[0]<=x2 and elem[1]>=y1 and elem[1]<=y2: x_coord.append(elem[0]) y_coord.append(elem[1]) bzz.append(elem) flag=True if len(x_coord)<(x2-x1+1) and len(y_coord)<(y2-y1+1): flag=False if flag: k=0 for j in range(x1,x2+1): if not j in x_coord: flag=False break else: for elem in bzz: if elem[0]==j: ys.append(elem[1]) if not flag: for j in range(y1,y2+1): if not j in ys: if j in y_coord: flag=True else: flag=False break if flag: otvet+='YES\n' else: otvet+='NO\n' print(otvet) ```
instruction
0
45,753
24
91,506
No
output
1
45,753
24
91,507
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,295
24
92,590
Tags: greedy, sortings Correct Solution: ``` n,m = map(int,input().split()); z = list(map(int,input().split())); ans = [] csum=0 for i in range(len(z)): csum+=z[i]; if(csum<=m): ans.append(0); else: tmparr = z[0:i]; tcsum = csum; tmparr.sort(reverse = True) for i in range(len(tmparr)): tcsum-=tmparr[i]; if(tcsum<=m): ans.append(i+1) break print(*ans) ```
output
1
46,295
24
92,591
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,296
24
92,592
Tags: greedy, sortings Correct Solution: ``` from sys import * buckets = [0]*101 n, M = map(int, stdin.readline().split()) ts = [int(t) for t in stdin.readline().split()] full_sum = 0 for i in range(n): cur_M = M cur_sum = full_sum bucket_idx = 100 ans = 0 while cur_sum > cur_M - ts[i]: if cur_sum - cur_M + ts[i] >= buckets[bucket_idx]*bucket_idx: cur_sum -= buckets[bucket_idx]*bucket_idx ans += buckets[bucket_idx] else: tmp = (cur_sum - cur_M + ts[i] - 1) // bucket_idx + 1 ans += tmp cur_sum -= bucket_idx*tmp bucket_idx -= 1 stdout.write(str(ans)+" ") full_sum += ts[i] buckets[ts[i]] += 1 stdout.write("\n") ```
output
1
46,296
24
92,593
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,297
24
92,594
Tags: greedy, sortings Correct Solution: ``` R = lambda: map(int, input().split()) n,m = R() L = list(R()) f = [0]*101 su = 0 for i in range(n): su += L[i] p = su-m c = 0 #print(p,su) if p > 0: for j in reversed(range(1,101)): if f[j] > 0: if p < (f[j]*j): c += ((p+j-1)//j) break else: c += f[j] p -= (j*f[j]) print(c,end=' ') f[L[i]] += 1 ```
output
1
46,297
24
92,595
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,298
24
92,596
Tags: greedy, sortings Correct Solution: ``` n,m=map(int,input().split()) ticket=list(map(int,input().split())) sum=0 for i in range(n): sum+=ticket[i] if(sum<=m): print(0,end=" ") else: tmp=sorted(ticket[0:i]) tmpSum=sum c=0 index=i-1 while(True): if(tmpSum<=m): print(c,end=" ") break else: tmpSum-=tmp[index] index-=1 c+=1 #Lorenzo ```
output
1
46,298
24
92,597
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,299
24
92,598
Tags: greedy, sortings Correct Solution: ``` n,maxi=list(map(int,input().split())) List=list(map(int,input().split())) List2=['0'] for i in range(1,n): c=List[:] count=0 while sum(c[:i])>maxi-c[i]: index=c.index(max(c[:i])) c[index]=0 count+=1 List2.append(str(count)) print(' '.join(List2)) ```
output
1
46,299
24
92,599
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,300
24
92,600
Tags: greedy, sortings Correct Solution: ``` n, m = map(int, input().split()) t = list(map(int, input().split())) mm = []; ss = 0 for i in range(n): if sum(mm) + t[i] <= m: print(0, end = ' ') else: mm = sorted(mm); ss = sum(mm); xx = 0; tmp = [] while ss + t[i] > m: tmp.append(mm.pop()) ss -= tmp[-1] xx += 1 print(xx, end = ' ') while len(tmp) != 0: mm.append(tmp.pop()) mm.append(t[i]) ```
output
1
46,300
24
92,601
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,301
24
92,602
Tags: greedy, sortings Correct Solution: ``` n,m=[int(x) for x in input().split()] a=[int(x) for x in input().split()] ans=[0]*n pre=[0]*n pre[0]=a[0] for i in range(1,n): pre[i]=pre[i-1]+a[i] aux=[] aux.append(a[0]) for i in range(1,n): if(pre[i]>m): temp=pre[i] count=0 aux.sort() j=len(aux)-1 while(temp>m): temp=temp-aux[j] j=j-1 count=count+1 ans[i]=count aux.append(a[i]) for i in ans: print(i, end=' ') ```
output
1
46,301
24
92,603
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
instruction
0
46,302
24
92,604
Tags: greedy, sortings Correct Solution: ``` #------------------------------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 n,M=map(int,input().split()) l=list(map(int,input().split())) k=[0]*100 a=[0]*(n+1) ans=[] for i in range(1,n+1): a[i]+=a[i-1]+l[i-1] for i in range(1,n+1): if a[i]<=M: ans.append(0) else: d=l[:i-1] asi=0 d.sort(reverse=True) for j in range(len(d)): if a[i]<=M: break else: a[i]-=d[j] asi+=1 ans.append(asi) print(*ans,sep=" ") ```
output
1
46,302
24
92,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` n = [] t = [] n=list(map(int, input().split())) t=list(map(int, input().split())) result =[] for i in range(len(t)): number =int(0) x=t[0:i+1] re=int(0) for j in range (i+1): re+=x[j] x.pop(i) while re>n[1]: re-=max(x) x.pop(x.index(max(x))) number+=1 result.append(number) print (" ".join(str(x) for x in result)) ```
instruction
0
46,303
24
92,606
Yes
output
1
46,303
24
92,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` from sys import stdin from collections import defaultdict, Counter from bisect import bisect_left from math import sqrt from heapq import * ############################################################### def iinput(): return int(stdin.readline()) def minput(): return map(int, stdin.readline().split()) def linput(): return list(map(int, stdin.readline().split())) ############################################################### t = 1 while t: t -= 1 n, m = minput() a = linput() req = 0 heap = [] heapify(heap) fail = [] cnt = 0 for i in range(n): if req + a[i] <= m: req += a[i] else: temp = heap.copy() cnt = 0 sm = req while sm + a[i] > m: sm += heappop(temp) cnt += 1 req += a[i] heappush(heap, -1 * a[i]) fail.append(cnt) print(*fail) ```
instruction
0
46,304
24
92,608
Yes
output
1
46,304
24
92,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` import bisect a, b = map(int, input().split()) A = list(map(int, input().split())) B = [] IN = [] kk = 0 for i in range(len(A)): #print(kk) kkl = int(kk) + A[i] j = 0 while kkl > b and j < len(B): kkl -= B[- j - 1] j += 1 IN.append(j) bisect.insort(B, A[i]) kk += A[i] print(*IN) ```
instruction
0
46,305
24
92,610
Yes
output
1
46,305
24
92,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` n, m = map(int,input().split()) a = list(map(int,input().split())) b = [] sum1 = 0 ans = [] for i in range(n): sum1 = sum(a[:i + 1]) cnt = 0 while(sum1 > m): cnt+=1 sum1 -= b[-cnt] ans.append(cnt) b.append(a[i]) b.sort() print(*ans) ```
instruction
0
46,306
24
92,612
Yes
output
1
46,306
24
92,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` n,m = map(int, input().split()) iss = list(map(int, input().split())) ii2 = [] for i in range(len(iss)): iss3 = iss[0:i+1] iss3.sort() iss3.reverse() k = 0 ii = 0 for j in range(i+1): k+= int(iss[j]) if k <= m: ii2.append('0') else: while k > m: k -= int(iss3[0]) iss3.pop(0) ii+=1 ii2.append(str(ii)) print(' '.join(ii2)) ```
instruction
0
46,307
24
92,614
No
output
1
46,307
24
92,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` import heapq n,m=map(int,input().split()) a=list(map(int,input().split())) ans=[] b=[a[0]] for i in range(1,n): b.append(b[-1]+a[i]) c=[] heapq.heapify(c) l=0 k=0 for i in range(n): if b[i]>m: r=b[i]-m while r>l: l+=(heapq.heappop(c))*-1 k+=1 ans.append(k) else: ans.append(0) heapq.heappush(c,a[i]*-1) print(*ans) ```
instruction
0
46,308
24
92,616
No
output
1
46,308
24
92,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` inp = list(map(int,input().split())) t=inp[1] inp = list(map(int,input().split())) l=[] for i in range(1,len(inp)+1): l.append(sum(inp[:i])) for i in range(len(l)): if(l[i]<t): print (0,end=" ") else: k=l[i]-t j=inp[:i+1] j.sort(reverse=True) sumi=0 count=0 p=0 while(sumi<k): sumi=sumi+j[count] count+=1 print (count,end=" ") ```
instruction
0
46,309
24
92,618
No
output
1
46,309
24
92,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: * The i-th student randomly chooses a ticket. * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student. The duration of the whole exam for all students is M minutes (max t_i ≀ M), so students at the end of the list have a greater possibility to run out of time to pass the exam. For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam. For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home. Input The first line of the input contains two integers n and M (1 ≀ n ≀ 100, 1 ≀ M ≀ 100) β€” the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains n integers t_i (1 ≀ t_i ≀ 100) β€” time in minutes that i-th student spends to answer to a ticket. It's guaranteed that all values of t_i are not greater than M. Output Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam. Examples Input 7 15 1 2 3 4 5 6 7 Output 0 0 0 0 0 2 3 Input 5 100 80 40 40 40 60 Output 0 1 1 2 3 Note The explanation for the example 1. Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0. In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M). In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M). Submitted Solution: ``` from sys import stdin, stdout, maxsize as mxs from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect from typing import Counter from itertools import accumulate mod = pow(10, 9) + 7 mod2 = 998244353 def inp(): return stdin.readline().strip() def iinp(): return int(inp()) def out(var, end="\n"): stdout.write(str(var)+"\n") def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end) def lmp(): return list(mp()) def mp(): return map(int, inp().split()) def smp(): return map(str, inp().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)] def remadd(x, y): return 1 if x%y else 0 def ceil(a,b): return (a+b-1)//b def isprime(x): if x<=1: return False if x in (2, 3): return True if x%2 == 0: return False for i in range(3, int(sqrt(x))+1, 2): if x%i == 0: return False return True class MaxHeap: def __init__(self, maxsize): self.maxsize = maxsize self.size = 0 self.Heap = [0] * (self.maxsize + 1) self.Heap[0] = mxs self.FRONT = 1 # Function to return the position of # parent for the node currently # at pos def parent(self, pos): return pos // 2 # Function to return the position of # the left child for the node currently # at pos def leftChild(self, pos): return 2 * pos # Function to return the position of # the right child for the node currently # at pos def rightChild(self, pos): return (2 * pos) + 1 # Function that returns true if the passed # node is a leaf node def isLeaf(self, pos): if pos >= (self.size//2) and pos <= self.size: return True return False # Function to swap two nodes of the heap def swap(self, fpos, spos): self.Heap[fpos], self.Heap[spos] = (self.Heap[spos], self.Heap[fpos]) # Function to heapify the node at pos def maxHeapify(self, pos): # If the node is a non-leaf node and smaller # than any of its child if not self.isLeaf(pos): if (self.Heap[pos] < self.Heap[self.leftChild(pos)] or self.Heap[pos] < self.Heap[self.rightChild(pos)]): # Swap with the left child and heapify # the left child if (self.Heap[self.leftChild(pos)] > self.Heap[self.rightChild(pos)]): self.swap(pos, self.leftChild(pos)) self.maxHeapify(self.leftChild(pos)) # Swap with the right child and heapify # the right child else: self.swap(pos, self.rightChild(pos)) self.maxHeapify(self.rightChild(pos)) # Function to insert a node into the heap def insert(self, element): if self.size >= self.maxsize: return self.size += 1 self.Heap[self.size] = element current = self.size while (self.Heap[current] > self.Heap[self.parent(current)]): self.swap(current, self.parent(current)) current = self.parent(current) # Function to print the contents of the heap def Print(self): for i in range(1, (self.size // 2) + 1): print(" PARENT : " + str(self.Heap[i]) + " LEFT CHILD : " + str(self.Heap[2 * i]) + " RIGHT CHILD : " + str(self.Heap[2 * i + 1])) # Function to remove and return the maximum # element from the heap def extractMax(self): popped = self.Heap[self.FRONT] self.Heap[self.FRONT] = self.Heap[self.size] self.size -= 1 self.maxHeapify(self.FRONT) return popped n, k = mp() arr = lmp() ansl = [] ml = MaxHeap(2*n) s = 0 c = 0 for i in range(n): pl = [] ts = 0 while s>k-arr[i]: x = ml.extractMax() s -= x c += 1 pl.append(x) ts += x ml.insert(arr[i]) s += arr[i] for j in pl: ml.insert(j) s += ts ansl.append(c) c = 0 print(*ansl) ```
instruction
0
46,310
24
92,620
No
output
1
46,310
24
92,621
Provide tags and a correct Python 3 solution for this coding contest problem. The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is r units. Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer. Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether. To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project. Your task is to calculate the maximum possible size of such subset of projects. Input The first line of the input contains two integers n and r (1 ≀ n ≀ 100, 1 ≀ r ≀ 30000) β€” the number of projects and the initial rating of Polycarp, respectively. The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≀ a_i ≀ 30000, -300 ≀ b_i ≀ 300) β€” the rating required to complete the i-th project and the rating change after the project completion. Output Print one integer β€” the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose. Examples Input 3 4 4 6 10 -2 8 -1 Output 3 Input 5 20 45 -6 34 -15 10 34 1 27 40 -45 Output 5 Input 3 2 300 -300 1 299 1 123 Output 3
instruction
0
46,311
24
92,622
Tags: dp, greedy Correct Solution: ``` # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout import math import copy #T = int(input()) #N = int(input()) #print(N) N,r = [int(x) for x in stdin.readline().split()] #arr = [int(x) for x in stdin.readline().split()] visited = [0]*N a = [0]*N b = [0]*N pos = 0 dp = {} for i in range(N): arr = [int(x) for x in stdin.readline().split()] a[i] = arr[0] b[i] = arr[1] if b[i]>=0: pos += 1 valid = 0 for i in range(pos): idx = -1 start = 0 gain = -50000 for j in range(N): # find available and largest gain # if gain tie, find largest start r if visited[j]==1 or b[j]<0: continue if b[j]>gain and r>=a[j]: gain = b[j] idx = j start = a[j] elif b[j]==gain and r>=a[j]: if a[j]>start: idx = j start = a[j] if idx==-1: break else: visited[idx] = 1 r += b[idx] valid = i+1 #print(idx,r) dp[r] = valid tmp = [] for i in range(N): if visited[i]==1 or b[i]>=0: continue tmp.append((a[i],b[i],i)) tmp.sort(key=lambda e: (e[0]+e[1],e[0]),reverse=True) #print(dp) for i in range(len(tmp)): dp_tmp = copy.deepcopy(dp) for threshold in dp: if threshold>=tmp[i][0]: new_r = threshold + tmp[i][1] if new_r in dp_tmp: dp_tmp[new_r] = max(dp[new_r],dp[threshold]+1) else: dp_tmp[new_r] = dp[threshold]+1 #print(dp_tmp) dp = dp_tmp res = 0 #print(dp) for key in dp: if key>=0: res = max(res,dp[key]) print(res) ```
output
1
46,311
24
92,623