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



Sample input:
3
2 2 4


Sample output:
4 0 4

Submission status: Accepted

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

ans_l=[]
ans1=0
s=0
for i in reversed(a):
 if s%2==0:
  ans1+=i
 else:
  ans1-=i
 s+=1

ans_l.append(ans1)
for i in range(n-1):
 ans_l.append((a[i]-ans_l[-1]//2)*2)
print(*ans_l)

Submission status: Accepted

Solution code:
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[-1])
print(*ans)

Submission status: Accepted

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

r = [0] * N

r[0] = sum(A[0 : N : 2]) - sum(A[1 : N : 2]) # O(N)


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

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

Submission status: Accepted

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

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

ans = [0] * N
ans[0] = x2//2
for i in range(N-1):
    ans[i+1] = A[i] - ans[i]
for i in range(N):
    ans[i] *= 2
    
print(*ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = [0 for i in range(N)]
ans[0] = sum(((-1)**i)*A[i] for i in range(N))//2
for i in range(1,N):
    ans[i] = A[i-1]-ans[i-1]
for i in ans:
    print(2*i,end = ' ')

Submission status: Accepted

Solution code:
N = int(input())
#N,M = map(int,input().split())
A = list(map(int,input().split()))
#A = [list(map(int,input().split())) for i in range(N)]
ans = [0 for i in range(N)]
ans[0] = int((A[0]+A[-1]-A[-2])//2)
ans[1] = int((A[1]+A[-2]-A[-1])//2)
ans[0] = sum(((-1)**i)*A[i] for i in range(N))//2
for i in range(1,N):
    ans[i] = A[i-1]-ans[i-1]
for i in ans:
    print(2*i,end = ' ')

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=0
t=0
for i in range(N):
  t+=A[i]
for i in range(1,N,2):
  s+=A[i]
X=[0]*N
X[0]=t-2*s
for i in range(N-1):
  X[i+1]=2*A[i]-X[i]
for i in range (N):
  print(X[i],end=" ")

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

N = int(input())
b = np.array(input().split(), dtype=int)

data = np.ones(2*N, dtype=int)
col = np.arange(2 * N) // 2
row = np.zeros(2 * N, dtype=int)
row[0] = N - 1
row[1:] = col[:-1]

A = csr_matrix((data, (row, col)), shape=(N, N))

ans = (spsolve(A, b) * 2).astype(int)
print(*ans)

Submission status: Accepted

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

a_sum = sum(A)

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

rain=[0]*N
rain[0] = a_sum-xor

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []

b.append(sum(a) - 2*sum(a[1:n-1:2]))
i = 0
while i < n-1:
    b.append(2*a[i]-b[i])
    i += 1

print(*b)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
w=0
for i in range(n-1):
    if i%2==0:
        w-=a[i]
    else:
        w+=a[i]
x=[a[-1]-w]
for i in range(n-1):
    x.append((a[i]-x[-1]//2)*2)
print(' '.join(map(str, x)))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
X1 = sum(A)
arr = [0]*N
for i in range(N):
  if i%2==1:
    X1 -= 2*A[i]
arr[0] = X1
for i in range(1, N):
  arr[i] = 2*A[i-1] - arr[i-1]
print(*arr)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N = int(input())
a = tuple(map(int,input().split()))
tmp = [0]
for i in range(1,N):
    tmp.append(2*a[i-1] - tmp[i-1])
res = [abs(tmp[N-1]//2 - a[N-1])]
for i in range(1,N):
    res.append(2*a[i-1]-res[i-1])
print(' '.join([str(res[i]) for i in range(N)]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
x = s-2*sum([a[i] for i in range(1,n-1,2)])
print(x)
for i in range(n-1):
    x = 2*a[i]-x
    print(x)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
value=sum(A)
T=[0 for i in range(N)]

T[0]=value-sum([a for i,a in enumerate(A) if i%2==1 and i>=1])*2
T[1]=value-sum([a for i,a in enumerate(A) if i%2==0 and i>=2])*2

for i in range(2,N):
    T[i]=T[i-2]+(A[i-1]-A[i-2])*2
print(" ".join(list(map(str,T))))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*n
s = sum(a)//2
tmp = 0
for i in range(1,n,2):
  tmp += a[i]
x[0] = s-tmp
for i in range(n-1):
  x[i+1] = a[i]-x[i]
for i in range(n):
  print(2*x[i],end=" ")

Submission status: Accepted

Solution code:
n = int(input())

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

total = sum(l)

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

ans = [total]

for i in range(1,n):
    ans.append(2*l[i-1]-ans[i-1])
ans = [str(i) for i in ans]
    
print(' '.join(ans))

Submission status: Accepted

Solution code:
N = int(input())

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

x = 0

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

x = x // 2

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

Submission status: Accepted

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

s=sum(A)//2
ans=[0]*N

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

ans[0]=(s-rem)*2

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



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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))

ans = []
X1 = sum(A) - (2 * A[1::2]).sum()
ans.append(X1)

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

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

Submission status: Accepted

Solution code:
n = int(input())
dam = list(map(int,input().split()))
mount = []
m1 = 0
for i in range(n):
    if i % 2 == 0:
        m1 += dam[i]
    else:
        m1 -= dam[i]
mount.append(m1)
for i in range(n):
    diff = mount[i]
    mount.append(dam[i]*2 - diff)
ans = mount[:-1]
print(*ans)

Submission status: Accepted

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

ans = [None] * n

x = 0

for i, ai in enumerate(a):
  if i % 2 == 0:
    x += ai
  else:
    x -= ai
    
ans[0] = x

for i, ai in enumerate(a[:-1]):
  x = 2 * ai - ans[i]
  ans[i+1] = x

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

Submission status: Accepted

Solution code:
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/arc067/tasks/arc067_a
# C - Factors of Factorial
"""
need to consider the case that ticket is not enough to lower everything
"""

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

pl[0] = p0

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

Submission status: Accepted

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

ans = [None] * N

x = 0
for i, ai in enumerate(A):
    if i % 2 == 0:
        x += ai
    else:
        x -= ai

ans[0] = x

for i, ai in enumerate(A[:-1]):
    x = 2 * ai - ans[i]
    ans[i+1] = x

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

Submission status: Accepted

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

ans = []

x = 0
for i, ai in enumerate(A):
    if i % 2 == 0:
        x += ai
    else:
        x -= ai

ans.append(x)

for ai in A:
    x = 2 * ai - x
    ans.append(x)

ans = [str(i) for i in ans[:-1]]
print(" ".join(ans))

Submission status: Accepted

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

A += A

g_rui = [0, A[0]]
k_rui = [0, A[1]]

for i in range(2, 2*N):
    if i % 2 == 0:
        x = g_rui[-1] + A[i]
        g_rui.append(x)
    if i % 2 != 0:
        x = k_rui[-1] + A[i]
        k_rui.append(x)

# print(A)
# print(g_rui)
# print(k_rui)

for i in range(N):
    if i % 2 == 0:
        ind = i//2
        a = g_rui[ind + N//2 + 1] - g_rui[ind]
        b = k_rui[ind + N//2] - k_rui[ind]
        print(a-b)
    else:
        ind = i//2
        a = k_rui[ind + N//2 + 1] - k_rui[ind]
        # print('a', a)
        b = g_rui[ind + N//2 + 1] - g_rui[ind + 1]
        # print('b', b)
        print(a-b)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
a=0
for i in range(n):
    if i%2==0:
        a+=A[i]
    else:
        a-=A[i]
ans=[a]
for i in range(n-1):
    ans.append((A[i]-ans[-1]//2)*2)
print(*ans, sep=' ')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(lambda x:2*int(x),input().split()))

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

ans = [x1]

for i in range(N-1):
    ans.append(A[i]-ans[-1])

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

Submission status: Accepted

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

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


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

print(*ans, sep=' ')

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = []
plus = sum(l)
minus = 0
for j in range(1,n,2):  
        
    minus += l[(j)%n]
ans.append(plus-2*minus)
for i in range(1,n):
    ans.append(2*l[i-1]-ans[i-1])

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
total = sum(a)

ans = total - 2 * sum(a[1:-1:2])
print(ans)
for i in range(1, N):
    ans = 2 * a[i - 1] - ans
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
RAIN = [0] * n

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

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

RAIN = [str(rain) for rain in RAIN]
answer = " ".join(RAIN)
print(answer)

Submission status: Accepted

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

for i in range(n):
    if i%2 == 0:
        dam[0] += a[i]
    else:
        dam[0] -= a[i]

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

for i in range(n):
    if i < n-1:
        print(dam[i], end=" ")
    else:
        print(dam[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(*R)

Submission status: Accepted

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

S=sum(A)
X1=S-2*sum([A[i] for i in range(N) if i&1])

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sumall = sum(a)
sumodd = [0,a[1]*2]
sumeven = [0,a[0]*2]
for i in range(1,n//2+1):
    sumeven.append(sumeven[-1]+a[2*i]*2)
    if i<n//2:
        sumodd.append(sumodd[-1]+a[2*i+1]*2)
ans = []
for i in range(n):
    if i%2 == 0:
        ans.append(sumall-sumeven[i//2]-sumodd[-1]+sumodd[i//2])
    else:
        ans.append(sumall-sumodd[i//2]-sumeven[-1]+sumeven[i//2+1])
print(*ans)

Submission status: Accepted

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

x0 = 0

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

x = [x0]

for i in range(N - 1):
    x.append(A[i] - x[i])

ans = []

for i in range(N):
    ans.append(int(x[i] * 2))

print(*ans)

Submission status: Accepted

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

ans = []
x  = 0
for  i in range(n):
    if i%2 == 0:
        x += a[i]
    else:
        x -= a[i]

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

print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
asum=sum(a)
y=[0]*n
y[-1]=a[-1]
for i in range(n-1):
    if i%2==0:
        y[-1]-=a[i]
    else:
        y[-1]+=a[i]
for i in range(n-1):
    y[i]=a[i-1]*2-y[i-1]
print(*y)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
x=[0]*n
c=0
for i in range(1,n-1):
  if i%2!=0:
    c+=a[i]
x[0]=s-2*c
for i in range(1,n):
  x[i]=2*a[i-1]-x[i-1]
print(" ".join(map(str,x)))

Submission status: Accepted

Solution code:
N = int(input())
dum_list = list(map(int,input().split(' ')))

goukei = sum(dum_list)
dum_list = [2*x for x in dum_list]

ans_list = []
ans = ''

tmp = 0
for i in range(1,N-1,2):
  tmp += dum_list[i]
  
ans_list.append(goukei - tmp)
ans += str(ans_list[0])

for i in range(N-1):
  ans_list.append(dum_list[i] - ans_list[i])
  ans += ' ' + str(ans_list[i+1])
  
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
al = list(map(int, input().split()))

x = al[-1]
for i in range(n-1):
    x += (-1)**(i+1) * al[i]
x //= 2
xl = [x]

for i in range(n-1):
    xl.append(al[n-i-2] - xl[i])

print(*reversed(list(map(lambda a:a*2, xl))))

Submission status: Accepted

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# rを10**9にしてたらなんかしらんけど駄目だった 10にしたらいけた...

n = int(input())
dum = list(map(int, input().split()))
l, r = 0, (10 ** 10) // 2

while True:
    mid = (l + r) // 2
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        l = mid + 1
    else:
        r = mid


"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Accepted

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 10) // 2

while l < r:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Accepted

Solution code:
def examA():
    N, A, B = LI()
    ans = min(A*N,B)
    print(ans)
    return

def examB():
    N, D = LI()
    X = [LI() for _ in range(N)]
    ans = 0
    for i,j in itertools.combinations(X,2):
        cur = 0
        for k in range(D):
            cur += (i[k]-j[k])**2
        cur **=0.5
        if cur==int(cur):
            ans +=1
    print(ans)
    return

def examC():
    L, R = LI()
    cur = []; ans = 10**9
    for i in range(L,min(2019+L,R)+1):
        if i%2019==0:
            ans = 0
            break
        else:
            cur.append(i%2019)
    if ans==0:
        print(ans)
        return
    N = len(cur)
    for i,j in itertools.combinations(cur,2):
        ans = min(ans,(i*j)%2019)
    print(ans)
    return

def examD():
    N = I()
    A = LI()
    dis = [0]*N
    for i in range(N):
        cur = A[i-N+1]-A[i-N]
        dis[i] = cur*2
#    print(dis)
    ans = [0]*N
    for i in range(2,2*N,2):
        ans[i-N] = ans[i-N-2] + dis[i-N-2]
#    print(ans)
    ad = (sum(A) - sum(ans))//N
    for i in range(N):
        ans[i] += ad
    print(" ".join(map(str,ans)))
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(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()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = []
    x = (sum(A[0::2]) - sum(A[1::2])) // 2
    X.append(2 * x)
    for i in range(N - 1):
        x = A[i] - x
        X.append(2 * x)
    print(' '.join(str(i) for i in X))

main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    X = [0] * N
    X[0] = -sum(A) + 2*(sum(v for i, v in enumerate(A) if i % 2 == 0))
    for i in range(1,N):
        X[i] = 2*A[i-1] - X[i-1]
    return X
print(' '.join(str(i) for i in main()))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x = [0] * N
    for i in range(N):
        if i % 2 == 0:
            x[0] += A[i]
        else:
            x[0] -= A[i]
    for i in range(N-1):
        x[i+1] = 2 * A[i] - x[i]

    print(*x)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

S = sum(A)
S_odd = 0
for i in range(1, N+1):
    if i==N or i%2==0:
        continue
    S_odd += A[i]

Mn = S - 2*S_odd
M = [0 for _ in range(N+1)]
M[N] = Mn
for i in range(N-1, 0, -1):
    M[i] = 2*A[i] - M[i+1]

M = M[1:]
print(*M)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

M_0 = sum(A) - sum([ A[i]* 2 for i in range(1, N, 2)])
ans = [M_0]
for i in range(N-1):
    m = 2 * A[i] - ans[i]
    ans.append(m)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
	# print(R)

	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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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=' ')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    # right = 10**9
    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()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
# dif = A1-A2+A3-A4 ...
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)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
# dif = A1-A2+A3-A4 ...
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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