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:
#133d
import math
N = int(input()) #3≤N≤10^5 -1
A_list = list(map(int, input().split()))
ans_list=[]
#円形に N 個の山が連なっており、時計回りに山 1, 山 2, …, 山 N と呼ばれます。Nは奇数です。
#これらの山の間に N個のダムがあり、ダム 1, ダム 2, …, ダム N と呼ばれます。
#ダム i (1≤i≤N) は山 i と山 i+1 の間にあります (山 N+1 は山 1のことを指します)。
#山 i(1≤i≤N) に 2x リットルの雨が降ると、ダム i−1 とダム i にそれぞれ x リットルずつ水が溜まります
#(ダム 0 はダム Nのことを指します)。

#ある日、各山に非負の偶数リットルの雨が降りました。
#その結果、ダム i(1≤i≤N) には合計で Aiリットルの水が溜まりました。
#各山に降った雨の量を求めてください。この問題の制約下では解が一意に定まることが証明できます。

#ex
#3
#  2  2   4
#---------------
#4  0   4   (4)

#5
#  3   8   7   5   5
#2   4  12   2   8   (2)

#連立方程式を立てて、整理すると一番左端の回答は以下になる
first_ans = sum(A_list[0::2]) - sum(A_list[1::2])
ans_list.append(first_ans)
#それ以外は下記の式で求まるので回す。
for i in range(0,N-1):
    ans_list.append(2*A_list[i] - ans_list[i])
    
print(' '.join(map(str, ans_list)))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
n=0
for i in range(1,N):
    B.append(A[i]-B[-1])
B.append(A[0]-B[-1])
#print(B)
X=(B[0]-B[-1])//2
Y=[X]
Z=[X*2]
for i in range(N-1):
    Y.append(A[i]-Y[i])
    Z.append(Y[-1]*2)
print(*Z)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())
x = [0]*n

xsum = sum(a) // 2
x[0] = xsum - sum(a[1::2])

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

print(*list(map(lambda y: 2*y, x)))

Submission status: Accepted

Solution code:
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

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

print(str(b[n-1]) + " ",end = "")
for i in range(n-1):
    print(str(c[i]) + " ", end = "")

Submission status: Accepted

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

Submission status: Accepted

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

first_mountain = 0
for index in range(len(a_list)):
    if index % 2 == 0:
        first_mountain += a_list[index]
    else:
        first_mountain -= a_list[index]

mountain_rain[0] = first_mountain
for index in range(1, n):
    mountain_rain[index] = (a_list[index-1] - mountain_rain[index-1] // 2) * 2

ret = " ".join(map(str, mountain_rain))
print(ret)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split(" ")]
x = [np.sum(a) - np.sum(a[1::2])*2]
for i in a[:-1]:
    x.append(2*i-x[-1])
print(" ".join(map(str, x)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
lists=list(map(int,input().split()))
x_1=0
for _ in range(n):
    if _%2==0:
        x_1+=lists[_]
    else:
        x_1-=lists[_]
        
anslist=[]
anslist.append(x_1)
for i in range(n-1):
    x=2*lists[i]-anslist[-1]
    anslist.append(x)
print(*anslist)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())-1
As = list(map(int,input().split()))
ans = [0 for i in range(N+1)]
ans[0] = sum(As)
for i in range(N):
	if i % 2 == 1:
		ans[0] -= 2*As[i]
for i in range(1,N+1):
	ans[i] = 2*As[i-1]-ans[i-1]
s = ""
for e in ans:
    s += str(e)
    s += ' '
print(s[:-1])

Submission status: Accepted

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

S = sum(A)
sA = 0
for i in range(1,N,2):
    sA +=A[i]
x[0] = S - 2*sA
print(x[0],end=" ")

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

Submission status: Accepted

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

x = 0
for i in range(N): # x_0の値を得る
    if i % 2 == 0:
        x += A[i]
    else:
        x -= A[i]

for i in range(N):
    print(x, end=' ') # x_iをprint
    x = 2 * A[i] - x # x_(i+1)を得る

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]

for a in x:
    print(a, end=' ')

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    X = [0] * N
    S = sum(A)
    # 初期
    X[0] = S - sum([2*A[i] for i in range(1,N) if i%2 == 1])
    # 漸化式
    for i in range(1, N):
        X[i] = 2*A[i-1] - X[i-1]

    print(' '.join(map(str, X)))
    
    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:
#D
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
a.appendleft(0)
b=deque([0 for i in range(n+1)])
s=sum(a)
t=0
for i in range(1,(n-1)//2+1):
    t+=2*a[2*i]
b[1]=s-t
for i in range(2,n+1):
    b[i]=(a[i-1]-b[i-1]//2)*2
b.popleft()
print(" ".join(list(map(str,b))))

Submission status: Accepted

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

    top = (N + 1) // 2
    a1 = 0
    for i in range(top):
        if i == top - 1:
            a1 += A[i] * ((-1) ** i)
        else:
            a1 += (A[i] + A[~i]) * ((-1) ** i)

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

    print(*ans)


if __name__ == '__main__':
    p_d()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

i = 0
m = [0] * N
m[0] = i

tmp = m[-1]
m[-1] -= i // 2
for j in range(1, N):
    c = m[j - 1] // 2
    t = (L[j] - c) * 2

    m[j] = t

a = sum(m)
b = sum(L)
if a == b:
    print(m[-1], *m[:-1])
    exit()

m[-1] = tmp

i = b - a
m = [0] * N
m[0] = i

m[-1] -= i // 2
for j in range(1, N):
    c = m[j - 1] // 2
    t = (L[j] - c) * 2

    m[j] = t
print(m[-1], *m[:-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    N = ii()
    A = lmis()
    x = sum(A[::2]) - sum(A[1::2])
    for i in range(N):
        print(x)
        x = 2 * A[i] - x
        

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

"""解法
公式PDF

A_1＋ A_2 ＋ ... A_N = X_1 + X_2 + ... + X_N = S とする

(X_i + X_{i+1})/2 = A_i より

X_i + X_{i+1} = 2A_i

X1 = S - (X_2 + ... + X_N)
   = S - 2(A_2 + A_4 + A_{N-1})

これにより、X_1, X_2 ... を順に求めればよいが、O(N^2)は難しい

そこでO(N)で解くために

X_i + X_{i+1} = 2A_i より
X_{i+1} = 2 * A_i - X_i

の漸化式をつくれるので、それを解く
"""
import sys


def solve():
    N = int(sys.stdin.readline())
    As = list(map(int, sys.stdin.readline().split()))

    S = sum(As)
    Xs = [0]*N
    # 初期状態を決める(Xs[0])
    Xs[0] = S - 2 * sum(As[1:N:2])

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

    print(*Xs)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def solve(n, a):
    b0 = sum([((-1)**(i%2)) * a[i] for i in range(n)]) // 2
    b = [b0]
    for i in range(n-1):
        b.append(a[i]-b[i])
    b = [2*b[i] for i in range(n)]
    return " ".join(map(str, b))

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

Submission status: Accepted

Solution code:
n = int(input())
a_ls = [int(i) for i in input().split()]
last = a_ls[-1]
for i, a in enumerate(a_ls[:-1]):
    if i % 2 == 0:
        last -= a
    else:
        last += a
a_ls[-1] = last // 2
for i in range(n-2, -1, -1):
    a_ls[i] -= a_ls[i+1]
print(" ".join([str(i*2) for i in a_ls]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
xx1 = 0
x = []
for i in range(N):
    xx1 += a[N-1-i]*(-1)**(i)
    #print(xx1)
x1 = xx1//2
xi = 0
x.append(x1)
for i in range(1,N):
    xi = a[i-1] - x[i-1]
    x.append(xi)
ans = [str(k*2) for k in x]
print(' '.join(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

m_list = [0]*n
for i in range(0, n, 2):
    m_list[0] += a_list[i]

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


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

m_str = [str(m) for m in m_list]
print(' '.join(m_str))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x0 = sum([e * ((-1) ** i) for i, e in enumerate(a)]) // 2
x = [x0]
for i in range(1, n):
	x.append(a[i - 1] - x[-1])
xx = [str(2 * e) for e in x]
print(' '.join(xx))

Submission status: Accepted

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

for i in range(n-1):
    mt_amount[i+1] = dam_amount[i]*2 - mt_amount[i]
print(*mt_amount)

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    ans = [sum(a) - 2 * sum(a[1::2])]
    for _a in a[:-1]:
        ans.append(2 * _a - ans[-1])
    return " ".join(map(str, ans))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    ans = [sum(a) - 2 * sum(a[1::2])]
    for i in range(n - 1):
        ans.append(2 * a[i] - ans[-1])
    return " ".join(map(str, ans))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    e = [sum(a[1::2]), sum(a[2::2])]
    s = a[0] + sum(e)
    ans = []
    for i in range(n):
        ans.append(str(s - e[i % 2] * 2))
        if i < n - 1:
            e[i % 2] += a[i] - a[i + 1]
    return " ".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

s = sum(A)

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

for a in A[:-1]:
    x = 2 * a - x
    print('', x, end='')
print()

Submission status: Accepted

Solution code:
#奇数だから一個仲間外れにできるとの神(ki..sh..ak..i)の啓示

n = int(input())
a = [int(i) for i in input().split()]
w = [] #逆向きの答え
s = sum(a)/2
k = n//2
#w(n-1)を求める
a_odd = [a[2*i] for i in range(0,k)]
w.append(s-sum(a_odd))
for i in reversed(range(n-1)):
  w.append(a[i]-w[-1])
w.reverse()
for i in range(n):
  print(int(2*w[i]), end=" ")

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = [0]*N
    ans[0] = sum(A)
    for i in range(1,N,2):
        ans[0] -= 2*A[i]
    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:
N = int(input())
A = list(map(int, input().split()))

X = [0]*N
# 全体の和 - 偶数の和*2 = 一番目の値
# もしくは、(x/2)+(y/2)=A, ..B,..C -> x+y+z = A+B+C
X[0] = sum(A) - sum(A[1::2])*2

#最初の値から順番にダムの値を引けば答え
for i in range(1, N):
  X[i] = A[i-1]*2 - X[i-1]
  
print(*X)

Submission status: Accepted

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

N = int(input())
A = np.array(input().split())

rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1, N+1)%N])
mat = csr_matrix(([1]*(2*N), (rows, cols)), (N, N))
answer = (spsolve(mat,A) * 2 + .5).astype(int)
print(*answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

x = 0

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

ans = []
ans.append(x)

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

[print(x, end=" ") for x in ans]

Submission status: Accepted

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

M.append(sum(A[0::2])-sum(A[1::2]))
for i in range(1,N):
  M.append(-M[i-1]+A[i-1]*2)
print(" ".join(map(str,M)))

Submission status: Accepted

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

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

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

print(*ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
r = np.array([0]*(N+1))
for i in range(N):
  r[i+1] = A[i]-r[i]
x = r[N]
#print(r)
r[1::2] = r[1::2]*2-x
r[0::2] = r[0::2]*2+x
r = r[:N]
r = list(map(str,r))
print(" ".join(r))

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    f = sum(a)
    for i in range(1,N,2):
        f -= a[i]*2
    
    ans_list = [f]
    for i in range(N-1):
        ans_list.append((a[i]*2)-ans_list[-1])

    print(*ans_list)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * N
B[0] = sum(A[::2]) - sum(A[1::2])
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())
raw = list(map(int,input().split()))
a = 0
for i in range(n):
  a += (-1) ** i * raw[i]
ans = [a]
for i in range(n-1):
  ans.append(2*raw[i]-ans[-1])
print(' '.join(list(map(str,ans))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
dam_waters = tuple(map(int,input().split()))

rain_falls=[0 for _ in range(N)]
rain_falls[0] = sum(dam_waters[i]*(1-(i%2)*2) for i in range(N))
for i in range(1,N):
    rain_falls[i]=(dam_waters[i-1] - rain_falls[i-1]//2)*2

print(*rain_falls)

Submission status: Accepted

Solution code:
import numpy as np

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

X = [0]*N
X[0] = sum(A) - 2 * (sum(A[1:N-1:2]))
for i in range(1, N):
  X[i] = 2 * A[i-1] - X[i-1]
print (' '.join(map(lambda x: str(x), X)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dams = list(map(int, input().split()))
    S = sum(dams)
    res = [0]*N
    res[0] = S - 2*sum(dams[1:N:2])
    for i in range(1,N):
        res[i] = 2*dams[i-1]-res[i-1]
    print(*res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
a = inpl()
sum_a = sum(a)
a_2 = [i*2 for i in a]
ans = [0] * n

ans[0] = sum_a - sum(a_2[1::2])
for i in range(n-1):
    ans[i+1] = a_2[i] - ans[i]
print(*ans)

Submission status: Accepted

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

suma = sum(a)
for i in range(1, n, 2):
  suma -= 2*a[i]
x[0] = suma
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 = [int(x) for x in input().split()]
x = [0] * N
for i in range(N):
  x[0] += A[i] * (-1) ** i
for i in range(1,N):
  x[i] = x[i-1] * (-1) + 2 * A[i-1]
x = list(map(str,x))
print(" ".join(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
M = [0] * (2 * N)
for i in range(N):
  M[i + 1] = A[i] - M[i]
M[N] = (M[0] + M[N]) // 2
for i in range(N - 1):
  M[N + i + 1] = A[i] - M[N + i]
print(' '.join([str(m * 2) for m in M[N:]]))

Submission status: Accepted

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

N = int(input())
A = np.array(input().split())

#値の入る座標の準備
rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

#疎行列の作成
#csr_matrix((値だけのlist, 値の入る座標を示すtulpe:(rows, cols) ), 大きさ (N,N))
mat = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))
#print(rows,cols,mat)
 
answer = (spsolve(mat,A) * 2).astype(int)
print(*answer)

Submission status: Accepted

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

for i in range(n):
    b_arr[0] += (-1)**(i%2)*a_arr[i]

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

print(*b_arr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    
    X1 = sum(A) - 2*sum([a for a in A[1::2]])
    ans = [str(X1)]
    for i in range(1,N):
        ans.append(str(2*A[i-1]-int(ans[-1])))
    print(" ".join(ans))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(*M)

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    # print(A[1::2])
    X1 = sum(A) - 2*sum([a for a in A[1::2]])
    ans = [str(X1)]
    for i in range(1,N):
        ans.append(str(2*A[i-1]-int(ans[-1])))
    print(" ".join(ans))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = []
for i in range(2):
    ans.append(str(s - sum(A[i+1:N+i-1:2])*2 ))
for i in range(2,N):
    ans.append(str(int(ans[i-2])+(A[i-1]-A[N+i-2])*2))

ans = ' '.join(ans)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
Y=[0]*N
S=sum(X)

Y[0]=S-2*sum([X[i] for i in range(N) if i%2==1])

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

print(*Y)

Submission status: Accepted

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

x = []
rain_sum = sum(a)
x.append(rain_sum - 2 * (sum(a[1:n:2])))

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

print(*x)

Submission status: Accepted

Solution code:
n = int(input())
b_list = list(map(int,input().split()))
c_list = []
sum_num = 0
for i in range(n):
    sum_num += b_list[i] * (-1)**i
c_list.append(sum_num)
for i in range(1,n):
    c_list.append(-c_list[i-1]+2*b_list[i-1])
print(" ".join(map(str,c_list)))

Submission status: Accepted

Solution code:
n = int(input())
D = list(map(int, input().split()))
Dam = [0]*n
t = D[0]
for i in range(n-1):
    if i%2 == 0:
        t-=D[i+1]
    else:
        t+=D[i+1]
Dam[0] = t
#print(t)

for i in range(n-1):
    Dam[i+1] = (D[i] - Dam[i]//2)*2
for i in Dam:
    print(i, end=' ')

Submission status: Accepted

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

M = [0]*n

M[0] = sum(A[i] if i%2==0 else -A[i] for i in range(n))

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

Submission status: Accepted

Solution code:
import sys
from math import ceil
from operator import itemgetter as get

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

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nod(a, b):
    while b: 
        a, b = b, a % b
    return a
 
def calc(n, c, d):
    return n - n // c - n // d + n // (c * d // nod(c, d))   


def main():
    n = iinput()
    q = rlinput()
    res = [0] * n
    res[0] = sum(q) - 2 * sum(q[1::2])
    for i in range(1, n):
        res[i] = 2 * q[i - 1] - res[i - 1]
    res = map(str, res)
    print(*res)
main()

Submission status: Accepted

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

ans = [0] * (n + 1)
ans[0], ans[1] = a[0] * 2, 0
temp = 0
for num, con in enumerate(a[1:]):
    temp += con
    ans[num+2] = temp * 2
    temp *= -1

diff = (ans[-2] + ans[0]) // 2 - a[-1]

sign = -1
for i in range(n):
    ans[i] += sign * diff
    sign *= -1

print(*ans[:-1])

Submission status: Accepted

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

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

x = rain[n] / 2

for i in range(n):
    if i % 2 == 0:
        print(int(rain[i] + x), end= " ")
    else:
        print(int(rain[i] - x), end= " ")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans =[0]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
minus = sum(a_double[1:n-1:2])
ans[0] = sum_rain-minus

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:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


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

    ans = [0] * N

    # First mountain
    s = 0
    for i in range(len(nums)):
        if i % 2:
            s += nums[i]
        else:
            s -= nums[i]

    ans[0] = abs(s)

    for i in range(1, len(nums)):
        ans[i] = int((nums[i-1] - (ans[i-1] / 2)) * 2)

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = [0] * n
# 合計を求める
x[0] = sum(a)
# 初項x_1
for i in range(1, n - 1, 2):
    x[0] -= 2 * a[i]
# 漸化式で前から求める
for i in range(1, n):
    x[i] = 2 * a[i - 1] - x[i - 1]
print(*x)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = [sum(a) - sum(a[1::2]) * 2]
    for i in range(len(a)-1):
        b.append((a[i] - b[i] // 2) * 2)
    print(*b)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for e in B:
    print(e, end=" ")

Submission status: Accepted

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

x = [0] * n

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

d = ((x[0] + x[n-1]) - a[n-1]) // 2

for j in range(n):
    x[j] = x[j] - ((-1) ** j) * d

ans = [0] * n
for j in range(n):
    ans[j] = 2 * x[j]

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

Submission status: Accepted

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

Submission status: Accepted

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

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   
s = sum(a)
p = [0 for _ in range(n)]
q = [0 for _ in range(n+1)]
for i in range(n) :
    if i>1 :
        p[i] = p[i-2] + a[i-2]
    q[n-i-2] = q[n-i] + a[n-i-1]

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

Submission status: Accepted

Solution code:
# from https://atcoder.jp/contests/abc133/submissions/6272850
n=int(input())
a=[int(i) for i in input().split()]
c=[0]
s=sum(a)

for i in range(2*n):
    c.append(c[-1]+a[(i*2+1)%n])
ans=[0]*n
for i in range(n):
    ans[i*2%n]=s-2*(c[i+n//2]-c[i])
print(*ans)

Submission status: Accepted

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

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

res = dict()
res[n - 1] = a

for i in range(n - 1):
    res[n - 2 - i] = 2 * nums[n - 2 - i] - res[n - i - 1]
res = [res[i] for i in range(n)]
print(' '.join(map(str, res)))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x1 = sum([a[h] if h%2==0 else -a[h] for h in range(n)])
print(x1,end = ' ')

for i in range(n-1):
	if i == 0:
		b = a[i]*2 - x1
		print(b,end=' ')
	else:
		print(a[i]*2 - b,end=' ')
		b = a[i]*2 - b

Submission status: Accepted

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

yama[0] = sum(dam) - 2*(sum( dam[i] for i in range(N) if i % 2 == 1 ))


#雨の量を計算していく
for i in range(1,N):
        yama[i] = 2*dam[i-1] - yama[i-1]

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # print(A)
    tot = sum(A)
    sub = 0
    for i in range(N):
        if i % 2 == 0:
            sub += A[i]
    ans = []
    ans.append(2*sub-tot)
    for i in range(N-1):
        ans.append(2*A[i]-ans[-1])
    # print(ans)
    return ans
if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))