message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the n-th position of the sequence. Input The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Print the element in the n-th position of the sequence (the elements are numerated from one). Examples Input 3 Output 2 Input 5 Output 2 Input 10 Output 4 Input 55 Output 10 Input 56 Output 1 Submitted Solution: ``` from math import ceil f = lambda a : (-1+(1+8*a)**0.5)/2 t = lambda a : a*(a-1)/2 n = int(input()) print(n-int(t(ceil(f(n))))) ```
instruction
0
59,293
5
118,586
Yes
output
1
59,293
5
118,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the n-th position of the sequence. Input The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Print the element in the n-th position of the sequence (the elements are numerated from one). Examples Input 3 Output 2 Input 5 Output 2 Input 10 Output 4 Input 55 Output 10 Input 56 Output 1 Submitted Solution: ``` import math number = input() current = 0 num = int(number) D = math.sqrt(1 + 8*num) n = ( D - 1 )/2 n = int(n) summa = n*(n+1)/2 if num == summa: n-=1 summa = n*(n+1)/2 if num>summa: num -= summa print (num) ```
instruction
0
59,294
5
118,588
No
output
1
59,294
5
118,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the n-th position of the sequence. Input The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Print the element in the n-th position of the sequence (the elements are numerated from one). Examples Input 3 Output 2 Input 5 Output 2 Input 10 Output 4 Input 55 Output 10 Input 56 Output 1 Submitted Solution: ``` from math import sqrt x=int(input()) print(int((x-((-1+sqrt(8*x)/2))))) ```
instruction
0
59,295
5
118,590
No
output
1
59,295
5
118,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the n-th position of the sequence. Input The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Print the element in the n-th position of the sequence (the elements are numerated from one). Examples Input 3 Output 2 Input 5 Output 2 Input 10 Output 4 Input 55 Output 10 Input 56 Output 1 Submitted Solution: ``` n=int (input()) i=1 if(n==99999998250180): print("0") else: if(n==100000000000000): print("1749820") else: while(n>0): n=n-i i=i+1 if(n==0): print(i-1) else: print(n+i-1) ```
instruction
0
59,296
5
118,592
No
output
1
59,296
5
118,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the n-th position of the sequence. Input The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Print the element in the n-th position of the sequence (the elements are numerated from one). Examples Input 3 Output 2 Input 5 Output 2 Input 10 Output 4 Input 55 Output 10 Input 56 Output 1 Submitted Solution: ``` from math import ceil def num_first_position(num): return (num * (num + 1)) // 2 def binary_search(target_position, num, start, end): while start < end: num_position = num_first_position(num) half = max(1, ((end - start) // 2)) if half == 0: break if num_position == target_position: break elif num_position < target_position: start = num + 1 num += half else: end = num num -= half num_position = num_first_position(num) if num_position == target_position: return num elif num_position > target_position: start_position = num_position - num + 1 diff = target_position - start_position return 1 + diff return num def solve(position): return binary_search(position, ceil(pow(10, 8) / 2), 1, pow(10, 8)) assert solve(3) == 2 assert solve(5) == 2 assert solve(10) == 4 assert solve(55) == 10 assert solve(56) == 1 assert solve(57) == 2 position = int(input().strip()) print(solve(position)) ```
instruction
0
59,297
5
118,594
No
output
1
59,297
5
118,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes Submitted Solution: ``` import sys s = input() pairs = [(3, 3), (4, 6), (5, 9), (6, 4), (7, 7), (8, 0), (9, 5), (0, 8)] for l in range(len(s) // 2 + 1): r = len(s) - l - 1 if l == r and int(s[l]) not in [3, 7]: print("No") sys.exit(0) elif (int(s[l]), int(s[r])) not in pairs: print("No") sys.exit(0) print("Yes") ```
instruction
0
59,358
5
118,716
Yes
output
1
59,358
5
118,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes Submitted Solution: ``` p = input() l = len(p) - 1 ans = "" s=["23", "10", "30", "11", "13", "12", "31", "33", "32","21"] for x in p: ans+=s[ord(x) -48] if ans == ans[::-1]: print("Yes") else: print("No") ```
instruction
0
59,360
5
118,720
Yes
output
1
59,360
5
118,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes Submitted Solution: ``` a = input() s = 0 for i in a: s += ord(i) - ord('0') if s % 13 == 0: print("Yes") else: print("No") ```
instruction
0
59,361
5
118,722
No
output
1
59,361
5
118,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output Output "Yes" or "No". Examples Input 373 Output Yes Input 121 Output No Input 436 Output Yes Submitted Solution: ``` a = input() tot = 0 for i in a: tot += int(i) if (tot % 13 == 0): print("Yes") else: print("No") ```
instruction
0
59,362
5
118,724
No
output
1
59,362
5
118,725
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,481
5
118,962
"Correct Solution: ``` from math import ceil,log N=int(input()) A=[int(i) for i in input().split()] def f(A): dp=[0]*16 L=[0]*N for i in range(16): dp[i]=i for n in range(N-2,-1,-1): ndp=[0]*16 nx=ceil(log(A[n]/A[n+1])/log(4)) #A for x in range(16): dx=nx+x if dx <=15: #print(max(0,dx)) ndp[x]=dp[max(0,dx)]+x else: ndp[x]=dp[15]+x+(N-1-n)*(dx-15) dp=ndp L[n]=dp[0] return L K=f(A)+[0] L=[0]+f(A[::-1])[::-1] ans=10**22 for i in range(N+1): ans=min(ans,i+2*L[i]+2*K[i]) print(ans) ```
output
1
59,481
5
118,963
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,482
5
118,964
"Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) def d4(x,y): ret = 0 while x > y: y *= 4 ret += 1 return ret def cost(ls): l = len(ls) ret = [0]*l stack = [(l-1,10**18)] for i in range(l-1)[::-1]: ret[i] = ret[i+1] if ls[i] <= ls[i+1]: d = d4(ls[i+1],ls[i])-1 if d > 0: stack.append((i,d)) else: d = d4(ls[i],ls[i+1]) while d: idx,num = stack.pop() if d > num: ret[i] += (idx-i)*num d -= num else: ret[i] += (idx-i)*d num -= d d = 0 if num: stack.append((idx,num)) return ret cp = cost(a) cn = cost(a[::-1]) for i in range(n): cp[i] *= 2 cn[i] *= 2 cn[i] += n-i ansls = [cp[0],cn[0]] for i in range(1,n): ansls.append(cp[i]+cn[n-i]) print(min(ansls)) ```
output
1
59,482
5
118,965
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,483
5
118,966
"Correct Solution: ``` # import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): #print(*args, **kwargs, file=sys.stderr) # in python 3.4 **kwargs is invalid??? print(*args, file=sys.stderr) dprint('debug mode') except Exception: def dprint(*args, **kwargs): pass inId = 0 outId = 0 if inId>0: dprint('use input', inId) sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件 if outId>0: dprint('use output', outId) sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件 atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit if True: N, = getIntList() #print(N) za = getIntList() else: N = 1000 import random za = [random.randint(1, 1000000000) for i in range(N) ] dprint('begin') zleft = [0 for i in range(N+1)] zright = [0 for i in range(N+1)] def getwork(zr, za): zr[0] = 0 st = [] for i in range(N): if i%10000 ==0: dprint('---', i) nt = [[za[i],0], [za[i],0], 1] st.append(nt) nr = zr[i] #dprint(st) while len(st)>1: b_2 = st[-2][1][1] b_1 = st[-1][0][1] bb = min(b_1,b_2) b_1 -=bb b_2 -=bb b_1p = 4 ** b_1 b_2p = 4 ** b_2 t2 = st[-2][1][0] * b_2p t1 = st[-1][0][0] * b_1p if t2 < t1: nr+= 2* st[-2][2] st[-2][0][1] +=1 st[-2][1][1] +=1 elif t2 < t1 * 4: ttt = [ st[-2][0], st[-1][1], st[-2][2] + st[-1][2] ] st[-2] = ttt st.pop() else: break #dprint(st) zr[i+1] = nr #dprint(nr) #dprint(st) assert nr < 1000000000000000 getwork(zleft, za) dprint('!!!!') getwork(zright, za[::-1]) #dprint(zleft) #dprint(zright) r = zright[N] for i in range(N+1): tr = i + zleft[i] + zright[N-i] r = min(r,tr) print(r) dprint('end') ```
output
1
59,483
5
118,967
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,484
5
118,968
"Correct Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def f(a, b): ret = 0 while a > b: ret += 2 b *= 4 return ret N = int(input()) A = list(map(int, input().split())) right = [0] * (N+1) st = [(1, A[-1], A[-1])] for i in range(N-2, -1, -1): a = A[i] st.append((1, a, a)) right[i] = right[i+1] while True: if len(st) == 1: break if st[-1][2] > st[-2][1]: na, amin, amax = st.pop() nb, bmin, bmax = st.pop() k = f(amax, bmin) right[i] += nb * k if st: st.append((na+nb, amin, bmax << k)) else: st.append((na+nb, amin, float("inf"))) else: break left = [0] * (N+1) left[1] = 1 st = [(1, A[0], A[0])] for i in range(2, N+1): a = A[i-1] st.append((1, a, a)) left[i] = left[i-1] + 1 while True: if len(st) == 1: break if st[-1][2] > st[-2][1]: na, amin, amax = st.pop() nb, bmin, bmax = st.pop() k = f(amax, bmin) left[i] += nb * k if st: st.append((na + nb, amin, bmax << k)) else: st.append((na+nb, amin, float("inf"))) else: break ans = float("inf") for i in range(N+1): ans = min(ans, left[i] + right[i]) print(ans) if __name__ == '__main__': main() ```
output
1
59,484
5
118,969
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,485
5
118,970
"Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines """ ・正、負の部分に分けて。本質的には正の場合ができればよい ・4A_i > A_{i+1} となってるものはまとめる。運命共同体の区間たちができる ・一番弱い区間と勝負する。成長すると次の区間とマージできる """ N,*A = map(int,read().split()) def calc_positive_case(N,A): INF = 1<<32 # ある場所を始点として、そこから全部positiveにしたい場合 dp = [0] * N left_end = [] right_end = [] items = [] mult_cnt = 0 for i,x in enumerate(A[::-1]): left_end.append(x); right_end.append(x); items.append(1) # 最小の矛盾を解消 while len(items) >= 2: l2,l1 = left_end[-2:] r2,r1 = right_end[-2:] n2,n1 = items[-2:] if r1*4<=l2: # mergeせず break while r1>l2: l2 *= 4; r2 *= 4; mult_cnt += n2 left_end.pop(); left_end[-1]=l1 right_end.pop(); right_end[-1]=r2 items.pop(); items[-1] += n1 if right_end[0] > INF: right_end[0] = INF dp[i] = mult_cnt return dp[::-1] pos = calc_positive_case(N,A) # ある点を正の始点としたときに必要な、4倍の回数 neg = calc_positive_case(N,A[::-1])[::-1] # ある点を負の始点としたときの~~ pos = [2*x for x in pos] + [0] neg = [0] + [2*x+i for i,x in enumerate(neg,1)] # -2倍の初期コストが乗る answer = min(x+y for x,y in zip(pos,neg)) print(answer) ```
output
1
59,485
5
118,971
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,486
5
118,972
"Correct Solution: ``` import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) def sub(a, minus=False): m = 20 inf = 10**15 dp = [[inf]*m for _ in range(n)] # i以降、a[i]に4^jをかけたところからソート for j in range(m): dp[-1][j] = j for i in range(n-2, -1, -1): if a[i]>a[i+1]: v = 0 ai = a[i]; ai1 = a[i+1] while ai>ai1: ai1 *= 4 v += 1 for j in range(m): if j+v<m: dp[i][j] = j + dp[i+1][j+v] else: dp[i][j] = j + dp[i+1][m-1] + (n-i-1)*(j+v-m+1) else: v = 0 ai = a[i]; ai1 = a[i+1] while True: ai *= 4 if ai<=ai1: v += 1 else: break for j in range(m): dp[i][j] = j + dp[i+1][max(0, j-v)] if minus: ans = [(2*min(dp[i][j] for j in range(m))+(n-i)) for i in range(n)] else: ans = [2*min(dp[i][j] for j in range(m)) for i in range(n)] return ans dp0 = sub(list(a)) dp1 = sub([item for item in a[::-1]], minus=True)[::-1] dp0.append(0) dp1.insert(0,0) ans = min((dp0[i]+dp1[i]) for i in range(n+1)) print(ans) ```
output
1
59,486
5
118,973
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,487
5
118,974
"Correct Solution: ``` import sys readline = sys.stdin.readline def f(a, b): return (1+(-(-a//b)-1).bit_length())//2 N = int(readline()) A = list(map(int, readline().split())) dpr = [0]*N Ar = A[:] cnt = 0 for i in range(1, N): res = 0 idx = i-1 while cnt <= idx: k = f(Ar[idx+1], Ar[idx]) if k: Ar[idx] *= 4**k res += k idx -= 1 if not k: break else: dpr[i] += cnt*k dpr[i] += dpr[i-1] + res while cnt < i: if Ar[cnt] < Ar[cnt+1]*4: cnt += 1 else: break dpl = [0]*N Al = A[:] cnt = N-1 for i in range(N-2, -1, -1): res = 0 idx = i+1 while cnt >= idx: k = f(Al[idx-1], Al[idx]) if k: Al[idx] *= 4**k res += k idx += 1 if not k: break else: dpl[i] += (N-1-cnt)*k dpl[i] += dpl[i+1] + res while cnt > i: if Al[cnt] < Al[cnt-1]*4: cnt -= 1 else: break dpl = [2*dpl[i] for i in range(N)] dpr = [0] + [i+1+2*dpr[i] for i in range(N)] inf = 10**20 ans = inf for i in range(N): ans = min(ans, dpr[i] + dpl[i]) print(ans) ```
output
1
59,487
5
118,975
Provide a correct Python 3 solution for this coding contest problem. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7
instruction
0
59,488
5
118,976
"Correct Solution: ``` N = int(input()) A = list(map(int, input().split())) R = [0] * (N+1) L = [0] * (N+1) l = 0 ap = A[-1]#float("inf") P = [0] * 20 stack = [0] for i in range(N): a = A[-1-i] #cnt = 0 while ap < a: #cnt += 2 l += (i-stack[-1])<<1 if stack[-1] != 0: del stack[-1] ap <<= 2 a4 = a<<2 while ap >= a4: ap >>= 2 stack.append(i) R[-(i+2)] = l ap = a ap = -A[0] l = 0 stack = [0] for i in range(N): l += 1 a = -A[i] #cnt = 0 while ap > a: #cnt += 2 l += (i-stack[-1])<<1 if stack[-1] != 0: del stack[-1] ap <<= 2 a4 = a << 2 while ap <= a4: ap >>= 2 stack.append(i) #l += i * cnt L[i+1] = l ap = a #print(L, R) ans = float("inf") for l, r in zip(L, R): ans = min(ans, l+r) print(ans) ```
output
1
59,488
5
118,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` from math import ceil, log log_2 = log(2) def max2(x, y): return x if x >= y else y def getNums(As, N): dp = list(range(16)) nums = [0] * N for i in reversed(range(N - 1)): dx = ceil( log( As[i] / As[i+1] ) / log_2 / 2 ) dp2 = [0] * 16 for x in range(16): nx = x + dx if nx <= 15: dp2[x] = dp[max2(0, nx)] + x else: dp2[x] = dp[15] + x + (N - 1 - i) * (nx - 15) dp = dp2 nums[i] = dp[0] return nums N = int(input()) As = list(map(int, input().split())) numPstvs = getNums(As, N) numNgtvs = getNums(As[::-1], N)[::-1] ans = float('inf') for i, (p, m) in enumerate(zip(numPstvs + [0], [0] + numNgtvs)): ans = min(ans, 2 * p + 2 * m + i) print(ans) ```
instruction
0
59,489
5
118,978
Yes
output
1
59,489
5
118,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` from collections import deque n = int(input()) a = list(map(int,input().split())) p = [0] * (n-1) m = [0] * (n-1) for i in range(n-1): x,y = a[i:i+2] cnt = 0 if(x > y): while(x>y): y *= 4 cnt += 2 else: x *= 4 while(x<=y): x*=4 cnt -= 2 p[i] = cnt for i in range(n-1): x,y = a[i:i+2] cnt = 0 if(x < y): while(x<y): x *= 4 cnt += 2 else: y *= 4 while(x>=y): y*=4 cnt -= 2 m[i] = cnt cumsum_p = [0] * (n+1) cumsum_m = [0] * (n+1) d = deque() for i in range(n-2,-1,-1): cumsum_p[i] = cumsum_p[i+1] if(p[i] < 0): d.appendleft((i,p[i])) elif(p[i] > 0): cnt = p[i] while(d): j,rem_j = d.popleft() if(cnt + rem_j <= 0): cumsum_p[i] += (j-i) * cnt if(cnt + rem_j < 0): d.appendleft((j,cnt + rem_j)) cnt = 0 break else: cumsum_p[i] += (j-i) * (-1 * rem_j) cnt = cnt + rem_j cumsum_p[i] += (n-i-1) * cnt d = deque() cumsum_m[1] = 1 for i in range(n-1): cumsum_m[i+2] = cumsum_m[i+1] + 1 if(m[i] < 0): d.appendleft((i,m[i])) elif(m[i] > 0): cnt = m[i] while(d): j,rem_j = d.popleft() if( cnt + rem_j <= 0 ): cumsum_m[i+2] += (i-j) * cnt if( cnt + rem_j < 0): d.appendleft((j,cnt + rem_j)) cnt = 0 break else: cumsum_m[i+2] += (i-j) * (-1*rem_j) cnt = cnt + rem_j cumsum_m[i+2] += (i+1) * cnt ans = cumsum_p[0] for i in range(n+1): ans = min(ans, cumsum_p[i] + cumsum_m[i]) print(ans) ```
instruction
0
59,490
5
118,980
Yes
output
1
59,490
5
118,981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` from math import ceil, log2 def getNums(As, N): dp = list(range(16)) nums = [0] * N for i in reversed(range(N - 1)): dx = ceil( log2( As[i] / As[i+1] ) / 2 ) if dx <= 0: dp0 = dp[0] dp = [dp0] * (-dx) + dp[:16+dx] else: dp15 = dp[15] k = N - 1 - i dp = dp[dx:] + list(range(dp15 + k, dp15 + k * dx + 1, k)) dp = [dpx + x for x, dpx in enumerate(dp)] nums[i] = dp[0] return nums N = int(input()) As = list(map(int, input().split())) numPstvs = getNums(As, N) numNgtvs = getNums(As[::-1], N)[::-1] ans = min([2 * p + 2 * m + i for i, (p, m) in enumerate(zip(numPstvs + [0], [0] + numNgtvs))]) print(ans) ```
instruction
0
59,491
5
118,982
Yes
output
1
59,491
5
118,983
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` from collections import deque q = deque([]) def ct(a,b): ans = 0 while abs(a)<abs(b): ans += 2 a *= 4 return ans N = int(input()) A = [int(a) for a in input().split()] # A = [3, 1, 4, 1] # N = len(A) X = [0] * (N) Y = [0] * (N) a = -1 for i in range(N): b = a if i > 0: X[i] = X[i-1] else: X[i] = 0 a = A[i] t = 0 if a > 0: X[i] += 1 a *= -2 if i > 0: t = 0 r = b/a while r >= 4: q.append(i) r /= 4 while abs(a)>abs(b): if len(q) == 0: X[i] += 2 * i else: X[i] += 2 * (i - q.pop()) b *= 4 q = deque([]) a = -1 for i in range(N): b = a if i > 0: Y[i] = Y[i-1] else: Y[i] = 0 a = A[N-1-i] t = 0 if a < 0: Y[i] += 1 a *= -2 if i > 0: t = 0 r = b/a while r >= 4: q.append(i) r /= 4 while abs(a)>abs(b): if len(q) == 0: Y[i] += 2 * i else: Y[i] += 2 * (i - q.pop()) b *= 4 mi = min(X[-1], Y[-1]) for i in range(N-1): if X[i]+Y[-2-i] < mi: mi = X[i]+Y[-2-i] print(mi) ```
instruction
0
59,492
5
118,984
Yes
output
1
59,492
5
118,985
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` class SegTree: """ init(init_val, ide_ele): 配列init_valで初期化 O(N) update(k, x): k番目の値をxに更新 O(logN) query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN) """ def __init__(self, segfunc, ide_ele): """ init_val: 配列の初期値 segfunc: 区間にしたい操作 ide_ele: 単位元 n: 要素数 num: n以上の最小の2のべき乗 tree: セグメント木(1-index) """ n = ide_ele self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = i # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def query(self, l, r): """ [l, r)のsegfuncしたものを得る l: index(0-index) r: index(0-index) """ res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res def main(): import random from math import log,ceil N=int(input()) n=N A=[random.randint(1,10**9) for i in range(N)] A=[log(A[i],4) for i in range(N)] B=[A[-i-1] for i in range(N)] memo=[0]*(N-1) ans=10**25 ope=[0 for i in range(N+1)] ope[N]=10**20 def segfunc(x,y): if ope[x]>ope[y]: return y elif ope[y]>ope[x]: return x else: return min(x,y) #####ide_ele##### ide_ele = N ################# for i in range(1,N): ope[i]=max(0,ceil(A[i-1]-A[i])) A[i]+=ope[i] rmq=SegTree(segfunc,ide_ele) S=sum(ope[i] for i in range(N)) ans=min(ans,2*S) zero=[N] #A1 ... AnのBIT(1-indexed) BIT = [0]*(n+1) #A1 ~ Aiまでの和 O(logN) def BIT_query(idx): res_sum = 0 while idx > 0: res_sum += BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def BIT_update(idx,x): while idx <= n: BIT[idx] += x idx += idx&(-idx) return for i in range(1,N): while i!=zero[-1]: k=rmq.query(i,zero[-1]) val=ope[k]+BIT_query(k+1) S-=val*(zero[-1]-i) BIT_update(i+1,-val) BIT_update(zero[-1]+1,val) zero.append(k) zero.pop() memo[i-1]+=2*S ope=[0 for i in range(N+1)] ope[N]=10**20 S=0 for i in range(1,N): ope[i]=max(0,ceil(B[i-1]-B[i])) S+=ope[i] B[i]+=ope[i] #print(time.time()-start) rmq=SegTree(segfunc,ide_ele) #print(time.time()-start) ans=min(ans,2*S+N) zero=[N] BIT=[0]*(n+1) for i in range(1,N): while i!=zero[-1]: k=rmq.query(i,zero[-1]) val=ope[k]+BIT_query(k+1) S-=val*(zero[-1]-i) BIT_update(i+1,-val) BIT_update(zero[-1]+1,val) zero.append(k) zero.pop() memo[N-1-i]+=2*S+(N-i) #print(time.time()-start) test=min(memo) print(min(test,ans)) if __name__=="__main__": main() ```
instruction
0
59,493
5
118,986
No
output
1
59,493
5
118,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` # try: n = int(input()) a = list(map(int, input().split())) i = 0 count = 0 while (i < n - 1): if a[i] <= a[i+1]: i += 1 elif i == 0: a[i] = a[i] * -2 count += 1 else: if a[i+1] * -2 > 10 **9: count = -1 break else: a[i+1] = a[i+1] * -2 count += 1 print(count) # except EOFError: # pass ```
instruction
0
59,494
5
118,988
No
output
1
59,494
5
118,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` N = int(input()) A = list(map(int, input().split())) num = float("inf") for i in range(N): tmp = 0 pre = A[i] for j in range(i + 1, N): q = A[j] while pre > q: q *= 4 tmp += 2 pre = q pre = A[i] for j in range(i - 1, -1, -1): q = A[j] while pre < q: q *= -2 tmp += 1 pre = q num = min(tmp, num) print(num) ```
instruction
0
59,495
5
118,990
No
output
1
59,495
5
118,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would like to make A_1 \leq A_2 \leq ... \leq A_N holds. Find the minimum number of operations required. If it is impossible, print `-1`. Constraints * 1 \leq N \leq 200000 * 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the answer. Examples Input 4 3 1 4 1 Output 3 Input 5 1 2 3 4 5 Output 0 Input 8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097 Output 7 Submitted Solution: ``` import sys import heapq hpush = heapq.heappush hpop = heapq.heappop input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) dpl = [0] * (N + 1) h = [] for i in range(N): x = a[i] * 2 if len(h): while h[0] < x: hpush(h, hpop(h) * 4) dpl[i + 1] += 2 hpush(h, x) dpl[i + 1] += dpl[i] + 1 a.reverse() dpr = [0] * (N + 1) h = [] for i in range(N): x = a[i] if len(h): while -h[0] > x: x *= 4 dpr[i + 1] += 2 hpush(h, -x) dpr[i + 1] += 1 res = float("inf") for i in range(N): res = min(res, dpl[i] + dpr[N - i]) print(res) ```
instruction
0
59,496
5
118,992
No
output
1
59,496
5
118,993
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,497
5
118,994
"Correct Solution: ``` # AGC024A a,b,c,k = map(int, input().split()) if k%2: print(b-a) else: print(a-b) ```
output
1
59,497
5
118,995
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,498
5
118,996
"Correct Solution: ``` A,B,C,K=map(int,input().split()) M=K%2 print((A-B)*(-1)**(M)) ```
output
1
59,498
5
118,997
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,499
5
118,998
"Correct Solution: ``` A, B, C, K = map(int, input().split()) if K%2 == 0: r = A-B else: r = B-A print(r) ```
output
1
59,499
5
118,999
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,500
5
119,000
"Correct Solution: ``` a, b, c, k = map(int, input().split()) ans = a-b if k%2: ans *= -1 print(ans) ```
output
1
59,500
5
119,001
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,501
5
119,002
"Correct Solution: ``` a,b,c,d = map(int,input().split(" ")) if d % 2 == 0: print(a-b) else: print(b-a) ```
output
1
59,501
5
119,003
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,502
5
119,004
"Correct Solution: ``` A,B,C,K=map(int,input().split()) print(B-A if K%2 else A-B) ```
output
1
59,502
5
119,005
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,503
5
119,006
"Correct Solution: ``` a,b,c,k = map(int,input().split()) ans = a-b if k%2==0: print(ans) else: print(ans*(-1)) ```
output
1
59,503
5
119,007
Provide a correct Python 3 solution for this coding contest problem. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0
instruction
0
59,504
5
119,008
"Correct Solution: ``` A, B, C, K = map(int, input().split()) o = B - A e = A - B if K % 2 == 0: r = e else: r = o print(r) ```
output
1
59,504
5
119,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` a,b,c,k = map(int ,input().split()) s = b-a if (k%2 == 0): s *= -1 print(s) ```
instruction
0
59,505
5
119,010
Yes
output
1
59,505
5
119,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` a,b,c,k=map(int,input().split()) print("Unfair" if abs(a-b)>10**18 else a-b if k%2==0 else b-a) ```
instruction
0
59,506
5
119,012
Yes
output
1
59,506
5
119,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` a, b, c, k = map(int, input().split()) ans = a - b if k % 2 == 0 else b - a print(ans) ```
instruction
0
59,507
5
119,014
Yes
output
1
59,507
5
119,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` a, b, _, k = map(int, input().split()) print((a - b)*((-1)**(k % 2))) ```
instruction
0
59,508
5
119,016
Yes
output
1
59,508
5
119,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` a, b, c, k = map(int,input().split()) if a==b==c: print(0) exit() for i in range(k): a_=b+c b_=a+c c_=a+b if abs(a_-b_) > 10**18: print('Unfair') exit() a=a_ b=b_ c=c_ if k==0: print(a-b) else: print(a_-b_) ```
instruction
0
59,509
5
119,018
No
output
1
59,509
5
119,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` A, B, C, K = map(int, input().split()) for i in range(K): temp_a = A temp_b = B temp_c = C print(A, B, C) A = temp_b + temp_c B = temp_a + temp_c C = temp_a + temp_b if abs(A - B) <= 10 ** 18: print(A - B) else: print("unfair") ```
instruction
0
59,510
5
119,020
No
output
1
59,510
5
119,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` import copy A,B,C,k = map(float,input().split()) if k%2 == 0: if k == 0: print(int(A-B)) else: print(int((A-B)*k)) elif k%2 == 1: print(-int((A-B)*k)) ```
instruction
0
59,511
5
119,022
No
output
1
59,511
5
119,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Constraints * 1 \leq A,B,C \leq 10^9 * 0 \leq K \leq 10^{18} * All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. Examples Input 1 2 3 1 Output 1 Input 2 3 2 0 Output -1 Input 1000000000 1000000000 1000000000 1000000000000000000 Output 0 Submitted Solution: ``` A,B,C,K = map(int,input().split()) for i in range(min(K, 100000)): A,B,C = B+C,C+A,A+B if A - B > 10**18: print("Unfair") exit() print(A-B) ```
instruction
0
59,512
5
119,024
No
output
1
59,512
5
119,025
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,529
5
119,058
"Correct Solution: ``` N, A, B, C, D = map(int, input().split()) dif = B - A ans = "NO" for i in range(N): pos = i neg = N - i - 1 high = D * pos - C * neg low = C * pos - D * neg if low <= dif <= high: ans = "YES" break print(ans) ```
output
1
59,529
5
119,059
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,530
5
119,060
"Correct Solution: ``` n,a,b,c,d=map(int,input().split()) l=r=a for i in range(n-1): if l+r<b*2: l+=c r+=d else: l-=d r-=c if l<=b<=r:print('YES') else:print('NO') ```
output
1
59,530
5
119,061
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,531
5
119,062
"Correct Solution: ``` n, a, b, m, M = map(int, input().split()) n -= 1 l, r = -1, n + 1 while r - l > 1: mid = (l + r) // 2 t = (n - 2 * mid) * (m + M) if abs(t - 2 * (b - a)) <= n * (M - m): print("YES") exit() if t > 2 * (b - a): l = mid else: r = mid print("NO") ```
output
1
59,531
5
119,063
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,532
5
119,064
"Correct Solution: ``` import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, a, b, c, d = map(int, readline().split()) diff = a - b for i in range(n - 1): l = i * c - (n - 1 - i) * d r = i * d - (n - 1 - i) * c if l <= diff <= r: return print("YES") print("NO") if __name__ == '__main__': main() ```
output
1
59,532
5
119,065
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,533
5
119,066
"Correct Solution: ``` n,a,b,c,d=map(int,input().split()) for i in range(n-1): if c*i-d*(n-1-i)<=abs(a-b)<=d*i-c*(n-1-i): print("YES") break else: print("NO") ```
output
1
59,533
5
119,067
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,534
5
119,068
"Correct Solution: ``` import sys N,A,B,C,D = map(int,input().split()) num = abs(A-B) nmax = (N-1) * D nmin = (N-1) * C flag = False for i in range(N-1): if nmax >= num and num >= nmin: flag = True break nmax -= D + C nmin -= C + D if flag: print ("YES") else: print ("NO") ```
output
1
59,534
5
119,069
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,535
5
119,070
"Correct Solution: ``` n,a,b,c,d = map(int,input().split()) if a > b: a,b = b,a b -= a n -= 1 dif = d-c for i in range(n%2,n+1,2): if c*i-dif*((n-i)//2) <= b <= d*i+dif*((n-i)//2): print("YES") exit() print("NO") ```
output
1
59,535
5
119,071
Provide a correct Python 3 solution for this coding contest problem. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES
instruction
0
59,536
5
119,072
"Correct Solution: ``` import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,a,b,c,d=map(int,input().split()) for k in range(n): # k 右に行った回数 L=a+k*c-(n-k-1)*d R=a+k*d-(n-k-1)*c if(L<=b<=R): print("YES") return print("NO") resolve() ```
output
1
59,536
5
119,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty. Aohashi would like to fill the empty squares with integers so that the following condition is satisfied: * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive). As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition. Constraints * 3 \leq N \leq 500000 * 0 \leq A \leq 10^9 * 0 \leq B \leq 10^9 * 0 \leq C \leq D \leq 10^9 * All input values are integers. Input Input is given from Standard Input in the following format: N A B C D Output Print `YES` if it is possible to fill the squares under the condition; print `NO` otherwise. Examples Input 5 1 5 2 4 Output YES Input 4 7 6 4 5 Output NO Input 48792 105960835 681218449 90629745 90632170 Output NO Input 491995 412925347 825318103 59999126 59999339 Output YES Submitted Solution: ``` p=print n,a,b,c,d=map(int,input().split()) for i in range(n): if i*c-d*(n-i-1)<=b-a<=i*d-c*(n-i-1):exit(p("YES")) p("NO") ```
instruction
0
59,537
5
119,074
Yes
output
1
59,537
5
119,075