Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]


def solve(X):
    if not ("1" in X and "2" in X and "3" in X):
        return 1e10

    MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
    ret = 1e10
    ret = min(ret, solve2(MS[0], A) + solve2(MS[1], B) + solve2(MS[2], C))
    ret = min(ret, solve2(MS[0], A) + solve2(MS[2], B) + solve2(MS[1], C))
    ret = min(ret, solve2(MS[1], A) + solve2(MS[0], B) + solve2(MS[2], C))
    ret = min(ret, solve2(MS[1], A) + solve2(MS[2], B) + solve2(MS[0], C))
    ret = min(ret, solve2(MS[2], A) + solve2(MS[0], B) + solve2(MS[1], C))
    ret = min(ret, solve2(MS[2], A) + solve2(MS[1], B) + solve2(MS[0], C))
    return ret


def solve2(M, target):
    def rec(Y, target):
        # Y: [1, 0, 0]
        if len(Y) == len(M):
            if len(set(Y)) == 1 and Y[0] == 0:
                return 1e10
            sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
            return abs(target - sum_M) + 10 * (Y.count(1) - 1)
        return min(rec(Y + [0], target), rec(Y + [1], target))
    ret = rec([], target)
    return ret


ans = 1e10


def rec(X):
    global ans
    if len(X) == N:
        ans = min(ans, solve(X))
        return
    rec(X + "1")
    rec(X + "2")
    rec(X + "3")


rec("")

print(ans)


Fixed submission:
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]


def solve(X):
    if not ("1" in X and "2" in X and "3" in X):
        return 1e10

    MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
    ret = 1e10
    A_ans = []
    B_ans = []
    C_ans = []
    for i in range(3):
        A_ans.append(solve2(MS[i], A))
        B_ans.append(solve2(MS[i], B))
        C_ans.append(solve2(MS[i], C))
    ret = min(ret, A_ans[0] + B_ans[1] + C_ans[2])
    ret = min(ret, A_ans[0] + B_ans[2] + C_ans[1])
    ret = min(ret, A_ans[1] + B_ans[0] + C_ans[2])
    ret = min(ret, A_ans[1] + B_ans[2] + C_ans[0])
    ret = min(ret, A_ans[2] + B_ans[0] + C_ans[1])
    ret = min(ret, A_ans[2] + B_ans[1] + C_ans[0])
    return ret


def solve2(M, target):
    def rec(Y, target):
        # Y: [1, 0, 0]
        if len(Y) == len(M):
            if len(set(Y)) == 1 and Y[0] == 0:
                return 1e10
            sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
            return abs(target - sum_M) + 10 * (Y.count(1) - 1)
        return min(rec(Y + [0], target), rec(Y + [1], target))
    ret = rec([], target)
    return ret


ans = 1e10


def rec(X):
    global ans
    if len(X) == N:
        ans = min(ans, solve(X))
        return
    rec(X + "1")
    rec(X + "2")
    rec(X + "3")


rec("")

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = set(list(map(int, input().split())))

MAX_N = int(1e4)
dp = [[-1 for i in range(10)] for i in range(MAX_N + 10)]
for j in range(1, 9 + 1):
    dp[0][j] = 0

mc = [2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(N + 1):
    for j in range(1, 9 + 1):
        if j not in A:
            continue

        if i < mc[j - 1]:
            continue

        for k in range(1, j + 1):
            tmp = dp[i - mc[j - 1]][k]
            if tmp == -1:
                continue
            if tmp == 0:
                tmp = ""
            tmp = str(tmp)
            dp[i][j] = max(dp[i][j], int(tmp + str(j)), int(str(j) + tmp))


ans = 0
for j in range(1, 9 + 1):
    ans = max(ans, dp[N][j])
print(ans)


Fixed submission:
import math


N, M = map(int, input().split())
A = list(map(int, input().split()))

MAX_N = int(1e4)
dp = [-1 for i in range(MAX_N + 20)]
dp[0] = 0

mc = [2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(N + 1):
    for j in A:
        tmp = dp[i]
        if tmp == -1:
            continue
        if tmp == 0:
            dp[i + mc[j - 1]] = max(dp[i + mc[j - 1]], j)
        else:
            dp[i + mc[j - 1]] = max(dp[i + mc[j - 1]], tmp * 10 + j)

ans = dp[N]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt, floor
from collections import defaultdict


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

X = defaultdict(int)
cnt = 2
while True:
    if P == 1 or cnt > P:
        break
    if P % cnt == 0:
        X[cnt] += 1
        P = P // cnt
    else:
        cnt += 1

ans = 1
for k, v in X.items():
    ans *= k ** (v // N)
print(ans)


Fixed submission:
from math import sqrt, floor
from collections import defaultdict


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

X = defaultdict(int)
cnt = 2
for a in range(2, floor(sqrt(P)) + 1):
    while P % a == 0:
        X[a] += 1
        P = P // a
if P > 1:
    X[P] += 1

ans = 1
for k, v in X.items():
    ans *= k ** (v // N)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    if p not in D:
        D[p] = [(i, y)]
    else:
        D[p].append((i, y))

for p in P:
    D[p].sort(key=lambda p: p[1])

ans = []
for p, pairs in D.items():
    for x, pair in enumerate(pairs):
        x += 1
        i = pair[0]
        y = pair[1]
        out = "{0:06d}{1:06d}".format(p, x)
        ans.append((i, out))
ans.sort(key=lambda p: p[0])
for an in ans:
    print(an[1])


Fixed submission:
N, M = map(int, input().split())
D = {}
for i in range(M):
    p, y = map(int, input().split())
    if p not in D:
        D[p] = [(i, y)]
    else:
        D[p].append((i, y))

for p in D.keys():
    D[p].sort(key=lambda p: p[1])

ans = [None for i in range(M)]
for p, pairs in D.items():
    for x, pair in enumerate(pairs):
        x += 1
        i = pair[0]
        y = pair[1]
        out = "{0:06d}{1:06d}".format(p, x)
        ans[i] = out
        # ans.append((i, out))
# ans.sort(key=lambda p: p[0])
for an in ans:
    print(an)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)

se = set()

for i in range(N):
    for j in range(N - i):
        s = S[j:j+i+1]
        se.add(s)
l = sorted(list(se))
ans = l[K - 1]
print(ans)


Fixed submission:
S = input()
K = int(input())
N = len(S)

se = set([])
for i in range(N):
    for k in range(5):
        s = S[i:i+k+1]
        se.add(s)
l = sorted(list(se))
ans = l[K - 1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import PriorityQueue


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = sum(A)
B_sum = sum(B)
diff = B_sum - A_sum
if diff < 0:
    print("No")
    exit()

Aq = PriorityQueue()
Bq = PriorityQueue()
for a in A:
    Aq.put((a, a))
for b in B:
    Bq.put((b, b))

cnt = 0

while cnt <= diff and (not Aq.empty()) and (not Bq.empty()):
    _, a = Aq.get()
    _, b = Bq.get()
    if a < b:
        ne_a = a + 2
        ne_b = b + 1
        Aq.put((ne_a, ne_a))
        Bq.put((ne_b, ne_b))
        cnt += 1

if Aq.empty() and Bq.empty():
    print("Yes")
else:
    print("No")


Fixed submission:
import math
from queue import PriorityQueue


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = sum(A)
B_sum = sum(B)
diff = B_sum - A_sum
if diff < 0:
    print("No")
    exit()

cnt = 0
for a, b in zip(A, B):
    if a < b:
        cnt += math.ceil((b - a) / 2)

if cnt > diff:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))


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

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if sum_v > Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))

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

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    used = sum(now)
    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))


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

coins = [10000, 5000, 1000]

ans = []
def dfs(sum_v, now, i):
    if len(ans) != 0:
        return

    used = sum(now)

    if len(now) == 3:
        if sum_v == Y:
            ans.append(now)
        return

    if sum_v + coins[i] * (N - used) < Y:
        return

    if sum_v > Y:
        return

    if i == 2:
        ne = now + [N - used]
        dfs(sum_v + coins[i] * (N - used), ne, i + 1)
    else:
        for j in range(N - used + 1):
            ne = now + [j]
            dfs(sum_v + coins[i] * j, ne, i + 1)

dfs(0, [], 0)
if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(" ".join(map(str, ans[0])))
Buggy python submission (verdict: Runtime Error):
from math import gcd

N = int(input())
T = [int(input()) for i in range(N)]
ans = T[0]
def lcm(a, b):
    g = gcd(a, b)
    return a * b // g

for i in range(1, N):
    ans = lcm(ans, T[i])
print(ans)


Fixed submission:
from fractions import gcd

N = int(input())
T = [int(input()) for i in range(N)]
ans = T[0]
def lcm(a, b):
    g = gcd(a, b)
    return a * b // g

for i in range(1, N):
    ans = lcm(ans, T[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
TSSTTTSS

Fixed submission:
st = []
X = input()
for x in X:
    if not len(st) == 0:
        top = st.pop()
        if top == "S" and x == "T":
            continue
        else:
            st.append(top)
            st.append(x)
    else:
        st.append(x)
print(len(st))
Buggy python submission (verdict: Runtime Error):
a, b = input().strip().split()
print(a/b)

Fixed submission:
a, b = map(int, input().strip().split())
print(a/b)
Buggy python submission (verdict: Runtime Error):
n,d=input().split()
n=int(n)
d=int(d)
a=d*2+1
if n%a==0:
    print(n//a)
else:
    print(n//a+1)

Fixed submission:
r=int(input())
a=3*r**2
print(int(a))

Buggy python submission (verdict: Runtime Error):
N = input()
D = input()
n = int(N)
d = int(D)
k = (n+2*d)/(2*d+1)
print(k)

Fixed submission:
r = input()
a = int(r)
print(3*a*a)

Buggy python submission (verdict: Runtime Error):
r = input()
r = int(a)
print(3*r*r)

Fixed submission:
r = input()
a = int(r)
print(3*a*a)
Buggy python submission (verdict: Runtime Error):
import math
n,d=map(int,raw_input())
print int( math.ceil(float(n)/(2*d+1)))


Fixed submission:
import math
n,d=map(int,raw_input().split())
print int( math.ceil(float(n)/(2*d+1)))
Buggy python submission (verdict: Runtime Error):
S=raw_input()
f=False
for i in range(len(S)-1):
    if S[i]==S[i+1]:f=True
if f:
    print("Bad")
else:
    print("Good")    


Fixed submission:
S=raw_input()
f=False
for i in range(len(S)-1):
    if S[i]==S[i+1]:f=True
if f:
    print("Bad")
else:
    print("Good")
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=[-1]*(3*(10**5))
p=0
A=map(int,raw_input().split())
Q=[]
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse();    
A.sort()
A.reverse()        

for c,b in Q:
    if A[-1] < c:
        A+=[c]*b
        A.sort(); A.reverse()
        A=A[:N]
print(sum(A[:N]))

Fixed submission:
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
    if b+n<=N:
        s+=c*b
        n+=b
    else:
        s+=c*(N-n)
        break
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    for _ in range(b):
        A.append(c)
A.sort()
A.reverse()        
print(sum(A[:N]))

Fixed submission:
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
    if b+n<=N:
        s+=c*b
        n+=b
    else:
        s+=c*(N-n)
        break
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
for i in range(M):
    b,c=map(int,raw_input().split())
    for _ in range(b):
        A.append(c)
A.sort()
A.reverse()        
print(sum(A[:N]))

Fixed submission:
#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
    if b+n<=N:
        s+=c*b
        n+=b
    else:
        s+=c*(N-n)
        break
print(s)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8

I=raw_input()
n,k=map(int, I.split(" "))

def f(n):
    if n==3:return 2
    if n%2==0:return f(n-1)
    return f(n-1)+1

if f(n)>=k:
    print("YES")
else:
    print("NO")

Fixed submission:
#coding:utf-8

I=raw_input()
n,k=map(int, I.split(" "))

def f(n):
    if n<3:return 0
    if n==3:return 2
    if n%2==0:return f(n-1)
    return f(n-1)+1

if f(n)>=k or k==1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
S=raw_input()

all=1
a=ab=abc=0

for _ in range(len(S)):
    i=_+1
    c=S[_]
    if c=="A":
        a+=all
    if c=="B":
        ab+=a
    if c=="C":
        abc+=ab
    if c=="?":
        abc=abc*3+ab
        ab=ab*3+a
        a=a*3+all
        all*=3
print(abc%((10**9)+7))

    














Fixed submission:
#coding:utf-8
S=raw_input()

all=1
a=ab=abc=0
MOD=(10**9)+7
for _ in range(len(S)):
    i=_+1
    c=S[_]
    if c=="A":
        a+=all
    if c=="B":
        ab+=a
    if c=="C":
        abc+=ab
    if c=="?":
        abc=abc*3+ab
        ab=ab*3+a
        a=a*3+all
        all*=3
    a%=MOD
    ab%=MOD
    abc%=MOD
    all%=MOD
print(abc%((10**9)+7))
Buggy python submission (verdict: Runtime Error):
import Queue
def main():
H,W=map(int,raw_input().split())
    s=[raw_input() for i in range(H)]
    print(s)
    q=Queue.Queue()
    visited=[[False]*W for _ in range(H)]
    dist=[[1145141919810]*W for _ in range(H)]
    visited[0][0]=True
    dist[0][0]=0
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    q.put((0,0))

    while not q.empty():
        x,y=q.get()
        for i in range(4):  
            xx=x+dx[i]
            yy=y+dy[i]
            if (not 0<=xx<H) or (not 0<=yy<W): continue
            if s[xx][yy] == "#" :continue
            if visited[xx][yy]:continue
            visited[xx][yy]=True
            dist[xx][yy]=dist[x][y]+1
            q.put((xx,yy))
    if dist[H-1][W-1]:
        print(-1)
        return
    use=[[False]*W for _ in range(H)]
    use[H-1][W-1]=True
    use[0][0]=True
    (x,y)=(H-1, W-1)
    while (x,y) != (0,0):
        use[x][y]=True
        mpos=(-1,-1)
        mval=1145141919
        for i in range(4):
            xx=x+dx[i]
            yy=y+dy[i]
            if (not 0<=xx<H) or (not 0<=yy<W): continue     
            if dist[xx][yy] < mval:
                mpos=(xx,yy)
                mval=dist[xx][yy]
        x,y=mpos
    cnt=0
    for x in range(H):
        for y in range(W):
            if s[x][y] == "." and not use[x][y]: cnt+=1
    print(cnt)

Fixed submission:
import Queue
def main():
    H,W=map(int,raw_input().split())
    s=[raw_input() for i in range(H)]
    q=Queue.Queue()
    visited=[[False]*W for _ in range(H)]
    dist=[[1145141919810]*W for _ in range(H)]
    visited[0][0]=True
    dist[0][0]=0
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    q.put((0,0))

    while not q.empty():
        x,y=q.get()
        for i in range(4):  
            xx=x+dx[i]
            yy=y+dy[i]
            if (not 0<=xx<H) or (not 0<=yy<W): continue
            if s[xx][yy] == "#" :continue
            if visited[xx][yy]:continue
            visited[xx][yy]=True
            dist[xx][yy]=dist[x][y]+1
            q.put((xx,yy))
    if not visited[H-1][W-1]:
        print(-1)
        return
    use=[[False]*W for _ in range(H)]
    use[H-1][W-1]=True
    use[0][0]=True
    (x,y)=(H-1, W-1)
    while (x,y) != (0,0):
        use[x][y]=True
        mpos=(-1,-1)
        mval=1145141919
        for i in range(4):
            xx=x+dx[i]
            yy=y+dy[i]
            if (not 0<=xx<H) or (not 0<=yy<W): continue     
            if dist[xx][yy] < mval:
                mpos=(xx,yy)
                mval=dist[xx][yy]
        x,y=mpos
    cnt=0
    for x in range(H):
        for y in range(W):
            if s[x][y] == "." and not use[x][y]: cnt+=1
    print(cnt)
main()
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
N=input()
S=raw_input()

st=[]
for s in S:
    if len(st) >= 1:
        a=st.pop()
        if a == '(' and s == ')':
            continue
        st.append(a)
    st.append(s)
migi=0
hidari=0
for s in st:
    if s == ")":migi+=1
    else: hidari+=1
print "("*migi + S + ")"*hidari


Fixed submission:
#coding:utf-8
N=input()
S=raw_input()

st=[]
for s in S:
    if len(st) >= 1:
        a=st.pop()
        if a == '(' and s == ')':
            continue
        st.append(a)
    st.append(s)
migi=0
hidari=0
for s in st:
    if s == ")":migi+=1
    else: hidari+=1
print "("*migi + S + ")"*hidari
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n // 2, 0, -1):
    a[i] = sum(a[i::i]) % 2
print(sum(a))
print(*(i for i, b in enumerate(a) if b))

Fixed submission:
r = int(input())
print(3*r**2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max_ = -1
max_2 = -1
for i in range(n):
    if i == 0:
        tmp = a[i]
        a[i] = 0
        max_ = max(a)
        print(max_)
        a[i] = tmp
        if a[0]>=max_:
            max_ = a[0]
        continue
    else:
        if max_<=a[i]:
            if max_2 == -1:
                tmp = a[i]
                a[i] = 0
                max_2 = max(a)
                print(max_2)
                a[i] = tmp
            else:
                print(max_2)
        else:
            print(max_)
Buggy python submission (verdict: Runtime Error):
n,a,b=IL()
print(min(a*n,b))

Fixed submission:
#ABC133-A
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,a,b=IL()
print(min(a*n,b))
Buggy python submission (verdict: Runtime Error):
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,d=IL()
X=[IL() for i in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(X[i][k]-X[j][k])**2
        if int(dis**0.5)=dis**0.5:
            c+=1
print(c)

Fixed submission:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,d=IL()
X=[IL() for i in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(X[i][k]-X[j][k])**2
        if int(dis**0.5)==dis**0.5:
            c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m
        m=(l+r)//2
    else:
        r=m
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()

Fixed submission:
### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<=r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m+1
        m=(l+r)//2
    else:
        r=m-1
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()
Buggy python submission (verdict: Runtime Error):
#ABC129-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
D=[True]*n
for i in range(m):
    D[I()-1]=False
A=[0]*n
if D[0]:
    A[0]=1
    if D[1]:
        A[1]=2
    else:
        A[1]=0
else:
    A[0]=0
    if D[1]:
        A[1]=1
    else:
        A[1]=0
for i in range(2,n):
    if D[i]:
        A[i]=A[i-1]+A[i-2]
    else:
        A[i]=0
print(A[n-1]%1000000007)

Fixed submission:
#ABC129-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
D=[True]*n
for i in range(m):
    D[I()-1]=False
A=[0]*n
if n==1:
    if D[0]:
        print(1)
    else:
        print(0)

else:
    if D[0]:
        A[0]=1
        if D[1]:
            A[1]=2
        else:
            A[1]=0
    else:
        A[0]=0
        if D[1]:
            A[1]=1
        else:
            A[1]=0
    for i in range(2,n):
        if D[i]:
            A[i]=A[i-1]+A[i-2]
        else:
            A[i]=0
    print(A[n-1]%1000000007)