message
stringlengths
2
30.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
237
109k
cluster
float64
10
10
__index_level_0__
int64
474
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. Constraints * 0 \leq A, B, C \leq 50 * A + B + C \geq 1 * 50 \leq X \leq 20 000 * A, B and C are integers. * X is a multiple of 50. Input Input is given from Standard Input in the following format: A B C X Output Print the number of ways to select coins. Examples Input 2 2 2 100 Output 2 Input 5 1 0 150 Output 0 Input 30 40 50 6000 Output 213 Submitted Solution: ``` a,b,c,x = map(int,[input() for i in range(4)]) c = 0 for i in range(a+1): for j in range(b+1): for n in range(c+1): if t = i*500 + j*100 + n*50 == x: c +=1 print(c) ```
instruction
0
42,748
10
85,496
No
output
1
42,748
10
85,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. Constraints * 0 \leq A, B, C \leq 50 * A + B + C \geq 1 * 50 \leq X \leq 20 000 * A, B and C are integers. * X is a multiple of 50. Input Input is given from Standard Input in the following format: A B C X Output Print the number of ways to select coins. Examples Input 2 2 2 100 Output 2 Input 5 1 0 150 Output 0 Input 30 40 50 6000 Output 213 Submitted Solution: ``` a = int(input()) b = int(input()) c = int(input()) x = int(input()) res = 0 for i in range(a): for j in range(b): for k in range(c): sum = 500*i + 100*j + 50*k if sum == x: res += 1 print(res) ```
instruction
0
42,749
10
85,498
No
output
1
42,749
10
85,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. Constraints * 0 \leq A, B, C \leq 50 * A + B + C \geq 1 * 50 \leq X \leq 20 000 * A, B and C are integers. * X is a multiple of 50. Input Input is given from Standard Input in the following format: A B C X Output Print the number of ways to select coins. Examples Input 2 2 2 100 Output 2 Input 5 1 0 150 Output 0 Input 30 40 50 6000 Output 213 Submitted Solution: ``` import sys input = sys.stdin.readline A=int(input()) B=int(input()) C=int(input()) X=int(input()) ans = 0 for i in range(A+1): for j in range(B+1): if 0 <= (x - 500*i - 100*j) // 50 <= C: ans += 1 print(ans) ```
instruction
0
42,750
10
85,500
No
output
1
42,750
10
85,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. Constraints * 0 \leq A, B, C \leq 50 * A + B + C \geq 1 * 50 \leq X \leq 20 000 * A, B and C are integers. * X is a multiple of 50. Input Input is given from Standard Input in the following format: A B C X Output Print the number of ways to select coins. Examples Input 2 2 2 100 Output 2 Input 5 1 0 150 Output 0 Input 30 40 50 6000 Output 213 Submitted Solution: ``` a = int(input()) b = int(input()) c = int(input()) x = int(int(input())/50) cnt = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): s = int(i + j*2 + k*10) if s == x: cnt += 1 print(cnt) ```
instruction
0
42,751
10
85,502
No
output
1
42,751
10
85,503
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,831
10
85,662
"Correct Solution: ``` L = [int(input()) for i in range(5)] print( min(L[0],L[1],L[2])+ min(L[3],L[4])-50) ```
output
1
42,831
10
85,663
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,832
10
85,664
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0565 """ import sys from sys import stdin input = stdin.readline def main(args): pastas = [int(input()) for _ in range(3)] drinks = [int(input()) for _ in range(2)] total = min(pastas) + min(drinks) - 50 print(total) if __name__ == '__main__': main(sys.argv[1:]) ```
output
1
42,832
10
85,665
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,833
10
85,666
"Correct Solution: ``` a=[int(input())for _ in[0]*5] print(min(a[:3])+min(a[3:])-50) ```
output
1
42,833
10
85,667
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,834
10
85,668
"Correct Solution: ``` import sys import math p1=int(input()) p2=int(input()) p3=int(input()) j1=int(input()) j2=int(input()) p_min=min(p1,p2,p3) J_min=min(j1,j2) min_sum=p_min+J_min-50 print(min_sum) ```
output
1
42,834
10
85,669
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,835
10
85,670
"Correct Solution: ``` def main(): a = int(input()) b = int(input()) c = int(input()) d = int(input()) e = int(input()) ans = -50 if a <= b: if a <= c: ans += a else: ans += c else: if b <= c: ans += b else: ans += c if d <= e: ans += d else: ans += e print(ans) main() ```
output
1
42,835
10
85,671
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,836
10
85,672
"Correct Solution: ``` num_list = [] daikin = 0 for num in range(3): i = int(input()) num_list.append(i) num_list.sort() daikin += num_list[0] num_list = [] for num1 in range(2): i = int(input()) num_list.append(i) num_list.sort() daikin += num_list[0] daikin -= 50 print(daikin) ```
output
1
42,836
10
85,673
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,837
10
85,674
"Correct Solution: ``` menu = [] for _ in range(5): price = int(input()) menu.append(price) pasta = menu[:3] drink = menu[3:] print(min(pasta) + min(drink) - 50) ```
output
1
42,837
10
85,675
Provide a correct Python 3 solution for this coding contest problem. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848
instruction
0
42,838
10
85,676
"Correct Solution: ``` # AOJ 0565: Lunch # Python3 2018.6.30 bal4u p = [int(input()) for i in range(5)] print(min(p[:3])+min(p[3:])-50) ```
output
1
42,838
10
85,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848 Submitted Solution: ``` a=[int(input()) for i in range(5)] print(min(a[:3])+min(a[3:5])-50) ```
instruction
0
42,840
10
85,680
Yes
output
1
42,840
10
85,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen. Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day. output Output the minimum price of the set menu for the day in one line. Example Input 800 700 900 198 330 Output 848 Submitted Solution: ``` print(min(int(input()),int(input()),int(input())) + min(int(input()),int(input())) - 50) ```
instruction
0
42,841
10
85,682
Yes
output
1
42,841
10
85,683
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,005
10
86,010
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` R=lambda:map(int,input().split()) n = int(input ()) a=list(R()) q =int(input()) p=[] ax= [-1]*n for _ in range (q):p.append(list (R())) temp=0 for i in range(q-1,-1,-1): if p[i][0]==2:temp = max(temp,p[i][1]) elif ax[p[i][1]-1]==-1:ax[p[i][1]-1] = max(temp,p[i][2]) for i in range (0,n): if ax[i]==-1:print(max(temp,a[i]),end=" ") else:print(ax[i],end=" ") ```
output
1
43,005
10
86,011
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,006
10
86,012
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` import sys import bisect input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = [0] * n q = int(input()) x = [] t = [] for i in range(q): inp = list(map(int, input().split())) if len(inp) == 2: x.append(inp[1]) t.append(i) else: p, z = inp[1:] p -= 1 b[p] = i a[p] = z if len(x) > 1: for i in range(len(x) - 2, -1, -1): x[i] = max(x[i], x[i + 1]) for i in range(n): idx = bisect.bisect_left(t, b[i]) if idx < len(x): print(max(a[i], x[idx]), end=' ') else: print(a[i], end=' ') print() ```
output
1
43,006
10
86,013
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,007
10
86,014
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` n = int(input()) a = [int(item) for item in input().split()] q = int(input()) qu = list() an = [-1]*n m = 0 for i in range(q): qu.append(tuple(map(int, input().split()))) for i in range(q): if qu[q-i-1][0] == 2: m = max(m, qu[q-i-1][1]) else: if an[qu[q-i-1][1]-1] == -1: an[qu[q-i-1][1]-1] = max(m, qu[q-i-1][2]) for i in range(n): if an[i] == -1: an[i] = max(m, a[i]) print(*an) ```
output
1
43,007
10
86,015
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,008
10
86,016
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` n = int(input()) lis=list(map(int,input().split())) lis=[[0,i] for i in lis] k = int(input()) li=[] m=0 for i in range(k): li.append(list(map(int,input().split()))) for i in range(k): if len(li[k-i-1])==2: m=max(li[k-i-1][1],m) else: if lis[li[k-i-1][1]-1][0]==0: lis[li[k-i-1][1]-1][0]=1 lis[li[k-i-1][1]-1][1]=max(m,li[k-i-1][2]) for i in range(n): if lis[i][0]==0: lis[i][1]=max(m,lis[i][1]) for i in range(n): print(lis[i][1],end=' ') ```
output
1
43,008
10
86,017
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,009
10
86,018
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` import sys in_file = sys.stdin n = int(in_file.readline().strip()) a = list(map(int, in_file.readline().strip().split())) q = int(in_file.readline().strip()) ls = [list(map(int, in_file.readline().strip().split())) for _ in range(q)] mxs = [-1]*q mxs[-1] = ls[-1][1] if ls[-1][0] == 2 else -1 for i in range(q-2, -1, -1): mxs[i] = max(mxs[i+1], ls[i][1] if ls[i][0] == 2 else -1) o = [max(mxs[0], x) for x in a] for i in range(q): if ls[i][0] != 1: continue p, x = ls[i][1:] o[p-1] = max(x, mxs[i]) sys.stdout.write(" ".join(map(str, o))) sys.stdout.flush() ```
output
1
43,009
10
86,019
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,010
10
86,020
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` n = int(input()) arr = list(map(int,input().rstrip().split())) q = int(input()) events = [] for i in range(q) : a = list(map(int,input().rstrip().split())) events.append(a) changes = {} for i in range(q) : if (events[i][0]== 1) : if events[i][1] not in changes.keys() : changes.update({events[i][1] : i}) else : changes[events[i][1]] = i max_payoff = {} for i in changes.keys() : max_payoff.update({changes[i] : 0}) max_pay = 0 for i in range(q-1,-1,-1) : if (events[i][0]== 2) : if (max_pay < events[i][1]) : max_pay = events[i][1] if i in max_payoff.keys() : max_payoff[i] = max_pay for i in range(1,len(arr)+1) : if (i in changes.keys()) : arr[i-1] = max(max_payoff[changes[i]], events[changes[i]][2]) elif (arr[i-1] < max_pay) : arr[i-1] = max_pay # print(events) # print(changes) for i in arr : print(i,end=' ') print() ```
output
1
43,010
10
86,021
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,011
10
86,022
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` n = int(input()) sp = list(map(int, input().split())) m = int(input()) pos = [-1] * (n + 1) m1 = 0 mem = [] for i in range(m): sp1 = list(map(int, input().split())) mem.append(sp1) if sp1[0] == 1: sp[sp1[1] - 1] = sp1[2] pos[sp1[1] - 1] = i else: m1 = max(m1, sp1[1]) maxs = [-1] * (m + 1) for i in range(m - 1, -1, -1): sp1 = mem[i] if (sp1[0] == 2): if (i == m - 1 or sp1[1] > maxs[i + 1]): maxs[i] = sp1[1] else: maxs[i] = maxs[i + 1] else: maxs[i] = maxs[i + 1] for i in range(n): if pos[i] != -1 and sp[i] < maxs[pos[i]]: sp[i] = maxs[pos[i]] elif pos[i] == -1: sp[i] = max(sp[i], maxs[0]) print(*sp) ```
output
1
43,011
10
86,023
Provide tags and a correct Python 3 solution for this coding contest problem. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
instruction
0
43,012
10
86,024
Tags: binary search, brute force, data structures, sortings Correct Solution: ``` n = int(input()) a = [int(s) for s in input().split()] q = int(input()) b = [None]*n rnd = 0 xs = [] for i in range(q): qi = [int(s) for s in input().split()] if qi[0] == 1: b[qi[1]-1] = (qi[2], rnd) else: xs.append(qi[1]) rnd += 1 maxx = 0 if xs: maxx = xs[-1] for i in range(len(xs)-2, -1, -1): if xs[i] < maxx: xs[i] = maxx else: maxx = xs[i] xs.append(0) for i in range(n): if not b[i]: a[i] = max(maxx, a[i]) else: a[i] = max(b[i][0], xs[b[i][1]]) print(*a) ```
output
1
43,012
10
86,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` n=int(input()) init=[-1]+[int(x) for x in input().split()] Q=[tuple(map(int,input().split())) for q in range(int(input()))] p=[-1]*(n+1) qmax=0 for i in range(1,len(Q)+1): q1=Q[-i] if q1[0]==2: qmax=max(qmax,q1[1]) else: if p[q1[1]]==-1: p[q1[1]]=max(qmax,q1[2]) for i in range(1,n+1): if p[i]==-1: p[i]=max(init[i],qmax) print(*p[1:]) ```
instruction
0
43,013
10
86,026
Yes
output
1
43,013
10
86,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` from sys import stdin input = stdin.readline n = int(input()) a = [int(i) for i in input().split()] q = int(input()) payoff = [0]*q a_receipt = [0]*n for _ in range(q): pay = [int(i) for i in input().split()] if pay[0] == 1: a[pay[1]-1] = pay[2] a_receipt[pay[1]-1] = _ else: payoff[_] = pay[1] max_payoff = 0 for i in range(q): max_payoff = max([max_payoff, payoff[q-i-1]]) payoff[q-i-1] = max_payoff for i in range(n): print(max([a[i], payoff[a_receipt[i]]]), end = ' ') ```
instruction
0
43,014
10
86,028
Yes
output
1
43,014
10
86,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def toord(c): return ord(c)-ord('a') def lcm(a, b): return a*b//lcm(a, b) mod = 998244353 INF = float('inf') from math import factorial, sqrt, ceil, floor, gcd from collections import Counter, defaultdict, deque from heapq import heapify, heappop, heappush # ------------------------------ # f = open('./input.txt') # sys.stdin = f from bisect import bisect_left def main(): n = N() arr = RLL() q = N() rec = [] recp = [] alp = [-1]*(n+1) for i in range(q): now = RLL() if now[0]==1: p, x = now[1: ] arr[p-1] = x alp[p-1] = i else: x = now[1] while rec and x>=rec[-1]: rec.pop() recp.pop() rec.append(x) recp.append(i) if len(rec)==0: print(*arr) exit() for i in range(n): p = bisect_left(recp, alp[i]) if p<len(rec): arr[i] = max(arr[i], rec[p]) print(*arr) if __name__ == "__main__": main() ```
instruction
0
43,015
10
86,030
Yes
output
1
43,015
10
86,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` n, a, q = int(input()), [*map(int, input().split())], int(input()) ops = [] for i in range(q): t, *b = map(int, input().split()) ops.append((t, b)) b = [-1] * n m = -1 for op, ar in reversed(ops): if op == 2: m = max(m, ar[0]) else: p, x = ar p -= 1 if b[p] == -1: b[p] = max(x, m) print(' '.join(str(bi if bi != -1 else max(m, ai))for ai,bi in zip(a,b))) ```
instruction
0
43,016
10
86,032
Yes
output
1
43,016
10
86,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` # n,x,y=map(int,input().split()) # A=[int(i) for i in input().split()] # i=0 # flag=False # while(i<n): # pre=A[i] # if(i<x): # Bef=A[:i] # else: # Bef=A[i-x:i] # if(i+y+1>=n): # Aft=A[i+1:] # else: # Aft=A[i+1:i+1+y] # flag1=True # flag2=True # for k in range(len(Bef)): # if(Bef[k]<=pre): # flag1=False # break # for k in range(len(Aft)): # if(Aft[k]<=pre): # flag2=False # break # if(flag1 and flag2): # print(i+1) # break # else: # i+=1 # h,l=map(int,input().split()) # num=(l**2)-(h**2) # den=2*h # print(num/den) n=int(input()) A=[int(i) for i in input().split()] q=int(input()) arr=[0]*q maxe=0 ind=0 temp=[] for i in range(q): arr[i]=[int(k) for k in input().split()] if(arr[i][0]==2): if(arr[i][1]>=maxe): maxe=arr[i][1] ind=i if(arr[i][0]==1): temp.append((i,arr[i][1],arr[i][2])) # print(temp) # print(maxe) # print(ind) for i in range(n): if(A[i]<maxe): A[i]=maxe for i in range(len(temp)): if(temp[i][0]>ind): A[temp[i][1]-1]=temp[i][2] else: if(temp[i][2]>maxe): A[temp[i][1]-1]=temp[i][2] else: A[temp[i][1]-1]=maxe print(*A) ```
instruction
0
43,017
10
86,034
No
output
1
43,017
10
86,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` n=int(input()) bal=list(map(int,input().split())) q=int(input()) while(q>0): x=list(map(int,input().split())) if(x[0]==1): bal[x[1]-1]=x[2] else: for i in bal: if(i<x[1]): i=x[1] else: break q=q-1 for j in range(0,n): print(bal[j],end=" ") ```
instruction
0
43,018
10
86,036
No
output
1
43,018
10
86,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` import sys input=sys.stdin.buffer.readline def queries(seg_tree,l,r): maxi=0 while(l<r): if(l%2==1): maxi=max(maxi,seg_tree[l]) l+=1 elif(r%2==0): maxi=max(maxi,seg_tree[r]) r-=1 l//=2 r//=2 maxi=max(maxi,seg_tree[l]) return maxi n=int(input()) a=list(map(int,input().split())) q=int(input()) seg_tree=[-1 for i in range(2*q)] indx=[0 for i in range(n)] for i in range(q): b=list(map(int,input().split())) if(b[0]==1): a[b[1]-1]=b[2] indx[b[1]-1]=i else: seg_tree[q+i]=b[1] for i in range(q-1,0,-1): seg_tree[i]=max(seg_tree[2*i],seg_tree[2*i+1]) for i in range(n): a[i]=max(a[i],queries(seg_tree,indx[i]+q,2*q-1)) print(*a) ```
instruction
0
43,019
10
86,038
No
output
1
43,019
10
86,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have. Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt. You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events. Input The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens. The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens. The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events. Each of the next q lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x. Output Print n integers — the balances of all citizens after all events. Examples Input 4 1 2 3 4 3 2 3 1 2 2 2 1 Output 3 2 3 4 Input 5 3 50 2 1 10 3 1 2 0 2 8 1 3 20 Output 8 8 20 8 10 Note In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4 In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) def toord(c): return ord(c)-ord('a') def lcm(a, b): return a*b//lcm(a, b) mod = 998244353 INF = float('inf') from math import factorial, sqrt, ceil, floor, gcd from collections import Counter, defaultdict, deque from heapq import heapify, heappop, heappush # ------------------------------ # f = open('./input.txt') # sys.stdin = f from bisect import bisect_left def main(): n = N() arr = RLL() q = N() rec = [] recp = [] alp = [-1]*(n+1) for i in range(q): now = RLL() if now[0]==1: p, x = now[1: ] arr[p-1] = x alp[p-1] = i else: x = now[1] while rec and x>=rec[-1]: rec.pop() recp.pop() rec.append(x) recp.append(i) if len(rec)==0: print(*arr) exit() for i in range(n): p = bisect_left(recp, alp[i]) ma = rec[min(p, len(recp)-1)] arr[i] = max(arr[i], ma) print(*arr) if __name__ == "__main__": main() ```
instruction
0
43,020
10
86,040
No
output
1
43,020
10
86,041
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,085
10
86,170
Tags: greedy, implementation, sortings Correct Solution: ``` n,m = [int(t) for t in input().split()] tags = [int(t) for t in input().split()] tags.sort() #ascending fruits = {} for _ in range(m): fruit = input() if fruit not in fruits: fruits[fruit] = 1 else: fruits[fruit] += 1 counts = [] for k in fruits: counts.append(fruits[k]) counts.sort(reverse=True) minimum = 0 for i in range(len(counts)): minimum += counts[i] * tags[i] maximum = 0 for i in range(len(counts)): maximum += counts[i] * tags[len(tags) - i - 1] print(minimum, maximum) ```
output
1
43,085
10
86,171
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,086
10
86,172
Tags: greedy, implementation, sortings Correct Solution: ``` n,m=map(int,input().split()) m1=list(map(int,input().split())) l1=[] l2=[] for i in range(m): l1.append(input()) l3=list(set(l1)) for i in range(len(l3)): l2.append(l1.count(l3[i])) m1.sort() l2.sort(reverse=True) j=0 s1=0 for i in range(len(l2)): s1=s1+l2[i]*m1[j] j=j+1 j=0 s2=0 m1.sort(reverse=True) for i in range(len(l2)): s2=s2+l2[i]*m1[j] j=j+1 print(s1,s2) ```
output
1
43,086
10
86,173
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,087
10
86,174
Tags: greedy, implementation, sortings Correct Solution: ``` # -*- coding: utf-8 -*- from collections import Counter n,m = map(int,input().split()) x = sorted(list(map(int,input().split()))) y= list(input() for j in range(m)) k,a,b = Counter(y),0,0 for i in range(len(k)): a += list(sorted(k.values()))[::-1][i]*x[i] b += list(sorted(k.values()))[::-1][i]*x[::-1][i] print(a,b) ```
output
1
43,087
10
86,175
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,088
10
86,176
Tags: greedy, implementation, sortings Correct Solution: ``` n,m=map(int,input().split()) a=sorted(map(int,input().split())) q={} for i in range(m): o=input() if o in q:q[o]+=1 else:q[o]=1 w=sorted(q[i] for i in q)[::-1] e,r=0,0 for i in range(len(w)): e+=w[i]*a[i] r+=w[i]*a[n-1-i] print(e,r) ```
output
1
43,088
10
86,177
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,089
10
86,178
Tags: greedy, implementation, sortings Correct Solution: ``` from collections import Counter n,m = map(int,input().split()) a = sorted(map(int,input().split())) fruits = Counter([input() for i in range(m)]) fruits = sorted([fruits[x] for x in fruits]) k = len(fruits) def dot(a,b): ans = 0 for i in range(len(a)): ans += a[i]*b[i] return ans hi = dot(fruits,a[-k:]) lo = dot(fruits[::-1],a[:k]) print(lo,hi) ```
output
1
43,089
10
86,179
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,090
10
86,180
Tags: greedy, implementation, sortings Correct Solution: ``` #!/usr/bin/env python3 n, m = tuple(map(int, input().split())) prices = sorted(list(map(int, input().split()))) fruits = {} for i in range (m): fruit = input() if fruit in fruits: fruits[fruit] += 1 else: fruits[fruit] = 1 fruitcount = sorted(list(fruits.values())) minsum = 0 maxsum = 0 for i in range (len(fruitcount)): minsum += fruitcount[-i - 1] * prices[i] maxsum += fruitcount[-i - 1] * prices[-i - 1] print(minsum, maxsum) ```
output
1
43,090
10
86,181
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,091
10
86,182
Tags: greedy, implementation, sortings Correct Solution: ``` import sys import math n, m = [int(x) for x in (sys.stdin.readline()).split()] ni = [int(x) for x in (sys.stdin.readline()).split()] d = dict() for i in range(m): st = (sys.stdin.readline()).split()[0] if st in d: d[st] += 1 else: d[st] = 1 ni.sort() ls = list(d.values()) ls.sort(reverse = True) j = 0 smin = 0 for i in ls: smin += ni[j] * i j += 1 smax = 0 j = n - 1 for i in ls: smax += ni[j] * i j -= 1 print(smin, smax) ```
output
1
43,091
10
86,183
Provide tags and a correct Python 3 solution for this coding contest problem. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30
instruction
0
43,092
10
86,184
Tags: greedy, implementation, sortings Correct Solution: ``` a=input() a=a.split() p=input() p=p.split() r=[] for k in range (int(a[1])): b=input() r.append(b) t=[] y=1 s=0 pu=0 yo=len(r) r.sort() MAYOR=0 MENOR=0 while s<yo: ve=r.count(r[0]) t.append(ve) while pu<ve: pu=pu+1 r.remove(r[0]) yo=yo-pu pu=0 t.sort(reverse=True) if len(p)<=len(t): menor=len(p) else: menor=len(t) for yonax in range (1,len(p)): for carol in range (len(p)-yonax): if int(p[carol])>int(p[carol+1]): ee=int(p[carol]) p[carol]=int(p[carol+1]) p[carol+1]=ee for yo in range (menor): aa=int(p[yo])*int(t[yo]) MENOR=MENOR+aa for alexandra in range (1,len(p)): for ferder in range (len(p)-alexandra): if int(p[ferder+1]) >int(p[ferder]): ee=int(p[ferder]) p[ferder]=int(p[ferder+1]) p[ferder+1]=ee for M in range (menor): a=int(p[M])*int(t[M]) MAYOR=MAYOR+a print(MENOR,MAYOR) ```
output
1
43,092
10
86,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` import re in1 = [int(x) for x in re.split("\\s", input())] in2 = [int(x) for x in re.split("\\s", input())] words = [] count = [] for x in range(in1[1]): inX = input() if inX not in words: words.append(inX) count.append(1) else: count[words.index(inX)] += 1 count.sort() count.reverse() in2.sort() y = 0 totalA = 0 totalB = 0 for x in count: totalA += x*in2[y] y += 1 y = 0 in2.reverse() for x in count: totalB += x*in2[y] y += 1 print(str(totalA) + " " + str(totalB)) ```
instruction
0
43,093
10
86,186
Yes
output
1
43,093
10
86,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` n,m = map(int,input().split()) ll = list(map(int, input().split())) ll = sorted(ll) Frukt = [] Frukt1 = [0] * m for i in range(m): q = False l = input().strip() for j in range(len(Frukt)): if Frukt[j] == l: Frukt1[j] += 1 q = True break if q == False: Frukt.append(l) Frukt1[len(Frukt)-1] += 1 Frukt1 = sorted(Frukt1) minn = 0 maxx = 0 k = -1 for i in range(1,len(Frukt1)+1): if Frukt1[-i] != 0: minn += ll[i-1] * Frukt1[-i] maxx += ll[k] * Frukt1[-i] k -= 1 print(minn,maxx) ```
instruction
0
43,094
10
86,188
Yes
output
1
43,094
10
86,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` n,m=map(int,input().split()) from collections import Counter price=sorted([int(i) for i in input().split()]) price1=sorted(price,reverse=True) l=[input() for i in range(m)] c=Counter(l) l1=[] mini=0 for i in c: l1.append(c[i]) #l2=sorted(l1) l3=sorted(l1,reverse=True) for i in range(len(c)): mini+=l3[i]*price[i] maxi=0 for i in range(len(c)): maxi+=l3[i]*price1[i] print(mini,maxi) ```
instruction
0
43,095
10
86,190
Yes
output
1
43,095
10
86,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` from collections import Counter n,m = map(int,input().split()) prices = list(map(int,input().split())) fruits = [] for i in range(m): fruit = str(input()) fruits.append(fruit) freq = Counter(fruits) prices = sorted(prices) maximum = 0 minimum = 0 freq = sorted(freq.items(), key=lambda x:x[1], reverse = True) i = 0 for fruit,amnt in freq: maximum += amnt * prices[~(i)] minimum += amnt * prices[i] i += 1 ans = [minimum, maximum] for i in ans: print(i,end=' ') ```
instruction
0
43,096
10
86,192
Yes
output
1
43,096
10
86,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` n, m = map(int, input().split()) x = sorted(list(map(int, input().split()))) a = 26 * [0] for i in range(m): fruit = input() a[ord(fruit[0]) - 97] += 1 a.sort(reverse=True) minimum, maximum = 0, 0 for j in range(26): try: minimum += a[j] * x[j] except IndexError: break x.sort(reverse=True) for k in range(26): try: maximum += a[k] * x[k] except IndexError: break print(minimum, maximum) ```
instruction
0
43,097
10
86,194
No
output
1
43,097
10
86,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` n, m = map(int, input().split()) x = sorted(list(map(int, input().split()))) a = [] for i in range(m): fruit = input() a.append(fruit) b = list(set(a)) c = [] for i in range(len(b)): c.append(a.count(b[i])) c.sort(reverse=True) minimum, maximum = 0, 0 for j in range(26): try: minimum += c[j] * x[j] except IndexError: break x.sort(reverse=True) for k in range(26): try: maximum += c[k] * x[k] except IndexError: break print(minimum, maximum) ```
instruction
0
43,098
10
86,196
No
output
1
43,098
10
86,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` k=0 r=0 n, m = map(int, input().split()) pt = sorted(map(int, input().split()))[:n] ar = list(set([input() for _ in range(m)])) for i in range(0,len(ar)): k+=pt[i] for i in range(n-1,n-len(ar)-1,-1): r+=pt[i] j=(m-len(ar)) if j>0: k+=pt[0] r+=pt[n-1] print(k,r) ```
instruction
0
43,099
10
86,198
No
output
1
43,099
10
86,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Examples Input 5 3 4 2 1 10 5 apple orange mango Output 7 19 Input 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Output 11 30 Submitted Solution: ``` x = input().split() n = int(x[0]) m = int(x[1]) y = input().split() for i in range(0,n): y[i] = int(y[i]) y.sort() y2 = y[::-1] D = {} for i in range(0,m): x = input() if x in D: D[x] += 1 else: D[x] = 1 T = list(D.values()) T = list(reversed(T)) best = 0 for i in T: best += y[0]*i y.remove(y[0]) worst = 0 for i in T: worst += y2[0]*i y2.remove(y2[0]) print(best,worst) ```
instruction
0
43,100
10
86,200
No
output
1
43,100
10
86,201
Provide tags and a correct Python 3 solution for this coding contest problem. Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109). Output Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4. Examples Input 1 1 3 4 Output 3 Input 6 2 1 1 Output 1 Input 4 4 4 4 Output 0 Input 999999999 1000000000 1000000000 1000000000 Output 1000000000 Note In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
instruction
0
43,456
10
86,912
Tags: brute force, implementation Correct Solution: ``` #!/usr/bin/env python3 n, a, b, c = map(int, input().split()) k = 4 - n%4 if k == 1: print(min(a, b + c, 3*c, )) elif k == 2: print(min(2*a, b, 2*c)) elif k == 3: print(min(3*a, a + b, c)) else: print(0) ```
output
1
43,456
10
86,913
Provide tags and a correct Python 3 solution for this coding contest problem. Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109). Output Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4. Examples Input 1 1 3 4 Output 3 Input 6 2 1 1 Output 1 Input 4 4 4 4 Output 0 Input 999999999 1000000000 1000000000 1000000000 Output 1000000000 Note In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
instruction
0
43,457
10
86,914
Tags: brute force, implementation Correct Solution: ``` n, a, b, c = map(int, input().split()) n = (4 - n % 4) % 4 print([0, min(a, b + c, 3 * c), min(2 * a, b, 2 * c), min(3 * a, a + b, c)][n]) ```
output
1
43,457
10
86,915
Provide tags and a correct Python 3 solution for this coding contest problem. Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109). Output Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4. Examples Input 1 1 3 4 Output 3 Input 6 2 1 1 Output 1 Input 4 4 4 4 Output 0 Input 999999999 1000000000 1000000000 1000000000 Output 1000000000 Note In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
instruction
0
43,458
10
86,916
Tags: brute force, implementation Correct Solution: ``` n,a,b,c=[int(i) for i in input().split()] dp=[1<<1000]*10000 dp[0]=0 ans=1<<1000 cost=1<<1000 for i in range(10000): if i>=1 : dp[i]=min(dp[i-1]+a,dp[i]) if i>=2 : dp[i]=min(dp[i-2]+b,dp[i]) if i>=3 : dp[i]=min(dp[i-3]+c,dp[i]) if (i+n)%4==0: if cost>dp[i]: cost=dp[i] ans=i print (cost) ```
output
1
43,458
10
86,917
Provide tags and a correct Python 3 solution for this coding contest problem. Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 109). Output Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4. Examples Input 1 1 3 4 Output 3 Input 6 2 1 1 Output 1 Input 4 4 4 4 Output 0 Input 999999999 1000000000 1000000000 1000000000 Output 1000000000 Note In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
instruction
0
43,459
10
86,918
Tags: brute force, implementation Correct Solution: ``` n, a, b, c = map(int, input().split()) if n % 4 == 0: print (0) else: inf = 1000000000 dp = [inf for x in range(20)] dp[n % 4] = 0 sol = inf for i in range(1 + (n % 4), 20): dp[i] = min(dp[i-1] + a, min(dp[i-2] + b, dp[i-3] + c)) if i % 4 == 0: sol = min(sol, dp[i]) print (sol) ```
output
1
43,459
10
86,919