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:
def main():
    from itertools import cycle
    from operator import add, sub

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

    cycl_oper = cycle((add, sub))

    M0 = 0  # 山0(0-ind)への降雨量
    for op, x in zip(cycl_oper, A):
        M0 = op(M0, x)

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

    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
y = [0 for _ in range(n)]
suma = sum(a)
ans = []
memo1 = 2*sum([a[j%n] for j in range(0, 0+n, 2)])-suma
memo2 = 2*sum([a[j%n] for j in range(1, 1+n, 2)])-suma
ans.append(str(memo1))
ans.append(str(memo2))
# (i+n-2)%n - (i-2)%n
for i in range(2,n):
	if i%2 == 0:
		memo1 = memo1 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo1))
	else:
		memo2 = memo2 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo2))
print(" ".join(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()

ans = [2*A[0]]

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

error = (ans[0]+ans[-1])//2 - A[-1]

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

Submission status: Accepted

Solution code:
import numpy as np

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

ans = []

ans.append(str(sum(W) - 2 * sum([W[i] for i in range(N) if i % 2 == 1])))

for i in range(1, N):
    ans.append(str( 2*W[i-1] - int(ans[i-1])))

print(" ".join(ans))

Submission status: Accepted

Solution code:

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

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

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))
x = [0 for i in range(n)]
start = sum(a)
for i in range(1, n, 2):
    start -= 2 * a[i]
# print(start)
x[0] = start
for i in range(n - 1):
    x[i + 1] = 2 * a[i] - x[i]
print(*x)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
D = list(map(int, sys.stdin.readline().rstrip().split()))
D_sum = 0 
D_sum_gusu = 0

for i, d in enumerate(D, 1):
    D_sum += d
    if i % 2 == 0:
        D_sum_gusu += d

ans = []

r = D_sum - 2 * D_sum_gusu
ans.append(r)
for d in D[:-1]:
    r = 2 * d - r
    ans.append(r)

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

ans=[0]*n

ans[0]=sum([A[i]*((-1)**i) for i in range(n)])
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()))

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

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [None]*N
    twox = 0
    for i in range(N):
        twox += A[i] * (-1)**i
    R[0] = int(twox)
    for i in range(1, N):
        R[i] = int((A[i-1] - R[i-1]/2)*2)
    print(' '.join(map(str, R)))
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

tmp = 0
for i in range(N):
    tmp = A[i] * 2 - tmp

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

print(*ans)

Submission status: Accepted

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

s = sum(a)

start = s-2*sum(a[1::2])

li = [start]

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

print(*li)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ev=[]
for i in range(n):
  if i%2==1:ev.append(a[i])
x=[0]*n
x[0]=sum(a)-2*sum(ev)
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()))
pA = [(-1)**(0)*A[0]]
mA = [(-1)**(0+1)*A[0]]
for i in range(1,N):
  pA.append((-1)**(i)*A[i] + pA[i-1])
  mA.append((-1)**(i+1)*A[i] + mA[i-1])

ansl = []
for s in range(N):
  if s == 0:
    ansl.append(pA[N-1])
  else:
    if s%2 == 0:
      ansl.append( pA[N-1]-pA[s-1] + mA[s-1] )
    elif s%2 == 1:
      ansl.append( mA[N-1]-mA[s-1] + pA[s-1] )
print(*ansl)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy as np
B = []
m = N//2
b = 0
for i in range(m):
  b = b + A[2*i] - A[2*i+1]
b += A[N-1]
B.append(b)
n = 0
for i in range(N-1):
  c = 2*A[i]-B[n]
  B.append(c)
  n += 1
B=[str(d) for d in B]
B=" ".join(B)
print(B)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    wa=sum(l)
    lgu=l[1::2]
    yama1=wa-2*sum(lgu)
    pre=yama1
    print(pre,end=' ')
    for i in range(n-1):
        nextyama=2*l[i]-pre
        pre=nextyama
        print(nextyama,end=' ')
    print()
resolve()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    m=n//2
    a=list(map(int,readline().split()))

    s=sum(a)//2
    ans=[0]*n
    k=n-1
    t=0
    if n==3:
        for i in range(n):
            ans[k]=(s-a[i])*2
            k+=1
            k%=n
    else:
        for i in range(n):
            if i==0:
                tmp=i
                for j in range(m):
                    t+=a[i]
                    i+=2
                    i%=n
                nex=i
            else:
                t-=a[tmp]
                tmp+=2
                tmp%=n
                t+=a[nex]
                nex+=2
                nex%=n
            ans[k]=(s-t)*2
            k+=2
            k%=n

    print(*ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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

first = sum([a*2 if i%2==0 else -a*2 for i, a  in enumerate(As)])//2
ans = [str(first)]
for i, a in enumerate(As[:-1]):
    ans.append(str((a*2)-first))
    first = (a*2)-first
print(' '.join(ans))

Submission status: Accepted

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

ans = []
x0 = sum(a) - 2 * sum(a[1::2])
ans.append(x0)

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

print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
goukei = sum(A)
jama = 0

for i in range(n // 2):
    jama += A[2 * i + 1]

ans = [0] * n

ans[0] = goukei - jama * 2

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

print(*ans, sep=" ")

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

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

    print(*B)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split())) #ダムの水
#山ダム山ダム山ダム。。。。。
B=[0]*N
A1=0
for i in range(N):
    if i%2==0:
        A1+=A[i]
    else:
        A1-=A[i]
B[0]=A1
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())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if i%2==0:
    ans+=a[i]
  else:
    ans-=a[i]
for i in range(n):
  print(int(ans))
  ans=(a[i]-ans/2)*2

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split()))
s = 0
for i,a in enumerate(A):
    if i%2:
        s -= a
    else:
        s += a

ans = [-1 for i in range(N)]
ans[0] = s

for i in range(1,N):
    ans[i] = (A[i-1]-ans[i-1]//2)*2
print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
N = int(input())

A = list(map(int,input().split()))
s = 0
for i,a in enumerate(A):
    if i%2:
        s -= a
    else:
        s += a

ans = [-1 for i in range(N)]
ans[0] = s

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

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    x = sum(a[::2]) - sum(a[1::2])
    ans = str(x)
    tmp = x
    for i in a[:-1]:
        tmp = 2 * i - tmp
        ans += ' ' + str(tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    x1 = sum(a[::2]) - sum(a[1::2])
    x = [0] * n
    ans = str(x1)
    tmp = x1
    for i in a[:-1]:
        tmp = 2 * i - tmp
        ans += ' ' + str(tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    x1 = sum(a[::2]) - sum(a[1::2])
    x = [0] * n
    x[0] = x1
    for i, j in enumerate(a[:-1], 1):
        x[i] = 2 * j - x[i - 1]
    ans = ' '.join(map(str, x))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    x1 = sum(a[::2]) - sum(a[1::2])
    x = [x1]
    for i in a[:-1]:
        x.append(2 * i - x[-1])
    ans = ' '.join(map(str, x))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(1,n):
    if i==n-1:
        x[n-1]=2*a[n-1]-x[0]
    else:
        x[i]=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()))
s = sum(a) - sum(a[1::2]) * 2
print(s)
for i in a[:-1]:
    j = (2*i)-s
    print(j)
    s = j

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
p = All-sum(a2[1::2])
a3 = [p]
for i in range(n-1) :
    p = a[i]*2 - p
    a3.append(p)
mountain = ""
for j in range(n) :
    mountain += str(a3[j])
    if j == n-1 :
        print(mountain)
        exit()
    mountain += " "

Submission status: Accepted

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

result = ""
for i in range(n):
    if i != 0: result += " "
    result += str(b[i])
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
tot = sum(a) // 2
ans = [-1] * n
now = sum(a[:n - 1:2])
i = 0
j = n - 1
while ans[j] == -1:
    ans[j] = tot - now
    now += a[j] - a[i]
    j = (j + 2) % n
    i = (i + 2) % n
print(*map(lambda x: 2 * x, ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    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]

    print(*B)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = []
dif = 0

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

ans.append(s-2*dif)

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


print(*ans)

Submission status: Accepted

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

mt_rain =[0]*N
mt_all =sum(A)
dam_even = sum(A[1::2]) #偶数番目のダムの増えた水
mt_rain[0] = mt_all - 2*dam_even #1番目の山の降水量

#2番目の山以降
for i in range(1,N):
    mt_rain[i] =2*A[i-1] -mt_rain[i-1]
print(*mt_rain)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
num = 0
Ans = [0] * N
for a in A:
    num = (a - num // 2) * 2

num //= 2
for i, a in enumerate(A):
    Ans[i] = str(num)
    num = (a - num // 2) * 2

print(' '.join(Ans))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

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

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

    print(*ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(*ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = tuple(map(int, input().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:
import sys
n = int(input())
a = [ 2*int(i) for i in sys.stdin.readline().split()]
f = (sum(a) - 2* sum(a[1::2]))//2
ans = [f] + [0 for i in range(n-1)]
for i in range(n-1):
    ans[i+1] =  a[i] - ans[i]
print(" ".join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = [ 2*int(i) for i in sys.stdin.readline().split()]
ans = [0 for i in range(n)]
for i in range(1, n):
    ans[i] = a[i-1] - ans[i-1]
ans[0] = (a[n-1] - ans[n-1])//2
for i in range(1, n):
    ans[i] +=  ans[0]*(-1)**(i%2)
print(" ".join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

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

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

C = [0] * N
sign = [(-1)**(i+1) for i in range(N)]

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

ans_n1 = C[N-1] // 2
for i in range(N-1):
    print(C[i] + sign[i] * ans_n1, end=' ')
print(ans_n1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
d_ls = list(map(int, input().split()))
m_0 = 0
for i in range(n):
    if i % 2 == 0:
        m_0 += d_ls[i]
    else:
        m_0 -= d_ls[i]
m_ls = [0] * n
m_ls[0] = m_0
for i in range(n-1):
    m_ls[i+1] = 2*d_ls[i] - m_ls[i]
m_ls = list(map(str,m_ls))
print(' '.join(m_ls))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
xp = sum(a[::2]) - sum(a) // 2
ans = [xp * 2]
for i in range(N - 1):
    ans.append((a[i] - xp) * 2)
    xp = a[i] - xp
print(' '.join(list(map(str, ans))))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,sin,cos
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
chk=0
ans=[]

for i in range(2,n,2):
    chk+=arr[i-1]

x1 = sum(arr)-chk*2
#print(sum(arr),chk)
ans.append(x1)
for i in range(1,n):
    ans.append(2*arr[i-1] - ans[i-1])
print(*ans)

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()))

target = sum(a)//2

b = a[1:n:2]
a.append(a[0])

ans = []
ans.append((target-sum(b))*2)

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

for i in range(n):
    print(ans[i], end=' ')

Submission status: Accepted

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

tmp=0
for item in a:
    tmp=item-tmp
print(tmp)

mount=tmp

for item in a[:-1]:
    mount=(item-mount//2)*2
    print(mount)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
a2 = 0 # 一番最初の値を求める X1 = total A - 1つずつ (最初以外は、ペアとなる(足してXになる)相手が存在する) 
for i in range(1, n, 2):
    a2 += a[i]
 
ans = [0] * n
ans[0] = sum_a - 2*a2
for i in range(1, n):
    ans[i] = 2*a[i-1] - ans[i-1] # 最初がわかれば、あとは漸化式 Xi + Xi+1 = 2Aiに沿って算出可能
print(*ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
b0 = a[0]
b1 = a[0]
for i in range(1,N):
    c = a[i]
    if i % 2 == 0:
        b0 += c
        b1 -= c
    else:
        b0 -= c
        b1 += c
b[0] = b0
b[1] = b1
for i in range(2,N):
    b[i] = b[i-2] - 2*a[i-2]+2*a[i-1]
print(*b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
rain = [0] * N


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

M[0]=maxi//4
tmp=10**9

while M[0]/2 != tmp:
  for i in range(1,N):
    M[i]= 2*(A[i-1]-M[i-1]//2)
  tmp = A[-1] - M[N-1]//2
  #print(M,tmp)
  if M[0] != tmp*2:
    M[0] = (M[0]+tmp*2)//2
    if M[0]%2!=0:
      M[0] +=1
else:
  print(*M)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
a = 0
for i in range(N):
  a += (-1) ** i * A[i]
res = [0 for _ in range(N)]
res[0] = a
print('{} '.format(res[0]), end='')
for i in range(1, N - 1):
  res[i] = 2 * A[i-1] - res[i-1]
  print('{} '.format(res[i]), end='')
res[N-1] = 2 * A[N-2] - res[N-2]
print(res[N-1])