Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
setA = set()
water = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams=cur
i = n-1
while(1):
    if i==0:
        if dams+cur== a[0]:
            break
        else:
            water[0]-=cur
            dams=water[0]//2
            cur = dams
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Fixed submission:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:

            water[0]-=cur
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Fixed submission:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:

            water[0]-=cur
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Fixed submission:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:
            water[0]-=2
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)


Fixed submission:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:
            water[0]-=2
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)






Fixed submission:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)