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

for i in range(0, min(A[0], A[-1]) * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            # print('M', M)
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる


Fixed submission:
import sys
input = sys.stdin.buffer.readline
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
# print(f'{A=}, {A[1::2]=}')

M = [0] * N
M[0] = A.sum() - 2 * A[1::2].sum()

for i in range(N - 1):
    M[i + 1] = 2 * A[i] - M[i]

print(*M, sep=' ')
# A1 + A2 + ... + AN = X1 + X2 + ... + XN = S
# XN+1 = N1とすると
# (Xi + Xi+1) / 2 = Ai
# Xi + Xi+1 = 2 * Ai
# X1 = S - (X2 + ... + XN) = S - 2(A2 + A4 + ... + AN-1)
# Xi+1 = 2Ai - Xi

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

for i in range(0, A[0] * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            # print('M', M)
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる


Fixed submission:
import sys
input = sys.stdin.buffer.readline
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
# print(f'{A=}, {A[1::2]=}')

M = [0] * N
M[0] = A.sum() - 2 * A[1::2].sum()

for i in range(N - 1):
    M[i + 1] = 2 * A[i] - M[i]

print(*M, sep=' ')
# A1 + A2 + ... + AN = X1 + X2 + ... + XN = S
# XN+1 = N1とすると
# (Xi + Xi+1) / 2 = Ai
# Xi + Xi+1 = 2 * Ai
# X1 = S - (X2 + ... + XN) = S - 2(A2 + A4 + ... + AN-1)
# Xi+1 = 2Ai - Xi

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

for i in range(0, A[0] * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            # print('M', M)
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる


Fixed submission:
import sys
input = sys.stdin.buffer.readline
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
# print(f'{A=}, {A[1::2]=}')

M = [0] * N
M[0] = A.sum() - 2 * A[1::2].sum()

for i in range(N - 1):
    M[i + 1] = 2 * A[i] - M[i]

print(*M, sep=' ')
# A1 + A2 + ... + AN = X1 + X2 + ... + XN = S
# XN+1 = N1とすると
# (Xi + Xi+1) / 2 = Ai
# Xi + Xi+1 = 2 * Ai
# X1 = S - (X2 + ... + XN) = S - 2(A2 + A4 + ... + AN-1)
# Xi+1 = 2Ai - Xi

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
D = np.zeros(N + 1, dtype='int')
D[:-1] = A // 2
D[1:] = A // 2
# print(D)

idx = A.argmin()
A = np.append(A[idx:], A[:idx])
# print('A', A)
# print('idx', idx)

for i in range(0, A[0] * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            M = np.array(M)
            # print('M', M)
            idx2 = len(M) - idx
            # print('idx2', idx2)
            M = np.append(M[idx2:], M[:idx2])
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる


Fixed submission:
import sys
input = sys.stdin.buffer.readline
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
# print(f'{A=}, {A[1::2]=}')

M = [0] * N
M[0] = A.sum() - 2 * A[1::2].sum()

for i in range(N - 1):
    M[i + 1] = 2 * A[i] - M[i]

print(*M, sep=' ')
# A1 + A2 + ... + AN = X1 + X2 + ... + XN = S
# XN+1 = N1とすると
# (Xi + Xi+1) / 2 = Ai
# Xi + Xi+1 = 2 * Ai
# X1 = S - (X2 + ... + XN) = S - 2(A2 + A4 + ... + AN-1)
# Xi+1 = 2Ai - Xi