Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(10**9)

    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+a[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+b[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(M)]

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

print(ans)

Fixed submission:
def main():
    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+b[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(M)]

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

print(ans)

Fixed submission:
def main():
    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+b[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

flg = 1
for i in range(N):
  if A[i] in A[i+1:]:
    print("NO")
    flg= 0
    break
if flg:
  print("YES")


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort()

flg = 1
for i in range(N-1):
  if A[i]==A[i+1]:
    print("NO")
    flg= 0
    break
if flg:
  print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from itertools import accumulate
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
E = [0]*N

for i in range(N):
  E[i] = (p[i]+1)/2
  
#acc = list(accumulate(E))
#print(E,acc)

for i in range(N-K+1):
  if i == 0:
    ans = sum(E[i:i+K])
  else:
    ans = max(ans,sum(E[i:i+K]))
print(ans)




Fixed submission:
import itertools 
N,K =list(map(int,input().split()))
p =list(map(int,input().split()))
E = [0] * N

for i in range(N):
  E[i]=(p[i]+1)/2
acc = [0]
acc += list(itertools.accumulate(E))

ans = 0
for i in range(N-K+1):
  ans = max(acc[i+K] - acc[i], ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
E = [0]*N

for i in range(N):
  E[i] = (p[i]+1)/2
  

for i in range(N-2):
  if i == 0:
    ans = sum(E[i:i+K])
  else:
    ans = max(ans,sum(E[i:i+K]))
print(ans)



Fixed submission:
import itertools 
N,K =list(map(int,input().split()))
p =list(map(int,input().split()))
E = [0] * N

for i in range(N):
  E[i]=(p[i]+1)/2
acc = [0]
acc += list(itertools.accumulate(E))

ans = 0
for i in range(N-K+1):
  ans = max(acc[i+K] - acc[i], ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = list(map(int, input().split()))
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
 
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1])

Fixed submission:
H,N = list(map(int, input().split()))
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
 
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  i = p.index(n)
  if n == p[0]:
    cnt += 1
  elif min(p[:i]) >= n:
    cnt += 1
print(cnt)

Fixed submission:
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  if n == p[0]:
    cnt += 1
    min = n
  elif min >= n:
    cnt += 1
    min = n
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int, input().split()))

cnt = 1
for i in range(N):
  if i >= 1 and p[i] <= min(p[0:i]):
      cnt += 1
print(cnt)


Fixed submission:
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  if n == p[0]:
    cnt += 1
    min = n
  elif min >= n:
    cnt += 1
    min = n
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N):
  for j in range(i+1):
    if i > 1 and p[i] > p[i-1]:
      break
    elif p[i] > p[j]:
      break
    elif i == j:
      cnt += 1

print(cnt)


Fixed submission:
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  if n == p[0]:
    cnt += 1
    min = n
  elif min >= n:
    cnt += 1
    min = n
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N):
  for j in range(i+1):
    if p[i] > p[j]:
      break
    elif i == j:
      cnt += 1

print(cnt)


Fixed submission:
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  if n == p[0]:
    cnt += 1
    min = n
  elif min >= n:
    cnt += 1
    min = n
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N):
  for j in range(i+1):
    if p[i] > p[j]:
      break
    elif i == j:
      cnt += 1

print(cnt)

Fixed submission:
N = int(input())
p = list(map(int,input().split()))

cnt = 0
for n in p:
  if n == p[0]:
    cnt += 1
    min = n
  elif min >= n:
    cnt += 1
    min = n
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input().rstrip().split()
N,M = int(s[0]),int(s[1])

a=[]
for i in range(M):
  a.append(input().rstrip().split())

pen =0
AClist =[]
ACflag= [0]*N
#print(a,len(a))

for i in range(len(a)):
  if a[i][1] == "AC" and ACflag[int(a[i][0])] == 0:
    AClist.append(a[i])
    ACflag[int(a[i][0])] = 1
  if a[i][1] == "WA" and ACflag[int(a[i][0])] == 0:
    pen += 1

print(len(AClist),pen)

Fixed submission:
N,M = list(map(int,input().split()))

lac = [0]*(N+1)
lpcnt = [0]*(N+1)

for i in range(M):
  s = input().split()
  n = int(s[0])
  if s[1] == "AC":
    lac[n] =1
    continue
  if s[1] == "WA" and lac[n] == 0:
    lpcnt[n] += 1

cnt = 0
for i in range(N+1):
  if lac[i] == 1:
    cnt += lpcnt[i]
  
print(sum(lac), end=" ")
print(cnt)
Buggy python submission (verdict: Runtime Error):
K,X =int(input()),int(input())
if K*500>=X:
  print("Yes")
else:
  print("No")

Fixed submission:
s = input().rstrip().split()
K,X =int(s[0]),int(s[1])
if K*500>=X:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):

import itertools,bisect
N =int(input())
L = list(map(int,input().split()))
L.sort()

def j(a,b,c):
  if a<b+c and c<b+a and b<a+c:
    return True
  else:
    return False

cnt = 0
l = list(itertools.combinations(range(N),2))
for i1,i2 in l:
  a,b = L[i1],L[i2]
  if a == b:
    ib = bisect.bisect_right(L, b)
    ic = bisect.bisect_right(L, a+b)
  else:
    ib = bisect.bisect_left(L, b)
    ic = bisect.bisect_left(L, a+b)
  if ic - ib >=1:
    cnt += ic - ib -1
print(cnt)

Fixed submission:
import bisect
N =int(input())
L = sorted(list(map(int,input().split())))

cnt = 0

for i in range(N):
  for j in range(i+1,N):
    cnt += bisect.bisect_left(L,L[i]+L[j]) - (j+1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N =int(input())
L = list(map(int,input().split()))

def j(a,b,c):
  if a<b+c and c<b+a and b<a+c:
    return True
  else:
    return False

cnt = 0
l = list(itertools.combinations(range(N),3))
for i1,i2,i3 in l:
  a,b,c = L[i1],L[i2],L[i3]
  if j(a,b,c):
    cnt += 1
print(cnt)

Fixed submission:
import bisect
N =int(input())
L = sorted(list(map(int,input().split())))

cnt = 0

for i in range(N):
  for j in range(i+1,N):
    cnt += bisect.bisect_left(L,L[i]+L[j]) - (j+1)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

def div(n):
  l =[]
  for i in range(1,n+1):
    if n%i ==0:
      l.append(i)
  return l

A,B = list(map(int,input().split()))
maxy = fractions.gcd(A,B)
ly = div(maxy)
l = [1]

for i in ly[1:]:
  flg = 1
  for e in l:
    if fractions.gcd(i,e) > 1:
      flg = 0
  if i not in l and flg == 1:
    l.append(i)
print(len(l))


Fixed submission:
import fractions

def div(n):
  l =[]
  for i in range(1,n+1):
    if n%i ==0:
      l.append(i)
  return l

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i not in table:
        table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

A,B = list(map(int,input().split()))
maxy = fractions.gcd(A,B)

l2 = prime_decomposition(maxy)
print(len(l2) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))

for i in range(m):
  a.sort(reverse = True)
  a[0] //= 2
print(sum(a))


Fixed submission:
import heapq

n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a = list(map(lambda x:x*(-1),a))
heapq.heapify(a)

for i in range(m):
  mx = heapq.heappop(a)
  mx= -(-mx//2)
  heapq.heappush(a,mx)

a = list(map(lambda x:x*(-1),a))
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(M)]

for i in range(M):
  l1 = list(range(l[i][0],l[i][1]+1))
  if i == 0:
    valid = l1
  valid = set(valid) & set(l1)
print(len(valid))



Fixed submission:
N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(M)]

for e in l:
  L,R = e[0],e[1]
  if e == l[0]:
    _L,_R = L,R
  else:
    if _L < L:
      _L = L
    if _R > R:
      _R = R
if _R - _L >= 0:
  print(_R - _L + 1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[] for _ in range(N+1)]

for edge in edges:
  A[edge[0]].append([edge[1],edge[2]])
  A[edge[1]].append([edge[0],edge[2]])
  
depth = [-1] * (N+1)
depth[1] = 0

def dfs(A,s):
  for v in A[s]:
    if depth[v[0]] == -1:
      depth[v[0]] = depth[s] + v[1]
      dfs(A,v[0])
      
dfs(A,1)

for d in depth[1:]:
  if d % 2 == 0:
    print(0)
  else:
    print(1)





Fixed submission:
import sys
sys.setrecursionlimit(500*500)


N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[] for _ in range(N+1)]

for edge in edges:
  A[edge[0]].append([edge[1],edge[2]])
  A[edge[1]].append([edge[0],edge[2]])
  
depth = [-1] * (N+1)
depth[1] = 0

def dfs(A,s):
  for v in A[s]:
    if depth[v[0]] == -1:
      depth[v[0]] = depth[s] + v[1]
      dfs(A,v[0])
      
dfs(A,1)

for d in depth[1:]:
  if d % 2 == 0:
    print(0)
  else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int, input().split()))

s = 0

for i in range(len(ai) - 1):
    for j in range(i + 1, len(ai)):
        s += (ai[i] * ai[j])
        s %= (10 ** 9 + 7)

print(s)

Fixed submission:
n = int(input())
ai = list(map(int, input().split()))

square_sum_ai = sum(ai) ** 2
sum_ai_square = sum(map(lambda x: x ** 2, ai))

print(((square_sum_ai - sum_ai_square) // 2) % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n, k = map(int, input().split())
ai   = list(map(int, input().split()))

before = 1

for a in ai[ 0 : k ]:
    before *= a

for i in range(n - k):
    after = before * ai[i + k] // ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after


Fixed submission:
from math import log2

n, k = map(int, input().split())
ai   = list(map(lambda x: log2(int(x)), input().split()))

before = sum(ai[ 0 : k ])

for i in range(n - k):
    after = before + ai[i + k] - ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n, k = map(int, input().split())
ai   = list(map(int, input().split()))

before = reduce(lambda x, acc: x * acc, ai[ 0 : k ], 1)

for i in range(n - k):
    after = before * ai[i + k] // ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after


Fixed submission:
from math import log2

n, k = map(int, input().split())
ai   = list(map(lambda x: log2(int(x)), input().split()))

before = sum(ai[ 0 : k ])

for i in range(n - k):
    after = before + ai[i + k] - ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n, k = map(int, input().split())
ai   = list(map(int, input().split()))

before = reduce(lambda x, acc: x * acc, ai[ 0 : k ], 1)

for i in range(n - k):
    after = before * ai[i + k] // ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after


Fixed submission:
from math import log2

n, k = map(int, input().split())
ai   = list(map(lambda x: log2(int(x)), input().split()))

before = sum(ai[ 0 : k ])

for i in range(n - k):
    after = before + ai[i + k] - ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after
Buggy python submission (verdict: Time Limit Exceeded):
n    = int(input())
a_s  = list(map(int, input().split()))
q    = int(input())
bc_s = [ list(map(int, input().split())) for _ in range(q) ]

s = sum(a_s)
m = {}

for b, c in bc_s:
    nb = a_s.count(b) + m.get(b, 0)
    s += nb * (c - b)
    print(s)
    m[c] = nb + m.get(c, 0)


Fixed submission:
n    = int(input())
a_s  = list(map(int, input().split()))
q    = int(input())
bc_s = [ list(map(int, input().split())) for _ in range(q) ]

s = sum(a_s)
m = { a: 0 for a in a_s }

for a in a_s:
    m[a] += 1

for b, c in bc_s:
    nb = m.get(b, 0)
    s += nb * (c - b)
    print(s)
    m[b] = 0
    m[c] = nb + m.get(c, 0)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n  = input()
xs = map(int, input().split())

MAX  = 10 ** 18
OVER = MAX + 1

result = reduce(lambda x, acc: x * min(acc, OVER), xs)

if result <= MAX:
  print(result)
else:
  print(-1)

Fixed submission:
from functools import reduce

n  = input()
xs = list(map(int, input().split()))

MAX  = 10 ** 18

if 0 in xs:
  print(0)
  exit(0)

result = 1
  
for x in xs:
  result *= x
  
  if result > MAX:
    print(-1)
    exit(0)
    
print(result)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()

a = int(a)
b = int(b.replcae('.', ''))

print((a * b) // 100)

Fixed submission:
a, b = input().split()

a = int(a)
b = int(b.replace('.', ''))

print((a * b) // 100)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

graph = [
    [ False for _ in range(n) ]
    for _ in range(n)
]

hi = list(map(int,input().split()))

for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1][b - 1] = True
    graph[b - 1][a - 1] = True

count = 0

for j, link in enumerate(graph):
    if not any(link):
        count += 1

    else:
        linked_hi = [ hi[i] for i, connected in enumerate(link) if connected ]

        if all(map(lambda x: hi[j] > x, linked_hi)):
            count += 1

print(count)

Fixed submission:
n, m = [ int(x) for x in input().split() ]
hs   = [ int(x) for x in input().split() ] # len(hs) == n

vs = [ [] for _ in range(n) ]

for i in range(m):
    s, g = input().split()

    s = int(s) - 1
    g = int(g) - 1

    vs[s].append(g)
    vs[g].append(s)

goods = []

for i, v in enumerate(vs):
    if len(v) == 0:
        goods.append(i + 1)

    if all(hs[i] > hs[d] for d in v):
        goods.append(i + 1)

print(len(set(goods)))
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

a, b, n = map(int, input().split())

max_x = 0
x     = 0
a_b   = a / b

while n > 0:
    x = floor(a_b * (n % b))

    max_x = x if x > max_x else max_x

    n -= 1

print(max_x)

Fixed submission:
from math import floor

a, b, n = map(int, input().split())

x = min(b - 1, n)

print(floor(a * x / b) - a * floor(x / b))

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

a, b, n = map(int, input().split())

max_x = 0

while n > 0:
    x = floor(a * (n % b) / b)

    max_x = x if x > max_x else max_x

    n -= 1

print(max_x)

Fixed submission:
from math import floor

a, b, n = map(int, input().split())

x = min(b - 1, n)

print(floor(a * x / b) - a * floor(x / b))

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

a, b, n = map(int, input().split())

max_x = 0

while n > 0:
    x = floor(a * (n % b) / b)

    max_x = x if x > max_x else max_x

    n -= 1

print(max_x)

Fixed submission:
from math import floor

a, b, n = map(int, input().split())

x = min(b - 1, n)

print(floor(a * x / b) - a * floor(x / b))
Buggy python submission (verdict: Runtime Error):
n = int(log2(int(input())))

print(2 ** (n + 1) - 1)

Fixed submission:
from math import log2

n = int(log2(int(input())))

print(2 ** (n + 1) - 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

steps = []

for x in range(n):
    if n % (x + 1) == 0:
        steps.append(x + n // (x + 1) - 1)

print(min(steps))

Fixed submission:
n = int(input())

steps = []

for x in range(int(n ** 0.5)):
    if n % (x + 1) == 0:
        steps.append(x + n // (x + 1) - 1)

print(min(steps))
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

graph   = [ [] for _ in range(N) ]
queries = { p: 0 for p in range(N) }

for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())

    queries[p - 1] += x

answer = [ 0 ] * N

def dfs(p, p_before, acc):
    acc += queries[p]

    answer[p] = acc

    for child in graph[p]:
        if child == p_before:
            continue

        dfs(child, acc)

dfs(0, -1, 0)

print(*answer)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

graph   = [ [] for _ in range(N) ]
queries = { p: 0 for p in range(N) }

for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())

    queries[p - 1] += x

answer = [ 0 ] * N

def dfs(p, p_before, acc):
    acc += queries[p]

    answer[p] = acc

    for child in graph[p]:
        if child == p_before:
            continue

        dfs(child, p, acc)

dfs(0, -1, 0)

print(*answer)
Buggy python submission (verdict: Time Limit Exceeded):
'''
        2 A1 = M_1 + M_2
        2 A2 = M_2 + M_3
        2 A3 = M_3 + M_4
        2 A4 = M_4 + M_5
        2 A5 = M_5 + M_1
A1 + A2 + A3 = M_1 + M_2 + M_3

M_1 = (A1 + A2 + A3) - (M_2 + M_3 + M_4 + M_5)
M_2 = (A1 + A2 + A3) - (M_3 + M_4 + M_5 + M_6)
M_3 = (A1 + A2 + A3) - (M_4 + M_5 + M_6 + M_7)
'''

n    = int(input())
ai   = list(map(int, input().split()))
aix2 = list(map(lambda x: x * 2, ai))

sum_a = sum(ai)

def ring_get(xs, s, e, mod):
    ys = []
    i  = s % mod

    while i != (e % mod):
        ys.append(xs[i])
        i = (i + 2) % mod

    return ys

for i in range(1, n):
    print(sum_a - sum(ring_get(aix2, i, i + (n - 1), n)))

print(sum_a - sum(ring_get(aix2, 0, 0 + (n - 1), n)))

Fixed submission:
'''
        2 A1 = M_1 + M_2
        2 A2 = M_2 + M_3
        2 A3 = M_3 + M_4
        2 A4 = M_4 + M_5
        2 A5 = M_5 + M_1
A1 + A2 + A3 = M_1 + M_2 + M_3

M_1 = (A1 + A2 + A3) - (M_2 + M_3 + M_4 + M_5)
M_2 = (A1 + A2 + A3) - (M_3 + M_4 + M_5 + M_6)
M_3 = (A1 + A2 + A3) - (M_4 + M_5 + M_6 + M_7)
'''

n    = int(input())
ai   = list(map(int, input().split()))
aix2 = list(map(lambda x: x * 2, ai))

sum_a = sum(ai)

def ring_get(xs, s, e, mod):
    ys = []
    i  = s % mod

    while i != (e % mod):
        ys.append(xs[i])
        i = (i + 2) % mod

    return ys

beforeM = sum_a - sum(ring_get(aix2, 1, 1 + (n - 1), n))

print(beforeM)

for i in range(1, n):
    print(aix2[i - 1] - beforeM)
    beforeM = aix2[i - 1] - beforeM
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
stack = []
ans = 0
while len(s):
    stack.append(s.popleft())
    if len(stack) >= 3 and \
        stack[-3:] == ['A', 'B', 'C']:
        del stack[-3:]
        s.appendleft('A')
        s.appendleft('C')
        s.appendleft('B')
        ans += 1

print(ans)

Fixed submission:
s = input().replace('BC', 'D')
s = s.replace('B', 'C')
l = [x for x in s.split(sep='C') if x != '']
ans = 0
for subs in l:
    numA = 0
    for c in subs:
        if c == 'A':
            numA += 1
        elif c == 'D':
            ans += numA

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
stack = []
ans = 0
while len(s):
    stack.append(s.popleft())
    if len(stack) >= 3 and \
        stack[-3:] == ['A', 'B', 'C']:
        del stack[-3:]
        s.appendleft('A')
        s.appendleft('C')
        s.appendleft('B')
        ans += 1

print(ans)

Fixed submission:
s = input().replace('BC', 'D')
s = s.replace('B', 'C')
l = [x for x in s.split(sep='C') if x != '']
ans = 0
for subs in l:
    numA = 0
    for c in subs:
        if c == 'A':
            numA += 1
        elif c == 'D':
            ans += numA

print(ans)