message
stringlengths
2
39.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
450
109k
cluster
float64
2
2
__index_level_0__
int64
900
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≀ i ≀ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. When two wizards cooperate, the magical power is simply the sum, and you can use powerful magic to beat enemies that are strong to some extent. Your job is to output the total number of wizard pairs (i, j) (i β‰  j and 1 ≀ i ≀ n and 1 ≀ j ≀ n) that can win against enemies with magical power S. However, (i, j) and (j, i) are counted as the same pair. When one magical power is greater than the other, the side with the greater magical power wins. If they are equal, it does not mean that they have won by trade-off. Constraints * All inputs are integers * 1 ≀ n ≀ 20,000 * 1 ≀ ri ≀ 100 (1 ≀ i ≀ n) * 1 ≀ S ≀ 100 * The number of test cases does not exceed 100. Input The input consists of multiple test cases. Each test case follows the format below. n S r1 r2 ... rn The meaning of each variable is as in the problem statement. The end of the input is indicated by a line where two 0s are separated by a single space. Output Output the total number of pairs (i, j) (i β‰  j) that satisfy the conditions on one line for each case. Example Input 3 7 1 3 10 0 0 Output 2 Submitted Solution: ``` while 1: n,s=map(int,input().split()) if not n:break a=sorted([int(input()) for _ in range(n)],reverse=1) b=0 for i in range(n): try: for j in range(i+1,n): if a[i]+a[j]>s:b+=1 else:raise Exception;break except:break print(b) ```
instruction
0
36,801
2
73,602
No
output
1
36,801
2
73,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≀ i ≀ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. When two wizards cooperate, the magical power is simply the sum, and you can use powerful magic to beat enemies that are strong to some extent. Your job is to output the total number of wizard pairs (i, j) (i β‰  j and 1 ≀ i ≀ n and 1 ≀ j ≀ n) that can win against enemies with magical power S. However, (i, j) and (j, i) are counted as the same pair. When one magical power is greater than the other, the side with the greater magical power wins. If they are equal, it does not mean that they have won by trade-off. Constraints * All inputs are integers * 1 ≀ n ≀ 20,000 * 1 ≀ ri ≀ 100 (1 ≀ i ≀ n) * 1 ≀ S ≀ 100 * The number of test cases does not exceed 100. Input The input consists of multiple test cases. Each test case follows the format below. n S r1 r2 ... rn The meaning of each variable is as in the problem statement. The end of the input is indicated by a line where two 0s are separated by a single space. Output Output the total number of pairs (i, j) (i β‰  j) that satisfy the conditions on one line for each case. Example Input 3 7 1 3 10 0 0 Output 2 Submitted Solution: ``` while 1: n,s=map(int,input().split()) if not n:break a=sorted([int(input()) for _ in range(n)],reverse=1) b=0 for i in range(n): for j in range(i+1,n): if a[i]+a[j]>s:b+=1 else:break if a[i]+a[j]<=s:break print(b) ```
instruction
0
36,802
2
73,604
No
output
1
36,802
2
73,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≀ i ≀ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. When two wizards cooperate, the magical power is simply the sum, and you can use powerful magic to beat enemies that are strong to some extent. Your job is to output the total number of wizard pairs (i, j) (i β‰  j and 1 ≀ i ≀ n and 1 ≀ j ≀ n) that can win against enemies with magical power S. However, (i, j) and (j, i) are counted as the same pair. When one magical power is greater than the other, the side with the greater magical power wins. If they are equal, it does not mean that they have won by trade-off. Constraints * All inputs are integers * 1 ≀ n ≀ 20,000 * 1 ≀ ri ≀ 100 (1 ≀ i ≀ n) * 1 ≀ S ≀ 100 * The number of test cases does not exceed 100. Input The input consists of multiple test cases. Each test case follows the format below. n S r1 r2 ... rn The meaning of each variable is as in the problem statement. The end of the input is indicated by a line where two 0s are separated by a single space. Output Output the total number of pairs (i, j) (i β‰  j) that satisfy the conditions on one line for each case. Example Input 3 7 1 3 10 0 0 Output 2 Submitted Solution: ``` while 1: n,s=map(int,input().split()) if not n:break a=sorted([int(input()) for _ in range(n)],reverse=1) b=0 try: for i in range(n): for j in range(i+1,n): if a[i]+a[j]>s:b+=1 else:raise Exception;pass except:pass print(b) ```
instruction
0
36,803
2
73,606
No
output
1
36,803
2
73,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≀ i ≀ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. When two wizards cooperate, the magical power is simply the sum, and you can use powerful magic to beat enemies that are strong to some extent. Your job is to output the total number of wizard pairs (i, j) (i β‰  j and 1 ≀ i ≀ n and 1 ≀ j ≀ n) that can win against enemies with magical power S. However, (i, j) and (j, i) are counted as the same pair. When one magical power is greater than the other, the side with the greater magical power wins. If they are equal, it does not mean that they have won by trade-off. Constraints * All inputs are integers * 1 ≀ n ≀ 20,000 * 1 ≀ ri ≀ 100 (1 ≀ i ≀ n) * 1 ≀ S ≀ 100 * The number of test cases does not exceed 100. Input The input consists of multiple test cases. Each test case follows the format below. n S r1 r2 ... rn The meaning of each variable is as in the problem statement. The end of the input is indicated by a line where two 0s are separated by a single space. Output Output the total number of pairs (i, j) (i β‰  j) that satisfy the conditions on one line for each case. Example Input 3 7 1 3 10 0 0 Output 2 Submitted Solution: ``` while 1: n,s=map(int,input().split()) if not n:break a=[int(input()) for _ in range(n)] b=0 for i in range(n): for j in range(i+1,n): if a[i]+a[j]>s:b+=1 print(sum([a[i]+a[j]>s for i in range(n) for j in range(i+1,n)])) ```
instruction
0
36,804
2
73,608
No
output
1
36,804
2
73,609
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,911
2
73,822
Tags: math Correct Solution: ``` H, n = map(int, input().split()) d = list(map(int, input().split())) diff, max_damage = 0, 0 for di in d: diff += di max_damage = max(max_damage, -diff) if max_damage>=H: for i in range(n): H += d[i] if H<=0: print(i+1) exit() D = sum(d) if D>=0: print(-1) exit() D *= -1 ans = (H-max_damage+D-1)//D*n H -= (H-max_damage+D-1)//D*D for di in d: H += di ans += 1 if H<=0: print(ans) exit() ```
output
1
36,911
2
73,823
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,912
2
73,824
Tags: math Correct Solution: ``` H, n = map(int, input().split()) ds = [int(x) for x in input().split()] h = H mn = 0 for i, d in enumerate(ds): h += d mn = min(mn, h - H) if h <= 0: print(i + 1) break else: sd = sum(ds) if sd >= 0: print(-1) else: sd = -sd # print(mn, sd) repeat = (H + mn) // sd h = H - repeat * sd # print(repeat, h) for i, d in enumerate(ds): h += d if h <= 0: print(repeat * n + i + 1) break else: for i, d in enumerate(ds): h += d if h <= 0: print(repeat * n + i + 1 + n) break ```
output
1
36,912
2
73,825
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,913
2
73,826
Tags: math Correct Solution: ``` import math arr = input() H, M = [int(x) for x in arr.split(' ')] arr = input() arr = [int(x) for x in arr.split(' ')] p_sum = [0]*M s = 0 for i in range(M): s += arr[i] p_sum[i] = s if abs(s)>=H and s<=0: print(i+1) quit() #print(p_sum) # A = round deduction # m = max deduction during round if p_sum[-1]>=0: print(-1) quit() rounds = (H-abs(min(p_sum)))/abs(p_sum[-1]) #print(rounds) N = math.ceil( rounds ) #print(N) H = H + p_sum[-1]*N #print(H) res = N*M s = 0 for i in range(M): s += arr[i] #p_sum[i] = s if abs(s)>=H and s<=0: print(res+i+1) quit() ```
output
1
36,913
2
73,827
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,914
2
73,828
Tags: math Correct Solution: ``` from math import ceil h, n = map(int, input().split()) a, s, mi, ans = list(map(int, input().split())), 0, [float('inf'), 0], 0 for i in range(n): s += a[i] if s < mi[0]: mi = [s, i] if -s >= h: exit(print(i + 1)) if mi[0] > -1 or sum(a) > -1: exit(print(-1)) ans += ceil((h + mi[0]) / (-sum(a))) * n if (h + mi[0]) % (-sum(a)) == 0: ans += mi[1] + 1 else: diff = (-sum(a)) - ((h + mi[0]) % (-sum(a))) # print(ans, diff, mi) tem, flag = n, 1 for i in range(mi[1], -1, -1): diff += a[i] if diff < 0 and flag: tem, flag = i + 1, 0 elif diff == 0 and flag: tem, flag = i, 0 if diff >= 0: flag = 1 ans += tem print(ans) ```
output
1
36,914
2
73,829
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,915
2
73,830
Tags: math Correct Solution: ``` import math H, n = [int(i) for i in input().split(' ')] d = [int(i) for i in input().split(' ')] H_cur = H dead = False d_acc = [0] for i in range(n): d_acc.append(d_acc[-1]+d[i]) H_cur += d[i] if H_cur <= 0: print(i+1) dead = True break if not dead: if d_acc[-1] >= 0: print(-1) else: d_acc_min = min(d_acc) r = int(math.ceil((H+d_acc_min)/-d_acc[-1])) H_cur = H+r*d_acc[-1] for i in range(n): H_cur += d[i] if H_cur <= 0: print(r*n+i+1) break ```
output
1
36,915
2
73,831
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,916
2
73,832
Tags: math Correct Solution: ``` health, minutes = list(map(int,input().split())) change = list(map(int,input().split())) max = int(1e15) mini = max sum = 0 ans = 0 current = health for f in change: sum += f mini = min(mini, sum) if mini >= 0: print(-1) exit(0) rem = health if health > abs(mini): if sum >= 0: print(-1) exit(0) else: sum = -sum ans = int((health+mini)/sum) if int((health+mini)%sum) != 0: ans += 1 rem = health - sum * ans c = 1 for f in change: rem += f if rem <= 0: print(int(ans*minutes+c)) exit(0) c+=1 ```
output
1
36,916
2
73,833
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,917
2
73,834
Tags: math Correct Solution: ``` '''input 1 2 -1 1 ''' from sys import stdin import math def find_min_s(arr): min_s = 0 cur_sum = 0 for i in arr: cur_sum += i min_s = min(min_s, cur_sum) return min_s # main starts H, n = list(map(int, stdin.readline().split())) arr = list(map(int, stdin.readline().split())) s = sum(arr) min_s = find_min_s(arr) if s >= 0 and H + min_s > 0: print(-1) exit() else: #print(abs(min_s), abs(s)) q = 0 if H - abs(min_s) > 0: q = math.ceil((H - abs(min_s)) / (abs(s))) ans = q * n H = H - q * (abs(s)) i = 0 while H > 0 and i < len(arr): H += arr[i] i += 1 ans += 1 print(ans) ```
output
1
36,917
2
73,835
Provide tags and a correct Python 3 solution for this coding contest problem. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1
instruction
0
36,918
2
73,836
Tags: math Correct Solution: ``` def main(): ans=0 h,n=map(int,input().split()) d=[0] d+=list(map(int,input().split())) inf=0x3f3f3f3f3f3f3f3f maxx=inf for i in range(1,n+1): d[i]+=d[i-1] maxx=min(d[i],maxx) if h+maxx>0 and d[n]>=0: print(-1) return 0 l,r=0,inf while l<=r: mid=(l+r)>>1 #print(mid) if h+maxx<=0: break if h+d[n]*mid+maxx<=0: r=mid-1 else: l=mid+1 ans+=l*n h+=l*d[n] for i in range(1,n+1): if h+d[i]<=0: ans+=i print(ans) return 0 main() ```
output
1
36,918
2
73,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` # AC import sys from math import ceil def unique(lst): return dict((o, o) for o in lst).values() class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_int(self): return int(self.next()) def solve(self): h = self.next_int() n = self.next_int() x = [self.next_int() for _ in range(0, n)] for i in range(0, n): if i > 0: x[i] += x[i - 1] if h + x[i] <= 0: print(i + 1) return if x[-1] >= 0: print(-1) return rd = int(ceil((h + min(x)) / -x[-1])) h += x[-1] * rd for i in range(0, n): if h + x[i] <= 0: print(i + 1 + rd * n) return print('!!' + str(rd)) if __name__ == '__main__': Main().solve() ```
instruction
0
36,919
2
73,838
Yes
output
1
36,919
2
73,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` h, n = map(int, input().split()) d = [int(s) for s in input().split()] min_v = 0 summ = 0 for el in d: summ += el if summ < min_v: min_v = summ num = 0 if h + min_v > 0 and summ >= 0: print("-1") elif h + min_v <= 0: for el in d: h += el num += 1 if h <= 0: print(num) break elif summ < 0: num += ((h + min_v) // abs(summ))*n h = abs(min_v) + (h + min_v) % abs(summ) for el in d: h += el num += 1 if h <= 0: print(num) break if h > 0: for el in d: h += el num += 1 if h <= 0: print(num) break ```
instruction
0
36,920
2
73,840
Yes
output
1
36,920
2
73,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) H, n = mints() d = list(mints()) s = [0]*(n+1) for i in range(n): s[i+1] = s[i]+d[i] for i in range(n+1): if s[i] + H <= 0: print(i) exit(0) #print(s) if s[n] >= 0: print(-1) else: l = -1 r = H//(-s[n]) + 2 while r-l > 1: c = (l+r)//2 h = -c*s[n]-H z = -1 for i in range(n+1): if s[i] <= h: z = i break if z == -1: l = c else: r = c h = -r*s[n]-H z = -1 for i in range(n+1): if s[i] <= h: print(r*n+i) break ```
instruction
0
36,921
2
73,842
Yes
output
1
36,921
2
73,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` from math import * h, n = map(int, input().split()) d = list(map(int, input().split())) s = 0 sp = list(range(n)) ok = 0 for i in range(n): s += d[i] if s + h <= 0: print(i + 1) ok = 1 break sp[i] = s if not ok: if s >= 0: print(-1) else: m = n * ceil((h) / (-s)) for i in range(n): if sp[i] < 0: m = min(m, i + 1 + n * ceil((h + sp[i]) / (-s))) print(m) ```
instruction
0
36,922
2
73,844
Yes
output
1
36,922
2
73,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` hp, n = [int(i) for i in input().split()] damages = [int(i) for i in input().split()] sums = sum(damages) minim=0 current=0 for v in damages: current += v if current <= minim: minim = current max_loss = -minim cnt = 0 if sums>=0: for i,v in enumerate(damages): cnt += 1 hp += v if(hp<=0): print(cnt) break else: print(-1) else: total_damage = -sums rounds = (hp-max_loss)//total_damage if (hp-max_loss)%total_damage==0: rounds -= 1 hp -= rounds * total_damage cnt += n * rounds #print(rounds) #rounds = hp // total_damage #rest = hp % total_damage #if(rest==0): # rounds -= 1 # rest += total_damage #hp = rest #cnt += n*rounds while(hp>0): for i,v in enumerate(damages): cnt += 1 hp += v if(hp<=0): break print(cnt) ```
instruction
0
36,923
2
73,846
No
output
1
36,923
2
73,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` hp,n = map(int, input().split()) d=input() d=list(map(int, d.split())) per=0 Min=0 ind_min=-1 count=0 f=1 for i in range(n): per+=d[i] if (per<Min): Min=per ind_min=i if(hp+per<=0): f=0 print(i+1) if (f==1): if (per>=0): print(-1) else: t=((hp+Min)//(-per)) if ((hp+Min)%(-per)!=0): t+=1 count=n*t hp+=per*t j=0 while(hp>0 and j<n): hp+=d[j] j+=1 print(count+j) ```
instruction
0
36,924
2
73,848
No
output
1
36,924
2
73,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` H, n = map(int, input().split()) a = list(map(int, input().split())) pref = [0] died = False minipos = 0 mini = 99999999999 for i in range(n): cur = pref[-1] + a[i] if mini > cur: mini = cur minipos = i + 1 mini = min(mini, cur) pref.append(cur) if cur > H: print(i + 1) exit() if pref[-1] >= 0: print(-1) exit() ans = n * (H // -pref[-1] - 1) H %= abs(pref[-1]) if H - pref[-1] < -mini: pos = 1 while H - pref[-1] + pref[pos] > 0: pos += 1 ans += 1 else: pos = 1 while H + pref[pos] > 0: pos += 1 ans += 1 print(ans + 1) ```
instruction
0
36,925
2
73,850
No
output
1
36,925
2
73,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of n numbers: d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6). The i-th element means that monster's hp (hit points) changes by the value d_i during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h := h + d_i. The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely. Input The first line contains two integers H and n (1 ≀ H ≀ 10^{12}, 1 ≀ n ≀ 2β‹…10^5). The second line contains the sequence of integers d_1, d_2, ..., d_n (-10^6 ≀ d_i ≀ 10^6), where d_i is the value to change monster's hp in the i-th minute of a round. Output Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead. Examples Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 Output -1 Submitted Solution: ``` h,n = [int(i) for i in input().split()] dam = [int(i) for i in input().split()] mi = float("inf") su = 0 fake = h flag = False minu = 0 for v in dam: su+=v mi = min(mi,su) fake += v if(fake<=0 and not(flag)): flag = True minu+=1 elif(not(flag)): minu+=1 if(fake <= 0): print(minu) elif(su>=0): print(-1) else: full = abs(int((h+mi)/su)) h+= full*su res = full*n i = 0 while h>0: h+=dam[i%n] res+=1 i+=1 print(res) ```
instruction
0
36,926
2
73,852
No
output
1
36,926
2
73,853
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,909
2
75,818
Tags: brute force, dp, implementation Correct Solution: ``` from sys import stdin input = stdin.readline def solve(): n = int(input()) a = list(map(int, input().split())) # (n + number with -1 sign)%3 == 1 # dp[i][j][k][l]: choose from a[:i], j = (n + num with -1 sign) mod 3, # k = whether two consecutive same sign, l = 1 if last number is + else 0 if n == 1: print(max(a[0],-a[0])) return NINF = -10 ** 15 dp = [[[[NINF] * 2 for i in range(2)] for j in range(3)] for k in range(n)] dp[0][n % 3][0][1] = a[0] dp[0][(n + 1) % 3][0][0] = -a[0] for i in range(n-1): for j in range(3): for k in range(2): for l in range(2): if dp[i][j][k][l] > NINF: dp[i+1][j][k or l == 1][1] = max(dp[i+1][j][k or l == 1][1], dp[i][j][k][l] + a[i+1]) dp[i+1][(j + 1) % 3][k or l == 0][0] = max(dp[i+1][(j + 1) % 3][k or l == 0][0], dp[i][j][k][l] - a[i+1]) print(max(dp[n-1][1][1][1], dp[n-1][1][1][0])) if __name__ == '__main__': solve() ```
output
1
37,909
2
75,819
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,910
2
75,820
Tags: brute force, dp, implementation Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) INF = 10 ** 20 DP = [-INF] * 12 DP[1] = a[0] DP[5] = -a[0] for elem in a[1:]: newDP = [] newDP.append(DP[5] + elem) newDP.append(DP[3] + elem) newDP.append(DP[4] + elem) newDP.append(DP[1] - elem) newDP.append(DP[2] - elem) newDP.append(DP[0] - elem) newDP.append(max(DP[2] + elem, DP[8] + elem, DP[11] + elem)) newDP.append(max(DP[0] + elem, DP[6] + elem, DP[9] + elem)) newDP.append(max(DP[1] + elem, DP[7] + elem, DP[10] + elem)) newDP.append(max(DP[4] - elem, DP[7] - elem, DP[10] - elem)) newDP.append(max(DP[5] - elem, DP[8] - elem, DP[11] - elem)) newDP.append(max(DP[3] - elem, DP[6] - elem, DP[9] - elem)) DP = newDP if n == 1: print(a[0]) else: print(max(DP[7],DP[10])) ```
output
1
37,910
2
75,821
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,911
2
75,822
Tags: brute force, dp, implementation Correct Solution: ``` N = int(input()) a, b, c, d, e = float("-inf"), float("-inf"), float("-inf"), 0, 1 for x in map(int, input().split()): a, b, c, d, e = max(c + x, b - x), max(a + x, c - x), \ max(b + x, a - x, d - e * x), d + e * x, -e print([d, b][N > 1]) ```
output
1
37,911
2
75,823
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,912
2
75,824
Tags: brute force, dp, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() inf = float('inf') dp = [[[-inf, -inf, -inf] for _ in range(2)] for _ in range(n + 1)] dp[0][0][0] = 0 for i in range(n): for j in range(2): for k in range(3): dp[i+1][j][(k+1)%3] = max(dp[i+1][j][(k+1)%3], dp[i][j][k] + a[i]) dp[i+1][j][(k-1)%3] = max(dp[i+1][j][(k-1)%3], dp[i][j][k] - a[i]) if i + 1 < n: for k in range(3): dp[i+2][1][(k+2)%3] = max(dp[i+2][1][(k+2)%3], dp[i][0][k] + a[i] + a[i+1]) dp[i+2][1][(k-2)%3] = max(dp[i+2][1][(k-2)%3], dp[i][0][k] - a[i] - a[i+1]) ans = dp[n][1][1] print(ans) ```
output
1
37,912
2
75,825
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,913
2
75,826
Tags: brute force, dp, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() inf = 1002003004005006007 dp = [[[-inf, -inf, -inf] for _ in range(2)] for _ in range(n + 1)] dp[0][0][0] = 0 for i in range(n): for j in range(2): for k in range(3): dp[i+1][j][(k+1)%3] = max(dp[i+1][j][(k+1)%3], dp[i][j][k] + a[i]) dp[i+1][j][(k-1)%3] = max(dp[i+1][j][(k-1)%3], dp[i][j][k] - a[i]) if i + 1 < n: for k in range(3): dp[i+2][1][(k+2)%3] = max(dp[i+2][1][(k+2)%3], dp[i][0][k] + a[i] + a[i+1]) dp[i+2][1][(k-2)%3] = max(dp[i+2][1][(k-2)%3], dp[i][0][k] - a[i] - a[i+1]) ans = dp[n][1][1] print(ans) ```
output
1
37,913
2
75,827
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,914
2
75,828
Tags: brute force, dp, implementation Correct Solution: ``` n = int(input()) a = [int(i) for i in input().split()] if n == 1: print(a[0]) else: dp = [dict(), dict()] dp[0][(0, 0, 0)] = a[0] dp[0][(1, 0, 1)] = -a[0] for i in range(1, n): _i = i & 1 dp[_i].clear() for j in range(3): dp[_i][(j, 0, 0)] = dp[1 - _i].get((j, 0, 1), -2e14 - 5) + a[i] dp[_i][(j, 0, 1)] = dp[1 - _i].get(((j + 2) % 3, 0, 0), -2e14 - 5) - a[i] dp[_i][(j, 1, 0)] = max(dp[1 - _i].get((j, 0, 0), -2e14 - 5) + a[i], dp[1 - _i].get((j, 1, 0), -2e14 - 5) + a[i], dp[1 - _i].get((j, 1, 1), -2e14 - 5) + a[i]) dp[_i][(j, 1, 1)] = max(dp[1 - _i].get(((j + 2) % 3, 0, 1), -2e14 - 5) - a[i], dp[1 - _i].get(((j + 2) % 3, 1, 0), -2e14 - 5) - a[i], dp[1 - _i].get(((j + 2) % 3, 1, 1), -2e14 - 5) - a[i]) print(max(dp[(n - 1) & 1][((3 - (n + 2) % 3) % 3, 1, 0)], dp[(n - 1) & 1][((3 - (n + 2) % 3) % 3, 1, 1)])) ```
output
1
37,914
2
75,829
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,915
2
75,830
Tags: brute force, dp, implementation Correct Solution: ``` from heapq import nsmallest from math import inf as _inf import sys as _sys def main(): n, = _read_ints() a = tuple(_read_ints()) result = find_max_power_can_make(a) print(result) def _read_line(): result = _sys.stdin.readline() assert result[-1] == "\n" return result[:-1] def _read_ints(): return map(int, _read_line().split()) def find_max_power_can_make(heroes_powers): heroes_powers = tuple(heroes_powers) assert heroes_powers abs_powers_sum = sum(map(abs, heroes_powers)) if len(heroes_powers) <= 9: return _compute_using_brute_force(heroes_powers) zeros_n = heroes_powers.count(0) if zeros_n >= 2: return abs_powers_sum assert zeros_n <= 1 n = len(heroes_powers) if n % 3 == 1 % 3: can_invert_mod_3 = 0 elif n % 3 == 2 % 3: can_invert_mod_3 = 2 else: assert n % 3 == 3 % 3 can_invert_mod_3 = 1 result = -_inf for is_zero_positive in (False, True): if zeros_n == 0 or is_zero_positive: signs = [1 if x >= 0 else -1 for x in heroes_powers] else: signs = [1 if x > 0 else -1 for x in heroes_powers] negative_n = signs.count(-1) have_pair_of_same = any(signs[i] == signs[i + 1] for i in range(len(signs) - 1)) is_trivial = not (not have_pair_of_same and negative_n % 3 == can_invert_mod_3) if is_trivial: if negative_n % 3 == can_invert_mod_3: result = max(result, abs_powers_sum) continue negative_to_inverse_1 = negative_n while negative_to_inverse_1 % 3 != can_invert_mod_3: negative_to_inverse_1 -= 1 negative_to_inverse_2 = negative_to_inverse_1 + 3 else: negative_to_inverse_1 = negative_n - 3 negative_to_inverse_2 = negative_n + 3 min_pos = max( heroes_powers, key=lambda x: (x >= 0 if is_zero_positive else x > 0, -abs(x)) ) max_neg = max( heroes_powers, key=lambda x: (x < 0 if is_zero_positive else x <= 0, x) ) result = max(result, abs_powers_sum - 2 * abs(min_pos) - 2 * abs(max_neg)) if negative_to_inverse_1 >= 0: negative_to_remain_n = negative_n - negative_to_inverse_1 assert negative_to_remain_n > 0 negative_powers = tuple(filter( lambda x: x < 0 if is_zero_positive else x <= 0, heroes_powers )) if negative_to_remain_n <= len(negative_powers): negative_to_remain = nsmallest( negative_to_remain_n, negative_powers, key=abs ) result = max(result, abs_powers_sum - 2 * abs(sum(negative_to_remain))) if negative_to_inverse_2 <= n: positive_to_inverse_n = negative_to_inverse_2 - negative_n assert positive_to_inverse_n > 0 positive_powers = tuple(filter( lambda x: x >= 0 if is_zero_positive else x > 0, heroes_powers )) if positive_to_inverse_n <= len(positive_powers): positive_to_inverse = nsmallest( positive_to_inverse_n, positive_powers, key=abs ) result = max(result, abs_powers_sum - 2 * sum(positive_to_inverse)) return result def _compute_using_brute_force(seq): n = len(seq) if n == 1: return seq[0] return max( _compute_using_brute_force(seq[:i] + (-(seq[i] + seq[i+1]),) + seq[i+2:]) for i in range(n - 1) ) if __name__ == '__main__': main() ```
output
1
37,915
2
75,831
Provide tags and a correct Python 3 solution for this coding contest problem. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26]
instruction
0
37,916
2
75,832
Tags: brute force, dp, implementation Correct Solution: ``` N,x,y,z,v,w=input(),-9e9,-9e9,-9e9,0,1 for A in map(int,input().split()):x,y,z,v,w=max(z+A,y-A),max(x+A,z-A),max(y+A,x-A,v-w*A),v+w*A,-w print([v,y][N>'1']) ```
output
1
37,916
2
75,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` N,v,w=input(),0,1;x=y=z=-2e9 for A in map(int,input().split()):x,y,z,v,w=max(z+A,y-A),max(x+A,z-A),max(y+A,x-A,v-w*A),v+w*A,-w print([v,y][N>'1']) ```
instruction
0
37,917
2
75,834
Yes
output
1
37,917
2
75,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` N = int(input()) x, y, z, v, w = float("-inf"), float("-inf"), float("-inf"), 0, 1 for A in map(int, input().split()): x, y, z, v, w = max(z + A, y - A), max(x + A, z - A), \ max(y + A, x - A, v - w * A), v + w * A, -w print([v, y][N > 1]) ```
instruction
0
37,918
2
75,836
Yes
output
1
37,918
2
75,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` n = int(input()) s = list(map(int, input().split())) s.sort() if n%2==1: while len(s)!=1: s[-2] = -(s[-1] + s[-2]) del s[-1] else: while len(s)!=1: for i in range(0, len(s)-1, 2): s[i] = -(s[i]+s[i+1]) s = [s[i] for i in range(0, len(s), 2)] print(*s) ```
instruction
0
37,919
2
75,838
No
output
1
37,919
2
75,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` t = int(input()) li = list(map(int, input().split())) for k in range(t-1): l = [] i = 0 while i < (len(li)-1): a = abs(li[i] + li[i + 1]) l.append(a) i += 1 maximum = max(l) i=1 while i < (len(li)): a = -(li[i-1] + li[i]) if (abs(a) == maximum): li.insert(i-1, a) li.pop(i) li.pop(i) i += 1 print(abs(li[0])) ```
instruction
0
37,920
2
75,840
No
output
1
37,920
2
75,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` n=int(input()) l=[] no_of_negatives = 0 for x in input().split(): i=int(x) if(i<0): no_of_negatives+=1 l.append(-(i)) else: l.append(i) l.sort() #print(l) ans=sum(l[no_of_negatives:]) - sum(l[:no_of_negatives]) print(ans) ```
instruction
0
37,921
2
75,842
No
output
1
37,921
2
75,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While playing yet another strategy game, Mans has recruited n [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array a. Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers a_i and a_{i+1}, remove them and insert a hero with power -(a_i+a_{i+1}) back in the same position. For example if the array contains the elements [5, 6, 7, 8], he can pick 6 and 7 and get [5, -(6+7), 8] = [5, -13, 8]. After he will perform this operation n-1 times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve? Input The first line contains a single integer n (1 ≀ n ≀ 200000). The second line contains n integers a_1, a_2, …, a_n (-10^9 ≀ a_i ≀ 10^9) β€” powers of the heroes. Output Print the largest possible power he can achieve after n-1 operations. Examples Input 4 5 6 7 8 Output 26 Input 5 4 -5 9 -2 1 Output 15 Note Suitable list of operations for the first sample: [5, 6, 7, 8] β†’ [-11, 7, 8] β†’ [-11, -15] β†’ [26] Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) if n%3 == 1: print(sum(a)) else: a = sorted(a) l = [1]*n l[0] = -1 m = 1 check = False if a[0]<0: check = True if (n+m)%3 == 1: print(-1*a[0]+sum(a[1:])) else: for i in range(1,n): if (a[i]<0 and check): l[i]=1 elif a[i]>=0: l[i] = -1 m+=1 check = False elif a[i]<0: l[i] = -1 m+=1 check = True if (n+m)%3==1: break print(sum([a[i]*l[i] for i in range(n)])) ```
instruction
0
37,922
2
75,844
No
output
1
37,922
2
75,845
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot had a major argument with the Fairy Godmother (there were rumors that the argument occurred after the general spoke badly of the Godmother's flying techniques. That seemed to hurt the Fairy Godmother very deeply). As the result of the argument, the Godmother put a rather strange curse upon the general. It sounded all complicated and quite harmless: "If the squared distance between some two soldiers equals to 5, then those soldiers will conflict with each other!" The drill exercises are held on a rectangular n Γ— m field, split into nm square 1 Γ— 1 segments for each soldier. Thus, the square of the distance between the soldiers that stand on squares (x1, y1) and (x2, y2) equals exactly (x1 - x2)2 + (y1 - y2)2. Now not all nm squad soldiers can participate in the drill exercises as it was before the Fairy Godmother's curse. Unless, of course, the general wants the soldiers to fight with each other or even worse... For example, if he puts a soldier in the square (2, 2), then he cannot put soldiers in the squares (1, 4), (3, 4), (4, 1) and (4, 3) β€” each of them will conflict with the soldier in the square (2, 2). Your task is to help the general. You are given the size of the drill exercise field. You are asked to calculate the maximum number of soldiers that can be simultaneously positioned on this field, so that no two soldiers fall under the Fairy Godmother's curse. Input The single line contains space-separated integers n and m (1 ≀ n, m ≀ 1000) that represent the size of the drill exercise field. Output Print the desired maximum number of warriors. Examples Input 2 4 Output 4 Input 3 4 Output 6 Note In the first sample test Sir Lancelot can place his 4 soldiers on the 2 Γ— 4 court as follows (the soldiers' locations are marked with gray circles on the scheme): <image> In the second sample test he can place 6 soldiers on the 3 Γ— 4 site in the following manner: <image>
instruction
0
37,923
2
75,846
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) if n > m: n, m = m, n if n > 2 and m > 2: print(((n * m) + 1) // 2) elif n == 1: print(m) else: print(2 * (((m // 4) * 2) + min(m % 4, 2))) # Made By Mostafa_Khaled ```
output
1
37,923
2
75,847
Provide tags and a correct Python 3 solution for this coding contest problem. Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot had a major argument with the Fairy Godmother (there were rumors that the argument occurred after the general spoke badly of the Godmother's flying techniques. That seemed to hurt the Fairy Godmother very deeply). As the result of the argument, the Godmother put a rather strange curse upon the general. It sounded all complicated and quite harmless: "If the squared distance between some two soldiers equals to 5, then those soldiers will conflict with each other!" The drill exercises are held on a rectangular n Γ— m field, split into nm square 1 Γ— 1 segments for each soldier. Thus, the square of the distance between the soldiers that stand on squares (x1, y1) and (x2, y2) equals exactly (x1 - x2)2 + (y1 - y2)2. Now not all nm squad soldiers can participate in the drill exercises as it was before the Fairy Godmother's curse. Unless, of course, the general wants the soldiers to fight with each other or even worse... For example, if he puts a soldier in the square (2, 2), then he cannot put soldiers in the squares (1, 4), (3, 4), (4, 1) and (4, 3) β€” each of them will conflict with the soldier in the square (2, 2). Your task is to help the general. You are given the size of the drill exercise field. You are asked to calculate the maximum number of soldiers that can be simultaneously positioned on this field, so that no two soldiers fall under the Fairy Godmother's curse. Input The single line contains space-separated integers n and m (1 ≀ n, m ≀ 1000) that represent the size of the drill exercise field. Output Print the desired maximum number of warriors. Examples Input 2 4 Output 4 Input 3 4 Output 6 Note In the first sample test Sir Lancelot can place his 4 soldiers on the 2 Γ— 4 court as follows (the soldiers' locations are marked with gray circles on the scheme): <image> In the second sample test he can place 6 soldiers on the 3 Γ— 4 site in the following manner: <image>
instruction
0
37,924
2
75,848
Tags: constructive algorithms, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) if n>m:n,m=m,n if n==1:print(m) elif n==2:print((m//4)*4+min((m%4)*2,4)) else:print((n*m)-(n*m)//2) ```
output
1
37,924
2
75,849
Provide tags and a correct Python 3 solution for this coding contest problem. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even) β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions. Output Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Examples Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 Note In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
instruction
0
38,106
2
76,212
Tags: games Correct Solution: ``` n = int(input()) x = sorted(list(map(int, input().split()))) print(min([x[i + n // 2] - x[i] for i in range(n // 2)])) ```
output
1
38,106
2
76,213
Provide tags and a correct Python 3 solution for this coding contest problem. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even) β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions. Output Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Examples Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 Note In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
instruction
0
38,107
2
76,214
Tags: games Correct Solution: ``` from itertools import accumulate m = int(input())//2 X = [int(x) for x in input().split()] X.sort() Z = [X[i+m] - X[i] for i in range(m)] print(min(Z)) ```
output
1
38,107
2
76,215
Provide tags and a correct Python 3 solution for this coding contest problem. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even) β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions. Output Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Examples Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 Note In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
instruction
0
38,108
2
76,216
Tags: games Correct Solution: ``` n = int(input()) x = sorted(list(map(int, input().split()))) print(min([x[i + n // 2] - x[i] for i in range(n // 2)])) # Made By Mostafa_Khaled ```
output
1
38,108
2
76,217
Provide tags and a correct Python 3 solution for this coding contest problem. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even) β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions. Output Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Examples Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 Note In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
instruction
0
38,109
2
76,218
Tags: games Correct Solution: ``` def main(): n = int(input()) l = sorted(map(int, input().split())) print(min(b - a for a, b in zip(l, l[n // 2:]))) if __name__ == '__main__': main() ```
output
1
38,109
2
76,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input The first line on the input contains a single integer n (2 ≀ n ≀ 200 000, n is even) β€” the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≀ xi ≀ 109), giving the coordinates of the corresponding positions. Output Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Examples Input 6 0 1 3 7 15 31 Output 7 Input 2 73 37 Output 36 Note In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 2. Lesha bans the position at coordinate 3; 3. Vova bans the position at coordinate 31; 4. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans. Submitted Solution: ``` def main(): lo, hi = 0, int(input()) - 1 l = sorted(map(int, input().split())) for i in range(hi // 2): if l[lo] + l[hi] < l[lo + 1] + l[hi - 1]: lo += 1 else: hi -= 1 print(l[hi] - l[lo]) if __name__ == '__main__': main() ```
instruction
0
38,110
2
76,220
No
output
1
38,110
2
76,221
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,119
2
78,238
Tags: math Correct Solution: ``` #!/usr/bin/python3 n = int(input()) print(1 + 6 * (n * (n + 1) // 2)) ```
output
1
39,119
2
78,239
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,120
2
78,240
Tags: math Correct Solution: ``` j=int(input()) print (1+(j+1)*j*3) ```
output
1
39,120
2
78,241
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,121
2
78,242
Tags: math Correct Solution: ``` def main(): n = int(input()) print(n * (n + 1) * 3 + 1) if __name__ == '__main__': main() ```
output
1
39,121
2
78,243
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,122
2
78,244
Tags: math Correct Solution: ``` n=int(input()) print(int((3*(n+1)*n)+1)) ```
output
1
39,122
2
78,245
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,123
2
78,246
Tags: math Correct Solution: ``` a=int(input()) print(1+a*(a+1)*3) ```
output
1
39,123
2
78,247
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,124
2
78,248
Tags: math Correct Solution: ``` n=int(input()) if n==0: print(1) elif n==1: print(7) else: print(((6*(n+1))//2)*n+1) ```
output
1
39,124
2
78,249
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,125
2
78,250
Tags: math Correct Solution: ``` n = int(input()) ans = 1 + 3 * n * (n + 1) print(ans) ```
output
1
39,125
2
78,251
Provide tags and a correct Python 3 solution for this coding contest problem. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19
instruction
0
39,126
2
78,252
Tags: math Correct Solution: ``` n = int(input()) x = (n+1)*n*3 + 1 print(x) ```
output
1
39,126
2
78,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon. Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another. It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That's why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell. <image> Input The only line of the input contains one integer n (0 ≀ n ≀ 109). Output Output one integer β€” the number of hexagons situated not farther than n cells away from a given cell. Examples Input 2 Output 19 Submitted Solution: ``` n = int(input()) print(1 + (6 +n*6)*n//2) ```
instruction
0
39,127
2
78,254
Yes
output
1
39,127
2
78,255