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()))
S = sum(A)
Aoddsum = sum(A[1:N:2])
X1 = S - 2*Aoddsum
X = [X1]
for n in range(1, N):
    X.append(2*A[n-1] - X[n-1])
    
for x in X:
    print(x, end=" ")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Aodd = [a for i, a in enumerate(A, 1) if i%2 == 0]
Aoddsum = sum(Aodd)
X1 = S - 2*Aoddsum
X = [X1]
for n in range(1, N):
    X.append(2*A[n-1] - X[n-1])
    
for x in X:
    print(x, end=" ")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    s = sum(a)
    l1 = 0
    for i in range(n):
        if i%2==0:
            l1 += a[i]
        else:
            l1 -= a[i]
    print(l1,end=" ")
    for i in range(n-1):
        l1 = 2*a[i]-l1
        print(l1,end=" ")
    print()
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
x = list()
x0 = 0
for i in range(N):
    if i % 2==0:
        x0 += A[i]
    else:
        x0 -= A[i]
x.append(x0)
for i in range(1,N):
    xp = x[i-1]
    xi = (A[i-1]-xp//2)*2
    x.append(xi)
print(*x)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input133d.txt')

#+++++

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

sum = 0
for s in a:
    sum += s

asum = 0
for i in range(n):
    if i % 2 == 1:
        asum += a[i]

x1 = sum - 2 * asum

ret = []
ret.append(x1)

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

for i in ret:
    print(i, end =" ")

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = input().split()
A = np.array(A).astype(type(N))
S = np.sum(A)

SS = np.array([A[i] for i in range(1,A.shape[0],2)])

X = np.zeros((N))
X[0] = S -2*sum(SS)
for i in range(0,N-1):
    X[i + 1] = 2*A[i] - X[i]  

for i in X:
    print("{} ".format(int(i)),end="")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(e) for e in input().split()]
result = [sum(a[::2])-sum(a[1::2])]
for i in range(len(a) - 1):
  result.append(2*a[i]-result[i])
print(' '.join(map(str, result)))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = ["*"]*n
x[0] = sum(a[::2])-sum(a)//2

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

for i in range(n):
    x[i] = str(2*x[i])

print(" ".join(x))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, A: "List[int]"):
    X = []
    x1 = sum(A) - sum(A[1::2]) * 2
    X.append(x1)
    for i in range(1, N):
        X.append(2 * A[i-1] - X[i-1])
    s = ' '.join([str(x) for x in X])
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
water=list(map(int,input().split()))
x=[]
temp=0
for i in range(1,n,2):
    temp+=water[i]
x.append(sum(water)-2*temp)
for j in range(n-1):
    x.append(2*water[j]-x[-1])
res=map(str,x)
print(' '.join(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ls = [int(x) for x in input().split()]
ls[0] = sum(ls[0::2]) - sum(ls[1::2])
ls[n-1] = 2*ls[n-1] - ls[0]
for i in range(n-2, 0, -1):
    ls[i] = 2*ls[i] - ls[i+1]
print(*ls)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
arr = []
ans = 0
n = 1
for i, a in enumerate(A):
  ans += a*(-1)**(i)
  
a1 = ans  
arr.append(ans)

while(n < N-1):
  ans = 2*A[n-1] - ans
  n += 1
  arr.append(ans)
  
ans = 2*A[N-1] - a1
arr.append(ans)

print(*arr)

Submission status: Accepted

Solution code:
#abc133d

n=int(raw_input())
a=map(int,raw_input().split())
s=sum(a)
s2=0
for i in xrange(1,n,2):
 s2+=a[i]
x=[0]*n
x[0]=s-2*s2
print x[0],
for i in xrange(1,n):
 x[i]=2*a[i-1]-x[i-1]
 print x[i],
print

Submission status: Accepted

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

# X1の拘束条件
# A1 * 2 && last

ansx1 = 0
is_m = False
for a in reversed(A):
    if is_m:
        ansx1 -= a
    else:
        ansx1 += a
    is_m = not is_m


ans = []
ans.append(ansx1)
prev = ansx1
for index in range(len(A)-1):
    d = 2 * (A[index] - int(prev //2))
    ans.append(d)
    prev = d

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(1,N):
    ans[i] = (A[i-1] - ans[i-1]/2)*2

for i in range(N):
    if i != N-1:
        print(int(ans[i]),end=' ')
    else:
        print(int(ans[i]))

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.zeros(N)

X[0] = int(np.sum(A[0::2]) - np.sum(A[1::2]))

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

Submission status: Accepted

Solution code:
def D_RainFlowsintoDams():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    x = total - 2*sum([A[i] for i in range(1, N -1, 2)])
    for i in range(N):
        print(x, end=" ")
        x = 2 * A[i] - x
def D_Determinant():
    # 行列式を使うと時間がかかりすぎる
    import numpy as np
    N = int(input())
    A = [list(map(int, input().split()))]
    A = np.array(A)
    # XB = A のXを求める
    X = (np.eye(N) + np.eye(N, k=1) + np.eye(N, k=-N+1)) * 0.5
    # X^{-1} を求める
    B = np.linalg.solve(X, A.T)
    # 両辺に左からX^{-1}をかける
    for x in range(N):
        print(int(B.T[0][x]), end=" ")

if __name__ == "__main__":
    D_RainFlowsintoDams()

Submission status: Accepted

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

Submission status: Accepted

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

water_sum = sum(a)
kotae = [-1 for _ in range(n)]

# 和を足しておく
kotae[0] = water_sum

# 全体の和からほかの山の水量を引いて行って山0の水量を求める
for i in range(n // 2):
    kotae[0] -= 2*a[(1+2*i) % n]

# 漸化式でほかのすべてを求める
for i in range(1, n):
    kotae[i] = 2*a[i-1] - kotae[i-1]

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
*a, = map(int, input().split())
x = 0
for i in range(n):
  if i % 2 == 0:
    x += a[i]
  else:
    x -= a[i]
ans = np.zeros(n,dtype='i8')
ans[0] = x//2

for j in range(n-1):
  ans[j+1] = a[j] - ans[j]

def db(y):
  return y*2
ans = db(ans)
print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
N = int(input()) # 奇数
inputs = [int(i) for i in input().split()]

double_inputs = list(map(lambda x: x * 2, inputs))
ans = [0 for _ in range(N)]
for i in range(N):
    if i == 0:
        ans[i] = sum(inputs) - sum(double_inputs[1::2])
    elif i == N - 1:
        ans[i] = double_inputs[-1] - ans[0]
    else:
        ans[i] = double_inputs[i-1] - ans[i-1]

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

Submission status: Accepted

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

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

print(*Y)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

water_sum = sum(A_array) 

now_water = water_sum - sum(A_array[1::2]) * 2
ans_array = []
# print(now_water)
ans_array.append(str(now_water))
for i in range(N-1):
    now_water = A_array[i] * 2 - now_water
    ans_array.append(str(now_water))

print(" ".join(ans_array))

Submission status: Accepted

Solution code:
import copy
def solve(ans):
  answers = []
  temp = copy.deepcopy(ans)
  flag = 1
  for i in range(len(ans)):
    ans[i] *= flag
    flag *= -1
  
  func = lambda x,y: x-y

  answers.append(sum(ans))

  for i in range(len(ans)-1):
    answers.append(int(2*func(temp[i], answers[i]/2)))
  return answers

n = int(input())

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

print(*solve(dam))

Submission status: Accepted

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

first_x2 = 0
flag = 1
for a in A:
    first_x2 += flag * a
    flag = -flag


ret = []
ret.append(str(first_x2))
for a in A:
    first_x2 = (a - (first_x2 // 2)) *2
    ret.append(str(first_x2))

ret.pop()
print(" ".join(ret))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
res = ""
res_tmp = 0
for j, a in enumerate(A):
    res_tmp += a if j % 2 == 0 else -a
res += (str(res_tmp) + " ")

for i, a in enumerate(A[:-1]):
    res_tmp = -res_tmp + a*2
    res += (str(res_tmp) + " ")
print(res[:-1])

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

#  # 山1の雨量は、左右のダムの大きい方
#  # 山1の雨量は、左右の山を見て候補値を絞り込む
#  # 例えば左右にそれぞれ6と4溜まっている場合、自分を0,2,4降った可能性を検討する
#  # ダムxの水量を見て、ありうる候補を見つける
#  # 最小値から見ると速いかも
#  # 山を-2すると、ダムを-2することができる
#  # 最小のダムを見つける
#  min_dam = min(A)
#  min_dam_idx = A.index(min_dam)
#  tmp_A = A[min_dam_idx:] + A[:min_dam_idx]
#  if min_dam == 0:
#      # 0のダムがある場合、その周りのダムは0が確定する
#      yamas = [0,0]
#      for i in range(2, N):
#          yamas.append(int((tmp_A[i]-yamas[-1]/2)*2))
#      yamas = yamas[N-min_dam_idx:] + yamas[:N-min_dam_idx]
#      print(yamas)
#  else:
#      # 最小のダムが0になるまで-2していく
#      tmp_A = [i - min_dam for i in tmp_A]
#      print(tmp_A)
#      yamas = [0,0]
#      for i in range(2, N):
#          yamas.append(int((tmp_A[i]-yamas[-1]/2)*2))
#      yamas = yamas[N-min_dam_idx:] + yamas[:N-min_dam_idx]
#      print(yamas)


'''
コンテスト後
雨の総量をSとおくと、
S = A1 + A2 + ... An
S = (W1+ W2 + ... Wn)/2
A1 = (W1+W2)/2
つまり、
2 = (W1+W2)/2
A2 = (W2+W3)/2
つまり、
2 = (W2 + W3)/2
S = 2A1 + 2A3 + ... 2AN//2

W1 = S - (W2 + W3 + ... Wn) = S - 2(A2 + A4 ... + An-1)
W1 = 8 - 2(2)
W2 = 8 - 2()

W1 + W2 = 2A1
W2 = 2A1 - W1
W2 = 2*2 - 4 = 0
W3 = 2A2 - W2 = 2*2 - 0 = 4
'''

S = sum(A)
W = [0 for i in range(N)]
W[0] = S - 2*sum([i for idx, i in enumerate(A[1:]) if idx % 2 == 0])
for i in range(1, N):
    W[i] = 2*A[i-1] - W[i-1]
for w in W:
    print(w, end=' ')

Submission status: Accepted

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

l = l+l
xl = []
for i in range(2):
    a = 0
    m = False
    for j in range(i, n+i):
        if m is False:
            a += l[j]
            m = True
        else:
            a -= l[j]
            m = False
    xl.append(a)
    
for i in range(2, n):
    xl.append(xl[-2] - l[i-2]*2 + l[i-1]*2)
    
print(" ".join(map(str, xl)))

Submission status: Accepted

Solution code:
n = int(input())
water = [int(x) for x in input().split()]
sum1 = sum(water)
sum2 = sum([v for i, v in enumerate(water) if i%2==1])

ans = [0] * n
ans[0] = sum1 - 2 * sum2
for i in range(1, n ):
    ans[i] = (water[i - 1] - ans[i - 1]//2) * 2
print(*ans)

Submission status: Accepted

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

m=[0]*n

for i in range(n):
  if i%2 == 0:
    m[0]+=a[i]
  else:
    m[0]-=a[i]
for i in range(1,n):
  m[i] =(a[i-1]-m[i-1]/2)*2
  
for i in range(n):
  print(int(m[i]),end=" ")

Submission status: Accepted

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

lo = 0
hi = max(2*A[0],2*A[-1])+1

while hi-lo > 0:
    mid = (hi+lo)//2
    t = mid
    for k in range(N):
        t = B[k]-t
    if t == mid:
        break
    elif t > mid:
        lo = mid
    else:
        hi = mid
C = [0 for k in range(N)]
C[0] = mid
for k in range(1,N):
    C[k] = B[k-1] - C[k-1]
print(*C)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A_LIST = np.array(list(map(int, input().split())))

x_list = np.zeros(N)
start_index = 0
x_list[start_index] = (A_LIST.sum() - 2 * A_LIST[1::2].sum()) / 2
tmp_index = start_index
for _ in range(N-1):
    next_index = (tmp_index+1) % N
    x_list[next_index] = A_LIST[tmp_index] - x_list[tmp_index]
    tmp_index = next_index
ans = ' '.join((x_list * 2).astype(int).astype(str))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
# l = int(((N*N)+1)/2)
b = []
for i in range(N):
    if i%2==0:
        b.append(1)
    else:
        b.append(-1)
c = np.dot(np.array(b),a)
x = [c]
for j in range(1,N):
    x_j = 2*a[j-1] - x[j-1]
    x.append(x_j)
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Accepted

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

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

f = 1
x1 = 0
for a in A:
    x1 += (a * f)
    f *= -1

x1 /= 2

X = []
X.append(x1)

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

X = [str(int(2 * x)) for x in X]
# print(X)

print(" ".join(X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main03():
    data = int(input())
    data2 = input().split()
    num = []
    for i in range(data):
        num.append(int(data2[i]))
    are = 0
    for i in range(1,data,1):
        if i % 2 == 1:
            are = are + num[i]
        else:
            are = are - num[i]
    are = num[0] - are
    results = []
    are = int(are / 2)
    results.append(are)
    for i in range(data-1):
        are = num[i] - are
        results.append((are))
    for i in range(data):
        print((results[i]*2), end='')
        print(" ", end='')
    print("")

if __name__ == "__main__":
    main03()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
xs = [None] * N
xs[0] = sum(A[i] * (1 if i % 2 == 0 else -1) for i in range(N))
for i in range(1, N):
    xs[i] = 2 * A[i - 1] - xs[i - 1]
print(' '.join(map(str, xs)))

Submission status: Accepted

Solution code:
a = int(input())
b = input().split(' ')

for i in range(len(b)):
    b[i] = int(b[i])

c = []
c_odd = 0
c_even = 0
for j in range(len(b)):
    if j % 2 != 0:
        c_odd = c_odd + b[j]
    else:
        c_even = c_even + b[j]
    
c_0 = c_even - c_odd
c.append(c_0)

for k in range(len(b) - 1):
    c.append(int(2 * (b[k] - c[k] / 2)))

for l in range(len(c)):
  c[l] = str(c[l])

print(' '.join(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    N = int(input())
    dam_list  = list(map(int, input().split(" ")))
    water_list = [0 for i in range(N)]
    upstream = dam_list[N-1]
    downstream = 0
    
    for i in range(N):
        water_list[N-1-i] = water_list[N-1-i] + upstream
        water_list[i] = water_list[i] + downstream

        if i == N-1:
            break

        upstream = upstream * -1 + dam_list[N-1 - (i+1)]
        downstream = downstream * -1 + dam_list[i]

    for i in water_list:
        print(i, end=" ")
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
v = list(map(int,input().split()))
v = v[0]
a = [int(e) for e in input().split()]
r = [0 for _ in range(v)]
r[0] = sum(a[0:v:2]) - sum(a[1:v:2])
for i in range(v -1):
     r[i +1] = -r[i] +2*a[i]
print(*r)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [None] * len(A)
    X[0] = sum(A) - 2 * sum([A[i] for i in range(1, len(A), 2)])
    for i in range(len(A)-1):
        X[i+1] = 2 * A[i] - X[i]
    
    print(' '.join(list(map(str, X))))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = sum(a)

x1 = s - 2 * (sum(a[1::2]))  # 偶数番目のindexを取得
x = [x1]
for i in range(2, n + 1):
    x.append(2 * a[i - 2] - x[i - 2])

print(*x)

Submission status: Accepted

Solution code:


N = int(input())
waterlist = list(map(int, input().split()))
mountain = [0 for _ in range(N)]
S = 0
for i in range(N):
    S += waterlist[i]
# print(S)
x1 = S
for i in range(1, N, 2):
    x1 -= waterlist[i] * 2
mountain[0] = x1
# print(x1)
for i in range(1, N):
    mountain[i] = 2*waterlist[i-1]-mountain[i-1]

# print(mountain)
# A = np.array(matrix)
# inv_A = np.linalg.inv(A)
# # print(inv_A)

# ansmatrix = inv_A.dot(W)*2
# # print(ansmatrix)
message = ""
for i in range(N):
    message += str(int(mountain[i]))
    if i == (N - 1):
        break
    message += " "
print(message)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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

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

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

    print(*x)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int,input().split()))
cc=1
d=[0 for i in range(a)]
d[0]=sum(b[0::2])-sum(b[1::2])
print(str(d[0]), end="")
for i in range(1,a):
  d[i]=b[i-1]*2-d[i-1]
  print(" "+str(d[i]), end="")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa = a+a
g = sum(a)//2
ans = []
for i in range(1):
    temp = sum([aa[i+1+j*2] for j in range(n//2)])
    ans.append(g-temp)
temp = ans[0]
for i in range(1,n):
    temp = a[i-1] - temp
    ans.append(temp)
for k in ans:
    print(2*k,end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
# まずX_1を求める
x_1 = s
for i in range(1,n,2):
    x_1 -= 2*a[i]
ans = [x_1]
for i in range(1, n):
    ans.append(2*a[i-1]-ans[i-1])
print(" ".join(list(map(str, ans))))

Submission status: Accepted

Solution code:
import sys

def solve(N, A):
    m = [int()] * (N)
    for i in range(N):
        m[0] += A[i] * (-1)**i

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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

M_list.append(sum(A_list)- 2 * sum(A_list[1::2])) 
#print(M_list[0])

for i in range (0,N-1):
         M_list.append(2 * A_list[i] - M_list[i])


print(*M_list)

Submission status: Accepted

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

N = int(input())
a_ = list(int(x) for x in input().split())
X_ = [0 for _ in range(N)]

X_sum = sum(a_)
logging.info("sum = " + str(X_sum))

X_[0] = X_sum - 2 * sum(a_[1::2])
logging.info("X_1 = " + str(X_[0]))

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

answer = ""
for i in X_:
    answer += str(i)
    answer += " "

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
c=l[-1]
for i in range(n-1):
  c=l[-i-2]-c
l1=[]
l1.append(str(c))
c1=c//2
for i in range(n-1):
  c1=l[i]-c1
  l1.append(str(c1*2))
print(" ".join(l1))

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(A)
x = s - 2 * sum(A[1::2])
print(x, end='')

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

Submission status: Accepted

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

reply_list =  []
for i in range(n):
    if i == 0:
        reply_list.append(sum(a_list[::2]) - sum(a_list[1::2]))
    elif i == 1:
        reply_list.append(a_list[0] + sum(a_list[1::2]) - sum(a_list[2::2]))
    else:
        reply_list.append(reply_list[-2] + a_list[i-2]*(-2) + a_list[i-1]*2)

reply_list = map(str, reply_list)
print(' '.join(reply_list))

Submission status: Accepted

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

ret_lst = []

S = sum(a)

a_even = a[1::2]

m1 = S - 2 * sum(a_even)
ret_lst.append(m1)

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

    ret_lst.append(next_m)

N = [str(n) for n in ret_lst]

print(' '.join(N))

Submission status: Accepted

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

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

ans = [X]

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

Submission status: Accepted

Solution code:
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

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

xn = 0
for i in range(n-1):
    xn = xn + (-1) ** (i+1) * int(A[i])

xn = xn + A[n-1]

x = []
x1 = 2*A[n-1]-xn
x.append(x1)

for i in range(n-1):
    xi=2*A[i]-x1
    x.append(xi)
    x1 = xi
print(*x)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
arr=[0]*(n)
fin=sum(a)
for i in range(len(a)):
    arr[i] = a[i]*2
sub = 0
for i in range(n-2,-1,-2):
    sub+=arr[i]
final=[]
final.append(fin-sub)
for i in range(n-1):
    final.append(arr[i]-final[-1])
print(*final)

Submission status: Accepted

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

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

res[0] = sum(A)

for i in range(N-1):
    if i%2 == 1:
        res[0] -= 2 * A[i]

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

result = ''
for res in res:
    result += str(res) + ' '
    
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if i % 2 == 0:
        print(evn[i] + A[i] + odd[N] - odd[i + 1], end="")
    else:
        print(odd[i] + A[i] + evn[N] - evn[i + 1], end="")
    
    if i < N - 1:
        print(" ", end="")
    else:
        print()

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(len(A)) if i % 2 == 1])
ansList = [x1]
for i in range(1, N):
    tmp = 2 * A[i-1] - ansList[-1]
    ansList.append(tmp)
ansList = [str(a) for a in ansList]
ans = ' '.join(ansList)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_rain = sum(a) // 2

rest_rain = 0
for i in range(1, n, 2):
    rest_rain += a[i]
first_ans = (sum_rain - rest_rain) * 2

res = []

res.append(first_ans)
prev_ans = first_ans

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

print(*res)

Submission status: Accepted

Solution code:
n = int(input())
dum = list(map(int, input().split()))
ame = [0]*n
S = sum(dum)
dumeven, dumodd = 0, 0

for i in range(0, n, 2):
    dumeven += dum[i]
for i in range(1, n-1, 2):
    dumodd +=  dum[i]
    
ame[0] = dumeven - dumodd
for i in range(1, n):
    ame[i] = 2*dum[i-1] - ame[i-1]
for i in range(n):
    print(str(ame[i]) + ' ', end="")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input())
a_list = list(map(int, input().split()))
x_list = []

s = sum(a_list)
x = s - 2 * sum(a_list[1::2])
x_list.append(x)
before = x
for i in range(n-1):
    x = 2 * a_list[i] - before
    x_list.append(x)
    before = x
print(' '.join(map(str, x_list)))

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
A = np.array(list(map(int, input().split())))
sgn = np.tile(np.array([1, -1]), N // 2)
sgn = np.concatenate([sgn, np.array([1])])
ans = np.empty(N, dtype=np.int)
ans[0] = (A * sgn).sum()
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 = [int(i) for i in input().split()]
List = [0 for i in range(N)]
Sum = 0
for i in range(1,N-1,2):
    Sum += A[i]
List[0] = sum(A)-(2*Sum)
for i in range(1,N):
    List[i] = 2*A[i-1]-List[i-1]

for i in List:
    print(i,end=" ")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solv(n, dams):
    m = (sum(dams[::2]) - sum(dams[1::2])) // 2
    ans = [m*2]
    for d in dams[:-1]:
        m = d - m
        ans.append(m*2)
    return ans


if __name__ == '__main__':

    n = int(input())
    dams = [int(a) for a in input().split()]
    ans = solv(n, dams)

    print(' '.join([str(a) for a in ans]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solv(n, dams):
    m = (sum(dams[::2]) - sum(dams[1::2])) // 2
    ans = [m*2]
    for i in range(n-1):
        m = dams[i] - m
        ans.append(m*2)
    return ans


if __name__ == '__main__':

    n = int(input())
    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)

    print(' '.join([str(a) for a in ans]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = [sum((1 if i%2==0 else -1)*v for i, v in enumerate(A))//2]

while len(ans)<n:
  ans.append(A[len(ans)-1]-ans[-1])

print(' '.join(map(str, map(lambda x: 2*x,ans))))