message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β€” into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 2. Each plate contains at least one piece of cake; 3. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≀ a, b ≀ 100, 2 ≀ n ≀ a + b) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 Note In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. Submitted Solution: ``` n,a,b=map(int,input().split()) ans=0 for i in range(1,n): x=n-i if a//x and b//i: ans=max(ans, min(a//x,b//i)) print(ans) ```
instruction
0
25,293
9
50,586
Yes
output
1
25,293
9
50,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β€” into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 2. Each plate contains at least one piece of cake; 3. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≀ a, b ≀ 100, 2 ≀ n ≀ a + b) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 Note In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. Submitted Solution: ``` n, a, b = map(int, input().split()) l = 0 r = 10**9 while r - l > 1: m = (l + r) // 2 if(a // m + b // m >= n): l = m else: r = m print(l) ```
instruction
0
25,294
9
50,588
No
output
1
25,294
9
50,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β€” into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 2. Each plate contains at least one piece of cake; 3. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≀ a, b ≀ 100, 2 ≀ n ≀ a + b) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 Note In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. Submitted Solution: ``` from math import * A = [int(x) for x in input().split()] n=A[0] a=A[1] b=A[2] if a<b: print(floor(a/2)) else: print(floor(b/2)) ```
instruction
0
25,295
9
50,590
No
output
1
25,295
9
50,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β€” into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 2. Each plate contains at least one piece of cake; 3. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≀ a, b ≀ 100, 2 ≀ n ≀ a + b) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 Note In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. Submitted Solution: ``` import sys import math import random #sys.setrecursionlimit(100000000) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ n,a,b=invr() ans=1 for i in range(1,1000): cake=[0]*n tempa=a tempb=b j=0 while tempa>=i and j<n: cake[j]=i tempa-=i j+=1 while tempb>=i and j<n: cake[j]=i tempb-=i j+=1 if j==n: ans=i print(ans) ```
instruction
0
25,296
9
50,592
No
output
1
25,296
9
50,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β€” into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 2. Each plate contains at least one piece of cake; 3. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake. Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≀ a, b ≀ 100, 2 ≀ n ≀ a + b) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake. Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 Note In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. Submitted Solution: ``` #Problem Set D: Collaborated with no one s = list(map(int, input().split())) #no. of plates n = int(s[0]) #no. of pieces from cake 1 a = int(s[1]) #no. of pieces from cake 2 b = int(s[2]) total = 0 if a > b: a = b for i in range(1, a+1): print("The current index is", i) ans = int(a/i+b) print("my answer is ", ans) if int(ans/i) >= n: total = max(i, total) print("The total is ", total) print(total) ```
instruction
0
25,297
9
50,594
No
output
1
25,297
9
50,595
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,579
9
51,158
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) p = 0 m = [] for s in input().split(): x = int(s) p += abs(x) m.append(x) m.sort() if len(m) > 2: m.pop(1) if n == 1: print(m[0]) elif m[0] > 0: print(p - 2 * m[0]) elif m[1] < 0: print(p + 2 * m[1]) else: print(p) ```
output
1
25,579
9
51,159
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,580
9
51,160
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() if max(a) > 1 and min(a) < 1: print(sum(abs(x) for x in a)) else: print(sum(abs(x) for x in a) - 2 * min(abs(x) for x in a)) ```
output
1
25,580
9
51,161
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,581
9
51,162
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) if n==1: print(input()) else: a = [int(x) for x in input().split()] b = [abs(x) for x in a] mina = min(a) maxa = max(a) if mina >= 0: print(sum(b) - 2 * mina) elif maxa <= 0: print(sum(b) + 2 * maxa) else: print(sum(b)) ```
output
1
25,581
9
51,163
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,582
9
51,164
Tags: dp, greedy, implementation Correct Solution: ``` from sys import stdin from collections import deque mod = 10**9 + 7 import sys sys.setrecursionlimit(10**5) from queue import PriorityQueue # def rl(): # return [int(w) for w in stdin.readline().split()] from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt,factorial,gcd,log2,inf,ceil # map(int,input().split()) # # l = list(map(int,input().split())) # from itertools import permutations import heapq # input = lambda: sys.stdin.readline().rstrip() input = lambda : sys.stdin.readline().rstrip() from sys import stdin, stdout from heapq import heapify, heappush, heappop n = int(input()) l = list(map(int,input().split())) if max(l)<=0: print((abs(sum(l)) + 2*max(l))) elif min(l)>=0: print(abs(abs(sum(l)) - 2*min(l))) else: ans = 0 for i in l: ans+=abs(i) print(ans) ```
output
1
25,582
9
51,165
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,583
9
51,166
Tags: dp, greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 #-*- encoding: utf-8 -*- import sys import bisect from collections import Counter read_int = lambda : int(sys.stdin.readline()) read_ints = lambda : map(int,sys.stdin.readline().split()) read_int_list = lambda : list(read_ints()) read = lambda : sys.stdin.readline().strip() read_list = lambda : sys.stdin.readline().split() def main(): n = read_int() a = read_int_list() if n == 1: print(a[0]) return ma,mi,ze = max(0,max(a)), min(0,min(a)), 0 in a all_neg = ma == 0 and not ze all_pos = mi == 0 and not ze if all_neg: print(-sum(a)+2*max(a)) elif all_pos: print(sum(a)-2*min(a)) else: print(sum(map(abs,a))) main() ```
output
1
25,583
9
51,167
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,584
9
51,168
Tags: dp, greedy, implementation Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) if n == 1: print(arr[0]) else: brr = [abs(i) for i in arr] fl = False for i in range(n - 1): if arr[i] * arr[i + 1] < 0: fl = True if not fl: print(sum(brr) - 2 * min(brr)) else: print(sum(brr)) ''' n = int(input()) arra = list(map(int, input().split())) arrb = list(map(int, input().split())) arra.sort() arrb.sort() a = 0 b = 0 for i in range(2 * n): if i % 2 == 0: if len(arra) == 0: arrb.pop() elif len(arrb) == 0 or arra[-1] >= arrb[-1]: a += arra[-1] arra.pop() else: arrb.pop() else: if len(arrb) == 0: arra.pop() elif len(arra) == 0 or arrb[-1] >= arra[-1]: b += arrb[-1] arrb.pop() else: arra.pop() print(a - b) ''' ''' n = int(input()) if n == 1 or n == 2: print('No') else: #if n % 2 == 1: print('Yes') print((n + 1) // 2, end = ' ') for i in range(1, n + 1, 2): print(i, end = ' ') print() print(n // 2, end = ' ') for i in range(2, n + 1, 2): print(i, end = ' ') ''' ''' n, k = map(int, input().split()) s = input() d = [0 for _ in range(k)] for i in s: d[ord(i) - ord('A')] += 1 #al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #for i in print(min(d) * k) ''' ```
output
1
25,584
9
51,169
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,585
9
51,170
Tags: dp, greedy, implementation Correct Solution: ``` n=int(input()) arr=list(map(int,input().split())) arr.sort() s=0 if n==1: s=arr[0] elif arr[-1]<0: s=abs(sum(arr))-abs(arr[-1])*2 elif arr[0]<0: for i in range(len(arr)): s+=abs(arr[i]) else: s=sum(arr)-2*arr[0] print(s) ```
output
1
25,585
9
51,171
Provide tags and a correct Python 3 solution for this coding contest problem. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4.
instruction
0
25,586
9
51,172
Tags: dp, greedy, implementation Correct Solution: ``` n=int(input()) arr=list(map(int,input().split())) arr.sort() arr1=[] arr2=[] val1=0 for i in range(n-1): val1+=arr[i] arr1.append(val1) val1=0 for i in range(n-1,0,-1): val1+=arr[i] arr2.append(val1) fans=-10000000000000000000000 for i in range(n-1): fans=max(fans,arr2[n-2-i]-arr1[i]) if(n==1): print(arr[0]) else: print(fans) ```
output
1
25,586
9
51,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` import sys n = int(input()) A = list(map(int,input().split())) if n == 1: print(A[0]) sys.exit(0) suma = 0 mine = 1000000001 d = False for i in range(0,n): mine = min(mine,abs(A[i])) suma += abs(A[i]) if i > 0 and ((A[i] >=0 and A[i-1] < 0) or (A[i]<0 and A[i-1]>=0)): d = True if d: print(suma) else: print(suma-2*mine) ```
instruction
0
25,587
9
51,174
Yes
output
1
25,587
9
51,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` n=int(input()); a=list(map(int, input().split())); a.sort(); ans=0; ck=0; d1=-10000000000; d2=10000000000 for i in a: ans+=abs(i); d1=max(d1, i); d2=min(d2, i) if i==0: ck=1 if ck==1: print(ans) elif n==1: print(a[0]) else: ans-=abs(d1)+abs(d2); ans+=abs(d1-d2); print(ans) ```
instruction
0
25,588
9
51,176
Yes
output
1
25,588
9
51,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` import sys input=sys.stdin.readline n=int(input()) ar=list(map(int,input().split())) if(n==1): print(ar[0]) elif(n==2): print(abs(ar[0]-ar[1])) else: flag=False for i in range(1,n): if(ar[i]*ar[i-1]<=0): flag=True break if(flag): ans=0 for i in range(n): ans+=abs(ar[i]) print(ans) else: mi=float('inf') ans=0 for i in range(n): mi=min(mi,abs(ar[i])) ans+=abs(ar[i]) print(abs(ans-mi*2)) ```
instruction
0
25,589
9
51,178
Yes
output
1
25,589
9
51,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` import sys import math import collections import heapq import decimal input=sys.stdin.readline n=int(input()) l=[int(i) for i in input().split()] if(len(l)==1): print(*l) else: mi=min(l) ma=max(l) if(mi>=0): print(sum(l)-2*mi) elif(ma<=0): print(-sum(l)+2*ma) else: s=0 for i in l: s+=abs(i) print(s) ```
instruction
0
25,590
9
51,180
Yes
output
1
25,590
9
51,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) k = 1e9 + 1 minL, minR = [], [] for i in range(n + 2): minL.append(k) for i in range(n + 1, -1, -1): minR.append(k) for i in range(1, n + 1): minL[i] = min(minL[i - 1], a[i - 1]) for i in range(n, 0, -1): minR[i] = min(minR[i + 1], a[i - 1]) sum = [] for i in range(n + 1): sum.append(0) for i in range(1, n + 1): sum[i] = sum[i - 1] + a[i - 1] ans = -k for i in range(1, n + 1): t = a[i - 1] if i > 1 and i < n: x = 2 * minL[i - 1] - sum[i - 1] y = 2 * minR[i + 1] - (sum[n] - sum[i]) L = min(x, sum[i - 1]) R = min(y, sum[n] - sum[i]) t -= (L + R) elif i > 1: x = 2 * minL[i - 1] - sum[i - 1] L = min(x, sum[i - 1]) t -= L elif i < n: y = 2 * minR[i + 1] - (sum[n] - sum[i]) R = min(y, sum[n] - sum[i]) t -= R ans = max(ans, t) print(ans) ```
instruction
0
25,591
9
51,182
No
output
1
25,591
9
51,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` a=int(input()) z=list(map(int,input().split())) if(len(z)==1): print(z[0]) exit() if(len(z)==2): print(max(z[1]-z[0],z[0]-z[1])) exit() mini=[0 for i in range(len(z))] maxa=[0 for i in range(len(z))] mini[0]=z[0] maxa[0]=z[0] mini[1]=min(z[1]-z[0],z[0]-z[1]) maxa[1]=max(z[0]-z[1],z[1]-z[0]) for i in range(2,len(z)): t1=z[i]-z[i-1] maxa[i]=max(mini[i-2]-t1,t1-mini[i-2],maxa[i-2]-t1,t1-maxa[i-2]) mini[i]=min(mini[i-2]-t1,t1-mini[i-2],maxa[i-2]-t1,t1-maxa[i-2]) t1=z[i-1]-z[i] maxa[i]=max(mini[i-2]-t1,t1-mini[i-2],maxa[i-2]-t1,t1-maxa[i-2]) mini[i]=min(mini[i-2]-t1,t1-mini[i-2],maxa[i-2]-t1,t1-maxa[i-2]) maxa[i]=max(maxa[i],maxa[i-1]-z[i],z[i]-maxa[i-1],mini[i-1]-z[i],z[i]-mini[i-1]) mini[i]=min(maxa[i],maxa[i-1]-z[i],z[i]-maxa[i-1],mini[i-1]-z[i],z[i]-mini[i-1]) print(maxa[-1]) ```
instruction
0
25,592
9
51,184
No
output
1
25,592
9
51,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` def f(arr,N): if N==1: return arr[0] a=0 a_min=10**9+1 b=0 c=False for i in arr: if i>=0: a+=i a_min=min(a_min,i) else: c=True b+=i if c: return a-b return a-2*a_min #Input N=int(input()) arr = list(map(int,input().strip().split())) print(f(arr,N)) ```
instruction
0
25,593
9
51,186
No
output
1
25,593
9
51,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and the value of the remaining slime changes to x - y. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. Input The first line of the input contains an integer n (1 ≀ n ≀ 500 000) denoting the number of slimes. The next line contains n integers a_i (-10^9 ≀ a_i ≀ 10^9), where a_i is the value of i-th slime. Output Print an only integer β€” the maximum possible value of the last slime. Examples Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 Note In the first example, a possible way of getting the last slime with value 4 is: * Second slime eats the third slime, the row now contains slimes 2, -1, 1 * Second slime eats the third slime, the row now contains slimes 2, -2 * First slime eats the second slime, the row now contains 4 In the second example, the first slime can keep eating slimes to its right to end up with a value of 4. Submitted Solution: ``` n=int(input()) a=list(map(int, input().split())) a.sort() if n==1: print(a[0]) else: i=0 while i<n and a[i]<=0: i+=1 if i==0: if n==2: print(sum(a)-2*a[0]) else: print(sum(a)-2*a[1]) elif i==n: print(2*a[-1]-sum(a)) else: print(sum(a[i:])-sum(a[:i])) ```
instruction
0
25,594
9
51,188
No
output
1
25,594
9
51,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory produces boxes of K kinds, boxes of the i-th kind can contain in themselves ai hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount. Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm. Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters. Input The first line contains two integers N and K (0 ≀ N ≀ 1018, 1 ≀ K ≀ 105) β€” the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains K integers a1, a2, ..., aK (1 ≀ ai ≀ 1018 for all i) β€” the capacities of boxes. Output Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to K in the order they are given in input. If there are many correct answers, output any of them. Examples Input 19 3 5 4 10 Output 2 4 Input 28 3 5 6 30 Output 1 5 Submitted Solution: ``` # cook your dish here n,k = map(int,input().split()) l = list(map(int,input().split())) c = 10**19 ind = -1 for i in range(k): if l[i] <= n: if (n%l[i]) < c: c = n%l[i] ind = i+1 if ind == -1: print(1,0) else: print(ind,n//l[ind-1]) ```
instruction
0
26,214
9
52,428
Yes
output
1
26,214
9
52,429
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,261
9
52,522
"Correct Solution: ``` n,*d=map(int,open(0).read().split()) s=sum(d)**2 for v in d:s-=v**2 print(s//2) ```
output
1
26,261
9
52,523
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,262
9
52,524
"Correct Solution: ``` n=int(input()) l=[int(i) for i in input().split()] s=0 for i in range(n): for j in range(i+1,n): s+=l[j]*l[i] print(s) ```
output
1
26,262
9
52,525
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,263
9
52,526
"Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) print((sum(a) ** 2 - sum((i ** 2 for i in a))) // 2) ```
output
1
26,263
9
52,527
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,264
9
52,528
"Correct Solution: ``` n=int(input()) d=list(map(int,input().split())) x=0 for i in range(n): x+=d[i]*sum(d[i+1:n]) print(x) ```
output
1
26,264
9
52,529
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,265
9
52,530
"Correct Solution: ``` n=int(input()) A=list(map(int,input().split())) f=0 for i in range(0,n-1): for j in range(i+1,n): f=f+A[i]*A[j] print(f) ```
output
1
26,265
9
52,531
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,266
9
52,532
"Correct Solution: ``` N=int(input()) d=list(map(int,input().split())) a=0 for i in range(N): for j in range(i+1,N): a+=d[i]*d[j] print(a) ```
output
1
26,266
9
52,533
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,267
9
52,534
"Correct Solution: ``` N = int(input()) A = list(map(int, input().split())) p = sum(A) q = sum([a * a for a in A]) print((p*p-q)//2) ```
output
1
26,267
9
52,535
Provide a correct Python 3 solution for this coding contest problem. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312
instruction
0
26,268
9
52,536
"Correct Solution: ``` N=int(input()) D=list(map(int,input().split())) a=0 b=0 for i in range(N): a+=(D[i])**2 b+=D[i] print((b**2-a)//2) ```
output
1
26,268
9
52,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` n = int(input()) d = list(map(int, input().split())) s = 0 for i in range(n - 1): s += d[i] * sum(d[i + 1 :]) print(s) ```
instruction
0
26,269
9
52,538
Yes
output
1
26,269
9
52,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` N = int(input()) d = [int(i) for i in input().split()] ans = (sum(d)) ** 2 for dd in d: ans -= dd ** 2 print(ans//2) ```
instruction
0
26,270
9
52,540
Yes
output
1
26,270
9
52,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` N=int(input()) d=list(map(int,input().split())) s=0 for j in range(N-1): for i in range(j+1,N): s+=d[j]*d[i] print(s) ```
instruction
0
26,271
9
52,542
Yes
output
1
26,271
9
52,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` N = int(input()) D = list(map(int,input().split())) ans = 0 for n in range(N-1): ans+=sum(D[n]*D[n+1:]) print(ans) ```
instruction
0
26,272
9
52,544
Yes
output
1
26,272
9
52,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` N = int(input()) D = list(map(int, input().split())) ans = 0 for i in range(0, N): for j in range(i, N+1): ans += (D[i] * D[j]) print(ans) ```
instruction
0
26,273
9
52,546
No
output
1
26,273
9
52,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` n = int(input()) D = list(map(int,input().split())) ans = 0 for i in range(n): for j in range(i): ans += D[i]*D[j] print(ans//2) ```
instruction
0
26,274
9
52,548
No
output
1
26,274
9
52,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` n=int(input()) d=list(map(int,input.split())) sam=0 for i in range(n): for j in range(n-1): sam=sam+(d[i]*d[J+1]) print(sam) ```
instruction
0
26,275
9
52,550
No
output
1
26,275
9
52,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points. There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values. Constraints * All values in input are integers. * 2 \leq N \leq 50 * 0 \leq d_i \leq 100 Input Input is given from Standard Input in the following format: N d_1 d_2 ... d_N Output Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served. Examples Input 3 3 1 2 Output 11 Input 7 5 0 7 8 3 3 2 Output 312 Submitted Solution: ``` a=int(input()) b=list(map(int,input().split())) c=0 for d,e in combinations(b,2): c+=d*e print(c) ```
instruction
0
26,276
9
52,552
No
output
1
26,276
9
52,553
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,489
9
52,978
"Correct Solution: ``` while 1: r0, w0, c, r = map(int, input().split()) if r0+w0+c+r < 1: break print(max((c*w0-r0+r-1)//r, 0)) ```
output
1
26,489
9
52,979
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,490
9
52,980
"Correct Solution: ``` import math while True: r0,w,c,r=map(int,input().split()) if [r0,w,c,r]==[0,0,0,0]: exit() ans=math.ceil((c*w-r0)/r) print(max(ans,0)) ```
output
1
26,490
9
52,981
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,491
9
52,982
"Correct Solution: ``` import math while True: r,w,c,vr = map(int,input().split()) if r==w==0: break r = math.ceil((w*c-r)/vr) if w*c-r>=0 else 0 print(r) ```
output
1
26,491
9
52,983
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,492
9
52,984
"Correct Solution: ``` while True: R0, W0, C, R = map(int, input().split()) if R0 + W0 + C + R == 0: break print(max((C * W0 - R0 + R -1) // R, 0)) ```
output
1
26,492
9
52,985
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,493
9
52,986
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(r0,w,c,r): c0 = r0/w if c0 >= c: print(0) return x = math.ceil((w*c-r0)/r) print(x) return #Solve if __name__ == "__main__": while 1: r0,w,c,r = LI() if r0 == w == c == r == 0: break solve(r0,w,c,r) ```
output
1
26,493
9
52,987
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,494
9
52,988
"Correct Solution: ``` def get_four_int(): four_int = input().split() for i, v in enumerate(four_int): four_int[i] = int(v) return four_int def get_min_roux_num(initial_roux, initial_water, ideal_concentration, min_unit): roux = initial_roux min_roux_num = 0 min_required_roux = initial_water * ideal_concentration while True: if roux >= min_required_roux: return min_roux_num roux += min_unit min_roux_num += 1 if __name__ == "__main__": while True: initial_roux, initial_water, ideal_concentration, min_unit = get_four_int() if initial_roux == 0: break min_roux_num = get_min_roux_num(initial_roux, initial_water, ideal_concentration, min_unit) print(min_roux_num) ```
output
1
26,494
9
52,989
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,495
9
52,990
"Correct Solution: ``` import math while True: r0, w0, c, r = map(int, input().split()) if (r0+w0+c+r) == 0: break else: tmp = math.ceil((w0*c - r0) / r) if tmp < 0: print(0) else: print(tmp) ```
output
1
26,495
9
52,991
Provide a correct Python 3 solution for this coding contest problem. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96
instruction
0
26,496
9
52,992
"Correct Solution: ``` while True: r0, w0, c, r = map(int, input().split()) if r0 == 0:break print(0 if w0 * c <= r0 else -((r0 - w0 * c) // r)) ```
output
1
26,496
9
52,993
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96 Submitted Solution: ``` R0, W0, C, R = list(map(int, input().split())) f=0 if R0 == W0 == C == R == 0: f+=1 while f==0: for X in range(10**5): if ((R0-W0*C)+R*X)>=0: y = ((R0-W0*C)+R*X)/C print(X) break else: continue R0, W0, C, R = list(map(int, input().split())) if R0 == W0 == C == R == 0: f+=1 ```
instruction
0
26,497
9
52,994
Yes
output
1
26,497
9
52,995
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96 Submitted Solution: ``` while (True): r_count = 0 r0, w0, c, r = map(int, input().split()) if not(r0 and w0 and c and r): break while ((r0 + r * r_count) / w0 < c): r_count += 1 print(r_count) ```
instruction
0
26,498
9
52,996
Yes
output
1
26,498
9
52,997
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96 Submitted Solution: ``` while True: R0, W0, C, R = map(int, input().split()) if R0 + W0 + C + R == 0: break n = 0 while True: if (n * R + R0) / W0 >= C: break n += 1 print(n) ```
instruction
0
26,499
9
52,998
Yes
output
1
26,499
9
52,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Curry making As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals. On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry. Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible. When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value. However, please note the following points regarding the curry making this time. * Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux. * The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer. * In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both. * Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur. Input The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format. > R0 W0 C R Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values ​​are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks. Output For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add. Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer. Sample Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output for Sample Input 2 3 0 0 9 96 Example Input 10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0 Output 2 3 0 0 9 96 Submitted Solution: ``` Q=[] while True: A=list(map(int,input().split())) if A==[0,0,0,0]: break else: Q.append(A) for k in range(len(Q)): for i in range(100000): P=(Q[k][0]+i*Q[k][3])/Q[k][2]-Q[k][1] if P>=0: print(i) break ```
instruction
0
26,500
9
53,000
Yes
output
1
26,500
9
53,001