Problem:


Score : 400 points

Problem Statement

There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.

Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).

When Mountain i (1 \leq i \leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).

One day, each of the mountains received a non-negative even number of liters of rain.

As a result, Dam i (1 \leq i \leq N) accumulated a total of A_i liters of water.

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 10^5-1

N is an odd number.

0 \leq A_i \leq 10^9

The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.

Sample Input 1

3
2 2 4

Sample Output 1

4 0 4

If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:

Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water.

Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water.

Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water.

Sample Input 2

5
3 8 7 5 5

Sample Output 2

2 4 12 2 8

Sample Input 3

3
1000000000 1000000000 0

Sample Output 3

0 2000000000 0



Sample input:
3
2 2 4


Sample output:
4 0 4

Submission status: Accepted

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

ans_list = [0]*N

not1_list = [ a_list[i] for i in range(1, N, 2) ]
ans_list[0] = sum(a_list) - 2 * sum(not1_list)
for i in range(1,N):
  ans_list[i] = a_list[i-1] * 2 - ans_list[i-1]
print(*ans_list)

Submission status: Accepted

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

mountains = [0]*N

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

mountains[0] = sum(dams)-2*sum_part_dams

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

print(*mountains)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a_s = sum(A)
lis=[0]*(N-1)
tmp = 0
sub=0
for i,a in enumerate(A[:-1:]):
  x = A[i]*2-tmp
  sub+=x
  lis[i]=x
  tmp = x
  
ans = [0]*N
a = a_s-sub
ans[0]=a
for i in range(1,N):
  if i%2==1:
    ans[i]=lis[i-1]-a
  else:
    ans[i]=lis[i-1]+a
    
print(*ans)

Submission status: Accepted

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

A_tmp = 0

for i in range(len(A)):
  if i%2 == 0:
    A_tmp += 2*A[i]
  else:
    A_tmp -= 2*A[i]

A1 = A_tmp // 2
ans = [A1]
for i in range(len(A)-1):
  ans.append(2*A[i]-ans[i])

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
A = list(map(int, input().split()))

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

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

for b in B:
    print(b)

Submission status: Accepted

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

N = int(input())
A = [int(x) for x in input().strip().split()]
S = sum(A)
x = [0 for _ in range(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:
n=int(input())
A=list(map(int,input().split()))
S=sum(A)//2
a=[]

for i in range(1,n,2):
  S=S-A[i]
a.append(2*S)
for i in range(n-1):
  a.append((A[i]-a[-1]//2)*2)
for i in range(n):
  print(a[i],end=' ')

Submission status: Accepted

Solution code:
n = int(input())
a = [2*int(_) for _ in input().split()]
t = a[-1]
x = [0 for _ in range(n)]
for i in range(-2, -n-1, -1):
    t = a[i] - t
x[0] = t // 2
for i in range(0, n-1):
    x[i+1] = a[i] - x[i]
for i in range(len(x)):
    print(x[i])

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
S = sum(A)
X1 = S -2*sum(A[1::2])
X = [0]*N
X[0] = X1
for i in range(0,N-1):
    X[i+1] = 2*A[i] - X[i]
for j in X:
  print(j,end=" ")

Submission status: Accepted

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

m1 = sum(A) - 2 * sum([x for i, x in enumerate(A) if i % 2 == 1])
ans = [m1]
for i in range(N-1):
    ans.append((A[i] - ans[-1] // 2) * 2)
print(*ans, sep=' ')

Submission status: Accepted

Solution code:
N=int(input())#奇数
D=[int(x) for x in input().split()]#ダムの貯水量
Ame=[0]
for i in range(N):
  Ame[0] +=D[i]*((-1)**i)
for i in range(1,N):
  Ame +=[2*D[i-1]-Ame[i-1]]
print(*Ame)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
asum = sum(a)
ad = 0

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

x.append((asum - ad))

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
# 山1に降った量の半分をxと置くと、山2はA1-x、山3はA2-(A1-x)となり、翻って山1はA3-(A2-(A1-x))
# x = A3-A2+A1+x
# x = (A1+A3-A2) // 2
x = (sum(A[::2]) - sum(A[1::2])) // 2
ans = [x*2]
for i in range(N-1):
    a = A[i] - x
    ans.append(a*2)
    x = a
print(*ans)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque()
for i in a:
  b.append(i)
c=0
for i in range(n):
  if i%2==0:
    c+=a[i]
  else:
    c-=a[i]
print(c)
for i in range(n-1):
  c=-c+2*b.popleft()
  print(c)

Submission status: Accepted

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


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

    total = sum(A)
    for i, a in enumerate(A):
        if i%2 == 0:
            continue
        total -= 2*a
    ans = [total]

    for i, a in enumerate(A):
        tmp = 2*a - ans[i]
        ans.append(tmp)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

# 解法メモ
# ひとつでも山の雨の量がわかれば全て求まる
# 3つの山があり、1つめの山の値をxとしたとき
# 1つめ: x
# 2つめ：A1 - x
# 3つめ：A2 - (A1 - x)
# 1つめ：A3 - (A2 - (A1 - x))
# 1つめ２つを式にする
# x = A3 - (A2 - (A1 - x))
# x = A3 - A2 + A1 - x
# 2x = A3 - A2 + A1
summary = 0

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

for i in range(N):
    print(summary)
    summary = (A[i] - (summary//2)) * 2

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	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)
	
	
	





if __name__ == '__main__':
	main()

Submission status: Accepted

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

ans=[0]*len(A)
without0=0
for i in range(1,len(A),2):
  without0+=A[i]
ans[0]=sum(A)-without0*2
for i in range(1,len(A)):
  ans[i]=A[i-1]*2-ans[i-1]
print(*ans)

Submission status: Accepted

Solution code:
# 2019-11-15 13:51:51(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    # x1 を求めると、連鎖的にxnまで求められる
    # n種類の降った量(x1, x2,...,xn)を求めるのに、それぞれのDとxを使ってちょうどn個の一次不定方程式が作れるので、解はただ一つの組みが存在する
    # nは必ず奇数
    n, *a = [int(x) for x in sys.stdin.read().split()]
    x0 = 0
    for i in range(n):
        if i % 2 == 0:
            x0 += a[i]
        else:
            x0 -= a[i]
    x0 //= 2 # 2x の量が一つの山にふる
    x = [x0]
    for i in range(1, n):
        xi = a[i-1] - x[i-1]
        x.append(xi)
    
    # xは半分の量のlistなので2倍して出力する
    for i in range(n):
        print(x[i] * 2, end=' ')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, A):
    """Test Case
    >>> print_ans(3, [2, 2, 4])
    4 0 4
    >>> print_ans(5, [3, 8, 7, 5, 5])
    2 4 12 2 8
    >>> print_ans(3, [1000000000, 1000000000, 0])
    0 2000000000 0
    """
    # x0 = S - (a2 + a4 + ...)
    S = sum(A)
    xr = [0] * N
    xr[0] = S - 2 * (sum(A[1::2]))
    for i in range(1,N):
        xr[i] = 2 * A[i-1] - xr[i-1] 
    print(" ".join(list(map(str, xr))))

if __name__ == '__main__':
    N =  int(input().rstrip())
    A= list(map(int, input().rstrip().split()))
    print_ans(N, A)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

b = [0]*N

b[0] = sum([A[i]*(-1)**i for i in range(N)])

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

print(*b)

Submission status: Accepted

Solution code:
def solve():
    N, *a_l = map(int, open(0).read().split())
    x_l = [0] * N

    x_l[0] = sum(a_l) - 2*(sum(a_l[1::2]))
    for i in range(1, N):
        x_l[i] = 2*a_l[i-1] - x_l[i-1]

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans_li = []

sum_val = sum(A) // 2
count = 0
for i in range((n - 1) // 2):
    count += A[2 * i + 1]

ans_li.append(2 * (sum_val - count))

for j in range(n-1):
    ans_li.append(2 * A[j] - ans_li[j])

print(*ans_li)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
#山の数

S=input().split()
damrainfall=list(S)
#各ダムに降った量　damrainfall[0]はNと1の間のダムのものとする

for i in range(n):
    damrainfall[i]=int(damrainfall[i])
#print(damrainfall)

totalrainfall=0
for i in range(n):
  totalrainfall+=damrainfall[i]

#totalrainfallは降った雨の総量

nigai=0
j=1
while j<n:
  nigai+=(damrainfall[j]*2)
  j+=2


mountainrainfall=[]
for i in range(n):
  mountainrainfall.append(0)

mountainrainfall[n-1]=totalrainfall-nigai

mountainrainfall[0]=damrainfall[0]*2-mountainrainfall[n-1]

k=1
while k<n:
  mountainrainfall[k]=damrainfall[k]*2-mountainrainfall[k-1]
  k+=1
  
print(mountainrainfall[n-1],end=" ")

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

sum_a = sum(al)

odd = 0
for i in range(n):
    if i % 2 == 1:
        odd += al[i]
        
ans_l = []
ans_l.append(sum_a - 2*odd)
his = sum_a - 2*odd
for i in range(n-1):
    his = al[i]*2 - his
    ans_l.append(his)

for i in ans_l:
    print(i)

Submission status: Accepted

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

i = 1
x = 0
result = []
for a in A:
    if i%2 == 0:
        x -= a
    else:
        x += a
    i += 1
result.append(x)
A.pop()
for a in A:
    tmp = 2*a - x
    result.append(tmp)
    x = tmp

print(*result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a = list(map(int,input().split()))
    l1=[0 for _ in range(n+1)]
    l2=[0 for _ in range(n+1)]

    for i in range(n):
        l1[i+1]=a[i]-l1[i]
    l1[0]=l1[n]
    l2[1]=a[0]-l1[0]
    l2[0]=l2[n]
    for i in range(1,n):
        l2[i+1]=a[i]-l2[i]
    ans=[]
    for i in range(n):
        ans.append( str(l1[i]+l2[i]) )
    print(' '.join(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    S=sum(A)
    oddS=sum(A[i] for i in range(1,n,2))
    ans=[0]*n
    ans[0]=S-2*oddS
    for i in range(n-1):
        ans[i+1]=2*A[i]-ans[i]
    print(*ans)
resolve()

Submission status: Accepted

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

def solve(N: int, A: "List[int]"):

    # ax+b
    xlist = [[1,0]]+[[] for _ in range(N)]
    for i in range(N):
        a = 0-xlist[i][0]
        b = A[i]*2-xlist[i][1]
        xlist[i+1]=[a,b]
    
    first = xlist[0]
    last = xlist[-1]
    a = first[0]-last[0]
    b = first[1]-last[1]
    x = -b//a

    answer = []
    for i in range(N):
        a = xlist[i][0]
        b = xlist[i][1]
        answer.append(a*x+b)
    
    print(*answer)

    return


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:
import sys
input = sys.stdin.readline

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

x1 = sum(A) - 2*sum(A[1::2])
X.append(x1)

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

print(*X)

Submission status: Accepted

Solution code:
# ABC133D - Rain Flows into Dams
def main():
    # X_0 = sum(A) - 2 * sum(A[1::2]), X_i = 2Ai - X_{i-1}
    N, *A = map(int, open(0).read().split())
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(" ".join(map(str, X)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

w = [0]*n
w[0] = sum(a) - 2*sum([ai for i, ai in enumerate(a) if (i + 1)%2 == 0])

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

print(*w)

Submission status: Accepted

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

list2 = [0]*n
dai1kou = 0
dai1kou += sum(list1[::2])
dai1kou -= sum(list1[1::2])
dai1kou = abs(dai1kou)
list2[0] = dai1kou
for i in range(1,n):
	list2[i] = (list1[i-1]-list2[i-1]//2)*2
print(" ".join(map(str,list2)))

Submission status: Accepted

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

ans=[]
for i in range(N):
    ans.append(0)

sum_A=sum(A)
sum_A_part=0
for j in range((N-1)//2):
    sum_A_part+=A[2*j]

ans[N-1]=sum_A-2*sum_A_part
ans[0]=2*A[N-1]-ans[N-1]
for k in range(1,N-1):
    ans[k]=2*A[k-1]-ans[k-1]

print(*ans)

Submission status: Accepted

Solution code:
# ABC133 D - Rain Flows into Dams
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()

A_even = []
M = [0]*N

for i in range(N):
    if i%2 == 1:
        A_even.append(A[i])

M[0] = sum(A)-2*sum(A_even)

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

print(*M)

Submission status: Accepted

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

s = sum(a)
b = 0
for i in range(1, n, 2):
    b += a[i]
result = [(s-b*2)//2]
for i in range(n-1):
    result.append(a[i]-result[-1])
result = [2*i for i in result]
print(*result)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N = I()
A = LI()
ans = [0]*N
dis = [0]*N
dis[0] = (A[1]-A[0])*2
for i in range(N-1):
    dis[i+1] = dis[i]+2*(A[-N+2*i+3]-A[-N+2*i+2])
#print(dis)

basic = (sum(A) - sum(dis))//N
ans[0] = basic
for i in range(1,N):
    ans[2*i-N] = basic + dis[i-1]

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
X = sum(A) - 2 * sum(A[1::2])

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

Submission status: Accepted

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

d = sum(A) // 2

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

for i in range(N):
    print(2 * d, end='')
    if i == N - 1:
        print('')
    else:
        print(' ', end='')
    d = A[i] - d

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
x=0
for i in range(1,N,2):
    x+=2*A[i]
X=[s-x]
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())
a = list(map(int, input().split()))
s = sum(a)//2
m = s - sum(a[1::2])
print(m*2, end=" ")
for i in range(n-1):
  m = a[i]-m
  print(m*2, end=" ")

Submission status: Accepted

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))

r_list = []
total = 0

for i in range(1, N, 2):
    total += a_list[i]

r_list.append(sum(a_list) - total * 2)

for i in range(1, N):
    r = a_list[i - 1] * 2 - r_list[i - 1]
    r_list.append(r)

ans = " ".join([str(w) for w in r_list])
print(ans)

Submission status: Accepted

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

answer_list = []

for i in range(N):
    answer = 0
    if i == 0:
        for j in range(N):
            # print(i, j, i-1-j, A[i-1-j])
            if j % 2 == 0:
                answer += A[i-1-j]
            else:
                answer -= A[i-1-j]
    else:
        answer = 2*A[i-1] - answer_list[i-1]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))

Submission status: Accepted

Solution code:
n = int(input())
bs = [int(x) for x in input().split()]
sign = 1
a_2 = bs[0]
for b in bs[1:]:
    a_2 += sign*b
    sign *= -1

ans = str(a_2) + ' '
for i in range(n-2):
    a_2 = 2*bs[i+1] - a_2
    ans += str(a_2) + ' '
ans = str(2*bs[i+2] - a_2) + ' ' + ans
print(ans)

Submission status: Accepted

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

ans_list = [0]*N
x = A[0]
for i in range(1, N-1):
    x += (-1)**i*A[i]
    
x += A[N-1]
ans_list[0] = str(x)
x //= 2
for i in range(N-1):
    x = A[i] - x
    ans_list[i+1] = str(2*x)
    
print(" ".join(ans_list))

Submission status: Accepted

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

minv = 0
maxv = 1000000000

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

ans = [0] * (n + 1)
ans[0] = nxt[n] // 2

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

Submission status: Accepted

Solution code:
# D - Rain Flows into Dams

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

rain = [-1]*N

sum_all = sum(A)
sum_skip = sum([A[idx] for idx in range(0,N-1,2)])

rain[-1] = sum_all - 2*sum_skip

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

print(*rain)

Submission status: Accepted

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

a_sum = sum(a)
a_sum //= 2

a_sum_0 = sum(a[1::2])

ans = []
a0 = a_sum -a_sum_0
ans.append(2*a0)
a[0] -= a0
for i in range(n-1):
    ans.append(2*a[i])
    a[i+1] -= a[i]
    
print(*ans)

Submission status: Accepted

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

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

a=1
for i in range(N):
    M[i]=S*a
    S=S-A[i]*a*2
    a*=(-1)

print(*M)

Submission status: Accepted

Solution code:
n = int(input())
dam = list(map(int, input().split()))
mt = [0]*n
# a[i]]は山iと山i+1に降った平均
mt[0] = sum(dam) - 2*sum(dam[1::2])
mt[n-1] = dam[n-1]*2-mt[0]
for i in range(1, n-1):
    mt[i] = dam[i-1]*2-mt[i-1]
print(' '.join(map(str, mt)))

Submission status: Accepted

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

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

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

print()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
oddsum = 0
for index in range(1, len(A), 2):
	oddsum += A[index]

x=[]
x.append(sum(A) - 2*oddsum)
for a in A[:-1]:
	x.append((a - x[-1]//2)*2)
print(" ".join(map(str, x)))

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 15 08:23:21 2019

@author: avina
"""

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

even_sum = 0
odd_sum = 0
for i in range(n):
    if i%2 ==0:
        even_sum+=l[i]
    else:
        odd_sum += l[i]
j = 0
for i in range(n):
    print(abs(even_sum - odd_sum), end = ' ')
    
    odd_sum, even_sum= even_sum - l[j],odd_sum + l[j]
    j += 1

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a=list(map(int,input().split()))
    r = []
    r.append(sum([a[i] for i in range(n) if i % 2 == 0])-sum([a[i] for i in range(n) if i % 2 ==1]))

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

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

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

S = sum(A)
x = S//2 - sum(A[1::2])

rain = [x+x]
for x in A[:-1]:
    rain.append(x+x-rain[-1])
print(' '.join(map(str,rain)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
dam = sum(A[::2]) - sum(A[1::2])

print(dam)
for i in A[:-1]:
    dam = (i - dam // 2) * 2
    print(dam)

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

x = [sum([a*(-1)**i for i, a in enumerate(A)])]

for a in A[:-1]:
  x.append(2*a - x[-1])

  
print(*x)

Submission status: Accepted

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

suma = sum(A)
tmp = 0
ans = [0] * N
for i in range(N):
    if i % 2 == 0:
        tmp += A[i]
ans[0] = (tmp*2) - suma
for i in range(N-1):
    ans[i+1] = (A[i] - (ans[i]//2))*2
print(" ".join(map(str, ans)))

Submission status: Accepted

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

    X1 = 0

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

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

    print(*X)



main()

Submission status: Accepted

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

    for i in range(N):
        ans[i] *= 2
    
    print(*ans)


main()

Submission status: Accepted

Solution code:
from itertools import*
n=int(input())
*a,=map(int,input().split())

a*=2
*odd,=accumulate([v if k%2 else -v for k,v in enumerate(a)])
*even,=accumulate([v if k%2==0 else -v for k,v in enumerate(a)])
#print(odd)
#print(even)
for i in range(n):
    if i%2==0:
        print(even[i+n-1]-even[i]+a[i],end=" ")
    else:
        print(odd[i+n-1]-odd[i]+a[i],end=" ")

Submission status: Accepted

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

t = [0] * N
t[0] = sum(A[::2]) - sum(A[1::2])
for i in range(1, N):
    t[i] = 2 * A[i - 1] - t[i - 1]
print(*list(map(str, t)))

Submission status: Accepted

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

t = [0] * N
t[0] = sum(A[::2]) - sum(A[1::2])
for i in range(1, N):
    t[i] = 2 * A[i - 1] - t[i - 1]
print(*[str(i) for i in t])

Submission status: Accepted

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

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

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

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

for i in range(N):
    if i < N - 1:
        print(B[i], end=' ')
    else:
        print(B[i])

Submission status: Accepted

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

# calculate 1st mount's rain
rain = 0
for i in range(N):
  if i%2==0:
    rain += dam_arr[i]
  else:
    rain -= dam_arr[i]
    
mount_arr.append(rain)

# caluculate others
for i in range(N-1):
  mount_arr.append(2*dam_arr[i]-mount_arr[-1])

mount_arr=[str(a) for a in mount_arr]
mount_arr=" ".join(mount_arr)
print(mount_arr)

Submission status: Accepted

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

for i, t in enumerate(a):
    double_x += (1 + -2 * (i % 2)) * t

ans[0] = double_x

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

print(*ans)

Submission status: Accepted

Solution code:
N=int(input())
D=[0]*N
A=list(map(int,input().split()))
for i in range(N):
    D[(i+1)*2%N] = D[i*2%N] + (A[(i*2+1)%N] - A[i*2%N])*2
r = (sum(A) - sum(D))//N
print(*list(map(lambda x: x+r, D)))

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0] * N
    S = sum(A)
    X[0] = S - 2 * sum([A[i] for i in range(N) if i % 2 == 1])
    A[0] -= X[0] // 2
    A[N-1] -= X[0] // 2

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

    print(*X)
    # print(*A)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
p = np.array(list(map(int,input().split())))
a0 = 0
for i in range(0,N,2):
    a0 += p[i]
    
for i in range(1,N-1,2):
    a0 -= p[i]
    
ans2 = [a0]*N
# iは-1している(slice)ので、+1しないといけないことに注意
for i,one in enumerate(p[1:]):
    ans2[i+1] = 2*p[i] - ans2[i] 
    
ans_s = ""
for one in ans2:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int , input().split()))
'''
#print(A)
b = [sum(A) - 2 * sum(A[1::2])]
print(b)
W = [0] * N
tmp0 = int(np.ceil(A[N-1] / 2) % 2)
tmp1 = int(np.ceil(A[0] / 2) % 2)
if tmp0 == 0 and tmp1 == 0:
    W[0] = int(min(np.ceil(A[N-1] / 2),np.ceil(A[0] / 2)))
elif tmp0 == 0 and tmp1 == 1:
    W[0] = int(np.ceil(A[N-1] / 2))
elif tmp0 == 1 and tmp1 == 0:
    W[0] = int(np.ceil(A[0] / 2))
else:
    W[0] = 0
for i in range(1,N):
    W[i] = 2 * A[i - 1] - W[i - 1]
print(*W)
'''
W = [0] * N
W[0] = sum(A) - 2 * sum(A[1:N - 1:2])

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
ans=[]

a=A.pop(0)
temp=0
for i in range(N-1):
    temp+=A[i]*(-1)**i

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

a=ans.pop(-1)    
print(a,*ans)

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())

    # b[0] == a[0] - a[1] + a[2] - a[3] + ...
    b = [sum(a) - 2 * sum(a[1::2])]

    for cur_a in a[:-1]:
        b.append(cur_a * 2 - b[-1])

    ans = b
    print(*ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())

    b = [sum([cur_a * (-1) ** in_i for in_i, cur_a in enumerate(a)])]

    for cur_a in a[:-1]:
        b.append((cur_a - b[-1] // 2) * 2)

    ans = b
    print(*ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())

    b = [cur_a*2 for cur_a in a]

    c = [0]
    for cur_b in b:
        c.append(cur_b - c[-1])
    compensation = c.pop(-1) // 2
    c = [cur_c + compensation * (-1) ** in_i for in_i, cur_c in enumerate(c)]

    ans = c
    print(*ans)
    return()

if __name__ == '__main__':
    main()