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):
from itertools import accumulate

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

cumevA = list(accumulate(A[::2]))
cumodA = list(accumulate(A[1::2]))

ans = [None] * N
for i in range(N):
    if i == 0:
        ans[i] = str(sumA - 2 * cumodA[-1])
    elif i == 1:
        ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[0]))
    elif i == N-1:
        ans[i] = str(sumA - 2 * (cumevA[-2]))
    else:
        if i % 2 == 0:
            ans[i] = str(sumA - 2 * (cumodA[-1] - cumodA[i // 2 - 1] + cumevA[i // 2 - 1]))
        else:
            ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[(i - 1) // 2] + cumodA[(i - 3) // 2]))

print(" ".join(ans))

Solution (Python):
from sys import exit

N = int(input())

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


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

n = A[N - 1] + a

_x = n
ans = []
for i in range(N - 1):
    if i == 0:
        ans.append(int((A[N - 1] - _x / 2) * 2))
        _x = (A[N - 1] - _x / 2) * 2
    else:
        ans.append(int((A[i - 1] - _x / 2) * 2))
        _x = (A[i - 1] - _x / 2) * 2

ans.append(n)

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

Solution (Python):
def main():
    n = int(input())
    a_list = list(map(int,input().split()))
    a = 0
    end = 0
    for i in range(n):
        if i%2 == 0:
            a += a_list[i]*0.5
        else:
            a -= a_list[i]*0.5

    out = str(int(a*2))
    point = a
    for i in range(n-1):
        point = a_list[i]-point
        out += " "+str(int(point*2))
    print(out)

if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
x = [0] * n
x[0] = sum(a) // 2 - sum(a[1::2])
for i in range(n - 1):
    x[i + 1] = a[i] - x[i]
print(*[i * 2 for i in x], sep=' ')

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

def initial():
    rain0 = 0
    for i in range(n):
        rain0 += ((-1)**i) * ds[i]
    return rain0

rain0 = initial()
rains = [rain0]

def solve():
    rain_i = rain0
    for i in range(n-1):
        if i != n-1:
            rain_i_ = 2 * ds[i] - rain_i
        else:
            rain_i_ = 2 * ds[i] - rain0
        
        rains.append(rain_i_)
        rain_i = rain_i_
        
solve()

for i in range(len(rains)):
    print(rains[i], end=" ")

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

from collections import deque
dA = deque(A)
ans= deque([])
Nans = 0
for itr, val in enumerate(dA):
  if itr % 2 == 0:
    Nans += val
  else:
    Nans -= val
ans.append(Nans)

for i in A:
  Nans = 2*i - Nans
  ans.append(Nans)
ans.pop()
print(' '.join(map(str, ans)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = []
x = A[N-1]
for i,j in zip(range(N-2, -1, -1), range(3, N+2)) :
  x += A[i]*((-1)**j)
for q in range(N):
  ans.append(x)
  x = 2*A[q] - x
ans = list(map(str, ans))
print(" ".join(ans))

Solution (Python):
N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
odds = range(0,N,2)
Ans=[]
Ans.append(-S + 2*sum([s for s,num in zip(A, range(N)) if num in odds] ) )
for i in range(1,N):
    Ans.append(2*A[i-1]-Ans[i-1])
print(" ".join(map(str,Ans) ))

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

sum_a = sum(A) // 2

cs_even = [0]
cs_odd = [0]

cse = 0
cso = 0
for i in range(0, N-2, 2):
    cse += A[i]
    cso += A[i+1]
    cs_even.append(cse)
    cs_odd.append(cso)
cse += A[N-1]
cs_even.append(cse)

ans_arr = []
for i in range(N):
    c0 = 0
    c1 = 0
    if i % 2 == 0:
        ans = sum_a - cs_even[i//2] - cs_odd[(N-1)//2] + cs_odd[i//2]
    else:
        ans = sum_a - cs_odd[i//2] - cs_even[(N+1)//2] + cs_even[(i+1)//2]
    ans *= 2
    ans_arr.append(str(ans))

print(' '.join(ans_arr))

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
R=[0]*N

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

R[0]=tmp1 // 2
R[N-1]=A[N-1]*2 - R[0]

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

print(*R)

Solution (Python):


from itertools import combinations
import math
import datetime
import numpy
from pprint import pprint
N = int(input())
A = [int(x) for x in input().split()]

ans = []

ans1 = 0
plus = 1
for i in range(N):
    ans1 += plus * A[i]
    plus *= -1

ans.append(ans1)
plus = -1
for i in range(1,N):
    t = i - 1
    a = ans[t] + plus * 2 * A[t]
    plus *= -1
    ans.append(a)

print(" ".join([str(abs(s)) for s in ans]))

Solution (Python):
n = int(input())
dat_a = list(map(int, input().split()))
dat_aa = map(lambda x: x*2, dat_a)
dat_aa = list(dat_aa)
s_in = sum(dat_a)


m = -1
index = -1
for i in range(n):
    if dat_aa[i] > m:
        m = dat_aa[i]
        index = i

res = [0] *n

for i in range(n):
    if i > 0:
        res[i] = dat_aa[i-1] - res[i-1]
    else:
        res[i] = dat_aa[n-1] - res[i]
s_out = sum(res)
d = s_in - s_out





for i in range(n):
    if i % 2 == 0:
        res[i] += d
    else:
        res[i] -= d
res = list(map(str, res))
print(" ".join(res))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mou = [0]*n
for i in range(1,n):
  mou[i*2%n] =  mou[(i-1)*2%n] + (a[i*2%n-1]-a[(i-1)*2%n])*2
mous = 0
for i in range(n):
  mous += a[i]-mou[i]
p = mous//n
for i in range(n):
  mou[i] += p
print(" ".join(map(str,mou)))

Solution (Python):
def calc(N, A):
    x_sum = sum(A) // 2
    for i in range(1, N, 2):
        x_sum -= A[i]
    x = [x_sum]
    for i in range(N - 1):
        x += [A[i] - x[i]]
    print(' '.join([str(2 * y) for y in x]))


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
odd_A = A[::2]
odd_sum = sum(odd_A)
even_A = A[1::2]
even_sum = sum(even_A)

y0 = odd_sum-even_sum
ans_list = []
ans_list.append(y0)
temp = y0
for i in range(N-1):

    y_i = 2*A[i] - temp
    ans_list.append(y_i)
    temp = y_i

print(*ans_list)

Solution (Python):
import collections as cl
N = int(input())
water = cl.deque(map(int,input().split()))
sum = sum(water)
ans = []
sum_odd = 0
sum_even = 0
for i in range(N):
  if i == 0:
    for k in range((N+1)//2):
      if i == 0:
        sum_odd += water[2*k]
        sum_even = sum - sum_odd
  else:
    xxx = sum_even
    yyy = sum_odd
    sum_odd = xxx + water[-1]
    sum_even = yyy - water[-1]
  ans.append((sum_odd - sum_even))
  water.rotate(-1)
  
print(*ans)

Solution (Python):
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = i2nn()
    B = [0] * N
    B[0] = min(A[0], A[-1]) * 2
    for i in range(1, N):
        B[i] = (A[i-1] - B[i-1] // 2) * 2
    
    d = (A[-1] - (B[0] + B[-1]) // 2)
    
    for i in range(N):
        if (i & 1) == 0:
            B[i] += d
        else:
            B[i] -= d
    print(' '.join([str(n) for n in B]))

main()

Solution (Python):
n=int(input())
a=list(map(int, input().split())) 
b=[]
b.append(sum(a)-sum(a[1:n-1:2])*2)

for i in range(n-1):
    b.append(round(a[i]-b[i]/2)*2)
print(' '.join(map(str, b)))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
M = [0 for i in range(N)]

M[0] = 0
for j in range(N-1):
    M[j+1] = (A[j] - int(M[j]//2)) * 2

n = int((A[N-1] - M[0]//2 - M[N-1]//2)//2)

for i in range(N):
    if i%2 == 0:
        print(M[i] + 2*n, end=" ")
    else:
        print(M[i] - 2*n, end=" ")

Solution (Python):
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    x = [0] * n
    x0 = 0
    for i in range(n):
        if i % 2 == 0:
            x0 += a[i]
        else:
            x0 -= a[i]
    x0 = x0
    x[0] = x0
    for i in range(n-1):
        x[i+1] = 2 * a[i] - x[i]
    print(' '.join([str(a) for a in x]))


main()

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
ans=[0]
for i in range(N):
    if i%2==0:
        ans[0]=ans[0]+A[i]
    else:
        ans[0]=ans[0]-A[i]
for n in range(1,N):
    ans.append(int(2*(A[n-1]-ans[n-1]/2)))
ans=[str(m) for m in ans]
print(" ".join(ans))

Solution (Python):
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

    
    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 = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

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


solve()

Solution (Python):
N = int(input())
A_list = [int(x) for x in input().split()]
now = 0
for a in A_list:
    now = a - now
ans = [str(now)]
for a in A_list[:-1]:
    now = (a - now//2) * 2
    ans.append(str(now))
print(" ".join(ans))

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

S = [0]*(N+1)

for n in range(N):
    S[n+1] = S[n] + ((-1)**n)*b[n]
    
ans = [0]*N
for n in range(N):
    ans[n] = b[n] - ((-1)**n)*S[n] + ((-1)**n)*(S[N]-S[n+1])
    
print(*ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*n

x[0] = sum(a)
for j in range(1, n, 2):
  x[0] -= 2*a[j]
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()))

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
a=0
M=(N-1)//2
sumA=sum(A)
oddA=0
for i in range(M+1):
    oddA+=A[2*i]
x=oddA-sumA//2

dp=[x]
for i in range(N-1):
    dp.append(A[i]-dp[-1])
for j in range(N):
    print(dp[j]*2,end=' ')

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

A = A + A

s1 = [0]
for i in range(N):
    s1.append((A[i] - s1[-1] // 2) * 2)

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

print(*ans[:-1], sep=' ')

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

x = [-1]*n

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

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



for i in range(n):
    print(x[i],end=" ")

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

Even = A[0::2]
Odd = A[1::2]

list1 = []
ans = sum(Even)-sum(Odd)
list1.append(int(ans))

for i in range(len(A)-1):
  ans = -ans + 2*A[i]
  list1.append(int(ans))

print(*list1)

Solution (Python):
N = int(input())
dams = [int(x) for x in input().split()]
kisu = sum([dams[i] for i in range(1,N,2)])
gusu = sum([dams[i] for i in range(0,N-1,2)])
x1 = gusu-kisu + dams[N-1]
monts = []
monts.append(x1)
for i in range(N-1):

  monts.append(int((dams[i] - monts[i]/2)*2))
for i in range(len(monts)):
  print(monts[i],"",end = "")

Solution (Python):
def a_zero(a):
	if len(a)%2==0:
		return -1
	else:
		tmp=0
		for i in range(len(a)):
			if i%2==0:
				tmp+=a[i]
			else:
				tmp-=a[i]
		return tmp

n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n)]
ans[0]=a_zero(a)
for i in range(1,n):
	ans[i]=2*(a[i-1]-ans[i-1]//2)
for i in range(len(ans)):
	if i!=len(ans)-1:
		print(ans[i],end=" ")
	else:
		print(ans[i])

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

for i in range(0, len(a)-1):
    ans.append(int(a[i]-ans[i]/2)*2)

for i in range(len(ans)):
    print(ans[i], end=" ")

Solution (Python):
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))

vec = (-1) ** np.arange(n)
b = np.zeros(n)
b[0] = np.dot(vec, a)
b[1] = np.dot(np.roll(vec, 1), a)
for i in range(2, n):
    sgn = (-1) ** (i % 2)
    b[i] = b[i - 2] - 2 * (a[i - 2] - a[i - 1])
print(' '.join([str(int(i)) for i in b]))

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split(' ')))
    tmp = 0
    for n,i in enumerate(a):
        if n%2 ==0:
           tmp += i
        else:
            tmp -=i
    print(tmp,'',end='')
    x_1 = tmp
    for i in a[0:n]:
        next = 2*i-tmp
        print(next,'',end='')
        tmp = next

if __name__ == '__main__':
    main()

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

ans = []
x = a[0]
y = a[0]

flg = False
for i in range(n-1):
   if flg:
     x += a[i+1]
     y -= a[i+1]
     flg = False
   else:
     x -= a[i+1]
     y += a[i+1]
     flg = True

ans.append(x)
ans.append(y)

p = 0

for i in range(n-2):
  ans.append(ans[p] -2*a[p] + 2*a[p+1] )
  p += 1

ans_str = " ".join(list(map(str,ans)))
print(ans_str)

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

lsA = list(map(int,input().split()))
tot = sum(lsA)

an = tot
for i in range(0,n-2,2):
  an -= 2*lsA[i]

ans = [2*lsA[i] for i in range(n)]
ans[n-1] = an
for i in range(n-2,-1,-1):
  ans[i] -= ans[i+1]

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
sum=0
ans=[0 for i in range(n)]
for i in range(n):
    if i%2==0:
        sum+=a[i]
    else:
        sum-=a[i]
ans[0]=int(sum/2*2)
ans[n-1]=int(a[n-1]*2-ans[0])
for j in range(n-2,0,-1):
    ans[j]=int(a[j]*2-ans[j+1])
print(*ans)

Solution (Python):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
ans=0
for x in range(0,1):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    ans=((ex-sum))
io=0
while(io!=n):
    print(ans*2,end=" ")
    ans=arr[(io)%n]-ans
    io+=1

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

x = (sum([a[i] for i in range(0, len(a), 2)]) -
     sum([a[i] for i in range(1, len(a), 2)]))//2

prev = 0
res = []
for i in range(len(a)-1):
    if i == 0:
        tmp = x*2
        res.append(x*2)
        prev = x*2
    tmp = (a[i] - prev//2)*2
    res.append(tmp)
    prev = tmp

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

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



N = i_inpl()
A = l_inpl()

ans = []
tmp = 0
for i, Ai in enumerate(A[:N-1]):
    tmp += Ai *(-1)**(i)
a1 = (tmp+A[N-1])
ans.append(a1)
t_ans = []
r_A = A[::-1]
for i in range(N-1):
    ans.append(2*r_A[i]-ans[i])
ans = [ans[0]] + ans[1:][::-1]
print(" ".join([ str(i) for i in ans]))

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

water = A[:]


ans = []
x = 0

ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    
    ans.append(y)
    x = y


x = (ans[0] + ans[-1]) // 2
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    
    ans.append(y)
    x = y






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

Solution (Python):
n=int(input())
a=list(map(int,input().split( )))
c=a[0]
for i in range(1,n-1):
	if i%2!=0:
		c=c-a[i]
	else:
		c=c+a[i]
ans=[]
ans.append(abs(c+a[-1]))
x1=abs((c+a[-1])//2)
t=x1
for i in range(n-1):
	t=abs(t-a[i])
	ans.append(2*t)
print(*ans)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
X = [0]*N
X_total = sum(A)
A_odd = sum([A[i % N] for i in range(1, N, 2)])
A_even = sum([A[i % N] for i in range(2, N+1, 2)])
for i in range(N):
    X[i] = X_total - 2*(A_odd if i % 2 == 0 else A_even)
    if i % 2 == 0: A_odd += A[i] - A[(i+1) % N]
    else: A_even += A[i] - A[(i+1) % N]
print(*X)

Solution (Python):


import sys










n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

ans =[0] * n




sum = 0
for i in range(n):


	if(i%2 == 0):
		sum+=hoge[i]
	else:
		sum-=hoge[i]


ans[0]=sum



for i in range(1,n):
	ans[i]=(hoge[(i-1)] - ans[i-1]//2)*2







tout=""

tout+=str(ans[0])


for i in range(1,n):
	tout+=" "
	tout+=str(ans[i])

print(tout)

Solution (Python):



def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for j in range(a):
        s -= 2 * al[(0 - (1 + 2 * (j + 1)) + n) % n]
    ans[n - 1] = s
    for i in range(n - 2, -1, -1):
        ans[i] = 2 * al[i] - ans[i + 1]
    print(" ".join([str(i) for i in ans]))

if __name__=="__main__":
    solve()

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







ans = [0] * N





for i in range(N):
    if i%2 == 0:
        tmp = -1
    else:
        tmp = 1
    tmp *= A[i] * 2
    ans[0] -= tmp
ans[0] //= 2

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

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

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
u = []
a = 0
for j, i in enumerate(l):
    a += i*((-1)**j)
u.append(a)
mae = a
for j, i in enumerate(l):
    usi = int((i - mae/2) * 2)
    u.append(usi)
    mae = usi
print(*u[:-1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x =0
for i,w in enumerate(a):
    x += (-1)**i*w
ans = [x]
for i,t in enumerate(a):
    ans.append(int(((ans[i]/2)-t)*(-2)))
print(' '.join(map(str, ans[:-1])))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = [0] * n
ans[0] = sum(a) - sum(a[1::2])*2

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

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

Solution (Python):
N=int(input())
listA=list(map(int,input().split()))
list1=[(-1)**(i+1)*listA[i] for i in range(N-1)]
SUM=sum(list1)
ans=listA[N-1]-SUM
listANS=[ans]
for i in range(N-1):
  ans=2*listA[i]-ans
  listANS+=[ans]
listANS=[str(i) for i in listANS]  
listANS=' '.join(listANS)
print(listANS)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(len(A)):
    B.append(A[i]*2)
B_2 = []
for i in range(len(B)):
    if i%2 != 0:
        B_2.append(B[i])
    else:
        pass


C = []
C.append(sum(A) - sum(B_2)) 

for i in range(len(A)-1):
    C.append(B[i]-C[i])
for i in range(len(C)):
    C[i] = str(C[i])

answer = ' '.join(C)
print(answer)

Solution (Python):
n=int(input())
lista = [int(i) for i in input().split()]

ans = [0]*n
sum_ = sum(lista)/2

tmp = 0
for i in range(0,n-1,2):
    tmp+=lista[i]
ans[-1] = int(sum_-tmp)*2


for i in range(n-1):
    ans[n-2-i] = int(lista[n-2-i]*2 - ans[n-1- i])

for i in range(n):
    print(ans[i]," ",end="")

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

ans = [] * (N)
temp = (A[1] - A[0])*2
for i in range(N)[2:]:
    temp = A[i]*2 - temp
a = int(temp/2)
ans.append(str(a))

temp = a
for i in range(N-1):
    temp = A[i]*2 - temp
    ans.append(str(temp))

print(' '.join(ans))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0]*N

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

d = B[0]/2 + B[N-1]/2 - A[N-1]
if d==0:
	print(*list(map(int, B)))
else:
	B[0] -= d
	for i in range(N-1):
		l = A[i]-B[i]/2
		B[i+1] = l*2
	print(*list(map(int, B)))

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

dam = [int(s) for s in input().split(' ')]

even = [i for index, i in enumerate(dam) if index % 2 == 0]
odds = [i for index, i in enumerate(dam) if index % 2 == 1]

sum_even = sum(even)
sum_odds = sum(odds)

mount = [sum_even - sum_odds]

dam.append(dam[0])
for i in range(0, num_mount-1):
    mount.append(2 * dam[i] - mount[i])

mount_str = map(str, mount)
print(' '.join(mount_str))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())
A = LI()

mountains = [-1 for i in range(N)]
last = sum(A)//2
for i in range(0,N-1,2):
    last -= A[i]

mountains[-1] = last

for i in reversed(range(N-1)):
    mountains[i] = A[i] - mountains[i+1]

for i in range(N):
    print(mountains[i]*2,end=" ")
print("")

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
tmp = A[0]

for i in range(1, N):
  if i % 2 == 0:
    tmp = tmp + A[i]
  else:
    tmp = tmp - A[i]
X = [tmp]*N
for i in range(0, N-1):
  X[i+1] = (A[i] - X[i] // 2) * 2
print(" ".join(list(map(str, X))))

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

X = [0]*N

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

for i in range(N-2,-1,-1):
    X[i]=2*A[i]-X[i+1]
    
sX=["a"]*N
for i in range(N):
    sX[i]=str(X[i])

print(" ".join(sX))

Solution (Python):
from collections import defaultdict
import numpy as np
from scipy.sparse import bsr_matrix
from scipy.sparse.linalg import spsolve
def inpl(): return list(map(int, input().split()))

N = int(input())
A = np.array(inpl(), dtype=np.int64) * 2

data = np.ones(2*N, dtype=np.int64)
R = np.array([i//2 + i%2 for i in range(-1, 2*N-1)], dtype=np.int64)
C = np.array([N-1, 0] + [i//2 + i%2 for i in range(2*N-2)], dtype=np.int64)
X = bsr_matrix((data, (R, C)), shape=(N, N), dtype=np.uint64)

ans = spsolve(X, A)

print(*[int(ans[i]) for i in range(-1, N-1)], sep = " ")

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

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

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

Solution (Python):
n=int(input())
a = [int(i) for i in input().split()]
s=0
for i in range(n):
  if i%2==0:
    s+=a[i]
  else:
    s-=a[i]
print(s,end=" ")
s=s//2
for i in range(0,n-1):
  s=(a[i]-s)*2
  print(s,end=" ")
  s=s//2

Solution (Python):
n = int(input())
d = list(map(int,input().split()))
m = [0]
for i in range(1,n):
  m.append(2*d[i-1] - m[i-1])
diff = 2*d[n-1] - m[n-1]
M = [diff//2]
for i in range(1,n):
  M.append(2*d[i-1] - M[i-1])
ans = list(map(str,M))
print(' '.join(ans))

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

k = 0
for i in range(1,N):
    k = A[i] - k

ans = (A[0] - k) // 2
ans_l = [None]*N

ans_l[1] = str(ans*2)
for i in range(1,N):
    ans = A[i] - ans
    if i==N-1:
        ans_l[0] = str(ans*2)
    else:
        ans_l[i+1] = str(ans*2)
print(" ".join(ans_l))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0] * N

A.reverse()
num = A[0]
for i in range(1, N):
    if i % 2 == 0:
        num -= A[i]
    else:
        num += A[i]

B[0] = num

for i in range(1, N):
    B[i] = 2 * (A[i] - (B[i - 1] // 2))
B.reverse()
B = list(map(str, B))
print(' '.join(B))

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

x = 0
rains = [x]
for a in A:
    x = a - x
    rains.append(x)

diff = (rains[-1] - rains[0]) // 2
result = []
for i, x in enumerate(rains[:-1]):
    if i % 2 == 0:
        result.append(str((x + diff) * 2))
    else:
        result.append(str((x - diff) * 2))

print(' '.join(result))

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

x = 0
for i,a in enumerate(A):
    if i%2==0:
        x += a
    else:
        x -= a
ans = [str(x)]
for i in range(1,N):
    x = 2*A[i-1] - x
    ans.append(str(x))

print(' '.join(ans))

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

ans = []

ans.append(
        int((sum(s) * 0.5 - sum(s[1::2]))*2)
        )
for i in range(n-1):
    ans.append(int((s[i]-ans[i]/2)*2))

print(*ans)

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

asum=sum(alist)
ans_list=[-1]*N

minus_even=sum(alist[1:N:2])
minus_odd=sum(alist[2:N:2])

for i in range(N//2):
  ans_list[2*i] = asum-2*minus_even
  ans_list[2*i+1] = asum-2*minus_odd
  
  minus_even += alist[(2*i+N)%N]-alist[(2*i+1)%N]
  minus_odd += alist[(2*i+N+1)%N]-alist[(2*i+2)%N]
  
ans_list[-1]=asum-2*minus_even
  
ans_list_str=map(str,ans_list)  
print(" ".join(ans_list_str))

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

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

X = [0]*N

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

for j in range(0,N-1):
    X[j+1] = 2 * (A[j] - int(X[j]/2))

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

Solution (Python):
import sys

input = sys.stdin.readline

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

X = [0 for _ in range(N)]


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

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

x = 0
for i,a in enumerate(A):
    if i%2==0:
        x += a
    else:
        x -= a
ans = [str(x)]
for i in range(1,N):
    x = 2*A[i-1] - x
    ans.append(str(x))

print(' '.join(ans))

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

def last_value(x):
    tmp2 = x
    for a in A:
        tmp = x
        x = a - tmp
    return x-tmp2

def bsearch(l,r):
    if l > r:
        return -1
    else:
        c = (l+r)//2
        last = last_value(c)
        if last < 0:
            return bsearch(l,c-1)
        elif last> 0:
            return bsearch(c+1,r)
        elif last == 0:
            return c
    
    
        
def solver(x):
    ans = [0] * N
    ans[0] = x*2
    for i,a in enumerate(A[:-1]):
        tmp = x
        x = a - tmp
        ans[i+1] = x * 2
    return ans


Left = 0
Right = min(A[0],A[N-1])

ans = solver(bsearch(Left,Right))

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

Solution (Python):
n = int(input())
a = tuple(map(int, input().split()))
m = [0] * n

for i in range(0, n, 2):
  m[0] += a[i]

for i in range(1, n, 2):
  m[0] -= a[i]

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

print(*m)

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

half_sum_water = sum(water) // 2

ans = []

m = n // 2
x0 = half_sum_water
for i in range(m):
    x0 = x0 - water[(1 + (i * 2)) % n]

print(x0 * 2,end = ' ')

x = x0
for i in range(n - 1):
    x = water[i] - x
    print(x * 2,end = ' ')

print()

Solution (Python):
n=int(input())
dam=[int(x) for x in input().split()]
yama=[0]*n
dam_sum=sum(dam)//2
diff=0
if n in (1,2):
    for j in range(n):
        diff=0
        for i in range(n):
            if i%2==0:
                continue
            diff+=dam[(i+j)%n]
        yama[j]=dam_sum - diff
        yama[j]*=2
else:
    diff_same=0
    for i in range(n):
            if i%2==0:
                continue
            diff_same+=dam[(i)%n]
    yama[0]=dam_sum - diff_same
    yama[0]*=2
    diff_odd=0
    for i in range(n):
            if i%2==0:
                continue
            diff_odd+=dam[(i+1)%n]
    yama[1]=dam_sum - diff_odd
    yama[1]*=2
    for j in range(2,n):
        if j%2==0:
            diff_same-=dam[(j-1)%n]
            diff_same+=dam[(j-2)%n]
            yama[j]=dam_sum - diff_same
        else:
            diff_odd-=dam[(j-1)%n]
            diff_odd+=dam[(j-2)%n]
            yama[j]=dam_sum - diff_odd
        yama[j]*=2
print(" ".join([str(x) for x in yama]))

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))
lenA = len(A)

m0 = sum([A[i] for i in range(lenA) if i%2==0]) \
   - sum([A[i] for i in range(lenA) if i%2==1])

res = [0]*lenA
res[0] = m0

last = m0
i = 1
for a in A[:-1]:
    res[i] = 2*(a-last//2)
    last = res[i]
    i += 1

print(*res)