Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = N // 2

    while True:
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = jump // 2 + 1
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = min(A[0], A[N - 1]) // 2

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    N = int(input())
    A = list(map(int, input().split()))


    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i-1] - ans[i-1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N-1] - (ans[N-1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = N // 2

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i*2) for i in ans]))

solve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = min(A[0], A[N - 1]) // 2

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    import numpy as np
    q = np.zeros(shape=(N, N))
    for i in range(N):
        for j in range(N):
            if i == j:
                q[i][j] = 1
            if i == N-1:
                q[i][0] = 1
            else:
                if i+1 == j:
                    q[i][j] = 1

    a = np.array(a_list)
    qinv = np.linalg.inv(q)
    dprint(q)
    x = 2 * np.dot(qinv, a)
    dprint(x)
    x = list(x.astype(int))
    print(" ".join([str(i) for i in x]))

solve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = min(A[0], A[N - 1]) // 2

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()