Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for b[0] in range(0,mi*2+1,2) :
    # print(x)
    # b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


# s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Fixed submission:
n = int(input())
a = [int(x) for x in input().split(' ')]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


# s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Fixed submission:
n = int(input())
a = [int(x) for x in input().split(' ')]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Fixed submission:
n = int(input())
a = [int(x) for x in input().split(' ')]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[-0]


for x in range(mi*2, -1,-2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = ""
for i in b :
    s = s + str(i) + " " 


print(s)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split(' ')]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[-0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = ""
for i in b :
    s = s + str(i) + " " 


print(s)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split(' ')]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))