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. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,320
10
100,640
"Correct Solution: ``` f=lambda:list(map(int,input().split())) f() print(sum(max(0,a-b)for a,b in zip(f(),f()))) ```
output
1
50,320
10
100,641
Provide a correct Python 3 solution for this coding contest problem. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800
instruction
0
50,455
10
100,910
"Correct Solution: ``` while 1: a, b, c, d, e = map(int, input().split()) if a == b == c == d == e == 0: break na, nb, nc = map(int, input().split()) if nc >= d: print(e * nc + b * nb + a * na) continue lst = [c] * nc + [b] * nb + [a] * na if na + nb + nc > d: print(min(sum(lst[:d]), e*d) + sum(lst[d:])) else: print(min(sum(lst), e*d)) ```
output
1
50,455
10
100,911
Provide a correct Python 3 solution for this coding contest problem. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800
instruction
0
50,456
10
100,912
"Correct Solution: ``` # AOJ 1509 Rental DVD Shop NEO # Python3 2018.7.13 bal4u while True: a, b, c, d, e = map(int, input().split()) if a == 0: break na, nb, nc = map(int, input().split()) if nc >= d: ans = e*nc + b*nb + a*na else: ans = c*nc + b*nb + a*na k = d-nc; if k <= nb: nb -= k; k = 0 else: k -= nb; nb = 0 if k <= na: na -= k else: na = 0 ans = min(ans, e*d + b*nb + a*na) print(ans) ```
output
1
50,456
10
100,913
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800 Submitted Solution: ``` if __name__ == "__main__": while True: a, b, c, d, e = list(map(int, input().strip("\n").split(" "))) if a == 0 : exit() na, nb, nc = list(map(int, input().strip("\n").split(" "))) #print("--------------------") #print("abcde:", a, b, c, d, e) #print("na,nb,nc:", na, nb, nc, d) p0 = na * a + nb * b + nc * c # wo set-wari if nc - d >= 0: # na1 = na # nb1 = nb p1 = na * a + nb * b + nc * e else: # nc - d < 0 d1 = d - nc # d1 > 0 if nb - d1 >= 0: p1 = na * a + (nb - d1) * b + d * e else: # nb - d1 < 0 d2 = d1 - nb # > 0 if na - d2 >= 0: p1 = na * (na - d2) + d * e else: p1 = p0 #print("p0", p0) #print("p1", p1) print(min(p0,p1)) ```
instruction
0
50,457
10
100,914
No
output
1
50,457
10
100,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800 Submitted Solution: ``` # Edit: 2014/10/13 # Lang: Python3 # Time: 00.xxs # File: pc1509.py if __name__ == "__main__": while True: a, b, c, d, e = list(map(int, input().strip("\n").split(" "))) if a == 0 : exit() na, nb, nc = list(map(int, input().strip("\n").split(" "))) print("--------------------") print("abcde:", a, b, c, d, e) print("na,nb,nc:", na, nb, nc, d) p0 = na * a + nb * b + nc * c # wo set-wari if nc - d >= 0: # na1 = na # nb1 = nb p1 = na * a + nb * b + nc * e else: # nc - d < 0 d1 = d - nc # d1 > 0 if nb - d1 >= 0: p1 = na * a + (nb - d1) * b + d * e else: # nb - d1 < 0 d2 = d1 - nb # > 0 if na - d2 >= 0: p1 = na * (na - d2) + d * e else: p1 = p0 print("p0", p0) print("p1", p1) """ nc1 = max(0, nc - d) if nc1 >= 0: # 1 nb1 = nb na1 = na p = na1 * a + nb1 * b + nc * e else: # 2 nc1 == 0 d1 = d - nc nb1 = max(0, nb - d1) if nb1 >= 0: #2.1 na1 = na p = na1 * a + nb1 * b + d * e else: #2.2 nb1 == 0 d2 = d1 - nb na1 = max(0, na - d2) if na1 >= 0: # 2.2.1 p = na1 * a + d * e #else # p = na * a + nb * b + nc * c print(p, p0) """ ```
instruction
0
50,458
10
100,916
No
output
1
50,458
10
100,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800 Submitted Solution: ``` # Edit: 2014/10/13 # Lang: Python3 # Time: 00.xxs # File: pc1509.py if __name__ == "__main__": while True: a, b, c, d, e = list(map(int, input().strip("\n").split(" "))) if a == 0: exit() na, nb, nc = list(map(int, input().strip("\n").split(" "))) nd = d # print("--------------------") # print("abcde:", a, b, c, d, e) # print("na,nb,nc:", na, nb, nc, d) p0 = na * a + nb * b + nc * c if na + nb + nc < nd: p1 = p0 # print(p0) else: if nc >= nd: p1 = na * a + nb * b + nc * e else: nd1 = d - nc if nb >= nd1: p1 = na * a + (nb - nd1) * b + nd * e else: nd2 = nd1 - nb if na >= nd2: p1 = (na - nd2) * a + nd * e else: print("error!!") # print("p0 :", p0) # print("p1 :", p1) #print("ans:",min(p0,p1)) print(min(p0, p1)) ```
instruction
0
50,459
10
100,918
No
output
1
50,459
10
100,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem I started a part-time job at the rental DVD shop "NEO". First of all, I decided to study the fee system of this store. There are three types of rental DVDs, old, semi-new, and new, and the rental fee for one DVD is a yen, b yen, and c yen, respectively. The set rental shown below can be applied multiple times at the time of accounting. * Select a few DVDs for which set rental has not yet been applied. * If the number of selected DVDs is d or more, the total price of the selected DVDs exceeds (the number of selected DVDs) * e yen, rent them for (the number of selected DVDs) * e yen. You can. * If the number of selected DVDs is less than d, and the total price of the selected DVDs exceeds d * e yen, you can rent them for d * e yen. * If the above does not apply, the selected DVD will be rented at the regular rate. Here I noticed a problem. The set rental is not applied automatically when you go to the cash register, but is applied manually. This may result in the application of suboptimal set rentals (which can be cheaper). This can lead to complaints. I hate complaints, so I decided to create a program that calculates the price when the set rental is optimally applied. Constraints The input satisfies the following conditions. * All values ​​contained in the input are integers * 0 <a <b <e <c ≤ 1000 * 0 <d ≤ 100000 * 0 ≤ na, nb, nc ≤ 100000 * 0 <na + nb + nc * No more than 100 datasets Input The input consists of multiple datasets. Each dataset is represented below. The first line is given five integers a, b, c, d, e separated by spaces. The number of rentals is given on the second line. The three integers na, nb, nc are given separated by spaces. Represents the number of old, semi-new, and new DVDs, respectively. The end of the input consists of 5 zeros. a b c d e na nb nc Output For each dataset, output the charge when the set rental is optimally applied on one line. Example Input 70 100 340 4 200 1 1 4 70 100 340 4 200 0 1 3 70 100 340 4 200 1 1 2 0 0 0 0 0 Output 970 800 800 Submitted Solution: ``` # Edit: 2014/10/13 # Lang: Python3 # Time: 00.xxs # File: pc1509.py if __name__ == "__main__": while True: a, b, c, d, e = list(map(int, input().strip("\n").split(" "))) if a == 0 and b == 0 and c == 0 and d == 0 and e == 0: exit() na, nb, nc = list(map(int, input().strip("\n").split(" "))) #print("--------------------") #print("abcde:", a, b, c, d, e) #print("na,nb,nc:", na, nb, nc, d) if na + nb + nc < d or nc == 0: price = na * a + nb * b + nc * c print(price) continue if nc >= d: price = na * a + nb * b + nc * e print(price) continue if True: # 0 < nc < d price0 = na * a + nb * b + nc * c # wo set-wari if nb - (d - nc) >= 0: na = na nb -= (d - nc) nc = 0 else: na -= (d - nc - nb) nb = 0 nc = 0 price1 = na * a + nb * b + nc * c + d * e #print("abcde:", a, b, c, d, e) #print("na,nb,nc:", na, nb, nc, d) print(min(price0, price1)) #print("wo", price0) #print("w ", price1) continue ```
instruction
0
50,460
10
100,920
No
output
1
50,460
10
100,921
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,808
10
101,616
Tags: implementation, number theory Correct Solution: ``` """"""""""""""""""""""""""""""""""""""""""""" | author: mr.math - Hakimov Rahimjon | | e-mail: mr.math0777@gmail.com | """"""""""""""""""""""""""""""""""""""""""""" #inp = open("lepus.in", "r"); input = inp.readline; out = open("lepus.out", "w"); print = out.write TN = 1 # =========================================== def solution(): n = int(input()) if n>=0: print(n) else: print(max(int(str(n)[:-1]), int(str(n)[:-2]+str(n)[-1]))) # =========================================== while TN != 0: solution() TN -= 1 # =========================================== #inp.close() #out.close() ```
output
1
50,808
10
101,617
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,809
10
101,618
Tags: implementation, number theory Correct Solution: ``` i = int(input()) j = str(i) x = j k = [] for a in j: k.append(a) if i > 0 : print(i) else : n1 = j[ : len(j)-1] n2 = j[ : len(j)-2] + j[len(j)-1 :] i1 = int(n1) i2 = int(n2) print(max(i1,i2)) ```
output
1
50,809
10
101,619
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,810
10
101,620
Tags: implementation, number theory Correct Solution: ``` def removeLastDigit(n): return -(n//10) def removeSecondLastDigit(n): i = n % 10 return -(n//100 * 10 + i) n = int(input()) if(n >= 0): print(n) else: x = removeLastDigit(-n) y = removeSecondLastDigit(-n) if(x > y): print(x) else: print(y) ```
output
1
50,810
10
101,621
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,811
10
101,622
Tags: implementation, number theory Correct Solution: ``` n=input() l=[] g=[] for i in n: l.append(i) g.append(i) if int(n)<0: l.pop(-1) g.pop(-2) l=int(''.join(l)) g=int(''.join(g)) if int(n)<0: print(max(l,g)) else: print(int(n)) ```
output
1
50,811
10
101,623
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,812
10
101,624
Tags: implementation, number theory Correct Solution: ``` n=input() l=len(n) if int(n) >= 0: print(n) else: if l == 2: print(0) elif l==3 and int(n[-1])==0: print(0) else: print(n[:(l-2)]+str(min(int(n[-2]),int(n[-1])))) ```
output
1
50,812
10
101,625
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,813
10
101,626
Tags: implementation, number theory Correct Solution: ``` n = input() if '-' in n: if n[::-1][0]>n[::-1][1]: print(int(n[:len(n)-1])) else: print(int(n[:len(n)-2]+n[len(n)-1])) else: print(n) ```
output
1
50,813
10
101,627
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,814
10
101,628
Tags: implementation, number theory Correct Solution: ``` n = int(input()) if n>0: print(n) else: n*=(-1) if n//10 < (n//100)*10+n%10: print(-1*(n//10)) else: if (n//100)*10 + n%10 == 0: print(0) else: print(-1*((n//100)*10 + n%10)) ```
output
1
50,814
10
101,629
Provide tags and a correct Python 3 solution for this coding contest problem. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
instruction
0
50,815
10
101,630
Tags: implementation, number theory Correct Solution: ``` # -*- coding: utf-8 -*- # @Author: SyedAli # @Date: 2019-01-01 23:54:17 # @Last Modified by: SyedAli # @Last Modified time: 2019-01-02 00:07:31 n = int(input()) if n>0: print(n) else: n = abs(n) a = int (n/10) b = int(n/100) b = b*10+n%10 print(-min(a,b)) ```
output
1
50,815
10
101,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` def main(): strn = input() n = int(strn) if n >= 0: print(n) else: del_last = int(strn[:-1]) del_pult = int(strn[:-2] + strn[-1]) print(max(n, del_pult, del_last)) if __name__ == "__main__": main() ```
instruction
0
50,816
10
101,632
Yes
output
1
50,816
10
101,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/313/A bank_bal = input() len_bal = len(bank_bal) print(max(int(bank_bal), int(bank_bal[:len_bal - 2] + bank_bal[len_bal - 1]), int(bank_bal[:len_bal - 1]))) ```
instruction
0
50,817
10
101,634
Yes
output
1
50,817
10
101,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` n = int(input()) if n > 0: print(n) else : data_str = str(n) last = int(data_str[0:len(data_str)-1]) second_last = int(data_str[0:len(data_str)-2]+ data_str[len(data_str)-1]) if last>second_last: print(last) else : print(second_last) ```
instruction
0
50,818
10
101,636
Yes
output
1
50,818
10
101,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` def remove_at(i, s): return s[:i] + s[i+1:] n = int(input()) if n > 0: print(n) else: n *= (-1) n = str(n) n1 = remove_at(len(n)-1, n) n2 = remove_at(-2, n) n1, n2 = int(n1), int(n2) n1, n2 = n1*(-1), n2*(-1) print(max(n1, n2)) ```
instruction
0
50,819
10
101,638
Yes
output
1
50,819
10
101,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` import math t=int(input()) if t>=0: print(t) else: if t>-10: print(0) else: x=math.ceil(t/10) y=int(str(math.ceil(t/100))+str(t)[-1]) print(max(x,y)) ```
instruction
0
50,820
10
101,640
No
output
1
50,820
10
101,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` x = input() y = int(x) a = int(x[len(x)-2]) b = int(x[len(x)-1]) if(y > 0): print(x) else: if(a > b): print(x[:(len(x)-2)]+x[len(x)-1]) else: print(x[:(len(x)-1)]) ```
instruction
0
50,821
10
101,642
No
output
1
50,821
10
101,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` n=int(input()) if n==abs(n): print(n) else: p=abs(n) a=[int(x) for x in str(p)] if a[-1]>a[-2]: a.remove(a[-1]) else: a.remove(a[-2]) for i in range(len(a)): a[i]=str(a[i]) print('-'+"".join(a)) ```
instruction
0
50,822
10
101,644
No
output
1
50,822
10
101,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account. Output In a single line print an integer — the maximum state of the bank account that Ilya can get. Examples Input 2230 Output 2230 Input -10 Output 0 Input -100003 Output -10000 Note In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0. Submitted Solution: ``` n = input() d = [] for i in n: d.append(i) if len(d) > 3 or int(n) > 0: if int(n) < 0: a = [] for i in range(len(n) - 1, len(n) - 3, -1): a.append(n[i]) b = max(a) d.remove(b) print(*d, sep="") elif len(d) <= 3 and int(n) < 0: print(0) ```
instruction
0
50,823
10
101,646
No
output
1
50,823
10
101,647
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,982
10
101,964
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` # http://codeforces.com/contest/779/problem/A <<--finsihed # http://codeforces.com/contest/779/problem/B <<--finished # http://codeforces.com/contest/779/problem/C <<--finished def Pupils_redistribution(): n = int(input()) g1 = input().split() g1d = [0]*5 g2 = input().split() g2d = [0]*5 for i in g1: g1d[int(i)-1] += 1 for i in g2: g2d[int(i)-1] += 1 nd = [0] * 5 for i in range(len(g1d)): a = g1d[i]-g2d[i] if a%2 == 0: nd[i] = a/2 else: print("-1") break else: if sum(nd) ==0: sums = 0 for i in nd: if i >0: sums += i print(int(sums)) else: print("-1") #Pupils_redistribution() def Weird_rounding(): r= input().split() n = r[0] lenn = len(n) n2 = n k = int(r[1]) ten = 10**k count = 0 for i in range(lenn): if int(n2) % ten == 0: break if int(n2[lenn-i-1]) != 0: count += 1 n2 = n2[:(lenn-i-1)] + n2[(lenn-i):] if int(n2) == 0 and len(n2) >1: print(count + len(n2) - 1) else: print(count) #Weird_rounding() def Dishonest_sellers(): a = input().split() n = int(a[0]) k = int(a[1]) a = input().split() b = input().split() diff = [0] * n for i in range(n): diff[i] = (int(b[i]) - int(a[i]),i) diff = sorted(diff, reverse = True) count = 0 for i in range(n): if i < k: count += int(a[diff[i][1]]) else: if diff[i][0] >= 0: count += int(a[diff[i][1]]) else: count+= int(b[diff[i][1]]) print(count) Dishonest_sellers() ```
output
1
50,982
10
101,965
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,983
10
101,966
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) dif = [] for i in range(n): dif.append((a[i]-b[i], i)) dif.sort() s = 0 for i in range(k): s += a[dif[i][1]] a[dif[i][1]] = b[dif[i][1]] = 0 for i in range(len(a)): s += min(a[i], b[i]) print(s) ```
output
1
50,983
10
101,967
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,984
10
101,968
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n,k=map(int,input().split()) t=list(map(int,input().split())) c=list(map(int,input().split())) d=sorted([t[i]-c[i] for i in range(len(t))]) n=sum(t) for i in range(k,len(d)):n=n-max(d[i],0) print(n) ```
output
1
50,984
10
101,969
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,985
10
101,970
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` from sys import stdin, stdout n, k = map(int, stdin.readline().split()) pricesb = list(map(int, stdin.readline().split())) pricesa = list(map(int, stdin.readline().split())) cnt = [] for i in range(n): cnt.append((pricesb[i] - pricesa[i], i)) cnt.sort() ans = 0 for i in range(n): if i < k or cnt[i][0] < 0: ans += pricesb[cnt[i][1]] else: ans += pricesa[cnt[i][1]] stdout.write(str(ans)) ```
output
1
50,985
10
101,971
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,986
10
101,972
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` import math from collections import defaultdict def input_ints(): return list(map(int, input().split())) def solve(): n, k = input_ints() a = input_ints() b = input_ints() x = [(a[i] - b[i], b[i]) for i in range(n)] x = sorted(x) ans = 0 for i, p in enumerate(x): if i < k or p[0] <= 0: ans += p[0] + p[1] else: ans += p[1] print(ans) if __name__ == '__main__': solve() ```
output
1
50,986
10
101,973
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,987
10
101,974
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) wynik = 0 lista = [] for x in range(n): wynik = wynik + b[x] roznica = a[x] - b[x] if roznica < 0: wynik = wynik + roznica k = k - 1 else: lista.append(roznica) lista.sort() for x in range(len(lista)): if k > 0: wynik = wynik + lista[x] k = k - 1 print(wynik) ```
output
1
50,987
10
101,975
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,988
10
101,976
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` import sys,math from collections import deque,defaultdict import operator as op from functools import reduce #sys.setrecursionlimit(10**6) I=sys.stdin.readline #s="abcdefghijklmnopqrstuvwxyz" """ 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 gcd(x, y): while y: x, y = y, x % y return x def valid(row,col,rows,cols,rcross,lcross): return rows[row]==0 and cols[col]==0 and rcross[col+row]==0 and lcross[col-row]==0 def div(n): tmp=[] for i in range(2,int(n**.5)+1): if n%i==0: cnt=0 while(n%i==0): n=n//i cnt+=1 tmp.append((i,cnt)) if n>1: tmp.append((n,1)) return tmp def isPrime(n): if n<=1: return False elif n<=2: return True else: flag=True for i in range(2,int(n**.5)+1): if n%i==0: flag=False break return flag def s(b): cnt=0 while b>0: tmp=b%10 cnt+=tmp b=b//10 return cnt def main(): #ans="" n,k=mi() a=li() b=li() tmp=[(a[i],b[i]) for i in range(n)] my_arr=sorted(tmp,key=lambda x : x[0]-x[1]) cnt=0 i=0 cost=0 while cnt<n and(cnt<k or (my_arr[cnt][0]-my_arr[cnt][1])<0): cost+=my_arr[cnt][0] cnt+=1 while cnt<n: cost+=my_arr[cnt][1] cnt+=1 print(cost) if __name__ == '__main__': main() ```
output
1
50,988
10
101,977
Provide tags and a correct Python 3 solution for this coding contest problem. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
instruction
0
50,989
10
101,978
Tags: constructive algorithms, greedy, sortings Correct Solution: ``` n,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] res=[0 for i in range(n)] for i in range(n): res[i]=a[i]-b[i] res,a,b=zip(*sorted(zip(res,a,b))) res,a,b=[list(t) for t in (zip(*sorted(zip(res,a,b))))] add=0 c=0 for i in range(n): if(res[i]>0): if(c>=k): add+=b[i] if(c<k): add+=a[i] c+=1 elif(res[i]<=0): add+=a[i] c+=1 print(add) ```
output
1
50,989
10
101,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` n,m= map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) l=[(i,ii) for i,ii in zip(a,b)] l.sort(reverse=True,key = lambda x:x[1]-x[0]) ans=0 for ii,i in enumerate(l): if(ii<m): ans+=i[0] else: ans+=min(i[1],i[0]) print(ans) ```
instruction
0
50,990
10
101,980
Yes
output
1
50,990
10
101,981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` from math import * from collections import * from random import * from bisect import * import sys input=sys.stdin.readline t=1 while(t): t-=1 n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) r=[] for i in range(n): r.append([a[i]-b[i],i]) r.sort() pos=0 for i in r: if(i[0]<=0): pos+=1 else: break re=0 for i in range(max(k,pos)): re+=a[r[i][1]] for i in range(max(pos,k),n): re+=b[r[i][1]] print(re) ```
instruction
0
50,991
10
101,982
Yes
output
1
50,991
10
101,983
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Mar 1 13:33:38 2017 @author: kyle """ a,b = map(int,input().split()) p1 = list(map(int,input().split())) p2 = list(map(int,input().split())) 3 delta = [(p1[i]-p2[i],i) for i in range(a)] delta.sort() #print(delta) ll=len([i for i in delta if i[0]<=0]) b = max(ll,b) l1 = [delta[i][1] for i in range(b)] l2 = [delta[i][1] for i in range(b,a)] m=[p1[i] for i in l1] n=[p2[i] for i in l2] print(sum(m+n)) ```
instruction
0
50,992
10
101,984
Yes
output
1
50,992
10
101,985
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = list(map(lambda x, y: x-y, a, b)) d.sort() kk = sum(map(lambda x: x < 0, d)) kk = max(k, kk) print(sum(b) + sum(d[:kk])) ```
instruction
0
50,993
10
101,986
Yes
output
1
50,993
10
101,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) wynik = 0 lista = [] if n == 200000 and k == 199999: for x in range(n): if b[x] < a[x]: wynik = wynik + b[x] else: wynik = wynik + a[x] else: if n == k: for x in range(n): wynik = wynik + a[x] else: for x in range(n): wynik = wynik + b[x] roznica = a[x] - b[x] if roznica < 0: wynik = wynik + roznica k = k - 1 else: lista.append(roznica) lista.sort() for x in range(len(lista)): if k > 0: wynik = wynik + lista[0] lista.pop(0) k = k - 1 print(wynik) ```
instruction
0
50,994
10
101,988
No
output
1
50,994
10
101,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` import operator n,k=[int(x)for x in input().split()] a,b=[[int(x)for x in input().split()]for y in range(2)] c={} s=0 for x in range(n): c[x]=a[x]-b[x] for x in range(max(k,len([c[o] for o in c if c[o]<0]))): c=dict(sorted(c.items(),key=operator.itemgetter(1))) s+=a[list(c)[0]] c.pop(list(c)[0]) for x in c: s+=b[x] print(s) ```
instruction
0
50,995
10
101,990
No
output
1
50,995
10
101,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` n, k = map(int, input().strip().split()) ai = list(map(int, input().strip().split())) bi = list(map(int, input().strip().split())) cost = list() for i in range(n): cost.append(ai[i]-bi[i]) cnt = 0 mi = 100000 co = cost[:] l = ai[:] for i in range(n): if cost[i] <= 0: cnt += ai[i] k -= 1 ai[i] = 0 if k > 0: cost.sort() for i in range(n): if cost[i] <= 0: continue else: ind = co.index(cost[i]) cnt += (l[ind]) l[ind] = 0 k -= 1 if not k: break for j in range(n): if l[j]: cnt += bi[j] print(cnt) else: for i in range(n): if ai[i]: cnt += bi[i] print(cnt) ```
instruction
0
50,996
10
101,992
No
output
1
50,996
10
101,993
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items. Input In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week). Output Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. Examples Input 3 1 5 4 6 3 1 5 Output 10 Input 5 3 3 4 7 10 3 4 5 5 12 5 Output 25 Note In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10. In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. Submitted Solution: ``` lineOne = input() dataOne = lineOne.split() n = int(dataOne[0]) rightNow = int(dataOne[1]) lTwo = input() discount = [int(i) for i in lTwo.split()] lThree = input() after = [int(i) for i in lThree.split()] diff = [None] * n ans = 0 # For each item get the cheaper one k = 0 for i in range(n): if discount[i] <= after[i]: ans += discount[i] k += 1 else: diff[i] = after[i] - discount[i] ans += after[i] # if not enough in first week while k < rightNow: highest = 0 for i in range(n): if diff[i] == None: continue if diff[highest] == None: highest = i continue if diff[i] > diff[highest]: highest = i ans -= diff[highest] k += 1 print(ans) ```
instruction
0
50,997
10
101,994
No
output
1
50,997
10
101,995
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,536
10
103,072
Tags: math Correct Solution: ``` from math import ceil def run(): x, y, k = map(int, input().split()) m = (y+1)*k - 1 if m % (x-1) == 0: # print('1', x, y, k) m = m // (x-1) print(m + k) else: # print('2', x, y, k) m = (m // (x-1)) print(m + k + 1) T = 1 if T: for i in range(int(input())): run() else: run() #@Time: 2020/09/14 22:36:41 ```
output
1
51,536
10
103,073
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,537
10
103,074
Tags: math Correct Solution: ``` import os def f(x,y,k): steps = 0 cost = k*(1+y) # cost of torches in sticks net_benefit = x-1 stick_trades = ((cost - 1) // net_benefit) + ((cost - 1) % net_benefit != 0) coal_trades = k steps = stick_trades + coal_trades return steps t = int(input()) for testcase in range(t): x,y,k = [int(x) for x in input().split()] print(f(x,y,k)) ```
output
1
51,537
10
103,075
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,538
10
103,076
Tags: math Correct Solution: ``` from math import * sInt = lambda: int(input()) mInt = lambda: map(int, input().split()) lInt = lambda: list(map(int, input().split())) t = sInt() for _ in range(t): x,y,k = mInt() ans = (y*k+k-1)//(x-1)+k if (y*k+k-1)%(x-1): ans += 1 print(ans) ```
output
1
51,538
10
103,077
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,539
10
103,078
Tags: math Correct Solution: ``` from math import * from bisect import * from collections import Counter,defaultdict from sys import stdin, stdout input = stdin.readline I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) for _ in range(I()): n,m,k=M() x=(m*k)+k if x%(n-1)!=1 and x%(n-1)!=0: x//=(n-1) x+=1 else: x//=(n-1) x+=k if n-1==1: print(x-1) else: print(x) ```
output
1
51,539
10
103,079
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,540
10
103,080
Tags: math Correct Solution: ``` from math import ceil t = int(input()) for i in range(t): x, y, k = map(int, input().split()) ans = ceil(((y + 1) * k - 3 + x) // (x - 1)) + k print(ans) ```
output
1
51,540
10
103,081
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,541
10
103,082
Tags: math Correct Solution: ``` for _ in range(int(input())): x,y,k = map(int,input().split()) a = ((y+1)*k - x)//(x-1) + 1 if ((y+1)*k - x)%(x-1)!=0: a+=1 print(a+k) ```
output
1
51,541
10
103,083
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,542
10
103,084
Tags: math Correct Solution: ``` t = int(input()) while t>0: x, y, k = map(int, input().split()) y_sticks = k * y total = k+y_sticks if (total-1)%(x-1) != 0: s_trades = (total-1)//(x-1) + 1 else: s_trades = (total-1)//(x-1) trades = k + s_trades print(trades) t-= 1 ```
output
1
51,542
10
103,085
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
instruction
0
51,543
10
103,086
Tags: math Correct Solution: ``` for _ in range(int(input())): x, y, k = map(int, input().split()) print(((k*(y+1) - 1)//(x-1)) + min((k*(y+1) - 1)%(x-1), 1) + k) ```
output
1
51,543
10
103,087
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999 Submitted Solution: ``` h = int(input()) l = [] for i in range(h): x,y,k = list(map(int, input().split())) n = y*k + k if (n-1)%(x-1) == 0: print((n-1)//(x-1) + k) else: print((n-1)//(x-1) + 1 + k) ```
instruction
0
51,544
10
103,088
Yes
output
1
51,544
10
103,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999 Submitted Solution: ``` import math for _ in range(int(input())): x,y,k=map(int,input().split()) c=(((y+1)*k)-x)//(x-1)+1 if((x+((c-1)*(x-1)))<((y+1)*k)): c+=1 print(c+k) ```
instruction
0
51,545
10
103,090
Yes
output
1
51,545
10
103,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: * exchange 1 stick for x sticks (you lose 1 stick and gain x sticks). * exchange y sticks for 1 coal (you lose y sticks and gain 1 coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The only line of the test case contains three integers x, y and k (2 ≤ x ≤ 10^9; 1 ≤ y, k ≤ 10^9) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least k torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999 Submitted Solution: ``` t = int(input()) for _ in range(t): x, y, k = [int(i) for i in input().split()] print((k*(y+1)-1+x-2)//(x-1)+k) ```
instruction
0
51,546
10
103,092
Yes
output
1
51,546
10
103,093