message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is actually a subproblem of problem G from the same contest. There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have. You have to answer q independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. Input The first line of the input contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of candies. The second line of each query contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the type of the i-th candy in the box. It is guaranteed that the sum of n over all queries does not exceed 2 ⋅ 10^5. Output For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement. Example Input 3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7 Output 3 10 9 Note In the first query, you can prepare a gift with two candies of type 8 and one candy of type 5, totalling to 3 candies. Note that this is not the only possible solution — taking two candies of type 4 and one candy of type 6 is also valid. Submitted Solution: ``` t=int(input()) for _ in range(t): n=int(input()) l=[] for i in range(n): a,b=map(int,input().split()) l.append((a,1-b)) d={} for i in l: if d.get(i[0])==None: d[i[0]]=[i[1]] else: d[i[0]].append(i[1]) # print(d) dict={} for key in d: ct_0=d[key].count(0) ct_1=len(d[key])-ct_0 if dict.get(len(d[key]))==None: dict[len(d[key])]=[[ct_0,ct_1]] else: dict[len(d[key])].append([ct_0,ct_1]) for key in dict: dict[key]=sorted(dict[key]) # print(dict) d={} ct=0 for key in sorted(dict,reverse=True): i=dict[key] j=key while j>0 and len(i)>0: if d.get(j)==None: d[j]=i.pop() d[j][0]=min(d[j][0],j) ct+=j j-=1 elif d[j][0]<i[-1][0]: temp=d[j] d[j]=i.pop() d[j][0]=min(d[j][0],j) i.append(d[j]) i=sorted(i) else: j-=1 # print(d,dict) ct_f1=0 for key in d: ct_f1+=d[key][0] print(ct,ct_f1) ```
instruction
0
69,923
9
139,846
No
output
1
69,923
9
139,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is actually a subproblem of problem G from the same contest. There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have. You have to answer q independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. Input The first line of the input contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of candies. The second line of each query contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the type of the i-th candy in the box. It is guaranteed that the sum of n over all queries does not exceed 2 ⋅ 10^5. Output For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement. Example Input 3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7 Output 3 10 9 Note In the first query, you can prepare a gift with two candies of type 8 and one candy of type 5, totalling to 3 candies. Note that this is not the only possible solution — taking two candies of type 4 and one candy of type 6 is also valid. Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) b=[0]*(n+1) c=[] for i in range(n): b[a[i]]+=1 b.sort(reverse=True) last=0 x=1 for j in range(n+1): if(b[j]-x==0 or b[j]==0): break if last==b[j]: c.append(b[j]-x) x+=1 else: x=1 c.append(b[j]) last=b[j] print(sum(set(c))) ```
instruction
0
69,924
9
139,848
No
output
1
69,924
9
139,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is actually a subproblem of problem G from the same contest. There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type 1 and two candies of type 2 is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have. You have to answer q independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. Input The first line of the input contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of candies. The second line of each query contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the type of the i-th candy in the box. It is guaranteed that the sum of n over all queries does not exceed 2 ⋅ 10^5. Output For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement. Example Input 3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7 Output 3 10 9 Note In the first query, you can prepare a gift with two candies of type 8 and one candy of type 5, totalling to 3 candies. Note that this is not the only possible solution — taking two candies of type 4 and one candy of type 6 is also valid. Submitted Solution: ``` from collections import Counter t=int(input()) while(t>0): n=int(input()) l=list(map(int,input().split())) c=Counter(l) l=list(c.values()) l.sort() # print(l) i=l[-1] #j=r-1 r=len(l) j=r-1 s=l[-1] while(j>0): i-=1 if l[j]>=i: j-=1 s+=i else: j-=1 if i==0: break print(s) t-=1 ```
instruction
0
69,925
9
139,850
No
output
1
69,925
9
139,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Nezzar buys his favorite snack — n chocolate bars with lengths l_1,l_2,…,l_n. However, chocolate bars might be too long to store them properly! In order to solve this problem, Nezzar designs an interesting process to divide them into small pieces. Firstly, Nezzar puts all his chocolate bars into a black box. Then, he will perform the following operation repeatedly until the maximum length over all chocolate bars does not exceed k. * Nezzar picks a chocolate bar from the box with probability proportional to its length x. * After step 1, Nezzar uniformly picks a real number r ∈ (0,x) and divides the chosen chocolate bar into two chocolate bars with lengths r and x-r. * Lastly, he puts those two new chocolate bars into the black box. Nezzar now wonders, what is the expected number of operations he will perform to divide his chocolate bars into small pieces. It can be shown that the answer can be represented as P/Q, where P and Q are coprime integers and Q not ≡ 0 (mod 998 244 353). Print the value of P⋅ Q^{-1} mod 998 244 353. Input The first line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2000). The second line contains n integers l_1, l_2, …, l_n (1 ≤ l_i, ∑_{i=1}^{n} l_i ≤ 2000). Output Print a single integer — the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo 998 244 353. Examples Input 1 1 2 Output 4 Input 1 1 1 Output 0 Input 1 5 1234 Output 15630811 Input 2 1 2 3 Output 476014684 Input 10 33 10 20 30 40 50 60 70 80 90 100 Output 675105648 Submitted Solution: ``` def calculate(p, q): mod = 998244353 expo = 0 expo = mod - 2 while (expo): if (expo & 1): p = (p * q) % mod q = (q * q) % mod expo >>= 1 return p n,k=map(int,input().split()) arr=range(n) arr=list(map(int,input().split())) for i in range(n): x=arr[i] if arr[i]<=k: p=i q=x-i print(calculate(p,q)) ```
instruction
0
70,075
9
140,150
No
output
1
70,075
9
140,151
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,276
9
140,552
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip()))) #to read non spaced string and elements are character to list of character get_charList_from_str = lambda: list(sys.stdin.readline().strip()) #to read integers get_int = lambda: int(sys.stdin.readline().strip()) #to print faster pt = lambda x: sys.stdout.write(str(x)) #--------------------------------WhiteHat010--------------------------------------# n = get_int() matrix = [] def nC2(n): return ( (n-1)*n )//2 for _ in range(n): matrix.append(get_string()) rowCount = 0 for row in matrix: rowCount += nC2(row.count('C')) matrixTrans = [] for i in range(n): matrixTrans.append([ matrix[j][i] for j in range(n) ]) colCount = 0 for row in matrixTrans: colCount += nC2(row.count('C')) print(colCount+rowCount) ```
output
1
70,276
9
140,553
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,277
9
140,554
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` '''input 3 .CC C.. C.C ''' from math import factorial as f n = int(input()) t = 0 r = [input() for _ in range(n)] for x in r: x1 = x.count("C") if x1 > 1: t += f(x1) // (2*(f(x1-2))) for y in range(n): c = [r[z][y] for z in range(n)] y1 = c.count("C") if y1 > 1: t += f(y1) // (2*(f(y1-2))) print(t) ```
output
1
70,277
9
140,555
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,278
9
140,556
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` n = int(input()) a = [] res = 0 for i in range(n): a += [input()] for i in range(n): x = 0 y = 0 for j in range(n): if a[i][j] == 'C': x += 1 if a[j][i] == 'C': y += 1 res += x * (x-1) // 2 + y * (y-1) // 2 print(res) ```
output
1
70,278
9
140,557
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,279
9
140,558
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` t = int(input()) l=[] for _ in range(t): #l.append(input()) h = input() h = list(h) l.append(h) #print(l) g = len(l[0]) count=0 for i in range(t): c=0 a=1 for j in range(g): if l[i][j]=='C': c+=1 count += (c*(c-1))//2 #count+=a for i in range(t): c=0 a=1 for j in range(g): if l[j][i] == 'C': c += 1 count += (c * (c - 1)) // 2 #count += a print(count) ```
output
1
70,279
9
140,559
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,280
9
140,560
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` import math def sum(a): s=0 for i in a: s=s+i return s def tsp(a): for i in range(len(a)): for j in range(i): x=a[i][j] a[i][j]=a[j][i] a[j][i]=x return a n = int(input()) a=[] for i in range(n): b = list(input()) a.append(b) b = [] s=0 for i in range(n): k=0 for j in range(n): if a[i][j] == 'C': k += 1 b.append(k*(k-1)//2) s=s+sum(b) a=tsp(a) b=[] for i in range(n): k=0 for j in range(n): if a[i][j] == 'C': k += 1 b.append(k*(k-1)//2) s=s+sum(b) print(s) ```
output
1
70,280
9
140,561
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,281
9
140,562
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` n = int(input()) arr = [] for i in range(0,n): a1 = input() a1 = list(a1) arr.append(a1) ans = 0 #print(arr) def fact(n): res = 1 for i in range(2,n+1): res=res*i return res def ncr(n,r): return fact(n)//(fact(r)*fact(n-r)) for i in range(0,n): count1 =0 count2 =0 for j in range(0,n): if arr[i][j]=='C': count1+=1 if arr[j][i]=='C': count2+=1 ans= ans+ncr(count1,2)+ncr(count2,2) print(ans) ```
output
1
70,281
9
140,563
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,282
9
140,564
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` import math n = int(input()) c = [list(input()) for i in range(n)] rowN = [0] * n colN = [0] * n for i in range(n): for j in range(n): rowN[i] += c[i][j] == 'C' colN[i] += c[j][i] == 'C' sum_ = 0 for i in range(n): rr = rowN[i] cc = colN[i] if rr > 1: sum_ += rr * (rr-1) // 2 if cc > 1: sum_ += cc * (cc-1) //2 print(sum_) ```
output
1
70,282
9
140,565
Provide tags and a correct Python 3 solution for this coding contest problem. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3)
instruction
0
70,283
9
140,566
Tags: brute force, combinatorics, constructive algorithms, implementation Correct Solution: ``` n=int(input()) a = [list(input()) for i in range(n)] c, r = [0]*n, [0]*n for i in range(n): s1 = 0 s2 = 0 for j in range(n): if a[i][j] == 'C': s1+=1 if a[j][i] == 'C': s2+=1 r[i] = s1*(s1-1)//2 c[i] = s2*(s2-1)//2 print(sum(r) + sum(c)) ```
output
1
70,283
9
140,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` t=int(input()) l=[] for i in range(t): l.append(input()) row=0 for i in range(t): a=l[i].count("C") row=row+(a*(a-1))//2 col=0 for i in range(t): con=0 for j in range(t): if l[j][i]=="C": con=con+1 col=col+(con*(con-1))//2 print(row+col) ```
instruction
0
70,284
9
140,568
Yes
output
1
70,284
9
140,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` n = int(input()) a = [] b = [] m = 0 ans = 0 for i in range(n): s = input() for j in range(n): b.append(s[j]) a.append(b[:]) b.clear() for m in range(n): for i in range(n - 1): for j in range(i + 1, n, 1): if a[m][i] == a[m][j] == "C": ans += 1 for m in range(n): for i in range(n - 1): for j in range(i + 1, n, 1): if a[i][m] == a[j][m] == "C": ans += 1 print(ans) ```
instruction
0
70,285
9
140,570
Yes
output
1
70,285
9
140,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` n = int(input()) s = [] for i in range(n): s.append(input()) counter = 0 for i in range(n): x = y = 0 for j in range(n): x += s[i][j] == 'C' y += s[j][i] == 'C' counter += x * (x-1) // 2+y * (y-1)//2 print(counter) # # CodeForcesian # ♥ # خیلی وقته دارم رو این سوال کار میکنم # تا به یک جواب جدید برسم # اما دیگه خسته شدم # میخوام سابمیتش کنم # امروز هر چی زدم غیر یکی همه تو همون سابمیت اول اکسپت شدن # واسه تک تکتون چنین چیزی رو واسه همه روزاتون اونم از صمیم قلب ارزو میکنم ```
instruction
0
70,286
9
140,572
Yes
output
1
70,286
9
140,573
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` n = int(input()) res = 0 ls = [] for i in range(n): s = input() cnt = 0 for ch in s: if ch == 'C': cnt += 1 if cnt > 1: res += cnt * (cnt - 1) // 2 ls.append(s) for i in range(n): cnt = 0 for j in range(n): if ls[j][i] == 'C': cnt += 1 if cnt > 1: res += cnt * (cnt - 1) // 2 print(res) ```
instruction
0
70,287
9
140,574
Yes
output
1
70,287
9
140,575
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` cc = [] result = 0 for i in range(int(input(""))): cc.append(list(input(""))) def getpairs(pairs): return ((pairs*(pairs-1))/2) #count rows def getcol(colnum): temp = [] for i in range(len(cc)): temp.append(cc[i][colnum]) return temp for i in range(len(cc)): result = result+getpairs(cc[i].count('C')) for i in range(len(cc)): result = result+getpairs(getcol(i).count('C')) print(result) ```
instruction
0
70,288
9
140,576
No
output
1
70,288
9
140,577
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` n = int(input()) a = [] h = 0 for i in range(n): b = [1 if i == "C" else 0 for i in input()] b.append(0) a.append(b) h -= sum(b) + 1 a.append([0] * (n + 1)) h += sum([sum(x) for x in a]) + 2 * n print(h) ```
instruction
0
70,289
9
140,578
No
output
1
70,289
9
140,579
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` def split(word): return list(word) def nCr(n, r): return (fact(n) / (fact(r) * fact(n - r))) def fact(n): res = 1 for i in range(2, n+1): res = res * i return res n=int(input()) r=dict() c=0 a=[] for i in range(n): a.append(0) for i in range(0,n): k=0 l=input() r=split(l) p=0 for j in r: if j=='C': k=k+1 a[p]=a[p]+1 p=p+1 if k==2: c=c+1 elif k>2: c=c+(nCr(k,2)) print(a) for i in range(0,n): if a[i]==2: c=c+1 elif a[i]>2: c=c+(nCr(a[i],2)) print(int(c)) ```
instruction
0
70,290
9
140,580
No
output
1
70,290
9
140,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake. Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Examples Input 3 .CC C.. C.C Output 4 Input 4 CC.. C..C .CC. .CC. Output 9 Note If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 2. (3, 1) and (3, 3) Pieces that share the same column are: 1. (2, 1) and (3, 1) 2. (1, 3) and (3, 3) Submitted Solution: ``` n = int(input()) a = [] count = 0 for i in range(n): a.append(input()) for item in range(n): if a[item].count('C') > 1: count += 1 for i in range(item+1,n): for j in range(n): if a[item][j] == a[i][j] and a[item][j] == 'C': count += 1 print(count) ```
instruction
0
70,291
9
140,582
No
output
1
70,291
9
140,583
Provide a correct Python 3 solution for this coding contest problem. Aika's house runs a small coffee shop. The scones baked by Aika's mother were very delicious and the shop was very prosperous. One of the jobs of Aika, a waitress, is to deliver the scones that are baked one after another to the customer's seat. The baked scones are placed on a tray and lined up on the counter. Let Ki be the number of scones on the i-th tray. Aika must carry exactly m scones to each customer. Aika can have as many trays as she wants at a time, and can distribute scones from multiple trays to one customer, or from one tray to multiple customers. There are so many customers coming to the coffee shop that even if you carry all the scones on the counter, you cannot deliver them to all of them. However, after reaching as many customers as possible, there may be less than m scones left over. Such scones will be given to Aika as a reward for helping. Suddenly, Aika thought about it. If you deliver scones to customers with only some trays instead of having all the trays at once, the number of surplus scones will be different. With proper tray selection, you may be able to leave more scones. Aika decided to choose one continuous range of trays on the counter so that her mother wouldn't notice that she was deliberately choosing trays. Also, since the remaining trays are carried by fathers and mothers, Aika has only one chance to get scones. By the way, how many scones can Aika get? Write a program to calculate. The number of trays n is 1 or more and 30,000 or less, and m is 1 or more and 100,000 or less. Also, each element Ki of the sequence is 0 or more and 232-1. input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is as follows. 1st line n m (integer integer; half-width space delimited) 2nd line Scone information on Obon K1 K2 ... Kn (all integers; half-width space delimited) Ki: Number of scones on the i-th tray The number of datasets does not exceed 50. output Outputs the maximum number of scones you can get for each dataset on one line. Example Input 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 Output 8 4 0 17 5
instruction
0
70,668
9
141,336
"Correct Solution: ``` from bisect import bisect_left as bl while True: n, m = map(int, input().split()) if n == 0: break klst = list(map(int, input().split())) cum = [] acc = 0 for k in klst: acc += k acc %= m cum.append(acc) use = [0] use_len = 1 ans = 0 for k in cum: ind = bl(use, k + 1) if ind < use_len: ans = max(ans, (k - use[ind]) % m) ans = max(ans, k) use.insert(bl(use, k), k) use_len += 1 print(ans) ```
output
1
70,668
9
141,337
Provide a correct Python 3 solution for this coding contest problem. Aika's house runs a small coffee shop. The scones baked by Aika's mother were very delicious and the shop was very prosperous. One of the jobs of Aika, a waitress, is to deliver the scones that are baked one after another to the customer's seat. The baked scones are placed on a tray and lined up on the counter. Let Ki be the number of scones on the i-th tray. Aika must carry exactly m scones to each customer. Aika can have as many trays as she wants at a time, and can distribute scones from multiple trays to one customer, or from one tray to multiple customers. There are so many customers coming to the coffee shop that even if you carry all the scones on the counter, you cannot deliver them to all of them. However, after reaching as many customers as possible, there may be less than m scones left over. Such scones will be given to Aika as a reward for helping. Suddenly, Aika thought about it. If you deliver scones to customers with only some trays instead of having all the trays at once, the number of surplus scones will be different. With proper tray selection, you may be able to leave more scones. Aika decided to choose one continuous range of trays on the counter so that her mother wouldn't notice that she was deliberately choosing trays. Also, since the remaining trays are carried by fathers and mothers, Aika has only one chance to get scones. By the way, how many scones can Aika get? Write a program to calculate. The number of trays n is 1 or more and 30,000 or less, and m is 1 or more and 100,000 or less. Also, each element Ki of the sequence is 0 or more and 232-1. input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is as follows. 1st line n m (integer integer; half-width space delimited) 2nd line Scone information on Obon K1 K2 ... Kn (all integers; half-width space delimited) Ki: Number of scones on the i-th tray The number of datasets does not exceed 50. output Outputs the maximum number of scones you can get for each dataset on one line. Example Input 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 Output 8 4 0 17 5
instruction
0
70,669
9
141,338
"Correct Solution: ``` def main(): while 1: N, M = map(int, input().split()) if N == M == 0: break data = [0]*(M+1) def add(k, x): while k <= M: data[k] += x k += k & -k def get(k): s = 0 while k: s += data[k] k -= k & -k return s M0 = 2**(M-1).bit_length() def lower_bound(x): w = i = 0 k = M0 while k: if i+k <= M and w + data[i+k] <= x: w += data[i+k] i += k k >>= 1 return i+1 *K, = map(int, input().split()) su = 0 ans = 0 for k in K: su = (su + k) % M v = get(su+1) w = lower_bound(v)-1 if w == M: w = 0 ans = max(ans, (su - w) % M) add(su+1, 1) print(ans) main() ```
output
1
70,669
9
141,339
Provide a correct Python 3 solution for this coding contest problem. Aika's house runs a small coffee shop. The scones baked by Aika's mother were very delicious and the shop was very prosperous. One of the jobs of Aika, a waitress, is to deliver the scones that are baked one after another to the customer's seat. The baked scones are placed on a tray and lined up on the counter. Let Ki be the number of scones on the i-th tray. Aika must carry exactly m scones to each customer. Aika can have as many trays as she wants at a time, and can distribute scones from multiple trays to one customer, or from one tray to multiple customers. There are so many customers coming to the coffee shop that even if you carry all the scones on the counter, you cannot deliver them to all of them. However, after reaching as many customers as possible, there may be less than m scones left over. Such scones will be given to Aika as a reward for helping. Suddenly, Aika thought about it. If you deliver scones to customers with only some trays instead of having all the trays at once, the number of surplus scones will be different. With proper tray selection, you may be able to leave more scones. Aika decided to choose one continuous range of trays on the counter so that her mother wouldn't notice that she was deliberately choosing trays. Also, since the remaining trays are carried by fathers and mothers, Aika has only one chance to get scones. By the way, how many scones can Aika get? Write a program to calculate. The number of trays n is 1 or more and 30,000 or less, and m is 1 or more and 100,000 or less. Also, each element Ki of the sequence is 0 or more and 232-1. input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is as follows. 1st line n m (integer integer; half-width space delimited) 2nd line Scone information on Obon K1 K2 ... Kn (all integers; half-width space delimited) Ki: Number of scones on the i-th tray The number of datasets does not exceed 50. output Outputs the maximum number of scones you can get for each dataset on one line. Example Input 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 Output 8 4 0 17 5
instruction
0
70,670
9
141,340
"Correct Solution: ``` # AOJ 0254: Scone # Python3 2018.6.25 bal4u s = [0 for i in range(30001)] while True: n, m = map(int, input().split()) if n == 0: break f = [-1 for i in range(m)] sum, nmax, ans = 0, 0, 0 a = list(map(int, input().split())) for i in range(n): sum += a[i] a[i] %= m if a[i] > nmax: nmax = a[i] if a[i] == m-1: ans = a[i] s[i+1] = s[i] + a[i] if s[i+1] >= m: s[i+1] -= m f[s[i+1]] = i+1 if ans == 0: if nmax == 0: ans = 0 elif sum < m: ans = sum else: done = False for ans in range(m-1, nmax-1, -1): for i in range(n+1): x = s[i]+ans if x >= m: x -= m if f[x] >= i: done = True break if done: break print(ans) ```
output
1
70,670
9
141,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Aika's house runs a small coffee shop. The scones baked by Aika's mother were very delicious and the shop was very prosperous. One of the jobs of Aika, a waitress, is to deliver the scones that are baked one after another to the customer's seat. The baked scones are placed on a tray and lined up on the counter. Let Ki be the number of scones on the i-th tray. Aika must carry exactly m scones to each customer. Aika can have as many trays as she wants at a time, and can distribute scones from multiple trays to one customer, or from one tray to multiple customers. There are so many customers coming to the coffee shop that even if you carry all the scones on the counter, you cannot deliver them to all of them. However, after reaching as many customers as possible, there may be less than m scones left over. Such scones will be given to Aika as a reward for helping. Suddenly, Aika thought about it. If you deliver scones to customers with only some trays instead of having all the trays at once, the number of surplus scones will be different. With proper tray selection, you may be able to leave more scones. Aika decided to choose one continuous range of trays on the counter so that her mother wouldn't notice that she was deliberately choosing trays. Also, since the remaining trays are carried by fathers and mothers, Aika has only one chance to get scones. By the way, how many scones can Aika get? Write a program to calculate. The number of trays n is 1 or more and 30,000 or less, and m is 1 or more and 100,000 or less. Also, each element Ki of the sequence is 0 or more and 232-1. input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is as follows. 1st line n m (integer integer; half-width space delimited) 2nd line Scone information on Obon K1 K2 ... Kn (all integers; half-width space delimited) Ki: Number of scones on the i-th tray The number of datasets does not exceed 50. output Outputs the maximum number of scones you can get for each dataset on one line. Example Input 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 Output 8 4 0 17 5 Submitted Solution: ``` from bisect import bisect_left as bl while True: n, m = map(int, input().split()) if n == 0: break klst = list(map(int, input().split())) cum = [] acc = 0 for k in klst: acc += k acc %= m cum.append(acc) use = [0] use_len = 1 ans = 0 for k in cum: ind = bl(use, m - k - 1) if ind < use_len: if use[ind] == m - k - 1: ans = max(ans, k + use[ind]) else: ans = max(ans, k + use[ind - 1]) ans = max(ans, (k + use[-1]) % m) use.insert(bl(use, k), k) use_len += 1 print(ans) ```
instruction
0
70,671
9
141,342
No
output
1
70,671
9
141,343
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,961
9
141,922
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` from sys import stdin, stdout import math DIV = int(1e5) def ceil(x, y): return (x + y - 1) // y n, m = map(int, stdin.readline().split()) r_a = [-1] * (m + 1) d_a = [[-1, -1] for _ in range(m + 1)] d_a[0] = [0, 0] for i in range(1, n+1): #t, x, y = map(float, stdin.readline().split()) #t = int(t) #x /= 10**5 #y = int(y) t, x, y = map(int, stdin.readline().split()) for j in range(m + 1): nj = 0 if t == 1: # nj = int(math.ceil(j + x)) nj = j + ceil(x, DIV) else: # nj = int(math.ceil(j * x)) nj = ceil(j*x, DIV) if nj > m: break if d_a[j][1] != -1: if d_a[j][0] == i and d_a[j][1] < y and d_a[nj][0] == -1: r_a[nj] = i d_a[nj] = [i, d_a[j][1] + 1] elif d_a[j][0] != i and d_a[nj][0] == -1: r_a[nj] = i d_a[nj] = [i, 1] r_a.pop(0) stdout.write(' '.join(map(str, r_a))) ```
output
1
70,961
9
141,923
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,962
9
141,924
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` n,m = map(int,input().split()) N = 10**5 dp = [0]+[-1] * (m) cnt = [0] * (m+1) for T in range(1,n+1): t,x,y = map(int,input().split()) for pre in range(m): if dp[pre] == -1: continue if t == 1: nxt = pre + (x-1)//N + 1 else: nxt = (pre*x -1) //N + 1 if dp[pre] == T: if cnt[pre] == y : continue if nxt > m: break elif dp[nxt] == -1: dp[nxt],cnt[nxt] = T,cnt[pre]+1 else: if nxt > m: break elif dp[nxt] == -1: dp[nxt],cnt[nxt] = T,1 print(*dp[1:]) ```
output
1
70,962
9
141,925
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,963
9
141,926
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` from math import ceil curr = 0 def ceil(x,y): return (x+y-1)//y def operation(type, x): global curr, DIV if type==1: return curr+ceil(x,DIV) elif type==2: return ceil(curr*x, DIV) n, m = [int(i) for i in input().split()] is_seen = [0 for i in range(m+1)] is_seen[0] = 1 ans = [-1 for i in range(m+1)] DIV = int(1e5) for timestep in range(n): t, x, y = [int(i) for i in input().split()] new_seen = [] for pos_bananas in range(m+1): if is_seen[pos_bananas]: curr = pos_bananas i = 1 while i<=y: curr = operation(t, x) if curr > m: break if is_seen[curr]: break new_seen.append(curr) ans[curr] = timestep+1 i+=1 for idx in new_seen: is_seen[idx] = 1 print(*ans[1:]) ```
output
1
70,963
9
141,927
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,964
9
141,928
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` #start_time = time.time() #def TIME_(): print(time.time()-start_time) import os, sys from io import BytesIO, IOBase import math BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os 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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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: self.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") def getInt(): return int(input()) def getStrs(): return input().split() def getInts(): return list(map(int,input().split())) def getStr(): return input() def listStr(): return list(input()) def getMat(n): return [getInts() for _ in range(n)] def getBin(): return list(map(int,list(input()))) def isInt(s): return '0' <= s[0] <= '9' def ceil_(a,b): return a//b + (a%b > 0) def ceil2(a,b): return math.floor((a+b-1)/b) """ We have all current possible values of K We can only ever increase If K = 0, then multiplying does nothing Type 1 ops: we just round up X/10^5 and add it to all of them Type 2 ops: """ TT = pow(10,5) N, M = getInts() ans = [-1]*(M+1) done = set([0]) LIM = float(M*TT) for i in range(1,N+1): t, x, y = getInts() if t == 1: x = ceil2(x,TT) for j in list(done): for k in range(y): j += x if j > M or j in done: break done.add(j) ans[j] = i else: x = float(x) for j in list(done): for k in range(y): j = ceil2(j*x,TT) if j > M or j in done: break done.add(j) ans[j] = i print(*ans[1:]) #for _ in range(getInt()): #print(solve()) #TIME_() ```
output
1
70,964
9
141,929
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,965
9
141,930
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` import sys def ceil(x,y): return (x + y - 1)//y def input(): return sys.stdin.readline().rstrip() MOD = int(1e5) def slv(): n, m = map(int, input().split()) ans = [-1]*(m + 1) ans[0] = 0 seen = [False]*(m + 1) seen[0] = True for i in range(n): t, x, y = map(int, input().split()) #slow bruteforce tmpstack = [] for ni in range(m + 1): cost = ans[ni] if not seen[ni]: continue for op in range(y): if t == 1: ni += ceil(x,MOD) else: ni *= x ni = ceil(ni,MOD) if ni > m: break if seen[ni]: break if ans[ni] < 0: tmpstack.append((ni,i + 1)) for idx,v in tmpstack: ans[idx] = v seen[idx] = True print(*ans[1:m + 1]) return def main(): t = 1 for i in range(t): slv() return if __name__ == "__main__": main() ```
output
1
70,965
9
141,931
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,966
9
141,932
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` import sys import math from collections import defaultdict,Counter,deque # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") 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") # sys.stdout=open("CP1/output.txt",'w') # sys.stdin=open("CP1/input.txt",'r') # mod=pow(10,9)+7 # t=int(input()) n,m=map(int,input().split()) ans=[-1]*(m+1) # limit=m*10**5 visit=set([0]) for i in range(n): t,x,y=map(int,input().split()) # a=list(map(int,input().split())) # print(d) if t==1: d=(x+10**5-1)//10**5 for k in list(visit): for j in range(y): k+=d if k>m or k in visit: break ans[k]=i+1 visit.add(k) else: for k in list(visit): for j in range(y): # if k*x>limit: # break k=math.ceil((k*x)/10**5) if k>m or k in visit: break ans[k]=i+1 visit.add(k) print(*ans[1:]) ```
output
1
70,966
9
141,933
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,967
9
141,934
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n,m = map(int,input().split()) dp = [0]+[n+1]*m ti = [0]*(m+1) for _ in range(1,n+1): t,x,y = map(int,input().split()) for i in range(m+1): if dp[i] == n+1 or ti[i] == y: continue ne = i+(x+99999)//100000 if t==1 else (i*x+99999)//100000 if ne > m or dp[ne] < _: continue ti[ne] = min(ti[ne],ti[i]+1) if dp[ne] == _ else ti[i]+1 dp[ne] = _ ti = [0]*(m+1) for i in range(m+1): if dp[i] == n+1: dp[i] = -1 print(*dp[1:]) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
output
1
70,967
9
141,935
Provide tags and a correct Python 3 solution for this coding contest problem. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations.
instruction
0
70,968
9
141,936
Tags: dfs and similar, dp, graphs, implementation Correct Solution: ``` import time #start_time = time.time() #def TIME_(): print(time.time()-start_time) import os, sys from io import BytesIO, IOBase from types import GeneratorType from bisect import bisect_left, bisect_right from collections import defaultdict as dd, deque as dq, Counter as dc import math, string, heapq as h BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os 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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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: self.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") def getInt(): return int(input()) def getStrs(): return input().split() def getInts(): return list(map(int,input().split())) def getStr(): return input() def listStr(): return list(input()) def getMat(n): return [getInts() for _ in range(n)] def getBin(): return list(map(int,list(input()))) def isInt(s): return '0' <= s[0] <= '9' def ceil_(a,b): return a//b + (a%b > 0) MOD = 10**9 + 7 """ We have all current possible values of K We can only ever increase If K = 0, then multiplying does nothing Type 1 ops: we just round up X/10^5 and add it to all of them Type 2 ops: """ TT = pow(10,5) def solve(): N, M = getInts() ans = [-1]*(M+1) ans[0] = 0 for i in range(1,N+1): t, x, y = getInts() cnt = 0 used = [0]*(M+1) for j in range(M+1): if used[j] or ans[j] == -1: continue cnt = 0 curr = j if curr == 0 and t == 2: continue while curr <= M and cnt <= y: if ans[curr] == -1: ans[curr] = i else: cnt = 0 used[curr] = 1 if t == 1: curr = ceil_(TT*curr + x,TT) else: curr = ceil_(curr * x,TT) cnt += 1 print(*ans[1:]) return #for _ in range(getInt()): #print(solve()) solve() #TIME_() ```
output
1
70,968
9
141,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip BASE = 10**5 def main(): n, m = map(int, input().split()) answer = [-1 for i in range(m + 1)] answer[0] = 0 for step in range(n): t, x, y = map(int, input().split()) bfs = [] dis = [-1 for i in range(m + 1)] cur = 0 for i in range(m + 1): if answer[i] != -1: bfs.append(i) dis[i] = 0 if len(bfs) == m + 1: break for u in bfs: if dis[u] == y: continue v = 0 if t == 1: v = math.ceil(u + x / BASE) else: v = math.ceil(u * x / BASE) if v > m: continue if dis[v] == -1: dis[v] = dis[u] + 1 bfs.append(v) answer[v] = step + 1 print(' '.join(str(x) for x in answer[1:])) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
70,969
9
141,938
Yes
output
1
70,969
9
141,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq,bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2**51, func=lambda a, b: a & b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b:max(a , b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n,m=map(int,input().split()) ans=[[-1,-1]for i in range(m+1)] ans[0][0]=[0,0] for i in range(1,n+1): t,x,y=map(int,input().split()) for j in range(m): if t==1: nex=int(math.ceil(j+x/100000)) else: nex=int(math.ceil((j*x)/100000)) if nex>m: break if ans[j][0]!=-1: if ans[j][0]==i: if ans[j][1]<y: if ans[nex][0]==-1: ans[nex]=[i,ans[j][1]+1] else: if ans[nex][0] == -1: ans[nex]=[i,1] for i in range(1,m+1): print(ans[i][0],end=" ") ```
instruction
0
70,970
9
141,940
Yes
output
1
70,970
9
141,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` import io import os from math import ceil def solve(N, M, TXY): def ceildiv(x, y): # x and y are floats, returns int return ceil(x / y) M100000 = float(M * 10 ** 5) # Can be up to 10**10 possible = {0} inf = 201 earliest = [inf] * (M + 1) for ts, (t, x, y) in enumerate(TXY, start=1): t = int(t) x = float(x) # x doesn't fit in int32 y = int(y) if t == 1: # assert 1 <= x <= M100000 x = ceildiv(x, 100000.0) for k in list(possible): for i in range(y): k = k + x if k > M or k in possible: break possible.add(k) earliest[k] = min(earliest[k], ts) else: # assert t == 2 # assert 100000 < x <= M100000 for k in list(possible): for i in range(y): if k * x > M100000: break k = ceildiv(k * x, 100000.0) if k in possible: break possible.add(k) earliest[k] = min(earliest[k], ts) return " ".join(str(x) if x != inf else "-1" for x in earliest[1:]) if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline TC = 1 for tc in range(1, TC + 1): N, M = [int(x) for x in input().split()] TXY = ((x for x in input().split()) for i in range(N)) ans = solve(N, M, TXY) print(ans) ```
instruction
0
70,971
9
141,942
Yes
output
1
70,971
9
141,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` import sys from math import ceil import io, os from queue import PriorityQueue input = lambda: sys.stdin.readline().rstrip() XDIV = int(1e5) class Problem(): def __init__(self): self.sol = [] self.M = None def _next_step(self, t, x, y, step): # print("step", step) i = self.M # last = 0 last = 0 if t == 1 else 1 while i >= last: k = i i -= 1 if self.sol[k] == -1: continue # print("k", k) j = 0 while j < y: j += 1 if t == 1: k = k + ceil(x / XDIV) else: k = ceil(k * x / XDIV) # print("nxtk", k) if k > self.M or self.sol[k] != -1: break self.sol[k] = step # print("sol", self.sol) def solve(self): N, M = map(int, input().split()) self.M = M self.sol = [-1] * (M + 1) self.sol[0] = 0 for i in range(N): t, x, y = map(int, input().split()) self._next_step(t, x, y, i + 1) self.sol.pop(0) sys.stdout.write(" ".join(map(str, self.sol))) def main(): p = Problem() T = 1 while T: p.solve() T -= 1 if __name__ == '__main__': main() ```
instruction
0
70,972
9
141,944
Yes
output
1
70,972
9
141,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` from math import ceil import sys input = sys.stdin.readline n, m = map(int, input().rstrip().split()) ans = [-1] * (m+1) ans[0] = 0 txy = [] for _ in range(n): a, b, c = map(int, input().rstrip().split()) txy.append((a, b/(10**5), c)) for time in range(n): for b in range(m+1): if time >= ans[b] >= 0: t, x, y = txy[time] banana = b if t == 1: while banana <= m and y >= 0: if ans[banana] == -1: ans[banana] = time + 1 elif b != banana: break banana = ceil(banana + x) y -= 1 else: while banana <= m and y >= 0: if ans[banana] == -1: ans[banana] = time + 1 elif b != banana: break banana = ceil(banana * x) y -= 1 print(' '.join(map(str, ans[1:]))) ```
instruction
0
70,973
9
141,946
No
output
1
70,973
9
141,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` import math import sys import collections import bisect import heapq arr = list(map(int,sys.stdin.readline().strip().split())) n = arr[0] m = arr[1] ks = set() ks.add(0) A = [] for _ in range(n): arr = list(map(int,sys.stdin.readline().strip().split())) A.append((arr[0],arr[1]/(10**5),arr[2])) res = [-1]*m for step,(t,x,y) in enumerate(A): if t == 1: nks = [] for k in ks: for i in range(1,y+1): nk = k + i*math.ceil(k+x) if nk <= m: nks.append(nk) if res[nk-1] == -1: res[nk-1] = step+1 else: break for k in nks: ks.add(k) else: nks = [] for k in ks: for i in range(1,y+1): nk = k + i*math.ceil(k*x) if nk <= m and nk not in ks: nks.append(nk) if res[nk-1] == -1: res[nk-1] = step+1 else: break for k in nks: ks.add(k) for i in res: print(i, end = " ") print("") ```
instruction
0
70,974
9
141,948
No
output
1
70,974
9
141,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` import math class Solution: def __init__(self, m): self.dict = {i: -1 for i in range(1, m+1)} self.dict[0] = 0 self.stack = set([0]) self.m = m self.div = 10**5 def update(self, t, x, y, step): new_set = set() for el in self.stack.copy(): for _ in range(1, y+1): if t == 1: el += math.ceil(x/self.div) else: el *= x el = math.ceil(el) if el > self.m or el in self.stack: break else: self.stack.add(el) self.dict[el] = step #self.stack = self.stack.union(new_set) #print(self.stack) if __name__ == "__main__": n, m = [int(el) for el in input().split()] sol = Solution(m) for i in range(n): t, x, y = [int(el) for el in input().split()] sol.update(t, x, y, i+1) for i in range(1, m): print(sol.dict[i], end=' ') print(sol.dict[m]) ```
instruction
0
70,975
9
141,950
No
output
1
70,975
9
141,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three parameters t_i, x_i, y_i in the input. Based on the value of t_i, you must do one of the following: Type 1: (t_i=1, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k + x_i) ⌉. Type 2: (t_i=2, x_i, y_i) — pick an a_i, such that 0 ≤ a_i ≤ y_i, and perform the following update a_i times: k:=⌈ (k ⋅ x_i) ⌉. Note that x_i can be a fractional value. See input format for more details. Also, ⌈ x ⌉ is the smallest integer ≥ x. At the i-th time-step, you must apply the i-th operation exactly once. For each j such that 1 ≤ j ≤ m, output the earliest time-step at which you can create exactly j bananas. If you cannot create exactly j bananas, output -1. Input The first line contains two space-separated integers n (1 ≤ n ≤ 200) and m (2 ≤ m ≤ 10^5). Then, n lines follow, where the i-th line denotes the operation for the i-th timestep. Each such line contains three space-separated integers t_i, x'_i and y_i (1 ≤ t_i ≤ 2, 1≤ y_i≤ m). Note that you are given x'_i, which is 10^5 ⋅ x_i. Thus, to obtain x_i, use the formula x_i= \dfrac{x'_i} {10^5}. For type 1 operations, 1 ≤ x'_i ≤ 10^5 ⋅ m, and for type 2 operations, 10^5 < x'_i ≤ 10^5 ⋅ m. Output Print m integers, where the i-th integer is the earliest time-step when you can obtain exactly i bananas (or -1 if it is impossible). Examples Input 3 20 1 300000 2 2 400000 2 1 1000000 3 Output -1 -1 1 -1 -1 1 -1 -1 -1 3 -1 2 3 -1 -1 3 -1 -1 -1 3 Input 3 20 1 399999 2 2 412345 2 1 1000001 3 Output -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 -1 -1 3 -1 2 -1 3 -1 Note In the first sample input, let us see how to create 16 number of bananas in three timesteps. Initially, k=0. * In timestep 1, we choose a_1=2, so we apply the type 1 update — k := ⌈(k+3)⌉ — two times. Hence, k is now 6. * In timestep 2, we choose a_2=0, hence value of k remains unchanged. * In timestep 3, we choose a_3=1, so we are applying the type 1 update k:= ⌈(k+10)⌉ once. Hence, k is now 16. It can be shown that k=16 cannot be reached in fewer than three timesteps with the given operations. In the second sample input, let us see how to create 17 number of bananas in two timesteps. Initially, k=0. * In timestep 1, we choose a_1=1, so we apply the type 1 update — k := ⌈(k+3.99999)⌉ — once. Hence, k is now 4. * In timestep 2, we choose a_2=1, so we apply the type 2 update — k := ⌈(k⋅ 4.12345)⌉ — once. Hence, k is now 17. It can be shown that k=17 cannot be reached in fewer than two timesteps with the given operations. Submitted Solution: ``` def solve(k,index,q,d): if index<len(q): t=q[index][0] x=q[index][1] x/=100000 y=q[index][2] if t==1: temp=k for i in range(y+1): temp=math.ceil(k+i*x) if temp not in d: d[temp]=index+1 solve(temp,index+1,q,d) else: solve(temp,index+1,q,d) else: temp=k for i in range(y+1): temp=math.ceil(k*pow(x,i)) if temp not in d: d[temp]=index+1 solve(temp,index+1,q,d) else: solve(temp,index+1,q,d) import math (n,m) = (int(x) for x in input().split()) d={} q=[] for _ in range(n): p=[int(x) for x in input().split()] q.append(p) solve(0,0,q,d) for _ in range(1,m+1): if _ not in d: print(-1,end=" ") else: print(d[_],end=" ") print() ```
instruction
0
70,976
9
141,952
No
output
1
70,976
9
141,953
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,067
9
142,134
Tags: greedy, implementation Correct Solution: ``` n, m, k = [int(i) for i in input().split()] lst = [1000000] * m for j in range(n): r, c = [int(y) for y in input().split()] lst[r - 1] = min(lst[r - 1], c) print(min(sum(lst), k)) ```
output
1
71,067
9
142,135
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,068
9
142,136
Tags: greedy, implementation Correct Solution: ``` n, m, k = [int(item) for item in input().split()] cont = {} for i in range(n): row, health = [int(item) for item in input().split()] if row in cont and health < cont[row] or \ row not in cont: cont[row] = health ''' sumOfHealth = 0 for val in cont.values(): sumOfHealth += val ''' sumOfHealth = sum(cont.values()) print(sumOfHealth if sumOfHealth<=k else k) ```
output
1
71,068
9
142,137
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,069
9
142,138
Tags: greedy, implementation Correct Solution: ``` n, m, k = map(int, input().split()) lst = [1000001] * n for i in range(n): r, c = map(int, input().split()) if lst[r - 1] > c: lst[r - 1] = c # thisset = {0} # for j in range(len(lst)): # thisset.add(lst[j]) out = 0 for num in lst: out += num if num != 1000001 else 0 print(out if out <= k else k) ```
output
1
71,069
9
142,139
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,070
9
142,140
Tags: greedy, implementation Correct Solution: ``` n, m, k = [int(x) for x in input().split()] teeth_rows = {} for i in range(n): r, c = [int(x) for x in input().split()] if r in teeth_rows: if teeth_rows[r] > c: teeth_rows[r] = c else: teeth_rows[r] = c #print(teeth_rows) answer = sum(teeth_rows.values()) if answer > k: print(k) else: print(answer) ```
output
1
71,070
9
142,141
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,071
9
142,142
Tags: greedy, implementation Correct Solution: ``` teeth,row , food = map(int,input().split()) l = [-1]*teeth ans = 0 for i in range(teeth): row,power = map(int,input().split()) if l[row-1] < 0 or l[row-1] > power: l[row-1] = power for i in l: if i == -1: continue else: ans += i if ans >= food: print(food) else: print(ans) ```
output
1
71,071
9
142,143
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,072
9
142,144
Tags: greedy, implementation Correct Solution: ``` n, m, k = list(map(int, input().split(' '))) my_dict = {} while n > 0: r, c = list(map(int, input().split(' '))) if r in my_dict and my_dict[r] > c or r not in my_dict: my_dict[r] = c n -= 1 sm = 0 for value in my_dict.values(): sm += value print(sm if sm <= k else k) ''' n, m, k = [int(item) for item in input().split(' ')] my_dict = dict() for i in range(n): r, c = [int(item) for item in input().split(' ')] if r in my_dict and my_dict[r] > c or r not in my_dict: my_dict[r] = c sm = sum(my_dict.values()) print(sm if sm <= k else k) ''' ```
output
1
71,072
9
142,145
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,073
9
142,146
Tags: greedy, implementation Correct Solution: ``` n, m, k = map(int, input().split()) a = [99999999] * (m) for i in range(n): nom, j = map(int, input().split()) a[nom - 1] = min(a[nom - 1], j) s = sum(a) print(min(s, k)) ```
output
1
71,073
9
142,147
Provide tags and a correct Python 3 solution for this coding contest problem. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13
instruction
0
71,074
9
142,148
Tags: greedy, implementation Correct Solution: ``` n, m, k = [int(x) for x in input().split()] a = [1000000] * m for i in range(n): r, c = [int(x) for x in input().split()] a[r - 1] = min(a[r - 1], c) print(min(k, sum(a))) ```
output
1
71,074
9
142,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13 Submitted Solution: ``` n,m,k=list(map(int,input().split())) rows={} for teeth in range(n): row,via=list(map(int,input().split())) if row not in rows: rows[row]=via elif rows[row]>via: rows[row]=via total=sum(rows.values()) print([k,total][total<k]) ```
instruction
0
71,075
9
142,150
Yes
output
1
71,075
9
142,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output In the first line output the maximum amount of crucians that Valerie can consume for dinner. Examples Input 4 3 18 2 3 1 2 3 6 2 3 Output 11 Input 2 2 13 1 13 2 12 Output 13 Submitted Solution: ``` inf=list(map(int,input().split())) t,r,c=inf[0],inf[1],inf[2] row=[999999999]*r for i in range(t): inf=list(map(int,input().split())) row[inf[0]-1]=min(row[inf[0]-1],inf[1]) ans=0 for i in row: ans+=i print(min(ans,c)) ```
instruction
0
71,076
9
142,152
Yes
output
1
71,076
9
142,153