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
Provide a correct Python 3 solution for this coding contest problem. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216
instruction
0
28,020
10
56,040
"Correct Solution: ``` n,*l=map(int,open(0).read().split()) a=1000 for s,t in zip(l,l[1:]): a+=a//s*max(t-s,0) print(a) ```
output
1
28,020
10
56,041
Provide a correct Python 3 solution for this coding contest problem. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216
instruction
0
28,021
10
56,042
"Correct Solution: ``` n = int(input()) a = list(map(int ,input().split())) x = 1000 for i in range(n-1): l = a[i] r = a[i+1] if (l < r): k = x//l x %= l x += k*r print(x) ```
output
1
28,021
10
56,043
Provide a correct Python 3 solution for this coding contest problem. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216
instruction
0
28,022
10
56,044
"Correct Solution: ``` N=int(input()) A=list(map(int,input().split())) ans=1000 for i in range(N-1): if A[i]>=A[i+1]: pass else: T=ans//A[i] ans+=T*(A[i+1]-A[i]) print(ans) ```
output
1
28,022
10
56,045
Provide a correct Python 3 solution for this coding contest problem. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216
instruction
0
28,023
10
56,046
"Correct Solution: ``` n = input() li = list(map(int,input().split())) orl = 1000 for i in range(len(li)-1): if li[i] < li[i+1]: orl = int(orl/li[i]) * (li[i+1]) + (orl - li[i] * int(orl/li[i])) print(orl) ```
output
1
28,023
10
56,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` n = int(input()) A = list(map(int, input().split())) m = 1000 for i in range(n-1): t = m//A[i] if A[i] < A[i+1]: m -= t*A[i] m += t*A[i+1] print(m) ```
instruction
0
28,024
10
56,048
Yes
output
1
28,024
10
56,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` #!/usr/bin/env python3 n, *a = map(int, open(0).read().split()) c = 1000 for i in range(1, n): if a[i] > a[i - 1]: c = c // a[i - 1] * a[i] + c % a[i - 1] print(c) ```
instruction
0
28,025
10
56,050
Yes
output
1
28,025
10
56,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) t=1000 for i in range(n-1): if a[i]<a[i+1]: tmp=t//a[i] tmp1=tmp*a[i+1] t+=tmp1-tmp*a[i] print(t) ```
instruction
0
28,026
10
56,052
Yes
output
1
28,026
10
56,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) now = 1000 for i in range(n-1): if (a[i] < a[i+1]): now += (now // a[i]) * (a[i+1] - a[i]) print(now) ```
instruction
0
28,027
10
56,054
Yes
output
1
28,027
10
56,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` def main(): n = int(input()) A = list(map(int,input().split())) flg = 0 MIN = [] MAX = [] i = 0 while i <n-1: mi = A[i] ma = A[i] if flg == 0: for j in range(i+1,n): mi = min(mi,A[j]) if A[i] < A[j]: flg = 1 MIN.append(mi) i = j if j == n-1: MAX.append(A[j]) break elif j == n-1: i = j break if flg == 1: for j in range(i+1,n): ma = max(A[i],ma) if A[i] > A[j]: flg = 0 MAX.append(ma) i = j break elif j == n-1: MAX.append(ma) i = j break s = 1000 for i,j in zip(MIN,MAX): t = s//i s -= t*i s += t*j print(s) main() ```
instruction
0
28,028
10
56,056
No
output
1
28,028
10
56,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` N = int(input()) A = list(map(int,input().split())) ans = 1000 s = A[0] S = A[0] for i in range(1,N): if s >= A[i]: s = A[i] elif S <= A[i]: S = A[i] else: t = ans//s ans = ans % s ans += t*S if i == N-1: break s,S = A[i+1],A[i+1] if i == N-1 and s < A[i]: t = ans//s ans = ans % s ans += t*A[i] print(ans) ```
instruction
0
28,029
10
56,058
No
output
1
28,029
10
56,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) ans = 1000 stock = 0 for i, num in enumerate(a): if i == n-1: ans += stock*num else: if num > a[i+1]: ans += stock*num stock = 0 elif num < a[i+1]: stock = ans//num ans %= num print(ans) ```
instruction
0
28,030
10
56,060
No
output
1
28,030
10
56,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints * 2 \leq N \leq 80 * 100 \leq A_i \leq 200 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Examples Input 7 100 130 130 130 115 115 150 Output 1685 Input 6 200 180 160 140 120 100 Output 1000 Input 2 157 193 Output 1216 Submitted Solution: ``` from functools import lru_cache n= int(input()) arr = [int(x) for x in input().strip().split()] @lru_cache(None) def helper(i, mon, stk): if i==len(arr): return mon ans = helper(i+1, mon, stk) buy = 1 while True: if arr[i]*buy<=mon: ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy)) else: break buy += 1 for s in range(1, stk+1): ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s)) return ans print(helper(0, 1000, 0)) ```
instruction
0
28,031
10
56,062
No
output
1
28,031
10
56,063
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,538
10
57,076
Tags: brute force, dp, greedy Correct Solution: ``` N = int(input()) winsell = (N)*[-1] pow = (2001)*[-1]; ans = int(0) for i in range(0,N): S, x = input().split() x = int(x) if S == "win": winsell[i] = x else: pow[x] = i; for i in range(2000,-1,-1): if pow[i]!=-1 and pow[i]>0: b = bool(0) for j in range(pow[i] - 1,-1,-1): if winsell[j] != 2001: if winsell[j] == i: b = 1 ans+=2**i for k in range(j,pow[i]+1): winsell[k]=2001 else: b = 1 if b == 1: break print(ans) # Sun Mar 24 2019 15:47:08 GMT+0300 (MSK) ```
output
1
28,538
10
57,077
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,539
10
57,078
Tags: brute force, dp, greedy Correct Solution: ``` import math if __name__ == '__main__': n = int(input()) win = [[]] sell = [0]*5000 res = 0 for i in range(n): temp = input().split() s = temp[0] x = int(temp[1]) if s == "sell": sell[x] = i if s == "win": win.append([x, i]) used = [0]*5005 win.sort(reverse=True) for i in range(len(win)-1): temp = win[i] f = temp[0] idx = temp[1] sosatb = True for j in range(idx, sell[f]+1): if used[j] == 1: sosatb = False break if sell[f] > idx and sosatb: for j in range(idx,sell[f]+1): used[j] = 1 res += 2**f print(res) # Sun Mar 22 2020 19:03:13 GMT+0300 (MSK) ```
output
1
28,539
10
57,079
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,540
10
57,080
Tags: brute force, dp, greedy Correct Solution: ``` n = int(input()) dp = [0]*2001 ans = 0 for i in range(n): s = input().split() move = s[0] d = int(s[1]) if move == "win": dp[d] = ans + 2**d else: ans = max(ans, dp[d]) print(ans) # Thu Mar 26 2020 09:12:32 GMT+0300 (MSK) ```
output
1
28,540
10
57,081
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,541
10
57,082
Tags: brute force, dp, greedy Correct Solution: ``` n = int(input()) v = [0 for i in range(2006)] ans = 0 for i in range(n): s = input().split() x = int(s[1]) if s[0] == 'win': v[x] = ans + 2**x else: ans = max(ans,v[x]) print(ans) ```
output
1
28,541
10
57,083
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,542
10
57,084
Tags: brute force, dp, greedy Correct Solution: ``` import math n = int(input()) Size = 2002 dp = [0] * (Size) for i in range(0, Size, 1) : dp[i] = -1 dp[0] = 0 for i in range (1 , n+1 , 1): s = input() In = s.split() x = int(In[1]) x = x + 1 if In[0] == "win" : dp[x] = max(0, dp[0]) if In[0] == "sell" : if dp[x] != -1 : dp[0] = max(dp[0], dp[x] + 2**(x-1)) ans = 0 for i in range(0, Size, 1) : ans = max(ans, dp[i]) print(ans) # Sun Mar 22 2020 11:48:26 GMT+0300 (MSK) ```
output
1
28,542
10
57,085
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,543
10
57,086
Tags: brute force, dp, greedy Correct Solution: ``` n = (int)(input()) d = [0 for i in range(2333)] ans = 0 for i in range(0, n): s = input().split() x = (int)(s[1]) if s[0] == 'win': d[x] = 2 ** x + ans else: ans = max(ans, d[x]) print(ans) ```
output
1
28,543
10
57,087
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,544
10
57,088
Tags: brute force, dp, greedy Correct Solution: ``` n = int(input()) d = [0 for i in range(2009)] ans = 0 for i in range(n): s = input().split() x = int(s[1]) if s[0] == 'win': d[x] = ans+ 2**x else: ans = max(d[x], ans) print(ans) # Made By Mostafa_Khaled ```
output
1
28,544
10
57,089
Provide tags and a correct Python 3 solution for this coding contest problem. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
instruction
0
28,545
10
57,090
Tags: brute force, dp, greedy Correct Solution: ``` N=int(input()) dp=[0 for t in range(0,5008)] arr=[0 for t in range(0,2008)] for i in range(1,N+1): u,v=input().split() v=int(v) if u[0]=='w': arr[v]=i elif arr[v]!=0 : dp[i]=max(dp[i],dp[arr[v]-1]+(1<<v)) dp[i]=max(dp[i],dp[i-1]) print(dp[N]) ```
output
1
28,545
10
57,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` def intercept(x, y, a, b): return not (y < a or x > b) n = int(input()) day = [] intervalo = [] valor = [] for i in range(n): line = input() line = line.split(' ') act = line[0] val = int(line[1]) day.append(val) if (act == 'win'): continue for j in range(i): if (day[j] == val): intervalo.append([j, i]) valor.append([val, len(intervalo)-1]) valor.sort() ans = 0 used = list(range(len(intervalo)+1)) for i in range(len(used)): used[i] = False for i in range(len(valor)-1, -1, -1): ind = valor[i][1] x1 = intervalo[ind][0] y1 = intervalo[ind][1] pos = True for j in range(0, len(intervalo)): if (j == ind): continue if (used[j] and intercept(x1, y1, intervalo[j][0], intervalo[j][1])): pos = False if (pos): ans += 2**valor[i][0] used[ind] = True print(ans) ```
instruction
0
28,546
10
57,092
Yes
output
1
28,546
10
57,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` n = int(input()) op = [] cap = [] plc = {} for i in range(0, n): inp = input().split(" ") op.append(inp[0]) cap.append(int(inp[-1])) if op[i] == "sell": for j in range(0, i): if cap[j] == cap[i]: plc[cap[j]] = j f = [0]*(n+1) for i in range(2, n+1): f[i] = f[i-1] if op[i-1] == "sell" and cap[i-1] in plc: f[i] = max(f[i], f[plc[cap[i-1]]+1] + 2**cap[i-1]) print(f[-1]) ```
instruction
0
28,548
10
57,096
Yes
output
1
28,548
10
57,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` n = int(input()) a = [] for i in range(n): b = input().split() a.append(b) print(a) d = [0 for i in range(n)] for i in range(1,n): if 'win' in a[i]: for j in range(i): d[i] = max(d[i],d[j]) else: for j in range(i): if 'win' in a[j] and a[j][1] == a[i][1]: d[i] = max(d[i],d[j] + 2**int(a[i][1])) print(d[n-1]) ```
instruction
0
28,550
10
57,100
No
output
1
28,550
10
57,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` import collections import math n=int(input()) co=0 ans=0 ar=[co]*2001 pos=[co-1]*2001 for i in range (2001): ar[i]=[] for i in range (n): a,с=input().split() b=int(с) if (a=="win"): ar[b].append(i) else: pos[b]=i bg=5001 ls=-1 for i in range (2000,-1,-1): if (pos[i]>=0): for j in range (len(ar[i])-1,-1,-1): if (ar[i][j]<=pos[i]) and ((ar[i][j]>=ls) or (pos[i]<=bg)): ans+=2**i if (ar[i][j]<=bg): bg=ar[i][j] if (pos[i]>=ls): ls=pos[i] print (ans) # Sun Mar 25 2018 13:50:02 GMT+0300 (MSK) ```
instruction
0
28,551
10
57,102
No
output
1
28,551
10
57,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` n=int(input()) a=[] for i in range(n): b,c=input().split() c=int(c) a.append(list()) a[i].append(b) a[i].append(c) cur=-1 result=0 for i in range(n-1,-1,-1): if a[i][0]=="sell": if a[i][1]>cur: for j in range(i,-1,-1): if a[j][0]=="win" and a[j][1]==a[i][1]: cur=a[i][1] elif a[i][1]==cur: result=result+2**cur cur=-1 print(result) # Tue Mar 27 2018 20:51:57 GMT+0300 (MSK) ```
instruction
0
28,552
10
57,104
No
output
1
28,552
10
57,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0 Submitted Solution: ``` n=int(input()) a=[2*[0]for i in range(0,n)] for i in range(0,n): a[i]=list(map(str,input().split())) na=[0]*2001 for i in range(0,2001): na[i]=[] c=[0]*(n+1) for i in range(0, n): ind=int(a[i][1]) if a[i][0]=='win': na[ind].append(i+1) else: c[i+1]=ind dp=[0]*(n+1) for i in range(1,n+1): dp[i]=dp[i-1] if c[i]!=0 and len(na[c[i]])>0: l=0 r=len(na[c[i]]) while(r-l>1): mid=(r+l)/2 mid=int(mid) if na[c[i]][mid]>=i: r=mid else: l=mid if na[c[i]][l]>=i: continue if dp[i]<2**c[i]+dp[na[c[i]][l]-1]: dp[i] = 2 ** c[i] + dp[na[c[i]][l] - 1] print(dp[n]) ```
instruction
0
28,553
10
57,106
No
output
1
28,553
10
57,107
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,556
10
57,112
Tags: greedy Correct Solution: ``` a,b=[int(i) for i in input().split()] c=[int(i) for i in input().split()] sums=0 count=0 l=[] l1=[] for i in range(0,len(c)): if(c[i]<0): l.append(c[i]) count=count+1 else: l1.append(c[i]) sums=sums+c[i] if(count==0): s=sorted(c) if(b%2==0): pass else: s[0]=s[0]*(-1) print(sum(s)) else: if(count==b ): s=sorted(c) for i in range(0,count): s[i]=s[i]*(-1) print(sum(s)) elif(b<count): s=sorted(c) for i in range(0,b): s[i]=s[i]*(-1) print(sum(s)) else: g=b-count for i in range(0,len(l)): l[i]=l[i]*(-1) v=l+l1 z=sorted(v) if(g%2==0): pass else: z[0]=(z[0]*((-1)**(b-count))) print(sum(z)) ```
output
1
28,556
10
57,113
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,557
10
57,114
Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) L=sorted([int(i) for i in input().split()]) neg=sum(i<0 for i in L) if k>neg: L=sorted(abs(i) for i in L) if (k-neg)%2==1: L[0]=-L[0] else: for i in range(k): L[i]=-L[i] print(sum(L)) ```
output
1
28,557
10
57,115
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,558
10
57,116
Tags: greedy Correct Solution: ``` def solve(): n,k = map(int, input().split()) a = list(map(int, input().split())) i=0 j=0 while i<n and a[i] < 0 and j<k: a[i]*=(-1) i+=1 j+=1 #print(j) if j==k: print(sum(a)) return else: if not i==n: x = min(a[i], a[i-1]) j = k-j if not j%2 ==0: print(sum(a)-2*x) return else: print(sum(a)) else: x = a[n-1] j = k-j if not j%2 ==0: print(sum(a)-2*x) return else: print(sum(a)) try: solve() except: pass ```
output
1
28,558
10
57,117
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,559
10
57,118
Tags: greedy Correct Solution: ``` n,k=map(int,input().strip().split()) l=list(map(int,input().strip().split())) ne = [] po= [] zeros=0 for i in l: if i<0: ne.append(i) elif i ==0: zeros+=1 else: po.append(i) # ne.reverse() if zeros==n: po =[0] ne=[0] elif len(ne)==0: if k%2==0: pass else: if zeros>0: pass else: po[0]*=-1 else: if len(ne)<k: ne=[i*-1 for i in ne] k-=len(ne) ne=ne+po po=[] ne.sort() if zeros>0: k=0 else: if k%2==0: k=0 else: ne[0]*=-1 k=0 elif len(ne)==k: ne=[i*-1 for i in ne ] k=0 else: for i in range(0,k ): ne[i]*=-1 print(sum(ne) + sum(po)) ```
output
1
28,559
10
57,119
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,560
10
57,120
Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(len(a)): if (a[i]<0 and k>0): a[i]=a[i]*(-1) k=k-1 if (k<0): break if (k>=0 and k%2==0): print(sum(a)) elif (k>=0 and k%2!=0): print(sum(a)-2*min(a)) ```
output
1
28,560
10
57,121
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,561
10
57,122
Tags: greedy Correct Solution: ``` def inp(): return map(int, input().split()) def arr_inp(): return [int(x) for x in input().split()] n, k = inp() a = arr_inp() for i in range(n): if k == 0 or a[i] > 0: break a[i] *= -1 k-=1 if k%2: a[a.index(min(a))]*=-1 print(sum(a)) ```
output
1
28,561
10
57,123
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,562
10
57,124
Tags: greedy Correct Solution: ``` n, k = [int(i) for i in input().split()] sequence = [int(i) for i in input().split()] for i in range(len(sequence)): if(k == 0): break if(sequence[i] < 0): k-=1 sequence[i] = -sequence[i] else: break sequence.sort() if(k%2 != 0): sequence[0] = -sequence[0] print(sum(sequence)) ```
output
1
28,562
10
57,125
Provide tags and a correct Python 3 solution for this coding contest problem. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
instruction
0
28,563
10
57,126
Tags: greedy Correct Solution: ``` import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**7) # OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" mod=10**9 + 7 """ x_move=[-1,0,1,0,-1,1,1,-1] y_move=[0,1,0,-1,1,1,-1,-1] """ def ii(): return int(I().strip()) def li(): return list(map(int,I().strip().split())) def mi(): return map(int,I().strip().split()) def ncr(n, r): r = min(r, n-r) numer = reduce(op.mul, range(n, n-r, -1), 1) denom = reduce(op.mul, range(1, r+1), 1) return numer // denom def ispali(s): i=0 j=len(s)-1 while i<j: if s[i]!=s[j]: return False i+=1 j-=1 return True def isPrime(n): if n<=1: return False elif n<=2: return True else: for i in range(2,int(n**.5)+1): if n%i==0: return False return True def main(): n,k=mi() arr=li() for i in range(n): if arr[i]<=0: if i==n-1: if k%2: arr[i]*=-1 else: arr[i]*=-1 k-=1 else: if k%2: if i>0 and arr[i-1]*-1<=0: if arr[i-1]>=arr[i]: arr[i]*=-1 else: arr[i-1]*=-1 else: arr[i]*=-1 k=0 if k==0: break # print(arr) print(sum(arr)) if __name__ == '__main__': main() ```
output
1
28,563
10
57,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` #n=int(input()) n,k = map(int, input().strip().split(' ')) lst = list(map(int, input().strip().split(' '))) k1=k i=0 if n==1: print(lst[0]*((-1)**k)) else: while i<n: if lst[i]<=0: k1-=1 lst[i]=lst[i]*-1 i+=1 else: if i==0: if k1%2==0: break else: lst[i]=lst[i]*-1 break else: if lst[i-1]<lst[i]: if k1%2==0: break else: lst[i-1]=lst[i-1]*-1 break else: if k1%2==0: break else: lst[i]=lst[i]*-1 break if k1==0: break print(sum(lst)) ```
instruction
0
28,564
10
57,128
Yes
output
1
28,564
10
57,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): if k > 0 and a[i] < 0: a[i] *= -1 k -= 1 else: break if k % 2 == 1 and a[i] != 0: if i == 0 or a[i] < a[i - 1]: a[i] *= -1 else: a[i - 1] *= -1 print(sum(a)) ```
instruction
0
28,565
10
57,130
Yes
output
1
28,565
10
57,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n and k != 0: if a[i] < 0: k -= 1 ans += -a[i] else: if k % 2 == 0: k = 0 ans += a[i] else: k = 0 if i != 0: if -a[i-1] > a[i]: ans += -a[i] else: ans += 2*a[i-1] + a[i] else: ans += -a[i] i += 1 if i >= n: if k % 2 != 0: ans += 2*a[-1] for u in range(i, n): ans += a[u] print(ans) ```
instruction
0
28,566
10
57,132
Yes
output
1
28,566
10
57,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` n,k = map(int,input().split()) lst = list(map(int,input().split())) #print(sum(lst),min) #print(sum(lst)-81852) index= 0 while(index<n and lst[index]<0): index+=1 first_pos = index #print("index",index) if(k>=index): for i in range(first_pos): lst[i] = -lst[i] rem = k-(index) rem = rem%2 if(rem==0): #print("cse1",end=' ') print(sum(lst)) elif(first_pos==0): #print("cse2",end=' ') print(sum(lst)-2*lst[first_pos]) elif(first_pos==n): print(sum(lst)-2*lst[first_pos-1]) else: #print("cse3",end=' ') print(sum(lst)-2*min(lst[first_pos],lst[first_pos-1])) else: for i in range(k): lst[i] = -lst[i] print(sum(lst)) ```
instruction
0
28,567
10
57,134
Yes
output
1
28,567
10
57,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` n, k = map(int, input().split()) a = [int(i) for i in input().split()] total = 0 for i in range(n): first = a[i] if (i == n - 1 and first < 0 and k > 0 and k % 2 == 0): total += 2 * first if (i == 0): if (first > 0 and k % 2 == 1): total -= 2 * first elif (i > 0): prev = a[i - 1] if (first > 0 and prev < 0 and k % 2 == 1): total -= 2 * abs(min(first, prev)) if (k > 0 and first < 0): total += abs(first) k -= 1 else: total += first print (total) ```
instruction
0
28,568
10
57,136
No
output
1
28,568
10
57,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` n, k = input().split() n = int(n); k = int(k) a = [int(i) for i in input().split()] neg = True j = 0 for i in range(k): if j < n and a[j] <= 0 and neg: a[j] = -a[j] j += 1 else: neg = False if j >= n: j = n-1 a[j] = -a[j] print(sum(a)) ```
instruction
0
28,569
10
57,138
No
output
1
28,569
10
57,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` #n=int(input()) n,k = map(int, input().strip().split(' ')) lst = list(map(int, input().strip().split(' '))) k1=k i=0 while i<n: if lst[i]<=0: k1-=1 lst[i]=lst[i]*-1 i+=1 else: if i==0: if k1%2==0: break else: lst[i]=lst[i]*-1 break else: if lst[i-1]<lst[i]: if k1%2==0: break else: lst[i-1]=lst[i-1]*-1 break else: if k1%2==0: break else: lst[i]=lst[i]*-1 break if k1==0: break print(sum(lst)) ```
instruction
0
28,570
10
57,140
No
output
1
28,570
10
57,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly k changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly k changes. Input The first line contains two integers n and k (1 ≤ n, k ≤ 105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of n integers ai (|ai| ≤ 104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output In the single line print the answer to the problem — the maximum total income that we can obtain after exactly k changes. Examples Input 3 2 -1 -1 1 Output 3 Input 3 1 -1 -1 1 Output 1 Note In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. Submitted Solution: ``` import sys import math import itertools import collections def getdict(n): d = {} if type(n) is list or type(n) is str: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 else: d[t] = 1 return d def cdiv(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a*b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def revn(n): return int(str(n)[::-1]) def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True #arr =['v', '^', '>', '<'] n, k = mi() a = li() i = 0 if n == 1: print(a[0] * (-1) ** k) else: while i < n and i < k and a[i] < 0: a[i] *= -1 i += 1 if (k - i) % 2 == 0 or 0 in a: print(sum(a)) else: print(sum(a) - 2 * min(a[i], a[i + 1])) ```
instruction
0
28,571
10
57,142
No
output
1
28,571
10
57,143
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,981
10
57,962
"Correct Solution: ``` c = 0 s = 0 num = 0 while True: try: p, n = [int(x) for x in input().split(",")] s += p * n c += n num += 1 except: break print(s) av = c // num if c%num >= num//2: av +=1 print(av) ```
output
1
28,981
10
57,963
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,982
10
57,964
"Correct Solution: ``` ans_n=0 ans_k=0 count=0 while True: try: N=list(map(int,input().split(","))) ans_n +=N[0]*N[1] ans_k +=N[1] count +=1 except: print(ans_n) ans=ans_k/count if int(ans)+0.5<=ans: ans=int(ans+1) print(ans) break ```
output
1
28,982
10
57,965
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,983
10
57,966
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys import os import math import itertools prices = [] amounts = [] for s in sys.stdin: price, amount = map(int, s.split(',')) prices.append(price * amount) amounts.append(amount) print(sum(prices)) mean = sum(amounts) / len(amounts) + 0.5 print(int(mean)) ```
output
1
28,983
10
57,967
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,984
10
57,968
"Correct Solution: ``` # -*- coding: utf-8 -*- _sum = 0 _avg = 0 n = 0 while 1: try: _s, _a = [int(e) for e in input().split(',')] _sum += _s * _a _avg += _a n += 1 except: print(_sum) print(int(_avg / n + 0.5)) break ```
output
1
28,984
10
57,969
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,985
10
57,970
"Correct Solution: ``` total, num, cnt = 0, 0, 0 try: while True: n, m = map(int, input().split(",")) total += n*m num += m cnt += 1 except EOFError: print(total) n = num/cnt n = int(n) if n%1 < 0.5 else int(n)+1 print(n) ```
output
1
28,985
10
57,971
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,986
10
57,972
"Correct Solution: ``` cnt=0 sell_num=0 total=0 while True: try: t,s=map(int,input().split(",")) except: break cnt+=1 sell_num+=s total+=t*s print(total) print(int(sell_num/cnt+0.5)) ```
output
1
28,986
10
57,973
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,987
10
57,974
"Correct Solution: ``` from decimal import Decimal, ROUND_HALF_UP c = p = i = 0 while 1: try: v, n = map(int, input().split(",")) i += 1 c += n p += n * v except:break print(p) print(Decimal(c / i).quantize(Decimal('0'), rounding=ROUND_HALF_UP)) ```
output
1
28,987
10
57,975
Provide a correct Python 3 solution for this coding contest problem. Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is given across multiple lines. All values ​​entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100. Output Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place. Example Input 100,20 50,10 70,35 Output 4950 22
instruction
0
28,988
10
57,976
"Correct Solution: ``` price, num, c = 0, 0, 0 while True: try: p, n = map(float, input().split(',')) price += p * n num += n c += 1 except: print(int(price)) num /= c s = str(num).split('.') if int(s[1][0]) > 4: print(int(num) + 1) else: print(int(num)) break ```
output
1
28,988
10
57,977