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 = tuple(map(int, input().split()))
M = [-1] * N
acc = 0
for i in range(1, N, 2):
    acc += A[i]
acc *= 2
M[0] = sum(A) - acc
for i in range(N-1):
    M[i+1] = 2*A[i] - M[i]
print(*M)

Submission status: Accepted

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

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    tmp = 0
    ans = [0] * n
    f = 1
    for i in a:
        tmp += f * i
        f = f * -1
    ans[0] = tmp
    ans[n - 1] = 2 * a[n - 1] - ans[0]
    for i in range(n - 2, 0, -1):
        ans[i] = 2 * a[i] - ans[i + 1]

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

b = []
for i in range(n):
    if (i == 0):
        b.append(s-2*e)
    else:
        b.append(2*a[i-1]-b[i-1])

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

Submission status: Accepted

Solution code:
n = int(input())
data = list(map(int, input().split()))
ans = [0]
for idx, a in enumerate(data):
    if idx%2 == 0:
        ans[0] += a
    else:
        ans[0] -= a

for i in range(n-1):
    dam = data[i]
    score = 2*dam - ans[-1]
    ans.append(score)

print(*ans)

Submission status: Accepted

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

b[0] = tmp-sum_r
#print(b[0])
for i in range(1,n):
    b[i] = a[i-1]*2-b[i-1]
    
print(" ".join([str(i) for i in b]))

Submission status: Accepted

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

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

mFR = [0]*(N+1)
for i in range(N):
    mFR[1] += A[i]*(pow(-1,i))
for i in range(2,N+1):
    mFR[i] = A[i-2]*2-mFR[i-1]
print(*mFR[1:])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    import sys

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
 
s_sum = sum(A)
 
ans = [None] * N
 
ans[0] = s_sum
for i in range(1, N, 2):
  ans[0] -= 2 * A[i]
 
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()))
a+=a
for i in range(2*n):
  if i%2:a[i]=-a[i]
for i in range(2*n-1):
  a[i+1]+=a[i]
a=[0]+a
for i in range(n):
  print(abs(a[n+i]-a[i]))

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
a=[int(i) for i in input().split()]
tmp = 0
res = [0]*n
f=1
for i in a:
    tmp += f*i
    f=f*-1
res[0]=tmp
res[n-1] = 2*a[n-1]-res[0]
for i in range(n-2,0,-1):
    res[i] = 2*a[i]-res[i+1]

print(*res)

Submission status: Accepted

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

Submission status: Accepted

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

B=[0 for i in range(N)]

B[0]=2
while 1:
  for i in range(1,N):
    B[i]=2*A[i]-B[i-1]
  if B[0]==2*A[0]-B[-1]:break
  else:
    B[0]= (B[0] + (2*A[0]-B[-1]))//2

B = [B[-1]]+B[:-1]

print(*B)

Submission status: Accepted

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

N=int(input().rstrip('\n'))
As = [int(x) for x in input().rstrip('\n').split()]
total = sum(As)
half = []
for i in range(N):
  if i==0:
    half.append((total-sum(As[1::2])*2)//2)
  else:
    half.append(As[i-1]-half[-1])
print(*[x*2 for x in half])

Submission status: Accepted

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

S = sum(A)
damu_sum = sum(A[1::2])
ans = S - 2 * (damu_sum)

ans_list = [ans]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))

    mount1_min = 0
    mount1_max = min(A_lsit[0], A_lsit[-1])

    mount_list = [0]*N

    while True:
        mount_list[0] = (mount1_min + mount1_max)//2
        for i in range(N-1):
            mount_list[i+1] = A_lsit[i] - mount_list[i]
        #print(mount_list)
        if A_lsit[N-1] - mount_list[N-1] == mount_list[0]:
            break
        elif A_lsit[N-1] - mount_list[N-1] < mount_list[0]:
            mount1_max = mount_list[0]
        else:
            if mount1_min != mount_list[0]:
                mount1_min = mount_list[0]
            else:
                mount1_min = mount_list[0]+1
    print(" ".join([str(m*2) for m in mount_list]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

# 2* x_0 = A[0] + A[N-1] + (A[2] + A[4] + ... (偶数項) ) - (A[1] + A[3] + ... (奇数項))
# あとは順次x_1, x_2, を求めていけば良い

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

X = [0] * N
X[0] = even - odd

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

X = [str(x) for x in X]
print(" ".join(map(str, X)))

Submission status: Accepted

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

# 2* x_0 = A[0] + A[N-1] + (A[2] + A[4] + ... (偶数項) ) - (A[1] + A[3] + ... (奇数項))
# あとは順次x_1, x_2, を求めていけば良い

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

X = [0] * N
X[0] = even - odd

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

X = [str(x) for x in X]
print(" ".join(X))

Submission status: Accepted

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


low=0
high=10**10

#binary search the value of rain onto Mountain1
while low<=high:
    mid=(low+high)//2

    cur=mid
    for i,a in enumerate(A):
        cur=a-cur
        if cur<0:#途中で足りなくなったら、midが大きすぎ
            break
       #break
    if cur>=mid:
        low=mid+1
    else:
        if i%2==0:
            high=mid-1
        else:
            low=mid+1


ans=[]
cur=high
for a in A:
    ans.append(cur*2)
    cur=a-cur
print(" ".join(map(str,ans)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
X = [0] * N
#iとi+1について式が成り立つ場合、漸化式がつくれる
X[0] = S - 2 * sum(A[1::2])
for i in range(1, N):
    X[i] = 2 * A[i-1] - X[i-1]
print(*X)

Submission status: Accepted

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

tmp = 0
pm = -1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
R.append(tmp)

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

print(*R)

Submission status: Accepted

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

'''プラススタート、マイナススタートの累積和を取る'''
plus_start = []
minus_start = []
'''後ろからの累積和'''
plus_start_rev = []
minus_start_rev = []

tmp = 0
pm = -1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    plus_start.append(tmp)
tmp = 0
pm = -1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    plus_start_rev.append(tmp)

tmp = 0
pm = 1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    minus_start.append(tmp)

tmp = 0
pm = 1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    minus_start_rev.append(tmp)

'''各山の降水量を計算する'''
for i in range(N):
    if i == 0:
        tmp = plus_start[-1]
        R.append(tmp)
        continue
    if i % 2 == 0:
        tmp = minus_start[i-1] + plus_start_rev[N-i-1]
    else:
        tmp = plus_start[i-1] + minus_start_rev[N-i-1]
    R.append(tmp)

print(*R)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())
    a_s = list(map(int, input().split()))

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

    add = a_s[-1] - ans[-1] // 2

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

    print(*ans)


# テストクラス


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
2 2 4"""
        output = """4 0 4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
3 8 7 5 5"""
        output = """2 4 12 2 8"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """3
1000000000 1000000000 0"""
        output = """0 2000000000 0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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

Submission status: Accepted

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

S = sum(A)
x1 = S - 2*sum(A[1::2])
 
X = [x1] * (N)
for i in range(1,N):
    X[i] = 2*A[i-1] - X[i-1]
 
print(' '.join([str(xi) for xi in X]))

Submission status: Accepted

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

def main(n,a):
    #a.insert(0,0)
    s=[0]*(2*n+1)
    sign=1
    for i in range(2*n):
        j=i%n
        s[i+1]=s[i]+sign*a[j]
        sign=sign*(-1)

    ans=[]
    sign=1
    for i in range(n):
        ans.append( sign*(s[n+i]-s[i]) )
        sign=sign*(-1)
    return ans

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(' '.join(map(str,ans)))

Submission status: Accepted

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

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

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

print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
#l, r = list(map(int, input().split()))
# A = list(map(int, input().split()))
a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
#a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#x = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
# for i in range(1, int(n**0.5)+1):
total = sum(a)
s = 0
for i in range(1, n):
    if i % 2 != 0:
        s += a[i]
x = []
x.append(total - 2*s)
for i in range(1, n):
    x.append(2*a[i-1]-x[i-1])

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

S = sum(A)

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

X1 = S - 2 * suma
ans = [X1]

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

print(*ans)

Submission status: Accepted

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

s = sum(a)
s1 = 0
for i in range(1,n,2):
    s1 += a[i]

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

print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    s = sum(a)
    s1 = 0
    for i in range(1,n,2):
        s1 += a[i]
    x1 = s-2*(s1)
    ans = [x1]
    for i in range(n-1):
        ans.append(2*a[i]-ans[-1])
    print(*ans)
    
main()

Submission status: Accepted

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

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


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

print(" ".join(map(str,[b[i]*2 for i in range(n)])))

Submission status: Accepted

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

b1 = 0
for index,i in enumerate(a):
  b1 += i * (-1)**(index)
b = [0]*n
b[0]=b1

for index,i in enumerate(a[:-1]):
  b[index + 1] = 2*i - b[index]
print(" ".join(str(i) for i in b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
A = rl()

X = 0
m = 1
for i in range(N):
	X += m*A[i]
	m *= -1

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

print(*[b*2 for b in B])

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
A = rl()

sumA = sum(A)

even = [0]
s = 0
for i in range(N-1, -(2*N+4), -2):
	s += A[i%N]
	even.append(s)
odd = [0]
s = 0
for i in range(N-2, -(2*N+4), -2):
	s += A[i%N]
	odd.append(s)

B = [0] * N
for i in range(N):
	r = 0
	if i%2==0:
		r = even[N//2-i//2+N//2+1]-even[N//2-i//2]
	else:
		r = odd[N//2-1-(i-1)//2+N//2+1]-odd[N//2-1-(i-1)//2]
	B[i] = r - (sumA-r)
print(*([B[-1]]+B[:-1]))

Submission status: Accepted

Solution code:
'''
        2 A1 = M_1 + M_2
        2 A2 = M_2 + M_3
        2 A3 = M_3 + M_4
        2 A4 = M_4 + M_5
        2 A5 = M_5 + M_1
A1 + A2 + A3 = M_1 + M_2 + M_3

M_1 = (A1 + A2 + A3) - (M_2 + M_3 + M_4 + M_5)
M_2 = (A1 + A2 + A3) - (M_3 + M_4 + M_5 + M_6)
M_3 = (A1 + A2 + A3) - (M_4 + M_5 + M_6 + M_7)
'''

n    = int(input())
ai   = list(map(int, input().split()))
aix2 = list(map(lambda x: x * 2, ai))

sum_a = sum(ai)

def ring_get(xs, s, e, mod):
    ys = []
    i  = s % mod

    while i != (e % mod):
        ys.append(xs[i])
        i = (i + 2) % mod

    return ys

beforeM = sum_a - sum(ring_get(aix2, 1, 1 + (n - 1), n))

print(beforeM)

for i in range(1, n):
    print(aix2[i - 1] - beforeM)
    beforeM = aix2[i - 1] - beforeM

Submission status: Accepted

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

Submission status: Accepted

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

b=[0]*n
oddsum=0
evensum=0
for i in range(n):
    if i%2==0:
        oddsum+=a[i]
    else:
        evensum+=a[i]

b[0]=oddsum-evensum

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

L=[str(a) for a in b]
ans=" ".join(L)
print(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[0] += A[i]
  else:
    ans[0] -= A[i]
for i in range(N-1):
  ans.append(2*(A[i] - ans[i]//2))
print(*ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    ans = [0] * N

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

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

    print(*ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

print(" ".join(str(i) for i in answer))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

sum_rain = sum(A)

# 山0以外の雨の総和
rest = 0
for i in range(1, N, 2):
    rest += A[i] * 2

rains = [0 for _ in range(N)]
rains[0] = sum_rain - rest
for i in range(1, N):
    rains[i] = (A[i-1] - rains[i-1] // 2) * 2

print(*rains)

Submission status: Accepted

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

#降った雨の総量
rain=sum(A)
#山Nに降った雨の量
r_N=rain
for  n in range(1,N):
    if n%2==1:
        r_N-=2*A[n-1]

ans=[]
tmp=r_N
for n in range(N):
    tmp=A[n-1]*2-tmp
    ans.append(tmp)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
r = np.array(list(map(int,input().split())))

pm = np.array([1,-1] * (n//2) + [1])


d = []
tmp = sum(r * pm)
d.append(str(tmp))
tmp -= r[0]

for i in range(n-1):
    tmp = r[i] - tmp
    d.append(str(tmp))
    tmp -= r[i+1]

print(' '.join(d))

Submission status: Accepted

Solution code:
N=int(input())
arr=list(map(int,input().split()))
total=sum(arr)
mt=[0]*N

for j in range(N-1):
    mt[j+1]=arr[j]*2-mt[j]
a=total-sum(mt)

for i in range(N):
    if i%2==0:
        mt[i]+=a
    else:
        mt[i]-=a
        
print(*mt)

Submission status: Accepted

Solution code:
import sys

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())


def main():
    N = ii()
    A = list(mi())
    B = [0]*N
    B[0] = sum(A[i]*((-1)**(i%2)) for i in range(N))
    for i in range(1, N):
        B[i] = 2*A[i-1]-B[i-1]
    print(*B)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp = sum(A[::2]) - sum(A[1::2])

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp_A = [0]*N
for i, x in enumerate(A):
	if i%2 == 0:
		tmp_A[i] = x
	else:
		tmp_A[i] = -x

tmp = sum(tmp_A)/2

ans = []

for i in range(N):
	print(int(tmp*2), end = " ")
	tmp = A[i] - tmp

print()

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

S = sum(A)
X = [0] * N

X[0] = S - 2 * sum(A[1::2])

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

print(*X)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


N = INT()
A = LIST()

a = [0] + list(accumulate(A[::2]))
b = [0] + list(accumulate(A[1::2]))

#print(a)
#print(b)

ans = []
for i in range(N):
	tmp = 0
	if i%2 == 0:
		tmp += a[-1] - a[i//2]*2
		tmp -= b[-1] - b[i//2]*2
	else:
		tmp += b[-1] - b[i//2]*2
		tmp -= a[-1] - a[(i+1)//2]*2
	ans.append(tmp)
print(*ans)

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
al = list(map(int, input().split()))
asum = sum(al)

first_q = al[1:n:2]
last_ind = n-2
curr_sum = sum(first_q)
q = deque(first_q)


ans = [0]*n
ans[0] = asum - curr_sum*2
for i in range(2,n,2):
    next_ind = (last_ind+2)%n
    next_a = al[next_ind]
    poped_a = q.popleft()
    curr_sum -= poped_a
    curr_sum += next_a
    ans[i] = asum - curr_sum*2
    last_ind = next_ind


first_q = al[2:n:2]
last_ind = n-1
curr_sum = sum(first_q)
q = deque(first_q)
ans[1] = asum - curr_sum*2
for i in range(3,n,2):
    next_ind = (last_ind+2)%n
    next_a = al[next_ind]
    poped_a = q.popleft()
    curr_sum -= poped_a
    curr_sum += next_a
    ans[i] = asum - curr_sum*2
    last_ind = next_ind

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
# ミソなのは対称性とかをきれいな解法を使わずに，a1を最初に求めて，そのあとは帰納法で次の数字を求めていくこと

S = sum(A)
x1 = S - 2*sum(A[1::2])

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

print(' '.join([str(xi) for xi in X]))

Submission status: Accepted

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

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

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

print(int(first*2), end = " ")
for i in range(len(c)):
  print(int(c[i]*2), end = " ")

Submission status: Accepted

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

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

S = sum(A)

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

Ret.append(S-2*s)

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

print(*Ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 0
for i,j in enumerate(a):
  if i%2==1:
    m+=-1*j
  else:
    m+=j
ans = [m]
for i in a[:-1]:
  b = -1*m+2*i
  ans.append(b)
  m = b
print(' '.join(map(str,ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    S = sum(A)
    X = [0 for _ in range(N)]

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

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


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(*ans)