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()))
star = 0
ans = [0 for i in range(n)]
for i in range(n):
    star += a[i]
for i in range((n-1)//2):
    ans[0] += 2*a[2*i+1]
    ans[1] += 2*a[2*i+2]
ans[0] = star-ans[0]
ans[1] = star-ans[1]
for i in range(1,n//2):
    ans[2*i] = ans[2*(i-1)] + 2*a[2*(i-1)+1] - 2*a[2*(i-1)]
    ans[2*i+1] = ans[2*(i-1)+1] + 2*a[2*(i-1)+2] - 2*a[2*(i-1)+1]
ans[n-1] = ans[n-3] + 2*a[n-2]  - 2*a[n-3]
for i in range(n):
    print(ans[i],end=' ')

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
    ans += -a if i & 1 else a
ans //= 2
for a in A:
    print(ans * 2, end=" ")
    ans = a - ans
print()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
a2 = 0
for i in range(1, n, 2):
    a2 += a[i]

ans = [0] * n
ans[0] = sum_a - 2*a2
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()))

B = [0] * N
for i,a in enumerate(A):
    if i < N- 1:
        B[i+1] = A[i] * 2 - B[i]
    else:
        diff = A[i] - (B[i] + B[0])//2

B = [diff]
for i,a in enumerate(A):
    if i < N-1:
        B.append(A[i]*2 - B[i])

print(*B)

Submission status: Accepted

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

su = 0
for i in range((n+1)//2):

    if i<(n-1)//2:
        su += (a[i]+a[n-i-1])*(-1)**i
    else:
        su += a[i]*(-1)**i

lis = [su]
for i in range(n-1):
    nex = 2*a[i]-lis[-1]
    lis.append(nex)

print(*lis)

Submission status: Accepted

Solution code:
n = int(input())

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

allw = sum(a)

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

x = allw

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
X =[0]*N
sum_=0
for i in range(N):
  if i%2==0:
    sum_=sum_+A[i]
  else:
    sum_=sum_-A[i]
X[0]=int(sum_/2)
for i in range(1,N):
  X[i]=A[i-1]-X[i-1]
X = list(np.array(X)*2)
print(*X)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
x2 = 0
for i in range(N):
    if i % 2 == 0:
        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]
res = map(lambda x: x*2, ans)
print(*res)

Submission status: Accepted

Solution code:
# D - Rain Flows into Dams

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

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

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

print(*ans)

Submission status: Accepted

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

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

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

print(*Y)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [x * 2 for x in A]

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

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

print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

res=[0]*n

res[0] = sum(a) - 2*sum(a[1::2])

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

print(*res)

Submission status: Accepted

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

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

B1 = sum(A) - mount
B = [0]*N
B[0] = B1

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

Submission status: Accepted

Solution code:
n=int(input()) 
a=[int(i) for i in input().split()]
b=0
c=1
for i in a:
    b+=i*c
    c*=-1
ans=[b]
for i in a:
    ans.append(2*i-ans[-1])
print(*ans[:-1])

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split()))
a = 0
for i in range(N):
  a -= ((-1)**(i+1))*A[i]
mt = [a] 
for i in range(1,N-1):
  mt.append(2*(A[i-1]-(mt[i-1]//2)))
  
mt.append(2*(A[N-1]-(mt[0]//2)))

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

Submission status: Accepted

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

p = 0
for a in A:
    p = a*2-p

ans = [p//2]
for a in A[:-1]:
    ans.append(a*2-ans[-1])
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
X = [0]*N
A = [0]*N
sum_water = 0
A = list(map(int,input().split()))
for i in range(1,N+1):
    if(i % 2 != 0):
        sum_water += A[i-1]
    else:
        sum_water -= A[i-1]
X[0] = sum_water
for i in range(1,N):
    ans = 2*A[i-1] - sum_water
    X[i] = ans
    sum_water = ans
print(" ".join(map(str, X)))

Submission status: Accepted

Solution code:
n = int( input() )
a = list( map( int, input().split() ) )
a = [ a[-1] ] + a + [ a[0] ]

x = [ 0 ] * ( n+1 )

for i in range( 1, n+1 ):
    x[n] = x[n] + a[i]

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

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

x = list( map( str, x ) )

print( " ".join( x[1:n+1] ) )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    n = int(stdin.readline().rstrip())
    As = list(map(int,stdin.readline().rstrip().split()))

    k = 0
    for i in range(n):
        k = As[i]*2 - k
    
    k=k//2
    for i in range(n):
        print(k,end=" ")
        k = As[i]*2 - k
main()

Submission status: Accepted

Solution code:
N = int(input())
Aprev = list(map(int, input().split()))
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(Aprev[i])
        B.append(-Aprev[i])
    else:
        A.append(-Aprev[i])
        B.append(Aprev[i])

listaltA = [0]
listaltB = [0]
for i in range(N):
    listaltA.append(listaltA[i] + A[i])
    listaltB.append(listaltB[i] + B[i])
listaltA.pop(0)
listaltB.pop(0)

ans = []
for i in range(N):
    if i == 0:
        ans.append(listaltA[-1])
    else:
        if i % 2 != 0:
            res = listaltA[i - 1] + (listaltB[-1] - listaltB[i - 1])
            ans.append(res)
        else:
            res = listaltB[i - 1] + (listaltA[-1] - listaltA[i - 1])
            ans.append(res)
print(*ans)

Submission status: Accepted

Solution code:
# 隣二つ影響しか受けない

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

M = 0
for i in reversed(A[::2]):
    M += i

for i in reversed(A[1:N:2]):
    M -= i
ans = [0] * N
ans[0] = M

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

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

Submission status: Accepted

Solution code:
N = int( input() )
A = list( map( int, input().split() ) )
M = [ 0 ] * N
ALL = sum( A ) // 2

ng = 2
pl = N - 1
S = sum( [ A[ i ] for i in range( ng, pl + 1, 2 ) ] )
for i in range( 1, N // 2 + 1 ):
  M[ 2 * i - 1 ] = 2 * ( ALL - S )
  pl = ( pl + 2 ) % N
  S += A[ pl ] - A[ ng ]
  ng = ( ng + 2 ) % N

ng = 1
pl = N - 2
S = sum( [ A[ i ] for i in range( ng, pl + 1, 2 ) ] )
for i in range( N // 2 + 1 ):
  M[ 2 * i ] = 2 * ( ALL - S )
  pl = ( pl + 2 ) % N
  S += A[ pl ] - A[ ng ]
  ng = ( ng + 2 ) % N

ret = ""
for i in M:
  ret += str( i ) + " "
print( ret[ : - 1 ])

Submission status: Accepted

Solution code:
n=int(input())

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

sum_rain = sum(t)

ans=[]

for i in range(n):
    if i%2==1:
        sum_rain -= t[i]*2
ans.append(sum_rain)

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

print(*ans)

Submission status: Accepted

Solution code:
def main():
    n,*A=map(int,open(0).read().split())
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(' '.join(map(str,B)))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(' '.join(map(str,B)))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(*B)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(*B)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int,input().split()))
ans = [arr[0]*2]*N
for i in range(1,N):
    ans[0] += arr[i]*2 if i % 2 == 0 else - arr[i]*2
ans[0] //= 2
for i in range(1,N):
    ans[i] = arr[i-1]*2 - ans[i-1]
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int,input().split()))
arr2 = [0]*N
ans = [0]*N
for i in range(N):
    arr2[i] = arr[i]*2
ans[0] = arr2[0]
for i in range(1,N):
    if i % 2 == 1:
        ans[0] -= arr2[i]
    else:
        ans[0] += arr2[i]
ans[0] //= 2
for i in range(1,N):
    ans[i] = arr[i-1]*2 - ans[i-1]
print(*ans)

Submission status: Accepted

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

s = sum(a)

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

ans = [""] * n
cnt = 0
while cnt < n:
    ans[(2 * cnt) % n] = str(m1)
    m1 += -2 * a[(2 * cnt) % n] + 2 * a[(2 * cnt + 1) % n]
    cnt += 1

print(" ".join(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

total = sum(A)
Ans = [0]*N

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

    s = sum(A)
    x1 = s

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

    X = [x1]
    for i in range(N):
        x = 2 * A[i] - X[i]
        X.append(x)

    print(*X[:-1])


if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

for k in range(N):
  print(X[k], end=" ")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc133/tasks/abc133_d

n = int(input())

nums = [int(i) for i in input().split()]
total = sum(nums)
ans = [0] * n
t = 0
for i in range(1, n, 2):
    t += nums[i] * 2
ans[0] = total - t
for i in range(1, n):
    ans[i] = nums[i - 1] * 2 - ans[i - 1]
print(*ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    Ae = A[1::2]
    Ao = A[::2]
    x1 = (sum(Ao)-sum(Ae))//2
    table = [0]*(N+1)
    table[0] = x1
    for i in range(N):
        table[i+1] = A[i] - table[i]

    for i in table[:N]:
        print(i*2, end=' ')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
from itertools import accumulate
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    Ae = A[1::2]
    Ao = A[::2]
    x1 = (sum(Ao)-sum(Ae))//2
    table = [0]*(N+1)
    table[0] = x1
    def rec(i):
        if i == N:
            return
        table[i+1] = A[i] - table[i]
        rec(i+1)
    rec(0)
    for i in table[:N]:
        print(i*2, end=' ')
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n-1):
    x.append(a[i] - x[i])
# print(x)
for i in range(n):
    print(x[i]*2, end=" ")

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int, input().split()))
total_odd = sum(aa[1::2])
total_eve = sum(aa[0::2])
tmp = total_eve - total_odd
outs = [tmp]
for i in range(1,n):
    tmp = 2*aa[i-1] - tmp
    outs.append(tmp)
print(' '.join(list(map(str,outs))))

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int, input().split()))
total_odd = sum(aa[1::2])
total_eve = sum(aa[0::2])
tmp = total_eve - total_odd
print(tmp)
for i in range(1,n):
    tmp = 2*aa[i-1] - tmp
    print(tmp)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
A = A + A
b_odd = sum([A[i] for i in range(1, N) if (i+1)%2==0 ])
b_even = sum([A[i] for i in range(2, N) if (i+1)%2!=0 ])
b_odd_s, b_odd_t = 2, N-1
b_even_s, b_even_t = 3, N

B = [0]*N
B[0] = str(S - 2*b_odd)
B[1] = str(S - 2*b_even)

for i in range(2, N):
  if (i+1) % 2:
    b_odd -= A[b_odd_s-1]
    b_odd_s += 2
    b_odd_t += 2 
    b_odd += A[b_odd_t-1]
    B[i] = str(S - 2*b_odd)
  else:
    b_even -= A[b_even_s-1]
    b_even_s += 2
    b_even_t += 2 
    b_even += A[b_even_t-1]
    B[i] = str(S - 2*b_even)

print(*B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    # A_j = (x_j + x_(j + 1)) // 2
    # -> x_1 = A_1 - A_2 + A_3 - .. + A_N
    x = [0 for _ in range(N)]
    x[0] = sum([((- 1) ** i) * A[i] for i in range(N)])
    for i in range(1, N):
        x[i] = 2 * A[i - 1] - x[i - 1]
    print(' '.join(map(str, x)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

diff = (mount[0] + mount[n-1]) // 2 - dam[n-1]
mount[0] -= diff

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

N = int(input())
A = getlist()

M = [0]
v = 0
for i in range(N):
	x = 2 * (A[i] - int((v // 2)))
	M.append(x)
	v = x
n = int(M[N] // 2)
ans = []
for i in range(1, N + 1):
	if i % 2 == 0:
		ans.append(M[i] + n)
	else:
		ans.append((M[i] - n))

ans2 = []
for i in range(N):
	ans2.append(str(ans[(N - 1 + i) % N]))
print(*ans2)

Submission status: Accepted

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

m = [0]*n
m[0] = sum(a)

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

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

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

Submission status: Accepted

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

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

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

print(' '.join([str(c) for c in x]))

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
s = sum(li)
lee = len(li)
kumi = lee//2
tmp = 0
for i in range(1,kumi+1):
    tmp += 2*li[2*(i-1)]
last = s - tmp
#print(last)
first = li[-1]*2-last
ans_li = [first]
for l in li:
    target = ans_li[-1]
    ans_li.append(l*2-target)
ans_li.pop(-1)
print(*ans_li)

Submission status: Accepted

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

B = []

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

print(*B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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

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

    print(*B)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    ans1 = sum(A) - sum(a * 2 for a in A[1:n:2])
    ANS = [ans1]
    for i in range(n - 1):
        ANS.append((A[i] - (ANS[-1] // 2)) * 2)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = [0]*N
ans[0] = sum(A) - sum_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()))
b = sum(A[::2]) - sum(A[1::2]) - A[-1]

M = [0] * N
M[0], M[-1] = A[-1] + b, A[-1] - b 

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

print(*M)

Submission status: Accepted

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

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

ans = [0]*N
ans[0] = one
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()))

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

print(x,end=" ")

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

Submission status: Accepted

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

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

print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[(-1)**i*a[i] for i in range(n)]
ans=[sum(b)//2]
for i in range(n-1):
    ans.append((a[i]-ans[i]))
print(' '.join(map(lambda x:str(x*2),ans)))

Submission status: Accepted

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

sumA = sum(As)
sumOdd = sum(As[::2])

B = 2*sumOdd - sumA
Bs = [B]
for A in As[:-1]:
    B = 2*A - B
    Bs.append(B)

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

Submission status: Accepted

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

def solver(k):
    global ans
    ans = [k]
    for i in range(N - 1):
        ans.append(2 * A[i] - ans[i])
    if not ans[0] + ans[-1] == 2 * A[-1]:
        x = (2 * A[-1] - ans[0] - ans[-1]) // 2
        for i in range(N):
            if i % 2 == 0:
                ans[i] += x
            else:
                ans[i] -= x
solver(0)
print(" ".join(map(str, ans)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = [0]*n
ok = 0
ng = min(a[-1], a[0]) + 1
if ng - ok == 1:
    b[0] = 0
    for i in range(1, n):
        b[i] = (a[i - 1] - b[i - 1] // 2) * 2
else:
    while ng - ok > 1:
        mid = (ok + ng)//2
        b[0] = mid*2
        for i in range(1, n):
            b[i] = (a[i-1] - b[i-1]//2)*2
        if sum(b) < sum_a:
            ok = mid
        elif sum(b) > sum_a:
            ng = mid
        elif sum(b) == sum_a:
            break
print(*b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
t=0
for i,a in enumerate(A):
    if i%2==0:  #奇数番目の時は足す
        t+=a
    else:       #偶数番目の時は引く
        t-=a
L=[]
for a in A:
    print t,
    t=a*2-t

Submission status: Accepted

Solution code:
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]
  
print(' '.join(map(str,b)))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(_) for _ in input().split()]
    ret = []
    x, sign = 0, 1
    for i in range(N):
        x += sign * A[i]
        sign *= -1
    ret.append(x)

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

    print(*ret)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
X = [0]*(N+1)
S = sum(A)

even_list = [A[i] for i in range(1, N) if (i+1) % 2 == 0]
odd_list = [A[i] for i in range(1, N) if (i+1) % 2 != 0]

X[1] = S - 2 * sum(even_list)
X[2] = S - 2 * sum(odd_list)

even = sum(even_list)
odd = sum(odd_list)
s_even_idx = 2
s_odd_idx = 3
t_even_idx = N-1
t_odd_idx = N
A = A + A

for i in range(3, N+1):
  if i%2:
    even -= A[s_even_idx-1]
    s_even_idx += 2 
    t_even_idx += 2 
    even += A[t_even_idx-1]
    X[i] = S - 2 * even
  else:
    odd -= A[s_odd_idx-1]
    s_odd_idx += 2
    t_odd_idx += 2
    odd += A[t_odd_idx-1]
    X[i] = S - 2 * odd

for i in range(1, N+1):
  print(X[i], end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  #連立方程式を行列にして解いた
  n=int(input())
  a=tuple(map(int,input().split()))
  ans=[0]*n
  ans[0]=sum([a[i]*(-1)**i for i in range(n)])
  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()))
  ans=[0]*n
  ans[0]=sum([a[i]*(-1)**i for i in range(n)])
  for i in range(1,n):
    ans[i]=ans[i-1]*(-1)+2*a[i-1]
  print(*ans)
if __name__=='__main__':
  main()

Submission status: Accepted

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

ans=[0]*n
s=int(sum(a)/2)
for i in range(1,n,2):
    s-=a[i]
ans[0]=s
for i in range(1,n):
    ans[i]=a[i-1]-ans[i-1]
print(*ans)

Submission status: Accepted

Solution code:
# D - Rain Flows into Dams

n = int(input())
a = list(int(x) for x in input().split())

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

tmp2 = x
ans = []
for i in range(n):
    if i==0:
        ans.append(tmp2 * 2)
    else:
        tmp2 = a[i-1] - tmp2
        ans.append(tmp2 * 2)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
s = 0
for i in range(N):
    if i % 2 == 0:
        s += A[i]
    else:
        s -= A[i]
ans = [s]
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()))

ans = sum(a)
for i in range(n):
  if i % 2:
    ans -= a[i] * 2
  
print(ans, end=" ")
  
for i in range(1, n):
  ans = a[i-1]*2 - ans
  print(ans, end=" ")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= 2

offset = 0
for i in range(n):
    offset = a[i]-offset
x = offset/2

cur = x
for i in range(n):
    print(int(cur), end=' ')
    cur = a[i]-cur

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
a_sum = sum(a)//2
a2 = a + a
l = [0 for i in range(2*n)]
for i in range(2*n):
    if i == 0:
        l[i] = 0
    elif i == 1:
        l[i] = a2[0]
    else:
        l[i] = l[i-2] + a2[i-1]
for i in range(n):
    ans.append(2*(a_sum - l[i+n-1] + l[i]))
print(" ".join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    AA = [0] * N

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

    val=cnt//2
    print('{} '.format(val), end='')
    for i in range(N-1):
        print('{} '.format(AA[i] - val), end='')
        val = AA[i] - val



resolve()

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
odd=sum(A[::2])
even=sum(A[1::2])
rtemp=10**9+1
ltemp=-1
while rtemp-ltemp>1:
    mid=(rtemp+ltemp)//2
    if odd-even-mid<=mid:
        rtemp=mid 

    else:
        ltemp=mid

ans=rtemp
D=[]
for i in range(n-1):
    D.append(ans*2)
    ans=A[i]-ans
    
D.append(ans*2)
print(*D)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(x) for x in input().split()]

temp = 0
c = 1
for i in range(n):
    temp += c * a_list[i]
    c *= -1

ans_list = [temp]
for i in range(n - 1):
    ans_list.append(2 * (a_list[i] - ans_list[i] // 2))
print(" ".join([str(ans) for ans in ans_list]))

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1,d2,d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

def main():
    n = II()
    aa = MII()
    total = sum(aa)
    x1 = total - 2*sum(aa[1::2])
    ans = [x1]
    for i in range(0, n-1):
        ans.append(2*aa[i]-ans[-1])
    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

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

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

x = [i * 2 for i in x]

print(*x)

Submission status: Accepted

Solution code:
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(1,N):
    X[i] = 2*A[i-1] - X[i-1]
print(*X)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
kx = list(map(int,input().split()))
k = kx[::2]
x = kx[1::2]
ans = [0]*n
ans[0] = sum(k)-sum(x)
for i in range(0,n-1):
  ans[i+1] = kx[i]*2-ans[i]
print(*ans)