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. 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: ``` l_raw = input().split() l = [int(n) for n in l_raw] try: l[0]/l[1] except: exit() if l[2] <= l[0]/l[1]: print(0) else: print(-(-(l[2]*l[1]-l[0])//l[3])) ```
instruction
0
26,501
9
53,002
No
output
1
26,501
9
53,003
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: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: a,b,c,d = LI() if a == 0: break for r in range(1000): if (a+d*r) / b >= c: rr.append(r) break return '\n'.join(map(str, rr)) print(main()) ```
instruction
0
26,502
9
53,004
No
output
1
26,502
9
53,005
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 1: R0,W0,C,R=map(int,input().split()) if not R0 and not W0 and not C and not R:break n=0 while 1: if W0>1 and int((R0+R*n)/W0)==C:break elif W0==1 and (R0+R*n)>=C:break n+=1 print(n) ```
instruction
0
26,503
9
53,006
No
output
1
26,503
9
53,007
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
27,999
9
55,998
Tags: binary search, implementation, math Correct Solution: ``` from sys import stdin, stdout import math import decimal as dm k, d, t = [int(x) for x in stdin.readline().split()] dm.getcontext().prec = 200 dc = (dm.Decimal(k) / dm.Decimal(d)).quantize(dm.Decimal('1'), rounding=dm.ROUND_CEILING) * dm.Decimal(d) segp = (dc + dm.Decimal(k)) / dm.Decimal(2 * t) segt = dc nseg = (dm.Decimal(1.0) / segp).quantize(dm.Decimal('1'), rounding=dm.ROUND_FLOOR) # print(nseg, segp) dt = nseg * segt p = dm.Decimal(1) - nseg * segp # print(p) kseg = min(p, dm.Decimal(k) / dm.Decimal(t)) # print(kseg) dt += kseg * dm.Decimal(t) p -= kseg dt += p * dm.Decimal(2 * t) stdout.write('{:.10}\n'.format(dt)) ```
output
1
27,999
9
55,999
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,000
9
56,000
Tags: binary search, implementation, math Correct Solution: ``` import math k,d,t=(map(int,input().strip().split(' '))) if(k%d==0): print(t) elif(k<d): x=k+(d-k)/2 cycle=(t//x) ans=cycle*d kaam=(t//x)*x kaam=t-kaam if(kaam<=k): ans+=kaam else: ans+=k kaam-=k ans+=2*kaam print(ans) else: xx=math.ceil(k/d)*d x=(k+(xx-k)/2) cycle = (t//x) ans=cycle*xx kaam = (t//x)*x kaam=t-kaam if(kaam<=k): ans+=kaam else: ans+=k kaam-=k ans+=2*kaam print(ans) ```
output
1
28,000
9
56,001
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,001
9
56,002
Tags: binary search, implementation, math Correct Solution: ``` k, d, t = map(int, input().split()) t *= 2 x = (k + d - 1) // d period = x * d score = 2 * k + period - k ans = t // score * period t %= score if t <= 2 * k: ans += t / 2 else: ans += k + (t - 2 * k) print('%.10f'% ans) ```
output
1
28,001
9
56,003
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,002
9
56,004
Tags: binary search, implementation, math Correct Solution: ``` k,d,t=map(int,input().split()) if k%d==0 : print(float(t)) exit() x=((k//d)+1)*d ##print(x) y=(k + (x-k)/2) #print(y) z=(t//y) #print(z*y) l=t-(z*y) m=min(l,k) l-=(m) #print(l) ans=(z*x+ m+ [0,l*2][l>0]) print(ans) ```
output
1
28,002
9
56,005
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,003
9
56,006
Tags: binary search, implementation, math Correct Solution: ``` k,d,t=input().split() k,d,t=int(k),int(d),int(t) time=0 if True: m=int((k-1)/d)*d+d-k #print(m) tc=k+0.5*m ta=k+m l=int(t/tc) time=ta*l #print(tc) #print(ta) #print(time) #print(l) if (k>t-l*tc): time+=t-l*tc #print(t-l*tc) else: time+=k time+=2*(t-l*tc-k) print(time) ```
output
1
28,003
9
56,007
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,004
9
56,008
Tags: binary search, implementation, math Correct Solution: ``` a = [int(x) for x in input().split(" ")] k = a[0] d = a[1] t = a[2] def solve(remain): once = k + remain / 2 times = t // once # final = t - times * once final = t % once if final <= k: timeNeed = final + times * (k + remain) else: final -= k timeNeed = k + final * 2 + times * (k + remain) print("{:.1f}".format(timeNeed)) pass if k % d == 0: print("{:.1f}".format(float(t))) elif k < d: remain = d - k solve(remain) else: remain = d - k % d solve(remain) ```
output
1
28,004
9
56,009
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,005
9
56,010
Tags: binary search, implementation, math Correct Solution: ``` k,d,t=map(int,input().split()) l=int(1) r=int(1000000000000000000) while l<r: m=(l+r)//2 if m*d>=k: r=m else: l=m+1 ck=d*l peerck=k+(ck-k)/2.0 l=int(0) r=int(1000000000000000000) while l<r: m=(l+r)//2 if (r-l)%2==1: m=m+1 if peerck*m<=t: l=m else: r=m-1 res=l*ck t=t-peerck*l if k>t: print (res+t) else : print (res+(t-k)*2+k) ```
output
1
28,005
9
56,011
Provide tags and a correct Python 3 solution for this coding contest problem. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
instruction
0
28,006
9
56,012
Tags: binary search, implementation, math Correct Solution: ``` k, d, t = (int(x) for x in input().split()) import math as m if d >= k: chunksize = d chunkspeed = k + (d-k)/2 else: lcm = k // m.gcd(k, d) * d lft = 0 rgt = lcm//d while lft != rgt: cur = (lft+rgt)//2 if d*cur < k: lft = cur+1 else: rgt = cur chunksize = lft * d chunkspeed = k + (chunksize-k)/2 chunks = m.floor(t / chunkspeed) # print(chunksize) # print(chunkspeed) ans = chunksize * chunks rem = t - (chunkspeed * chunks) if rem <= k: ans += rem else: ans += k rem -= k ans += rem*2 print(ans) ```
output
1
28,006
9
56,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` k,d,t=input().split() k,d,t=int(k),int(d),int(t) on=k off=d-(k-1)%d-1 cycle=on+off/2 time=(on+off)*(t//cycle) t-=cycle*(t//cycle) if t<k: print(t+time) else: print(time+k+(t-k)*2) ```
instruction
0
28,007
9
56,014
Yes
output
1
28,007
9
56,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` k,d,t=map(int,input().split()) m= (k+d-1)//d extra=m*d - k c=extra/2.0 tot=k+c dd=t//tot ans=dd*(k+extra) xx= t - dd*tot if xx<=k: ans=ans+xx else: ans=ans+k xx=xx-k ans=ans + xx*2 print(float(ans)) ```
instruction
0
28,008
9
56,016
Yes
output
1
28,008
9
56,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` from math import * # import sys # # sys.stdin = open("test.in", "r") k, d, t = map(int, input().split()) if d < k: d *= (k + d - 1) // d u = float(k + (d-k)*0.5) ans = floor(t / u) * d rem = t - floor(t/u) * u if rem < k: ans += rem else: ans += k rem -= k ans += 2 * rem print("%.10f" % ans) ```
instruction
0
28,010
9
56,020
Yes
output
1
28,010
9
56,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` import sys k, d, t = tuple(map(int, sys.stdin.readline().split())) t = 2 * t; req = ((k // d) + (k%d != 0) * 1) * d t_req = k * 2 + req - k; ans = (t // t_req) * req left = t % t_req if (k * 2 <= left): ans = ans + (left // 2) else: ans = ans + k + (left - 2 * k) / 2 print(ans) ```
instruction
0
28,012
9
56,024
No
output
1
28,012
9
56,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` k, d, t = (int(x) for x in input().split()) d_0 = d if k > d: d_0 = (k // d + k % d) * d # print(d_0) time = t // (k + (d_0 - k) * 0.5) t -= (k + (d_0 - k) * 0.5) * time if t < k: print(time * d_0 + t) else: print(time * d_0 + k + (t - k) * 2) # print(time, t) ```
instruction
0
28,013
9
56,026
No
output
1
28,013
9
56,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes. Submitted Solution: ``` from math import* from fractions import gcd import sys from audioop import reverse def main(): s=input() s=s.split() k=int(s[0]) d= int(s[1]) t=int(s[2]) x=(k*d)//gcd(k,d) n=(x-d) n//=d n-=1 n/=2 ans=t+n; print(ans) if __name__ == '__main__':main() ```
instruction
0
28,014
9
56,028
No
output
1
28,014
9
56,029
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,096
9
56,192
"Correct Solution: ``` N,M = map(int,input().split()) A = list(map(int,input().split())) cums = [0] for a in A: cums.append(cums[-1] + a) cump = [c%M for c in cums] from collections import Counter ctr = Counter(cump) ans = 0 for v in ctr.values(): ans += v*(v-1)//2 print(ans) ```
output
1
28,096
9
56,193
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,097
9
56,194
"Correct Solution: ``` from itertools import accumulate from collections import Counter n, m = map(int, input().split()) ans = sum(v * (v - 1) // 2 for v in Counter([ak % m for ak in accumulate(map(int, input().split()))] + [0]).values()) print(ans) ```
output
1
28,097
9
56,195
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,098
9
56,196
"Correct Solution: ``` N,M = (int(x) for x in input().split()) A_arr = [int(x) for x in input().split()] mM_map = {0:1} tmp = 0 for A in A_arr: tmp = (tmp+A)%M mM_map.setdefault(tmp, 0) mM_map[tmp] += 1 ans = 0 for v in mM_map.values(): ans += v*(v-1)//2 print(ans) ```
output
1
28,098
9
56,197
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,099
9
56,198
"Correct Solution: ``` n,m=map(int,input().split()) from collections import Counter from itertools import accumulate a=list(map(int,input().split())) b=list(accumulate(a)) b=[0]+b b=list(map(lambda x:x%m ,b)) e=Counter(b) ans=0 for i in e.values(): ans+=i*(i-1)//2 print(ans) ```
output
1
28,099
9
56,199
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,100
9
56,200
"Correct Solution: ``` from itertools import accumulate as ac from collections import Counter as c n,m=map(int,input().split()) a=0 for i in c([i%m for i in [0]+list(ac(list(map(int,input().split()))))]).values(): a+=i*(i-1)//2 print(a) ```
output
1
28,100
9
56,201
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,101
9
56,202
"Correct Solution: ``` n,m = map(int,input().split()) a = list(map(int,input().split())) s = [0 for i in range(0,n+1)] d = {0:1} ans = 0 for i in range(0,len(a)): s[i+1] += a[i] + s[i] r = s[i+1]%m ans += d.get(r,0) d[r] = d.get(r,0) + 1 print(ans) ```
output
1
28,101
9
56,203
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,102
9
56,204
"Correct Solution: ``` from collections import Counter N, M = map(int, input().split()) A = list(map(int, input().split())) B = [0] for i in range(N): B.append((B[-1]+A[i])%M) C = Counter(B) ans = 0 for mod, c in C.most_common(): ans += c*(c-1)//2 print(ans) ```
output
1
28,102
9
56,205
Provide a correct Python 3 solution for this coding contest problem. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25
instruction
0
28,103
9
56,206
"Correct Solution: ``` n,m=map(int,input().split());d={0:1};r=s=0 for i in input().split():s+=int(i);s%=m;x=d.get(s,0);r+=x;d[s]=x+1 print(r) ```
output
1
28,103
9
56,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` from collections import Counter N, M = map(int, input().split()) As = list(map(int, input().split())) ct = Counter() ct[0] = 1 s = 0 ans = 0 for a in As: s += a mod = s % M ans += ct[mod] ct[mod] += 1 print(ans) ```
instruction
0
28,105
9
56,210
Yes
output
1
28,105
9
56,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers and satisfy 1 \leq l \leq r \leq N. * A_l + A_{l+1} + ... + A_r is a multiple of M. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 2 \leq M \leq 10^9 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the number of the pairs (l, r) that satisfy the conditions. Note that the number may not fit into a 32-bit integer type. Examples Input 3 2 4 1 5 Output 3 Input 13 17 29 7 5 7 9 51 7 13 8 55 42 9 81 Output 6 Input 10 400000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Output 25 Submitted Solution: ``` import numoy as np N,M = list(map(int,input().split())) A = input().split() count = 0 A = np.array(A,dtype='int64') B = np.cumsum(A) C = np.append([0],B) L = [1 for i in range(len(C)) for t in range(len(C)) if i<t and (C[t] - C[i])%M==0] print(len(L)) ```
instruction
0
28,110
9
56,220
No
output
1
28,110
9
56,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops. Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount. Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors. Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery. Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness). Monocarp analyzed his competitors' data and came up with m possible consumer demand values k_1, k_2, ..., k_m, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him? Input The first line contains two integers n and m (1 ≀ n ≀ 2 β‹… 10^5; 1 ≀ m ≀ 2 β‹… 10^5) β€” the number of days the bakery is open and the number of possible values of consumer demand. The second line contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the number of bread loaves that will be baked each day. The third line contains m integers k_1, k_2, ..., k_m (1 ≀ k_1 < k_2 < ... < k_m ≀ 10^9) β€” the possible consumer demand values in the ascending order. Output Print m integers: for each consumer demand, print the unattractiveness of the bakery. Examples Input 5 4 5 2 1 3 7 1 3 4 10 Output 4 2 1 0 Input 8 9 3 1 4 1 5 9 2 6 1 2 3 4 5 6 7 8 9 Output 7 5 3 3 2 1 1 1 0 Note In the first example, let's describe what happens for couple consumer demands: If consumer demand is equal to 1: * at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1 - 1 = 0; * at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2 - 2 = 0; * at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3 - 3 = 0; * at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4 - 4 = 0; * at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5 - 1 = 4. In total, the unattractiveness of the bakery will be equal to 4. If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0. Submitted Solution: ``` from collections import deque from math import floor from heapq import heappush, heappop class DisjointSet: def __init__(self, n, amounts): self.n = n self.par = [-1] * n self.ranges = list() self.aValues = list() for i in range(n): self.ranges.append((i, i)) self.aValues.append(amounts[i]) self.maxRange = 0 self.unionCounter = 0 def findParent(self, i): if self.par[i] == -1: return i #no parent yet else: var = self.findParent(self.par[i]) self.par[i] = var return var def getKValueBetweenAdjSegments(self, i): par = self.findParent(i) potentialRange = (self.ranges[par][0], self.ranges[par][1] + 1) combinedAValue = self.aValues[par] ret = (combinedAValue - 1) // (potentialRange[1] - potentialRange[0]) return ret def union(self, a, b): self.unionCounter += 1 aPar = self.findParent(a) bPar = self.findParent(b) if aPar != bPar: aRange = self.ranges[aPar] bRange = self.ranges[bPar] self.aValues[bPar] += self.aValues[aPar] self.ranges[bPar] = (aRange[0], bRange[1]) self.par[aPar] = bPar # rightmost becomes parent self.maxRange = max(self.maxRange, self.ranges[bPar][1] - self.ranges[bPar][0]) return True return False def numComponents(self): componentParents = set() for i in range(n): componentParents.add(self.findParent(i)) return len(componentParents) splitted = [int(amit) for amit in input().split(" ")] n = splitted[0] m = splitted[1] amounts = [int(amit) for amit in input().split(" ")] k_arr = [int(amit) for amit in input().split(" ")] res = deque() if (n == 200000): print ("here1") exit() ds = DisjointSet(n, amounts) pq = list() legitVals = dict() for i in range(n-1): heappush(pq, (-1 * ds.getKValueBetweenAdjSegments(i), i)) kIndex = len(k_arr) - 1 visited = set() while kIndex >= 0 and len(pq) > 0: curK = k_arr[kIndex] peek = pq[0] peekValue = -1 * peek[0] peekIndex = peek[1] if peekIndex in visited: heappop(pq) continue if curK <= peekValue: actuallyUnioned = ds.union(peekIndex, peekIndex + 1) visited.add(peekIndex) heappop(pq) if actuallyUnioned: theParent = ds.findParent(peekIndex + 1) if theParent < n - 1: heappush(pq, (-1 * ds.getKValueBetweenAdjSegments(theParent), theParent)) else: res.appendleft(str(ds.maxRange)) kIndex -= 1 if (n == 200000): print ("here") while len(res) != len(k_arr): res.appendleft(str(ds.maxRange)) print (" ".join(res)) ```
instruction
0
28,470
9
56,940
No
output
1
28,470
9
56,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops. Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount. Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors. Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery. Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness). Monocarp analyzed his competitors' data and came up with m possible consumer demand values k_1, k_2, ..., k_m, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him? Input The first line contains two integers n and m (1 ≀ n ≀ 2 β‹… 10^5; 1 ≀ m ≀ 2 β‹… 10^5) β€” the number of days the bakery is open and the number of possible values of consumer demand. The second line contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the number of bread loaves that will be baked each day. The third line contains m integers k_1, k_2, ..., k_m (1 ≀ k_1 < k_2 < ... < k_m ≀ 10^9) β€” the possible consumer demand values in the ascending order. Output Print m integers: for each consumer demand, print the unattractiveness of the bakery. Examples Input 5 4 5 2 1 3 7 1 3 4 10 Output 4 2 1 0 Input 8 9 3 1 4 1 5 9 2 6 1 2 3 4 5 6 7 8 9 Output 7 5 3 3 2 1 1 1 0 Note In the first example, let's describe what happens for couple consumer demands: If consumer demand is equal to 1: * at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1 - 1 = 0; * at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2 - 2 = 0; * at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3 - 3 = 0; * at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4 - 4 = 0; * at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5 - 1 = 4. In total, the unattractiveness of the bakery will be equal to 4. If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0. Submitted Solution: ``` def spoilage(arr, n, customer_demand, m): res = [] for i in range(m): res.append(max_spoilage(arr, n, customer_demand[i])) return res def max_spoilage(arr, n, k): if k >= max(arr): return 0 if k <= min(arr): return n - 1 result = 0 cur_spoil = None loaves = [] for i in range(n): tmp = arr[i] - k if tmp > 0 and len(loaves) == 0: cur_spoil = (tmp, i + 1) loaves.append(cur_spoil) elif tmp > 0 and len(loaves) > 0: cur_spoil = (tmp, i + 1) loaves.append(cur_spoil) elif tmp < 0 and len(loaves) == 0: continue elif tmp < 0 and len(loaves) > 0: j = len(loaves) - 1 while j >= 0: cur_spoil = loaves[j] cur_spoil = (cur_spoil[0] + tmp, cur_spoil[1]) if cur_spoil[0] <= 0 and j == 0: result = max(result, i - cur_spoil[1] + 1) loaves.pop() elif cur_spoil[0] <= 0: loaves.pop() elif cur_spoil[0] >0: loaves[j] = cur_spoil j -= 1 if len(loaves) > 0: result = max(result, n - loaves[0][1]) if k == 2: print(loaves) return result if __name__ == "__main__": parameter = input().split() n = int(parameter[0]) m = int(parameter[1]) loaves = [] get_arr = input().split() for i in range(int(n)): loaves.append(int(get_arr[i])) customer_demand = [] get_arr = input().split() for i in range(int(m)): customer_demand.append(int(get_arr[i])) res = spoilage(loaves, n, customer_demand, m) for r in res: print(r) ```
instruction
0
28,471
9
56,942
No
output
1
28,471
9
56,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops. Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount. Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors. Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery. Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness). Monocarp analyzed his competitors' data and came up with m possible consumer demand values k_1, k_2, ..., k_m, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him? Input The first line contains two integers n and m (1 ≀ n ≀ 2 β‹… 10^5; 1 ≀ m ≀ 2 β‹… 10^5) β€” the number of days the bakery is open and the number of possible values of consumer demand. The second line contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the number of bread loaves that will be baked each day. The third line contains m integers k_1, k_2, ..., k_m (1 ≀ k_1 < k_2 < ... < k_m ≀ 10^9) β€” the possible consumer demand values in the ascending order. Output Print m integers: for each consumer demand, print the unattractiveness of the bakery. Examples Input 5 4 5 2 1 3 7 1 3 4 10 Output 4 2 1 0 Input 8 9 3 1 4 1 5 9 2 6 1 2 3 4 5 6 7 8 9 Output 7 5 3 3 2 1 1 1 0 Note In the first example, let's describe what happens for couple consumer demands: If consumer demand is equal to 1: * at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1 - 1 = 0; * at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2 - 2 = 0; * at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3 - 3 = 0; * at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4 - 4 = 0; * at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5 - 1 = 4. In total, the unattractiveness of the bakery will be equal to 4. If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0. Submitted Solution: ``` N, M = list(map(int, input().split())) bread = list(map(int, input().split())) demand = list(map(int, input().split())) ans = [] for i in range(len(demand)): dem = demand[i] stack = [] res = 0 for j in range(len(bread)): amt = bread[j] if amt > dem: stack.append([amt - dem, j]) elif amt < dem: need = dem - amt while stack and need > 0: rem, day = stack.pop() if rem >= need: rem -= need need = 0 res = max(j - day, res) if rem > 0: stack.append([rem, day]) break else: need -= rem res = max(j - day, res) else: pass if not stack: ans.append(res) else: while stack: x, y = stack.pop() res = max(res, N - y - 1) ans.append(res) print(ans) ```
instruction
0
28,472
9
56,944
No
output
1
28,472
9
56,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops. Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount. Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors. Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery. Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness). Monocarp analyzed his competitors' data and came up with m possible consumer demand values k_1, k_2, ..., k_m, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him? Input The first line contains two integers n and m (1 ≀ n ≀ 2 β‹… 10^5; 1 ≀ m ≀ 2 β‹… 10^5) β€” the number of days the bakery is open and the number of possible values of consumer demand. The second line contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the number of bread loaves that will be baked each day. The third line contains m integers k_1, k_2, ..., k_m (1 ≀ k_1 < k_2 < ... < k_m ≀ 10^9) β€” the possible consumer demand values in the ascending order. Output Print m integers: for each consumer demand, print the unattractiveness of the bakery. Examples Input 5 4 5 2 1 3 7 1 3 4 10 Output 4 2 1 0 Input 8 9 3 1 4 1 5 9 2 6 1 2 3 4 5 6 7 8 9 Output 7 5 3 3 2 1 1 1 0 Note In the first example, let's describe what happens for couple consumer demands: If consumer demand is equal to 1: * at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1 - 1 = 0; * at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2 - 2 = 0; * at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3 - 3 = 0; * at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4 - 4 = 0; * at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5 - 1 = 4. In total, the unattractiveness of the bakery will be equal to 4. If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0. Submitted Solution: ``` def spoilage(arr, n, customer_demand, m): res = [] for i in range(m): res.append(max_spoilage(arr, n, customer_demand[i])) return res def max_spoilage(arr, n, k): if k >= max(arr): return 0 if k <= min(arr): return n - 1 result = 0 cur_spoil = None loaves = [] for i in range(n): tmp = arr[i] - k if tmp > 0 and len(loaves) == 0: cur_spoil = (tmp, i + 1) loaves.append(cur_spoil) elif tmp > 0 and len(loaves) > 0: cur_spoil = (tmp, i + 1) loaves.append(cur_spoil) elif tmp < 0 and len(loaves) == 0: continue elif tmp < 0 and len(loaves) > 0: j = len(loaves) - 1 while j >= 0: cur_spoil = loaves[j] cur_spoil = (cur_spoil[0] + tmp, cur_spoil[1]) if cur_spoil[0] <= 0 and j == 0: result = max(result, i - cur_spoil[1] + 1) loaves.pop() elif cur_spoil[0] <= 0: loaves.pop() elif cur_spoil[0] >0: loaves[j] = cur_spoil j -= 1 if len(loaves) > 0: result = max(result, n - loaves[len(loaves)-1][1]) return result if __name__ == "__main__": parameter = input().split() n = int(parameter[0]) m = int(parameter[1]) loaves = [] get_arr = input().split() for i in range(int(n)): loaves.append(int(get_arr[i])) customer_demand = [] get_arr = input().split() for i in range(int(m)): customer_demand.append(int(get_arr[i])) res = spoilage(loaves, n, customer_demand, m) for r in res: print(r) ```
instruction
0
28,473
9
56,946
No
output
1
28,473
9
56,947
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,576
9
57,152
Tags: implementation, math Correct Solution: ``` n,m,x,y,z,p = map(int,input().split()) ps = [] for i in range(p): ps.append(list(map(int,input().split()))) x = x%4 y = y%2 z = ((z%4)*3)%4 for p in ps: mm,nn = m,n i,j = p for _ in range(x): i,j = j,nn-i+1 mm,nn = nn,mm for _ in range(y): i,j = i,mm-j+1 for _ in range(z): i,j = j,nn-i+1 mm,nn = nn,mm print(i,j) ```
output
1
28,576
9
57,153
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,577
9
57,154
Tags: implementation, math Correct Solution: ``` import sys try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass n, m, x, y, z, p = (int(i) for i in input().split()) points = [] for i in range(0, p): points.append([int(j) for j in input().split()]) x %= 4 y %= 2 z %= 4 for i in range(0, x): for i in range(0, p): point = [0, 0] point[1] = n - points[i][0] + 1 point[0] = points[i][1] points[i] = point n, m = m, n if y == 1: for i in range(0, p): points[i][1] = m - points[i][1] + 1 for i in range(0, z): for i in range(0, p): point = [0, 0] point[1] = points[i][0] point[0] = m - points[i][1] + 1 points[i] = point n, m = m, n for i in range(0, p): print('%d %d\n' % (points[i][0], points[i][1]), end = '') ```
output
1
28,577
9
57,155
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,578
9
57,156
Tags: implementation, math Correct Solution: ``` R,C,x,y,z,p=map(int, input().split()) tmpR=R; tmpC=C x%=4; y%=2; z%=4 z=4-z for k in range(p): i, j=map(int, input().split()) for t in range(x): tmpi=i i=j; j=R-tmpi+1 R,C= C,R for t in range(y): j=C-(j-1) for t in range(z): tmpi=i i=j; j=R-tmpi+1 R,C=C,R print(i, end=' '); print(j) R=tmpR; C=tmpC ```
output
1
28,578
9
57,157
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,579
9
57,158
Tags: implementation, math Correct Solution: ``` n,m,x,y,z,p=map(int,input().split()) x=x%4 y=y%2 z=z%4 n0,m0=n,m for i in range(p): n,m=n0,m0 x1,y1=map(int,input().split()) for j in range(x): x1,y1=y1,n-x1+1 n,m=m,n if y==1: y1=m-y1+1 # print(x1,y1) for i in range(z): x1,y1=m-y1+1,x1 n,m=m,n print(x1,y1) ```
output
1
28,579
9
57,159
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,580
9
57,160
Tags: implementation, math Correct Solution: ``` from sys import stdin def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] def clockwise(mod): for i in range(1, mod + 1): for j in range(p): if i & 1: a[j] = [a[j][1], (n + 1) - a[j][0]] else: a[j] = [a[j][1], (m + 1) - a[j][0]] def horizontal(mod): if mod: for i in range(p): if x & 1: a[i][1] = (n + 1) - a[i][1] else: a[i][1] = (m + 1) - a[i][1] def counter(mod): for i in range(1, mod + 1): for j in range(p): if x % 2: if i & 1: a[j] = [a[j][1], (m + 1) - a[j][0]] else: a[j] = [a[j][1], (n + 1) - a[j][0]] else: if i & 1: a[j] = [a[j][1], (n + 1) - a[j][0]] else: a[j] = [a[j][1], (m + 1) - a[j][0]] def print1(): for i in range(p): print(*a[i]) n, m, x, y, z, p = arr_inp(1) a = [arr_inp(1) for i in range(p)] # print(x % 4, y % 2, z % 4) clockwise(x % 4) horizontal(y % 2) if z % 4 > 0: counter(4 - (z % 4)) print1() ```
output
1
28,580
9
57,161
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,581
9
57,162
Tags: implementation, math Correct Solution: ``` n, m, x, y, z, p = map(int, input().split()) n, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4 def a(i, j, n, m, k): if k == 0: return i, j, n, m if k == 1: return j, n - i, m, n if k == 2: return n - i, m - j, n, m return m - j, i, m, n def b(i, j, m, k): if k == 0: return i, j if k == 1: return i, m - j for i in range(p): u, v = map(int, input().split()) u, v, q, p = a(u, v, n, m, x) u, v = b(u, v, p, y) u, v, q, p = a(u, v, q, p, z) print(u, v) ```
output
1
28,581
9
57,163
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,582
9
57,164
Tags: implementation, math Correct Solution: ``` n,m,x,y,z,p=map(int,input().split()) x%=4 y%=2 z%=4 tn,tm=n,m while p>=1: n,m=tn,tm p-=1 sx,sy=map(int,input().split()) for i in range(0,x): sx,sy=sy,n-sx+1 n,m=m,n if y>0: sy=m-sy+1 for i in range(0,z): sx,sy=m-sy+1,sx n,m=m,n print(sx,sy) ```
output
1
28,582
9
57,165
Provide tags and a correct Python 3 solution for this coding contest problem. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ
instruction
0
28,583
9
57,166
Tags: implementation, math Correct Solution: ``` from sys import stdin def candy (a,b,c,d,e): if (e == 0): return a,b,c,d if (e == 1): return b,c-a,d,c if (e == 2): return c-a,d-b,c,d return (d-b, a, d, c) def candy2 (a,b,c,e): if (e == 0): return a,b if (e ==1): return a, c-b def main(): ''' Name: Kevin S. sanchez ''' inp = stdin n, m, x, y, z, p = map(int, inp.readline().split()) n, m, x, y, z = n+1, m+1, x%4 , y % 2, (4-z)%4 for i in range (0,p): u, v = map(int, inp.readline().split()) u, v, q, p = candy(u,v,n,m,x) u,v = candy2(u,v,p,y) u,v,q,p = candy(u,v,q,p,z) print(u,v) main() ```
output
1
28,583
9
57,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` h, w, x, y, z, p = map(int, input().split()) x, y, z = x % 4, y % 2, z % 4 def rotation(a, b): global h, w res = (b, h - a + 1) w, h = h, w return res def flip(a, b): return a, w - b + 1 res = [] for i in range(p): a, b = map(int, input().split()) ch, cw = h, w for i in range(x): a, b = rotation(a, b) for i in range(y): a, b = flip(a, b) for i in range(3 * z): a, b = rotation(a, b) res += [str(a) + ' ' + str(b)] h, w = ch, cw print('\n'.join(map(str, res))) ```
instruction
0
28,584
9
57,168
Yes
output
1
28,584
9
57,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` def rotateClk(x,y,n): tmp = x x = y y = n+1- tmp return (x,y) def rev(x,y,m): return (x,m+1-y) n,m,x,y,z,p = [int(x) for x in input().split()] pts = [] for _ in range(p): pts.append([int(x) for x in input().split()]) x = x%4 y = y%2 z = z%4 for i,pt in enumerate(pts): if x == 1: pt = rotateClk(pt[0],pt[1],n) elif x == 2: pt = rotateClk(pt[0],pt[1],n) pt = rotateClk(pt[0],pt[1],m) elif x == 3: pt = rotateClk(pt[0],pt[1],n) pt = rotateClk(pt[0],pt[1],m) pt = rotateClk(pt[0],pt[1],n) pts[i] = pt for i,pt in enumerate(pts): if y == 1: pts[i] = rev(pt[0],pt[1],m if x%2 == 0 else n) for i,pt in enumerate(pts): if z == 3: pt = rotateClk(pt[0],pt[1],n if x%2 == 0 else m) elif z == 2: prev = n if x%2 == 0 else m pt = rotateClk(pt[0],pt[1],prev) pt = rotateClk(pt[0],pt[1],n if prev == m else m) elif z == 1: prev = n if x%2 == 0 else m pt = rotateClk(pt[0],pt[1],prev) pt = rotateClk(pt[0],pt[1],n if prev == m else m) pt = rotateClk(pt[0],pt[1],prev) pts[i] = pt for pt in pts: print(pt[0],pt[1]) ```
instruction
0
28,585
9
57,170
Yes
output
1
28,585
9
57,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` h, w, x, y, z, p = map(int, input().split()) x %= 4 y %= 2 z %= 4 def rot(a, b): global h global w res = b, h - a + 1 w, h = h, w return res def flip(a, b): return a, w - b + 1 for i in range(p): a, b = map(int, input().split()) sh, sw = h, w for i in range(x): a, b = rot(a, b) for i in range(y): a, b = flip(a, b) for i in range(3 * z): a, b = rot(a, b) print(a, b) h, w = sh, sw ```
instruction
0
28,586
9
57,172
Yes
output
1
28,586
9
57,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` n, m, x, y, z, p = map(int, input().split()) y = y % 2 x = x % 4 z = z % 4 for i in range(p): xi, yi = map(int, input().split()) t = (n,m) for j in range(x): xi, yi = yi, n - xi + 1 n, m = m, n if y == 1: yi = m - yi + 1 for j in range((-z)%4): xi, yi = yi, n - xi + 1 n, m = m, n n, m = t[0], t[1] print(xi, yi) ```
instruction
0
28,587
9
57,174
Yes
output
1
28,587
9
57,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` n, m, x, y, z, p = map(int, input().split()) y = y % 2 x = (x - z) % 4 for i in range(p): xi, yi = map(int, input().split()) if y == 1: yi = m - yi + 1 t = (n,m) for j in range(x): yi, xi = n - yi + 1, xi n, m = m, n n, m = t[0], t[1] print(xi, yi) ```
instruction
0
28,588
9
57,176
No
output
1
28,588
9
57,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` m,n,x,y,z,p = list(map(int,input().split())) x %= 4 y %= 2 z %= 4 a = [] for i in range(p): a.append(list(map(int,input().split()))) if x == 1: for i in range(p): a[i][0],a[i][1] = a[i][1],a[i][0] if n>m: a[i][1] = m-a[i][1]+1 else: a[i][0] = n-a[i][0]+1 elif x == 2: for i in range(p): a[i][1] = m-a[i][1]+1 a[i][0] = n-a[i][0]+1 elif x == 3: for i in range(p): a[i][0],a[i][1] = a[i][1],a[i][0] a[i][1] = m-a[i][1]+1 a[i][0] = n-a[i][0]+1 if y == 1: for i in range(p): a[i][0] = n-a[i][0]+1 if z == 1: for i in range(p): a[i][0],a[i][1] = a[i][1],a[i][0] a[i][1] = m-a[i][1]+1 a[i][0] = n-a[i][0]+1 elif z == 2: for i in range(p): a[i][1] = m-a[i][1]+1 a[i][0] = n-a[i][0]+1 elif z == 3: for i in range(p): a[i][0],a[i][1] = a[i][1],a[i][0] if n>m: a[i][1] = m-a[i][1]+1 else: a[i][0] = n-a[i][0]+1 for i in a: print(*i) ```
instruction
0
28,589
9
57,178
No
output
1
28,589
9
57,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` h, w, x, y, z, p = map(int, input().split()) x %= 4 y %= 2 z %= 4 def rot(a, b): global h global w return b, h - a + 1 w, h = h, w def flip(a, b): return a, w - b + 1 for i in range(p): a, b = map(int, input().split()) sh, sw = h, w for i in range(x): a, b = rot(a, b) for i in range(y): a, b = flip(a, b) for i in range(3 * z): a, b = rot(a, b) print(a, b) h, w = sh, sw ```
instruction
0
28,590
9
57,180
No
output
1
28,590
9
57,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns β€” from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk). The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. <image> Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input The first line of the input contains fix integers n, m, x, y, z, p (1 ≀ n, m ≀ 109; 0 ≀ x, y, z ≀ 109; 1 ≀ p ≀ 105). Each of the following p lines contains two integers xk, yk (1 ≀ xk ≀ n; 1 ≀ yk ≀ m) β€” the initial coordinates of the k-th candy. Two candies can lie on the same cell. Output For each of the p candies, print on a single line its space-separated new coordinates. Examples Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1 Note Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: QWER REWQ ASDF -> FDSA ZXCV VCXZ Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() R,C,x,y,z,p=value() x=x%4 y=y%2 z=z%4 for i in range(p): i,j=value() r,c=R,C for _ in range(x): i,j=j,r-i+1 r,c=c,r # print(i,j,'1st') for _ in range(y): i,j=i,c-j+1 # print(i,j,'2nd') for _ in range(z): i,j=c-j+1,i print(i,j) ```
instruction
0
28,591
9
57,182
No
output
1
28,591
9
57,183
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easier version of the problem. In this version, 1 ≀ n ≀ 10^5 and 0 ≀ a_i ≀ 1. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare n boxes of chocolate, numbered from 1 to n. Initially, the i-th box contains a_i chocolate pieces. Since Bob is a typical nice guy, he will not send Alice n empty boxes. In other words, at least one of a_1, a_2, …, a_n is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer k > 1 such that the number of pieces in each box is divisible by k. Note that Alice won't mind if there exists some empty boxes. Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box i and put it into either box i-1 or box i+1 (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of chocolate boxes. The second line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 1) β€” the number of chocolate pieces in the i-th box. It is guaranteed that at least one of a_1, a_2, …, a_n is positive. Output If there is no way for Charlie to make Alice happy, print -1. Otherwise, print a single integer x β€” the minimum number of seconds for Charlie to help Bob make Alice happy. Examples Input 3 1 0 1 Output 2 Input 1 1 Output -1
instruction
0
30,177
9
60,354
Tags: constructive algorithms, greedy, math, number theory, ternary search, two pointers Correct Solution: ``` n = int(input()) l = list(map(int,input().split())) s = sum(l) dupa = [] if s <= 1: print(-1) else: for i in range(n): if l[i] == 1: dupa.append(i) pref = [0] * s pref[0] = dupa[0] for i in range(1,s): pref[i] = pref[i-1] + dupa[i] wynik = 10000000000000 for i in list(range(2,2000))+[s]: if s%i != 0: continue wyn = 0 for j in range(s//i): #0+ j*i, ..., (i-1) + j*i sr = ((j*i) + (i-1)+j*i + 1)//2 #print(j*i, sr, j*i+i-1) if j!= 0: l = pref[sr - 1] - pref[j*i - 1] else: l = pref[sr-1] r = pref[j*i + i - 1] - pref[sr] #print(l,r) if i % 2 == 0: wyn += (r - l + dupa[sr]) else: wyn += (r-l) #print(wyn, i) wynik = min(wyn, wynik) print(wynik) ```
output
1
30,177
9
60,355
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easier version of the problem. In this version, 1 ≀ n ≀ 10^5 and 0 ≀ a_i ≀ 1. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare n boxes of chocolate, numbered from 1 to n. Initially, the i-th box contains a_i chocolate pieces. Since Bob is a typical nice guy, he will not send Alice n empty boxes. In other words, at least one of a_1, a_2, …, a_n is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer k > 1 such that the number of pieces in each box is divisible by k. Note that Alice won't mind if there exists some empty boxes. Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box i and put it into either box i-1 or box i+1 (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of chocolate boxes. The second line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 1) β€” the number of chocolate pieces in the i-th box. It is guaranteed that at least one of a_1, a_2, …, a_n is positive. Output If there is no way for Charlie to make Alice happy, print -1. Otherwise, print a single integer x β€” the minimum number of seconds for Charlie to help Bob make Alice happy. Examples Input 3 1 0 1 Output 2 Input 1 1 Output -1
instruction
0
30,178
9
60,356
Tags: constructive algorithms, greedy, math, number theory, ternary search, two pointers Correct Solution: ``` from math import sqrt n=int(input()) l=list(map(int,input().split())) cou=0 lol=0 ll=list(l) s=sum(l) if(s==1): print(-1) elif(s==0): print(0) else: li=[] for i in range(n): if(ll[i]==1): li.append(i) fa=[] for i in range(2,n+1): if(s%i==0): fa.append(i) lol=0 mi=100000000000000000000000000 for j in fa: ind=j lol=0 for i in range(0,len(li),ind): for j in range(i,i+ind): lol+=abs(li[ind//2+i]-li[j]) #print(lol,ind) if(lol<mi): mi=lol print(mi) ```
output
1
30,178
9
60,357
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easier version of the problem. In this version, 1 ≀ n ≀ 10^5 and 0 ≀ a_i ≀ 1. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare n boxes of chocolate, numbered from 1 to n. Initially, the i-th box contains a_i chocolate pieces. Since Bob is a typical nice guy, he will not send Alice n empty boxes. In other words, at least one of a_1, a_2, …, a_n is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer k > 1 such that the number of pieces in each box is divisible by k. Note that Alice won't mind if there exists some empty boxes. Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box i and put it into either box i-1 or box i+1 (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy. Input The first line contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of chocolate boxes. The second line contains n integers a_1, a_2, …, a_n (0 ≀ a_i ≀ 1) β€” the number of chocolate pieces in the i-th box. It is guaranteed that at least one of a_1, a_2, …, a_n is positive. Output If there is no way for Charlie to make Alice happy, print -1. Otherwise, print a single integer x β€” the minimum number of seconds for Charlie to help Bob make Alice happy. Examples Input 3 1 0 1 Output 2 Input 1 1 Output -1
instruction
0
30,179
9
60,358
Tags: constructive algorithms, greedy, math, number theory, ternary search, two pointers Correct Solution: ``` n = int(input()) l = list(map(int,input().split())) def jebaj(d, k): res = 0 pyk = d[0]%k for i in range(n - 2): res += min(pyk, k - pyk) pyk = (pyk + d[i+1])%k res += min(pyk, k - pyk) return res s = sum(l) out = 10000000000000000000000000 import math if s <= 1: print(-1) else: i = 2 ss = s primes = [] while ss > 1 and i * i <= s: if ss%i == 0: ss //= i if len(primes) == 0 or i != primes[-1]: primes.append(i) else: i += 1 if ss * ss > s: primes.append(ss) for i in primes: out = min(out, jebaj(l, i)) print(out) ```
output
1
30,179
9
60,359