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 = list(map(int, input().split()))

odd_sum = [0]
even_sum = [0]

for i in range(N):
    if i % 2 == 0:
        odd_sum.append(odd_sum[-1] + a_list[i])
        even_sum.append(even_sum[-1] - a_list[i])
    else:
        odd_sum.append(odd_sum[-1] - a_list[i])
        even_sum.append(even_sum[-1] + a_list[i])

ans = []
for i in range(N):
    a = a_list[i]

    if i % 2 == 0:
        a += (odd_sum[-1] - odd_sum[i + 1])
        a += even_sum[i]
    else:
        a += (even_sum[-1] - even_sum[i + 1])
        a += odd_sum[i]
    print(a)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr2=[0]*n
for i in range(0,2*n,2):
  arr2[i//2]=arr[i%n]
ans=[0]*n
s=sum(arr)//2
cum=[0]*n
start=sum(arr2[:n//2])
cum[0]=start
l=n//2
for i in range(n):
  start=start+arr2[(i+l)%n]-arr2[i]
  cum[(i+1)%n]=start
for i in range(n):
  ans[(n-1+i*2)%n]=(s-cum[i])*2
print(*ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""

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

    
def main():
    m = [0]*N
    sgn = (-1)
    Atot=0
    for n in range(N):
        Atot += sgn**(n)*A[n]
    m[0] = Atot//2
    for n in range(1,N):
        m[n] = A[n-1]-m[n-1]
    for n in range(N):
        m[n] = m[n]*2
    
        
    print(*m, sep=" ")
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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]
tmp = []
tmp.append(ans)
for j in range(1,N + 1):
        tmp.append(A[j - 1] * 2 - tmp[j - 1])

for i in range(len(tmp) -1 ):
        print(tmp[i])

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr2=[0]*n
for i in range(0,2*n,2):
  arr2[i//2]=arr[i%n]
ans=[0]*n
s=sum(arr)//2
cum=[0]*n
start=sum(arr2[:n//2])
cum[0]=start
l=n//2
for i in range(n):
  start=start+arr2[(i+l)%n]-arr2[i]
  cum[(i+1)%n]=start
for i in range(n):
  ans[(n-1+i*2)%n]=(s-cum[i])*2
print(*ans)

Submission status: Accepted

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

s = sum(a)
p = 0
for i in range(n):
    if i%2 == 1:
        p += a[i]*2

q = s-p
for i in range(n):
    print(q)
    q = a[i]*2-q

Submission status: Accepted

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

x = A[0]
for j, a in enumerate(A[1:]):
    if j%2==0:
      x -= a
    else:
      x += a
print(x)
for i in A[:-1]:
  x = 2*(i-x/2)
  print(int(x))

Submission status: Accepted

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

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

import numpy as np
ma = np.mean(A)
mx = np.mean(x)
x = (np.array(x) + ma - mx + 0.1).astype(int)
for i in range(N-1):
    print(x[i], end=" ")
print(x[-1])

Submission status: Accepted

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

sumA = sum(As)

ys = [0]*N
for i in range(1, N):
    ys[i] = As[i-1]-ys[i-1]

sumY = sum(ys)

z = sumA-sumY
#print(z)
#print(ys)
x = z - sumY

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = [None for k in range(N)]
x = sum(A)
y = 0
for n in range((N-1)//2):
	y += A[2*n]
ans[N-1] = x-y*2
ans[0] = A[N-1]*2 -ans[N-1]
for n in range(N-1):
	ans[n+1] = A[n]*2 - ans[n]
for a in ans:
	print(a, end=" ")

Submission status: Accepted

Solution code:
from collections import deque

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

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

ANS = [0] * n
for i in range(n):
    ans = 0
    if i % 2 == 0:
        ans += B[-1] - B[-2]
    else:
        ans += B[-2] - B[-1]

    if i - 2 >= 0:
        ans -= B[i - 2] * 2

    if i - 1 >= 0:
        ans += B[i - 1] * 2

    ANS[i] = ans

print(*ANS)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
sumA = 0
for i in range(N):
    sumA += A[i]
k = 0
ans = []
res = []
for i in range(N):
    if i % 2 == 0:
        res.append(A[i])
    else:
        res.append(-A[i])
P = sum(res)
ans.append(P)
tem = A[0]
tempans = P - tem
for i in range(N-1):
    tempans = -tempans+A[i]
    ans.append(tempans)
    tempans -= A[i+1]
print(*ans,sep = " ")

Submission status: Accepted

Solution code:
import math
import itertools

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

M = []
M.append(sum([A[i] if i % 2 == 0 else -A[i] for i in range(N)]))
for i in range(1, N):
    M.append(2*A[i-1]-M[i-1])

print(' '.join([str(m) for m in M]))

Submission status: Accepted

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

for x in X:
    print(x,end=" ")
print()

Submission status: Accepted

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

ans = [0] * N

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

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

ans = list(map(int, ans))
for i in ans:
    print(i, end=" ")

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
ans = []
sum_all = sum(A) / 2

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np





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


#
# if n <= 3:
#     ans = np.linalg.solve(A, arr)
#
#     for i in range(n - 1):
#         print(int(ans[i]), end=" ")
#
#     print(int(ans[n - 1]))
# else:

odd = 0
eq = 0
all = [0,0]

for i in range(n):
    if i % 2 == 0:
        eq += arr[i]
        all.append(eq)
    else:
        odd += arr[i]
        all.append(odd)


ans = [0 for i in range(n)]

base = eq-odd
base2 = odd-eq+2*arr[0]
for i in range(n):
    if i %2 ==  0:
        ans[i] = base
        if i == n-1:
            break
        base -= 2*arr[i]
        base += 2* arr[i+1]


    if i %2 ==  1:
        ans[i] =base2
        base2 -= 2*arr[i]
        base2 += 2*arr[i+1]



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

Submission status: Accepted

Solution code:
import sys
import numpy as np

N = int(sys.stdin.readline().rstrip())
AList = list(map(int,sys.stdin.readline().split()))

odd=True
sumRes=0
for a in AList:
  if odd:
    sumRes+=a
    odd = False
  else:
    sumRes-=a
    odd = True

x1 = sumRes//2
ansList = [x1]
for i in range(N):
  ansList.append(AList[i]-ansList[i])
  
ansList=np.array(ansList)
ansList=ansList[0:len(ansList)-1] * 2
print(' '.join(map(str, ansList)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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=' ')
#  ok = 0
#  ng = 2 * int(1e9) + 1
#  while abs(ok - ng) > 1:
#      m = (ok + ng) // 2
#      x = [0] * n
#      x[0] = m
#      f = True
#      for i in range(n):
#          x[(i + 1) % n] = a[i] - x[i]
#          if (i % 2 == 0) and (x[(i + 1) % n] < 0):
#              f = False
#          if (i % 2 == 1) and (x[(i + 1) % n] <= 0):
#              f = True
#      if x[-1] + x[0] < a[-1]:
#          f = False
#      if f:
#          ok = m
#      else:
#          ng = m
#  print(*[i * 2 for i in x], sep=' ')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!venv/bin/python
#from collections import defaultdict 
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]))

Submission status: Accepted

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

#print(dat_aa)
m = -1
index = -1
for i in range(n):
    if dat_aa[i] > m:
        m = dat_aa[i]
        index = i
#print("max = {0} [{1}]". format(dat_aa[index], index))
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
#print("sin")
#print(s_in)
#print(s_out)
#print(d)
#print(res)
for i in range(n):
    if i % 2 == 0:
        res[i] += d
    else:
        res[i] -= d
res = list(map(str, res))
print(" ".join(res))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    #print(B)
    d = (A[-1] - (B[0] + B[-1]) // 2)
    #print(d)
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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))

Submission status: Accepted

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

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*n
#for i in range(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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
#xが最初のやつ
dp=[x]
for i in range(N-1):
    dp.append(A[i]-dp[-1])
for j in range(N):
    print(dp[j]*2,end=' ')

Submission status: Accepted

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

Submission status: Accepted

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

# print(x)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
# E = 0.5 * (np.eye(n) + np.eye(n, n, 1) + np.eye(n, n, -n + 1))
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]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

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 # 10^9 + 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]))

# L, R = l_inpl()
# L %= 2019
# R %= 2019

# if R<=L:
#     R+=2019

# ans = INF
# for i in range(L, R+1):
#     for j in range(i+1, R+1):
#         print(i, j)
#         ans = min(ans, i*j%2019)

# print(ans)

Submission status: Accepted

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

water = A[:]
#print(water)

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

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





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