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

def plus_minus(idx):
    ans = [0] * n
    indicator = 1
    for new_i in range(idx, idx + n):
        ans[new_i % n] = indicator
        indicator *= -1
    #print(idx, ans)
    return ans

ans = []
for dam in range(n):
    total = 0
    pm = plus_minus(dam)
    for i, a in enumerate(A):
        total += pm[i] * a
    ans.append(total)

print(*ans, sep=" ")

Fixed submission:
from collections import defaultdict as dd

n = int(input())
A = list(map(int, input().split()))
odd_ac = dd(int)
even_ac = dd(int)
for i, a in enumerate(A):
    if i % 2 == 0:
        even_ac[i] = even_ac[i-2] + a
    else:
        odd_ac[i] = odd_ac[i-2] + a
#print(odd_ac)
#print(even_ac)

ans = []
for dam in range(n):
    is_odd = dam % 2
    total = 0
    if is_odd:
        total += odd_ac[n-2] - odd_ac[dam-2]
        total -= even_ac[n-1] - even_ac[dam-1]
        total += even_ac[dam-1]
        total -= odd_ac[dam-2]
    else:
        total += even_ac[n-1] - even_ac[dam-2]
        total -= odd_ac[n-2] - odd_ac[dam-1]
        total -= even_ac[dam-2]
        total += odd_ac[dam-1]

    ans.append(total)

print(*ans, sep=" ")

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
A = list(map(int, input().split()))
Arr = np.zeros((n, n))
for i in range(0, n-1):
    Arr[i][i] = 0.5
    Arr[i][i+1] = 0.5
Arr[n-1][n-1] = 0.5
Arr[n-1][0] = 0.5
#print(Arr)

inv_Arr = np.linalg.inv(Arr)
#print(inv_Arr)

ans = np.dot(inv_Arr, A)
ans = list(map(int, ans))
print(*ans, sep=" ")

Fixed submission:
from collections import defaultdict as dd

n = int(input())
A = list(map(int, input().split()))
odd_ac = dd(int)
even_ac = dd(int)
for i, a in enumerate(A):
    if i % 2 == 0:
        even_ac[i] = even_ac[i-2] + a
    else:
        odd_ac[i] = odd_ac[i-2] + a
#print(odd_ac)
#print(even_ac)

ans = []
for dam in range(n):
    is_odd = dam % 2
    total = 0
    if is_odd:
        total += odd_ac[n-2] - odd_ac[dam-2]
        total -= even_ac[n-1] - even_ac[dam-1]
        total += even_ac[dam-1]
        total -= odd_ac[dam-2]
    else:
        total += even_ac[n-1] - even_ac[dam-2]
        total -= odd_ac[n-2] - odd_ac[dam-1]
        total -= even_ac[dam-2]
        total += odd_ac[dam-1]

    ans.append(total)

print(*ans, sep=" ")

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

B = [0] * n
for i in range(n):
  for j in range(n):
    num = (i + j) % n
    if j % 2 == 0:
      B[i] += A[num]
    else:
      B[i] += -A[num]
print(*B, sep=" ")

Fixed submission:
from collections import defaultdict as dd

n = int(input())
A = list(map(int, input().split()))
odd_ac = dd(int)
even_ac = dd(int)
for i, a in enumerate(A):
    if i % 2 == 0:
        even_ac[i] = even_ac[i-2] + a
    else:
        odd_ac[i] = odd_ac[i-2] + a
#print(odd_ac)
#print(even_ac)

ans = []
for dam in range(n):
    is_odd = dam % 2
    total = 0
    if is_odd:
        total += odd_ac[n-2] - odd_ac[dam-2]
        total -= even_ac[n-1] - even_ac[dam-1]
        total += even_ac[dam-1]
        total -= odd_ac[dam-2]
    else:
        total += even_ac[n-1] - even_ac[dam-2]
        total -= odd_ac[n-2] - odd_ac[dam-1]
        total -= even_ac[dam-2]
        total += odd_ac[dam-1]

    ans.append(total)

print(*ans, sep=" ")