Problem:
 Score : 400 points    Problem Statement There are N mountains in a circle, called Mountain 1 , Mountain 2 , ... , Mountain N in clockwise order. N is an odd number.  Between these mountains, there are N dams, called Dam 1 , Dam 2 , ... , Dam N . Dam i ( 1 \leq i \leq N ) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1 ).  When Mountain i ( 1 \leq i \leq N ) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N ).  One day, each of the mountains received a non-negative even number of liters of rain.  As a result, Dam i ( 1 \leq i \leq N ) accumulated a total of A_i liters of water.  Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.      Constraints  All values in input are integers.  3 \leq N \leq 10^5-1  N is an odd number.  0 \leq A_i \leq 10^9  The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print N integers representing the number of liters of rain Mountain 1 , Mountain 2 , ... , Mountain N received, in this order.        Sample Input 1 3
2 2 4      Sample Output 1 4 0 4  If we assume Mountain 1 , 2 , and 3 received 4 , 0 , and 4 liters of rain, respectively, it is consistent with this input, as follows:   Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water.  Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water.  Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water.        Sample Input 2 5
3 8 7 5 5      Sample Output 2 2 4 12 2 8       Sample Input 3 3
1000000000 1000000000 0      Sample Output 3 0 2000000000 0

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in ['ios', 'win32', 'darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(x) for x in input().split()]

def main():
	N = INT()
	A = MAP()

	R = sum(A)
	

	def solve(i):
		if i<N-1:
			if M[i] != -1:
				mi = M[i]
			else:
				mi = 2*A[i]-solve(i+1)
				M[i] = mi
		else:
			mi = 2*A[i]-solve(0)
			M[i] = mi
		return mi

	
	M = [-1] * N
	M[0] = 0
	s = 0
	for i in range(1, N):
		s += solve(i)
	

	M = [-1] * N
	M[0] = (R-s)

	ans = [solve(i) for i in range(N)]
	print(' '.join(map(str, ans)))

if __name__ == "__main__":
	main()

Solution (Python):
def main():
    N = int(input())
    A = {i:inp for i, inp in enumerate(map(int, input().split()), 1)}

    for i in range(2, N+1):
        A[i] -= A[i - 1]
    
    const = A[N] // 2
    ret = [str(2 * const)]

    for i in range(1, N):
        if i % 2:
            ret.append(str(2 * (A[i] - const)))
        else:
            ret.append(str(2 * (A[i] + const)))

    ret = ' '.join(ret)
    print(ret)
    

if __name__=="__main__":
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
B=[0]*N
B[0]=S-2*sum(A[1::2])
for i in range(N-1):
    B[i+1]=2*A[i]-B[i]

print(*B)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
sum_a = 0
for i in range(n):
    if i%2==0:
        continue
    else:
        sum_a += a[i]
x1 = s-2*sum_a
ans = [x1]
for i in range(1,n):
    if i==n-1:
        x = 2*a[i]-ans[0]
    else:
        x = 2*a[i-1] - ans[i-1] 
    ans.append(x)
print(*ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
m=[]
for i in range(n):
  cnt+=(-1)**i*a[i]
m.append(cnt)
for i in range(1,n):
  m.append((a[i-1]-m[i-1]//2)*2)
for i in range(n):
  print(m[i],end=' ')

Solution (Python):
n = int(input())
*A, = map(int, input().split())
ans = [0] * n
ans[0] = sum(A)-2*sum([a for i, a in enumerate(A) if i % 2 != 0])
for i in range(1, n):
    ans[i] = 2*A[i-1]-ans[i-1]
print(*ans)

Solution (Python):
N = int(input())
Data = list(map(int,input().split()))
Ans  = [0]*N
a1 = 0
for i in range(N):
    sign = 1
    if i % 2 == 1:
        sign = -1
    a1 += (sign*Data[i])
Ans[0] = a1
for i in range(1,N):
    Ans[i] = Data[i-1]*2-Ans[i-1]

for a in Ans:
    print( a, end =' ')
print()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
D = 0
for i in range(N):
  D += A[i] * ((-1) ** i)
two_x1 = D
for i in range(N - 1):
  print(two_x1, end = ' ')
  two_x1 = -two_x1 + 2 * A[i]
print(two_x1)

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
X1 = sum(A) - 2 * sum(A[1::2])


def g():
    state = X1
    yield X1
    for i in range(N-1):
        state = 2 * A[i] - state
        yield state


print(*list(g()))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

s = sum(a)
x = [0] * n
x[0] = s - 2 * sum(a[1::2])
for i in range(n - 1):
    x[i + 1] = 2 * a[i] - x[i]

print(*x)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

r=10**9+5
l=-1
import copy
while(r-l>1):
	ans=[0]*n
	rain=(r+l)//2
	initrain = rain
	for i in range(n):
		rain = a[i]-rain
	if rain > initrain:
		l=initrain
	elif rain < initrain:
		r=initrain
	else:
		ans = initrain
		break
ret = [0]*n
ret[0] = ans
for i in range(1,n):
	ret[i] = a[i-1] - ret[i-1]

print(" ".join([str(x*2) for x in ret]))

Solution (Python):
def calculate(N, arr, S):
    result = []
    tmp = 0
    for i in range(len(arr)):
        if i % 2 == 1:
            tmp += arr[i] * 2

    x0 = S - tmp

    result.append(x0)

    for i in range(1, N):
        result.append(arr[i - 1] * 2 - result[i - 1])

    return result


def calculate2(i, arr):
    
    return sum(arr[::2]) * 2


def calculateTotaAmount(arr):
    return sum(arr)


def printArr(arr):
    result = ""
    for i in range(len(arr)):
        result += str(arr[i]) + " "

    return result



N = int(input())

S = input().split(" ")
aArr = [int(s) for s in S]

result = calculate(N, aArr, calculateTotaAmount(aArr))
print(" ".join([str(s) for s in result]))

Solution (Python):
import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    
    right = (max(dams)+1) * 2
    while True:
        center = (left + right) // 2
        if center % 2 == 1:
            center -= 1
        mountains[0] = center
        for i in range(1, n):
            mountains[i] = 2 * dams[i-1] - mountains[i-1]
        temp_dam = (mountains[0] + mountains[-1]) // 2
        if dams[-1] == temp_dam:
            break
        elif dams[-1] < temp_dam:
            right = center
        else:
            left = center
    ans = ' '.join(map(str, mountains))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

dif = sum([A[i] * pow(-1, i) for i in range(N - 1)])
ans = [0] * N
ans[0] = A[-1] + dif
ans[-1] = A[-1] - dif
for i in range(1, N - 1):
    ans[i] = 2 * A[i - 1] - ans[i - 1]
print(*ans)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])

dif = sum([A[i] * pow(-1, i) for i in range(N - 1)])
ans = [0] * N
ans[0] = A[-1] + dif
ans[-1] = A[-1] - dif
for i in range(1, N - 1):
    ans[i] = 2 * A[i - 1] - ans[i - 1]
print(*ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=[sum(A)-2*(sum(A[1::2]))]
for i in range(n-1):
    ans.append(2*A[i]-ans[i])
print(*ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
X=sum(A)-2*sum([A[i] for i in range(1,n,2)])
ans=[X]
for i in range(n-1):
    ans.append(2*A[i]-ans[i])
print(*ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [int(i) for i in input().split()]

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

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

print(' '.join(list(map(str,X))))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.append(a[0])
m_1 = [0] * (n + 1)
m_1[0] = 1
m_2 = [0] * (n + 1)
m_2[1] = 1

i = 0
while i < n - 1:
    m_1[i + 2] = m_1[i] + (a[i + 1] - a[i]) * 2
    i += 2
i = 1
while i <n - 1:
    m_2[i + 2] = m_2[i] + (a[i + 1] - a[i]) * 2
    i += 2
    
sub = m_1[0] - m_2[-1]
for i in range(len(m_2)):
    if m_2[i] != 0:
        m_2[i] += sub
        m_1[i] = m_2[i]
offset = (sum(a[:-1]) - sum(m_1[:-1])) // n
for i in range(n):
    print(m_1[i] + offset)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
rain = [0]
r0 = 0
for i in range(N):
    r0 += A[i] * (-1)**i
rain[0] = r0
for i in range(1, N):
    rain.append(2 * A[i-1] - rain[i-1])
print(" ".join([str(n) for n in rain]))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
rain = [0] * N
rain[0] = sum(A) - 2 * sum(A[i] for i in range(1, N, 2))
for i in range(N-1):
    rain[i+1] = 2 * A[i] - rain[i]
print(' '.join(map(str, rain)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
left = 0
right = 2 * A[0] + 2
while left < right:
    rain = [0] * N
    rain[0] = (left + right) // 4 * 2
    for i in range(N-1):
        rain[i+1] = 2 * A[i] - rain[i]
    rain0 = 2 * A[-1] - rain[-1]
    if rain[0] > rain0:
        right = rain[0]
    elif rain[0] < rain0:
        left = rain[0] + 2
    else:
        print(' '.join(map(str, rain)))
        exit()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ans = []
tmp = sum(a) - 2*sum([a[i] for i in range(1, n-1, 2)])
ans.append(tmp)
a.pop()
for x in a:
    tmp = 2*x - tmp
    ans.append(tmp)

print(*ans)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
point = 0
for i in range(n):
    if i%2 == 0:
        point += li[i]
    else:
        point -= li[i]
lin = [point]
for i in range(n-1):
    lin.append((li[i]-lin[i]//2)*2)
print(*lin)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().rstrip().split()])
A_sum = A.sum()
A_sum //= 2
ans = []
x1 = A_sum
j = 1
for i in range((N-1)//2):
    x1 -= A[j]
    j += 2
ans.append(2 * x1)
for k in range(1, N):
    x = A[k-1] - (ans[k-1] // 2)
    ans.append(2 * x)
print(* ans)

Solution (Python):
import numpy as np

n = int(input())
A = list(map(int,input().split()))
S = sum(A)

x = S-sum(A[1:-1:2])*2
print(x)
for a in A[:-1]:
    x = (a-x//2)*2
    print(x)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

a = 0
for i in range(N):
  a += A[i] * (1 if not i%2 else -1)

ans = [0] * N
ans[0] = a

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

print(*ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

a = 0
for i in range(N):
  a += A[i] * (1 if not i%2 else -1)

ans = [0] * N
ans[0] = a

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

print(*ans)
print()

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))

ans_list = [0]*N

not1_list = [ a_list[i] for i in range(1, N, 2) ]
ans_list[0] = sum(a_list) - 2 * sum(not1_list)
for i in range(1,N):
  ans_list[i] = a_list[i-1] * 2 - ans_list[i-1]
print(*ans_list)

Solution (Python):
N = int(input())
dams = list(map(int, input().split()))

mountains = [0]*N

sum_part_dams = 0
for i in range(1, N, 2):
    sum_part_dams += dams[i]

mountains[0] = sum(dams)-2*sum_part_dams

for i in range(1, N):
    mountains[i] = 2*dams[i-1]-mountains[i-1]

print(*mountains)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
a_s = sum(A)
lis=[0]*(N-1)
tmp = 0
sub=0
for i,a in enumerate(A[:-1:]):
  x = A[i]*2-tmp
  sub+=x
  lis[i]=x
  tmp = x
  
ans = [0]*N
a = a_s-sub
ans[0]=a
for i in range(1,N):
  if i%2==1:
    ans[i]=lis[i-1]-a
  else:
    ans[i]=lis[i-1]+a
    
print(*ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

A_tmp = 0

for i in range(len(A)):
  if i%2 == 0:
    A_tmp += 2*A[i]
  else:
    A_tmp -= 2*A[i]

A1 = A_tmp // 2
ans = [A1]
for i in range(len(A)-1):
  ans.append(2*A[i]-ans[i])

print(" ".join(map(str,ans)))

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())


A = list(map(int, input().split()))

B = [0]*N
for i in range(N):
    if i%2 == 0:
        B[0] += A[i]
    else:
        B[0] -= A[i]

for i in range(1,N):
    B[i] = 2*(A[i-1]-B[i-1]//2)

for b in B:
    print(b)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().strip().split()]
S = sum(A)
x = [0 for _ in range(N)]

x[0] = S - 2 * sum(A[1::2])
for i in range(1, N):
    x[i] = 2 * A[i-1] - x[i-1]

print(*x)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
S=sum(A)//2
a=[]

for i in range(1,n,2):
  S=S-A[i]
a.append(2*S)
for i in range(n-1):
  a.append((A[i]-a[-1]//2)*2)
for i in range(n):
  print(a[i],end=' ')

Solution (Python):
n = int(input())
a = [2*int(_) for _ in input().split()]
t = a[-1]
x = [0 for _ in range(n)]
for i in range(-2, -n-1, -1):
    t = a[i] - t
x[0] = t // 2
for i in range(0, n-1):
    x[i+1] = a[i] - x[i]
for i in range(len(x)):
    print(x[i])

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
S = sum(A)
X1 = S -2*sum(A[1::2])
X = [0]*N
X[0] = X1
for i in range(0,N-1):
    X[i+1] = 2*A[i] - X[i]
for j in X:
  print(j,end=" ")

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

m1 = sum(A) - 2 * sum([x for i, x in enumerate(A) if i % 2 == 1])
ans = [m1]
for i in range(N-1):
    ans.append((A[i] - ans[-1] // 2) * 2)
print(*ans, sep=' ')

Solution (Python):
N=int(input())
D=[int(x) for x in input().split()]
Ame=[0]
for i in range(N):
  Ame[0] +=D[i]*((-1)**i)
for i in range(1,N):
  Ame +=[2*D[i-1]-Ame[i-1]]
print(*Ame)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x = []
asum = sum(a)
ad = 0

for i in range(1,n,2):
    ad += 2 * a[i]

x.append((asum - ad))

for i in range(n-1):
    x.append(2*a[i]-x[i])

print(' '.join(map(str,x)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))



x = (sum(A[::2]) - sum(A[1::2])) // 2
ans = [x*2]
for i in range(N-1):
    a = A[i] - x
    ans.append(a*2)
    x = a
print(*ans)

Solution (Python):
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque()
for i in a:
  b.append(i)
c=0
for i in range(n):
  if i%2==0:
    c+=a[i]
  else:
    c-=a[i]
print(c)
for i in range(n-1):
  c=-c+2*b.popleft()
  print(c)

Solution (Python):
import sys
input = sys.stdin.readline


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

    total = sum(A)
    for i, a in enumerate(A):
        if i%2 == 0:
            continue
        total -= 2*a
    ans = [total]

    for i, a in enumerate(A):
        tmp = 2*a - ans[i]
        ans.append(tmp)

    print(" ".join(map(str, ans[:-1])))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
dam = list(map(int, input().split()))
mt = [0] * n
SUM = sum(dam)
mt0 = 0
for i in range(0,n,2):
  mt0 += dam[i]
mt[0] = mt0 * 2 - SUM
for i in range(1,n):
  mt[i] = dam[i-1] * 2 - mt[i-1]
print(*mt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))












summary = 0

for i in range(N):
    if i % 2 == 0:
        summary += A[i]
    else:
        summary -= A[i]

for i in range(N):
    print(summary)
    summary = (A[i] - (summary//2)) * 2

Solution (Python):
N = int(input())
A = list(map(int, input().split()))












summary = 0

for i in range(N):
    if i % 2 == 0:
        summary += A[i]
    else:
        summary -= A[i]

for i in range(N):
    print(summary)
    summary = (A[i] - (summary//2)) * 2

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines



























def main():
	n=int(input())
	A=list(map(int,input().split()))
	
	ans=[0]*(n)
	ans[0]=sum(A)-2*sum(A[1::2])
	for i in range(1,n):
		ans[i]=2*A[i-1]-ans[i-1]
	print(*ans)
	
	
	





if __name__ == '__main__':
	main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines



























def main():
	n=int(input())
	A=list(map(int,input().split()))
	
	ans=[0]*(n)
	ans[0]=sum(A)-2*sum(A[1::2])
	for i in range(1,n):
		ans[i]=2*A[i-1]-ans[i-1]
	print(*ans)
	
	
	





if __name__ == '__main__':
	main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

ans=[0]*len(A)
without0=0
for i in range(1,len(A),2):
  without0+=A[i]
ans[0]=sum(A)-without0*2
for i in range(1,len(A)):
  ans[i]=A[i-1]*2-ans[i-1]
print(*ans)

Solution (Python):

import sys










def main():
    
    
    
    n, *a = [int(x) for x in sys.stdin.read().split()]
    x0 = 0
    for i in range(n):
        if i % 2 == 0:
            x0 += a[i]
        else:
            x0 -= a[i]
    x0 //= 2 
    x = [x0]
    for i in range(1, n):
        xi = a[i-1] - x[i-1]
        x.append(xi)
    
    
    for i in range(n):
        print(x[i] * 2, end=' ')

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N, A):
    """Test Case
    >>> print_ans(3, [2, 2, 4])
    4 0 4
    >>> print_ans(5, [3, 8, 7, 5, 5])
    2 4 12 2 8
    >>> print_ans(3, [1000000000, 1000000000, 0])
    0 2000000000 0
    """
    
    S = sum(A)
    xr = [0] * N
    xr[0] = S - 2 * (sum(A[1::2]))
    for i in range(1,N):
        xr[i] = 2 * A[i-1] - xr[i-1] 
    print(" ".join(list(map(str, xr))))

if __name__ == '__main__':
    N =  int(input().rstrip())
    A= list(map(int, input().rstrip().split()))
    print_ans(N, A)

Solution (Python):
import sys

input = sys.stdin.readline

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

b = [0]*N

b[0] = sum([A[i]*(-1)**i for i in range(N)])

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

print(*b)

Solution (Python):
def solve():
    N, *a_l = map(int, open(0).read().split())
    x_l = [0] * N

    x_l[0] = sum(a_l) - 2*(sum(a_l[1::2]))
    for i in range(1, N):
        x_l[i] = 2*a_l[i-1] - x_l[i-1]

    print(' '.join(map(str, x_l)))


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

ans_li = []

sum_val = sum(A) // 2
count = 0
for i in range((n - 1) // 2):
    count += A[2 * i + 1]

ans_li.append(2 * (sum_val - count))

for j in range(n-1):
    ans_li.append(2 * A[j] - ans_li[j])

print(*ans_li)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
k=0
for i in range(n):
  if i%2==1:
    k+=a[i]
b[0]=sum(a)-k*2
for i in range(1,n):
  b[i]=2*a[i-1]-b[i-1]
yu=map(str,b) 
print(' '.join(yu))

Solution (Python):
n=int(input())


S=input().split()
damrainfall=list(S)


for i in range(n):
    damrainfall[i]=int(damrainfall[i])


totalrainfall=0
for i in range(n):
  totalrainfall+=damrainfall[i]



nigai=0
j=1
while j<n:
  nigai+=(damrainfall[j]*2)
  j+=2


mountainrainfall=[]
for i in range(n):
  mountainrainfall.append(0)

mountainrainfall[n-1]=totalrainfall-nigai

mountainrainfall[0]=damrainfall[0]*2-mountainrainfall[n-1]

k=1
while k<n:
  mountainrainfall[k]=damrainfall[k]*2-mountainrainfall[k-1]
  k+=1
  
print(mountainrainfall[n-1],end=" ")

for i in range(n-1):
      print(mountainrainfall[i],end=" ")

Solution (Python):



n = int(input())
al = list(map(int,input().split()))

sum_a = sum(al)

odd = 0
for i in range(n):
    if i % 2 == 1:
        odd += al[i]
        
ans_l = []
ans_l.append(sum_a - 2*odd)
his = sum_a - 2*odd
for i in range(n-1):
    his = al[i]*2 - his
    ans_l.append(his)

for i in ans_l:
    print(i)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

i = 1
x = 0
result = []
for a in A:
    if i%2 == 0:
        x -= a
    else:
        x += a
    i += 1
result.append(x)
A.pop()
for a in A:
    tmp = 2*a - x
    result.append(tmp)
    x = tmp

print(*result)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

X = []
X.append(sum(A)-2*sum(A[2*i+1] for i in range(N//2)))
for i in range(N-1):
  X.append(2*A[i]-X[-1])
print(*X)

Solution (Python):
def main():
    n=int(input())
    a = list(map(int,input().split()))
    l1=[0 for _ in range(n+1)]
    l2=[0 for _ in range(n+1)]

    for i in range(n):
        l1[i+1]=a[i]-l1[i]
    l1[0]=l1[n]
    l2[1]=a[0]-l1[0]
    l2[0]=l2[n]
    for i in range(1,n):
        l2[i+1]=a[i]-l2[i]
    ans=[]
    for i in range(n):
        ans.append( str(l1[i]+l2[i]) )
    print(' '.join(ans))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [int(i)*2 for i in input().split()]
ans = [int(sum([a[i]*((-1)**(i)) for i in range(n)])/2)]
for i in range(n-1):
    ans.append(a[i] - ans[i])
for o in ans: print(o)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = [0 for i in range(N)]
for i in range(N):
    ans[0] += A[-1 - i] * (-1) ** i
for i in range(N - 1):
    ans[i + 1] = A[i] * 2 - ans[i]
print(*ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    S=sum(A)
    oddS=sum(A[i] for i in range(1,n,2))
    ans=[0]*n
    ans[0]=S-2*oddS
    for i in range(n-1):
        ans[i+1]=2*A[i]-ans[i]
    print(*ans)
resolve()

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
ame=sum(a)
ans=[0]*n
ans[0]=ame-sum(a[1::2])*2
for i in range(n-1):
    ans[i+1]=a[i]*2-ans[i]
print(*ans)

Solution (Python):

import sys

def solve(N: int, A: "List[int]"):

    
    xlist = [[1,0]]+[[] for _ in range(N)]
    for i in range(N):
        a = 0-xlist[i][0]
        b = A[i]*2-xlist[i][1]
        xlist[i+1]=[a,b]
    
    first = xlist[0]
    last = xlist[-1]
    a = first[0]-last[0]
    b = first[1]-last[1]
    x = -b//a

    answer = []
    for i in range(N):
        a = xlist[i][0]
        b = xlist[i][1]
        answer.append(a*x+b)
    
    print(*answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
A = list( map(int, input().split()) )
x = [0]*N
SUM = sum(A)
x[0] = SUM
for i in range(1, N, 2):
    x[0] -= 2*A[i]
for i in range(1, N):
    x[i] = 2*A[i-1]-x[i-1]
print(*x)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = []
X = []

x1 = sum(A) - 2*sum(A[1::2])
X.append(x1)

for i in range(n-1):
  X.append(2*A[i] - X[-1])

print(*X)

Solution (Python):

def main():
    
    N, *A = map(int, open(0).read().split())
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(" ".join(map(str, X)))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
*a, = map(int, input().split())

w = [0]*n
w[0] = sum(a) - 2*sum([ai for i, ai in enumerate(a) if (i + 1)%2 == 0])

for i in range(n - 1):
    w[i + 1] = 2*a[i] - w[i]

print(*w)

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))

list2 = [0]*n
dai1kou = 0
dai1kou += sum(list1[::2])
dai1kou -= sum(list1[1::2])
dai1kou = abs(dai1kou)
list2[0] = dai1kou
for i in range(1,n):
	list2[i] = (list1[i-1]-list2[i-1]//2)*2
print(" ".join(map(str,list2)))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

ans=[]
for i in range(N):
    ans.append(0)

sum_A=sum(A)
sum_A_part=0
for j in range((N-1)//2):
    sum_A_part+=A[2*j]

ans[N-1]=sum_A-2*sum_A_part
ans[0]=2*A[N-1]-ans[N-1]
for k in range(1,N-1):
    ans[k]=2*A[k-1]-ans[k-1]

print(*ans)

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()

A_even = []
M = [0]*N

for i in range(N):
    if i%2 == 1:
        A_even.append(A[i])

M[0] = sum(A)-2*sum(A_even)

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

print(*M)

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))

s = sum(a)
b = 0
for i in range(1, n, 2):
    b += a[i]
result = [(s-b*2)//2]
for i in range(n-1):
    result.append(a[i]-result[-1])
result = [2*i for i in result]
print(*result)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N = I()
A = LI()
ans = [0]*N
dis = [0]*N
dis[0] = (A[1]-A[0])*2
for i in range(N-1):
    dis[i+1] = dis[i]+2*(A[-N+2*i+3]-A[-N+2*i+2])


basic = (sum(A) - sum(dis))//N
ans[0] = basic
for i in range(1,N):
    ans[2*i-N] = basic + dis[i-1]

print((' '.join(map(str, ans))))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
X = sum(A) - 2 * sum(A[1::2])

print(X,end=" ")
for i in range(N-1):
  X = 2 * A[i] - X
  print(X,end=" ")

Solution (Python):
N = int(input())
A = list( map(int, input().split()))

d = sum(A) // 2

for i in range(1, N - 1, 2):
    d -= A[i]

for i in range(N):
    print(2 * d, end='')
    if i == N - 1:
        print('')
    else:
        print(' ', end='')
    d = A[i] - d

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
x=0
for i in range(1,N,2):
    x+=2*A[i]
X=[s-x]
for i in range(1,N):
    X.append(2*A[i-1]-X[i-1])
print(*X)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)//2
m = s - sum(a[1::2])
print(m*2, end=" ")
for i in range(n-1):
  m = a[i]-m
  print(m*2, end=" ")

Solution (Python):


N = int(input().split()[0])
a_list = list(map(int, input().split()))

r_list = []
total = 0

for i in range(1, N, 2):
    total += a_list[i]

r_list.append(sum(a_list) - total * 2)

for i in range(1, N):
    r = a_list[i - 1] * 2 - r_list[i - 1]
    r_list.append(r)

ans = " ".join([str(w) for w in r_list])
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

answer_list = []

for i in range(N):
    answer = 0
    if i == 0:
        for j in range(N):
            
            if j % 2 == 0:
                answer += A[i-1-j]
            else:
                answer -= A[i-1-j]
    else:
        answer = 2*A[i-1] - answer_list[i-1]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))

Solution (Python):
n = int(input())
bs = [int(x) for x in input().split()]
sign = 1
a_2 = bs[0]
for b in bs[1:]:
    a_2 += sign*b
    sign *= -1

ans = str(a_2) + ' '
for i in range(n-2):
    a_2 = 2*bs[i+1] - a_2
    ans += str(a_2) + ' '
ans = str(2*bs[i+2] - a_2) + ' ' + ans
print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

ans_list = [0]*N
x = A[0]
for i in range(1, N-1):
    x += (-1)**i*A[i]
    
x += A[N-1]
ans_list[0] = str(x)
x //= 2
for i in range(N-1):
    x = A[i] - x
    ans_list[i+1] = str(2*x)
    
print(" ".join(ans_list))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

minv = 0
maxv = 1000000000

nxt = [0] * (n + 1)
for i in range(n):
  nxt[i+1] = a[i] * 2 - nxt[i]

ans = [0] * (n + 1)
ans[0] = nxt[n] // 2

for i in range(n):
  ans[i+1] = a[i] * 2 - ans[i]
    
for i in range(n):
  print(ans[i], end=' ')

Solution (Python):


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

rain = [-1]*N

sum_all = sum(A)
sum_skip = sum([A[idx] for idx in range(0,N-1,2)])

rain[-1] = sum_all - 2*sum_skip

for idx in reversed(range(N-1)):
    rain[idx] = 2*(A[idx] - rain[idx+1]//2)

print(*rain)

Solution (Python):
n = int(input())
a = list(map(int, input().split( )))

a_sum = sum(a)
a_sum //= 2

a_sum_0 = sum(a[1::2])

ans = []
a0 = a_sum -a_sum_0
ans.append(2*a0)
a[0] -= a0
for i in range(n-1):
    ans.append(2*a[i])
    a[i+1] -= a[i]
    
print(*ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

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

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

print(*M)

Solution (Python):
n = int(input())
dam = list(map(int, input().split()))
mt = [0]*n

mt[0] = sum(dam) - 2*sum(dam[1::2])
mt[n-1] = dam[n-1]*2-mt[0]
for i in range(1, n-1):
    mt[i] = dam[i-1]*2-mt[i-1]
print(' '.join(map(str, mt)))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

x1 = 0
for i in range(N):
    if i % 2 == 0:
        x1 += A[i]
    else:
        x1 -= A[i]

print(x1, end=' ')
for i in range(N-1):
    x1 = 2 * (A[i] - x1//2)
    print(x1, end=' ')

print()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
oddsum = 0
for index in range(1, len(A), 2):
	oddsum += A[index]

x=[]
x.append(sum(A) - 2*oddsum)
for a in A[:-1]:
	x.append((a - x[-1]//2)*2)
print(" ".join(map(str, x)))

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * n
    ls[0] = sum(a) - sum(a[1::2]) * 2
    for i in range(1, n):
        ls[i] = (a[i-1] - ls[i-1] // 2) * 2
    print(*ls)


if __name__ == '__main__':
    slove()

Solution (Python):

"""
Created on Tue Oct 15 08:23:21 2019

@author: avina
"""

n = int(input())
l = list(map(int, input().split()))

even_sum = 0
odd_sum = 0
for i in range(n):
    if i%2 ==0:
        even_sum+=l[i]
    else:
        odd_sum += l[i]
j = 0
for i in range(n):
    print(abs(even_sum - odd_sum), end = ' ')
    
    odd_sum, even_sum= even_sum - l[j],odd_sum + l[j]
    j += 1

Solution (Python):
def main():
    n = int(input())
    a=list(map(int,input().split()))
    r = []
    r.append(sum([a[i] for i in range(n) if i % 2 == 0])-sum([a[i] for i in range(n) if i % 2 ==1]))

    for i in range(1,n):
        r.append(a[i-1]*2-r[i-1])

    print(" ".join(list(map(str,r))))

main()

Solution (Python):
n = int(input())
a=list(map(int,input().split()))
r = []
r.append(sum([a[i] for i in range(n) if i % 2 == 0])-sum([a[i] for i in range(n) if i % 2 ==1]))

for i in range(1,n):
    r.append(a[i-1]*2-r[i-1])

print(" ".join(list(map(str,r))))

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ts = sum(a) - sum(a[1::2]) * 2
    ls = [0] * n
    ls[0] = ts
    for i in range(1, n):
        ls[i] = (a[i-1] - ls[i-1] // 2) * 2
    print(*ls)


if __name__ == '__main__':
    slove()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

S = sum(A)
x = S//2 - sum(A[1::2])

rain = [x+x]
for x in A[:-1]:
    rain.append(x+x-rain[-1])
print(' '.join(map(str,rain)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dam = sum(A[::2]) - sum(A[1::2])

print(dam)
for i in A[:-1]:
    dam = (i - dam // 2) * 2
    print(dam)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ts = sum(a[1::2]) * 2
    ls = [0] * n
    ls[0] = sum(a) - ts
    for i in range(1, n):
        ls[i] = (a[i-1] - ls[i-1] // 2) * 2
    print(*ls)


if __name__ == '__main__':
    slove()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

x = [sum([a*(-1)**i for i, a in enumerate(A)])]

for a in A[:-1]:
  x.append(2*a - x[-1])

  
print(*x)