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())
list1=list(map(int,input().split()))
list2=[]
def calc(n):
    tempsum=0
    for j in range(1,n+1):
        tempsum+=((-1)**(n-j))*list1[j-1]
    return tempsum
list2.append(calc(N))
for i in range(1,N):
    list2.append(2*list1[i-1]-list2[i-1])
str1=""
for i in range(len(list2)):
    str1+=str(list2[i])
    if i==len(list2)-1:
        print(str1)
    else:
        str1+=" "

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
sa = sum(a)
sa2 = sum(a[::2]) * 2
a.append(a[0])
ans[0] = sa2 - sa

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-



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

  Bn = [0 for _ in range(N)]
  while(True):
    for i in range(1,N):
      Bn[i] = (An[i-1]-Bn[i-1]//2)*2
    if (Bn[-1]+Bn[0])//2 == An[-1]:
      return Bn
    else:
      Bn[0] = An[-1]-Bn[-1]//2

if __name__ == "__main__":
  Bn = main()
  for b in Bn:
    print(b)

Submission status: Accepted

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

Kosui = [0]*N

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

    ans = [0] * N
    sign = -1
    for a in A:
        sign *= -1
        ans[0] += sign * a

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mixed = False
    for i in range(1, N):
        if A[i] % 2 != A[0] % 2:
            mixed = True
            break
    flag = 0
    if mixed:
        for i in range(N):
            if A[i] % 2 == 1:
                flag = i
                break
    Tentative = [0] * N
    for i in range(N-1):
        Tentative[(flag + i + 1) % N] += A[(flag + i) % N] - Tentative[(flag + i) % N]
        Tentative[(flag + i) % N] *= 2
    Tentative[(flag + N - 1) % N] *= 2
    dam = (Tentative[flag] + Tentative[flag - 1]) // 2
    diff = A[flag - 1] - dam
    if diff != 0:
        for i in range(N//2):
            Tentative[(flag + i) % N] += diff * (-1) ** (i % 2)
            Tentative[(flag - 1 - i) % N] += diff * (-1) ** (i % 2)
        Tentative[(flag + N // 2) % N] += diff * (-1) ** ((N//2) % 2) 

    print(" ".join(map(str, Tentative)))
 
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

x=x+A[N-1]
z=x
ans=[]
for i in range(N-1):
  ans.append(str(x))
  x=2*A[i]-x
ans.append(str(x))
print(" ".join(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

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

s = sum(a)

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

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


print(*ans)

Submission status: Accepted

Solution code:
input()
ff = [int(x) for x in input().strip().split(" ")]
a = sum([f if i%2 == 0 else -f for i, f in enumerate(ff)])
print(a, end=" ")
for f in ff[:-1]:
    a = 2*(f - a//2)
    print(a, end=" ")

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    x = [0] * N
    sumx = sum(A)
    x[0] = sumx - sum(A[1::2]) * 2
    for i in range(1, N):
        x[i] = A[i - 1] * 2 - x[i - 1]
    print(*x)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = [None] * N
x[0] = sum(A) - 2 * sum([a for a in A[1::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(int, input().split()))
avg = [0] * N

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

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

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

Submission status: Accepted

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

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


for i in range(1, n):
    y[i] = 2 * a[i - 1] - y[i - 1]
    
y = [str(i) for i in y]
print(" ".join(y))

Submission status: Accepted

Solution code:
dams_num = int(input())
dams_water = list(map(int, input().split()))

water_sum = sum(dams_water)
x_one = water_sum - 2 * (sum(dams_water[1:dams_num - 1:2]))
mountains_water = [x_one]
pre_x = x_one
for i in range(0, dams_num - 1):
    next_x = 2 * dams_water[i] - pre_x
    mountains_water.append(next_x)
    pre_x = next_x
print(' '.join(map(str, mountains_water)))

Submission status: Accepted

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

x[0] = 0
for i in range(n):
    aa = a[i] if i % 2 == 0 else -a[i]
    x[0] += aa
for i in range(1,n):
    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()))
X = [0] * N

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
total = sum(A)
X = np.zeros(N)
X[0] = total 

n =int((N-1)/2 )
for i in range(1,n+1):
    X[0] = X[0] - 2*A[2*i-1]
for j in range(1,N):
    X[j] = 2*A[j-1] - X[j-1]
for i in range(N):
    print("{}".format(int(X[i])),end=" ")

Submission status: Accepted

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

x1 = sum(A) - 2 * sum(A[1::2])
ans = []
ans.append(str(x1))
for i in range(N-1):
    x1 = 2 * A[i] - x1
    ans.append(str(x1))
print(' '.join(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

for num in X:
    print(num,end = " ")
print()

Submission status: Accepted

Solution code:
a=int(input())
a1 = a // 2
b1=list(input().split( ))
b=list(map(int, b1))
d=[]

s1=0
for j in range(a1):
    s1 += b[(2*j + 1)]
x1 = sum(b) - 2 * s1
d.append(x1)

for k in range(a-1):
    x = 2 * b[k] - d[k]
    d.append(x)

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

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
r = [-1]*N
sumA_ev = sum([A[i] for i in range(N) if i%2 == 1])
r[0] = sum(A) - 2*sumA_ev
for i in range(N-1):
  r[i+1] = 2*A[i] - r[i]
print(" ".join(map(str,r)))

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

all_mount = sum(A) // 2
A_1 = all_mount
for i in range(1, N, 2):
  A_1 -= A[i]
  
mounts = [A_1]
for i in range(N-1):
  mounts.append(A[i] - mounts[i])
  
print(" ".join(map(str, mounts)))

Submission status: Accepted

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

X = [0]*N

# X[0]を求めたい
hoge = 0
for i in range(1, N, 2):
    hoge += A[i]

X[0] = sum(A)-2*hoge

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

X_str_list = map(str, X)

ans = " ".join(X_str_list)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np


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


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    x = [0 for _ in range(n)]
    x[0] = sum(a) - (sum(a[1:n:2]) * 2)
    for i in range(2, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    x[1] = sum(a) - (sum(a[2:n:2]) * 2)
    for i in range(3, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    print(*x)


main()

Submission status: Accepted

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

# R = [r1, r2, ..., rn]
# a1 == r1//2 + r2//2
# a2 == r2//2 + r3//2
# ...
# an == rn//2 + r1//2
#
# a1 - a2 + a3 - a4 + ... - a{n-1} + an == r1

sgn = (-1 if i % 2 == 0 else 1 for i in range(1, N + 1))
r1 = sum(a * s for a, s in zip(A, sgn))

R = [r1]
for a in A:
    R.append(2 * a - R[-1])

print(' '.join(map(str, R[:-1])))

Submission status: Accepted

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

rain_sum=sum(a)  # 雨量の総和

ans=[]

t=0
for i in range(0,N-2,2):
    t += a[i]*2

Tn = rain_sum - t
T1 = a[N-1]*2 - Tn

ans.append(T1)

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

print(*ans)

Submission status: Accepted

Solution code:
# ABC133 D-Rain flows into dams

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

X = [0]*(N+1) # ふった雨の量を入れるリスト
S = sum(A)
X[0] = S - 2*(sum(A[1::2]))
X[N] = X[0]
for i in range(N):
    if i == 0:
        continue
    else:
        X[i] = 2*A[i-1] - X[i-1]
        
print(*X[:N])

Submission status: Accepted

Solution code:
# 2019/07/08
# かんにんぐ

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

res=[0]*n
res[0]=sum(A)-2*sum(A[1:n:2])

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

print(*res)

Submission status: Accepted

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

X = [0] * N

dam_amount = sum(A)

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

X[0] = dam_amount - 2*aaa

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

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

Submission status: Accepted

Solution code:


n = int(input())
Dn = list(map(int, input().split()))#ダム


memo = 0 # M_n = M_0
for i in range(n):
    memo += Dn[i]*(-1 if i%2==0 else 1)

memo *= -1

#print(memo)



M0_max = min(Dn[0], Dn[-1])*2 
Mn0 = 0

def set_Mn0():

    for i in range(0, M0_max+1, 2):
    
        valid = i == memo 
#    print(i, memo, valid)
#    print(Dn)
#    print()

        if valid:
            Mn0 = i
            break


m0_l = 0
m0_h = M0_max
mid = m0_l + m0_h
mid = mid//2 + mid%2

while mid != memo:
    if memo < mid :
        m0_h = mid
    else:
        m0_l = mid
    
    mid = m0_l + m0_h
    mid = mid // 2 + mid%2
    
    #print(mid)

Mn0 = mid


Mn = [0]*n
Mn[0] = Mn0
for i in range(1,n):
    Mn[i] = 2*Dn[i-1]-Mn[i-1]

print(*Mn)

Submission status: Accepted

Solution code:
n=int(input())
la=list(map(int,input().split()))
s=sum(la)
lk=[2*la[1+2*i] for i in range(n//2)]
k=sum(lk)
ly=[s-k]
for i in range(n-1):
    ly.append(2*la[i]-ly[i])
for k in ly:
    print(k,end=" ")

Submission status: Accepted

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

import sys
import copy
import math

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~

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()))
# solve
x = 0
for i in range(N):
    if i%2==0:
        x+=A[i]
    else:
        x-=A[i]
ans = [x]
for i in range(N-1):
    x = ans[i]
    ans.append(2*A[i]-x)
print(*ans)

Submission status: Accepted

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

l = -1
r = 2 * 10 ** 9 + 2

def f(m):
    C = A[:]
    C[0] -= m // 2
    C[-1] -= m // 2
    for i in range(n - 1):
        C[i + 1] -= C[i]
        C[i] = 0
        if C[i + 1] < 0:
            return i % 2 == 1
    if C[-1] == 0:
        return True
    return n % 2 == 0
    
while abs(r - l) > 1:
    # if r % 2 == 1:
    #     r -= 1
    # if l % 2 == 1:
    #     l += 1
    m = (l + r) // 2
    if f(m):
        r = m
    else:
        l = m

C = A[:]
C[0] -= r // 2
C[-1] -= r // 2
ans = [r]
for i in range(n - 1):
    ans.append(2 * C[i])
    C[i + 1] -= C[i]

print(*ans)

Submission status: Accepted

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

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

print(*l)

Submission status: Accepted

Solution code:
# x_(n+1) = 2*a_n - x_n
def xn(ans,a,n):
  for i in range(n-1):
    ans[i+1]=2*a[i]-ans[i]
  return ans
  

n = int(input())
A = list(map(int,input().split()))
ans = [0]*n
ans[0] = sum(A)-2*sum(A[1:n:2])
ans = xn(ans,A,n)
print(" ".join(list(map(str,ans))))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A_s = list(map(int,input().split()))
X_s = []
X_s.append(sum(A_s)-2*sum(A_s[1::2]))
for i,a in enumerate(A_s):
  X_s.append(2*A_s[i]-X_s[i])
X_s.pop()
print(' '.join(map(str,X_s)))

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
a=sum(A)//2#sumx
P=[0]*(N+1)
Q=[0]*(N+1)
for i in range(1,N+1):
    if i%2==1:
        P[i]+=P[i-1]+A[i-1]
    else:
        P[i] += P[i - 1]
T=[0]*N
T[0]=P[-1]-a
for i in range(1,N):
    T[i]=A[i-1]-T[i-1]
for t in T:
    print(2*t,end=' ')

Submission status: Accepted

Solution code:
input()
a=[int(x) for x in input().split()]
b=sum(a)-2*sum(a[1::2])
ans = [b]
for x in a:
    b = x*2-b
    ans.append(b)
print(*ans[:-1])

Submission status: Accepted

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

cnt =1
rain_others = 0
while cnt != n:
    rain_others += l[cnt] * 2
    cnt += 2
ans.append(sum(l)-rain_others)

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

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

Submission status: Accepted

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

s = sum(A)
x = []

A_ = sum([A[i] for i in range(1,n,2)])
x1 = s - 2*A_
x.append(x1)

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


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

Submission status: Accepted

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

alpha = (sum(A[:len(A):2])-sum(A[1:len(A)-1:2]))

ans = [alpha]

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    if i%2 == 0:
        x += a[i]
    else:
        x -= a[i]
x = x//2

for i in range(n):
    mount.append(x)
    x = a[i] - x
mount = list(map(lambda x: str(x*2), mount))

print(" ".join(mount))

Submission status: Accepted

Solution code:
import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

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

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x

Submission status: Accepted

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

l = -2
r = 2 * 10 ** 9 + 2

def f(m):
    C = A[:]
    C[0] -= m // 2
    C[-1] -= m // 2
    for i in range(n - 1):
        C[i + 1] -= C[i]
        C[i] = 0
        if C[i + 1] < 0:
            return i % 2 == 1
    if C[-1] == 0:
        return True
    return False
    
while abs(r - l) > 2:
    m = (l + r) // 2
    if m % 2 == 1:
        m -= 1
    if f(m):
        r = m
    else:
        l = m

C = A[:]
C[0] -= r // 2
C[-1] -= r // 2
ans = [r]
for i in range(n - 1):
    ans.append(2 * C[i])
    C[i + 1] -= C[i]

print(*ans)

Submission status: Accepted

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

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

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

print(*ans)

Submission status: Accepted

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

answer = (sum(A) - 2 * sum([A[i] for i in range(N) if i % 2 != 0])) // 2
answer_list = []
answer_list.append(answer)
for j in A:
  if (j - answer) < 0:
    break
  answer = j - answer
  answer_list.append(answer)
if answer_list[0] == answer_list[-1] and len(answer_list) == N+1:
  print(' '.join([str(i*2) for i in answer_list[:N]]))
  exit()

Submission status: Accepted

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

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

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

ans = ' '.join([str(n) for n in Y])
print(ans)

Submission status: Accepted

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

s=sum(a)

res=list()
res.append(s-2*sum([a[(2*j+1)] for j in range(int((n-1)/2))]))

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

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

Submission status: Accepted

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

lastx = sum(
    a * (1 if i % 2 == 0 else -1)
    for i, a in enumerate(A)
) // 2
print(lastx * 2, end="")

for a in A[:-1]:
    lastx = a - lastx
    print(" " + str(lastx * 2), end="")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = [0] * N
    ans[0] = sum(A) - 2*sum(A[1:N:2])
    for i in range(1, N):
        ans[i] = 2*A[i-1] - ans[i-1]
    return ' '.join(map(str, ans))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()] 
a = np.array(a)
x = np.zeros(n)

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
y,m = [],0
for i in range(1,n,2): m+=x[i]
p = sum(x)//2-m
for i in range(n):
    y.append(str(p*2))
    p = x[i]-p
print(" ".join(y))

Submission status: Accepted

Solution code:
### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<=r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m+1
        m=(l+r)//2
    else:
        r=m-1
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()

Submission status: Accepted

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

l = -1
r = 10 ** 9 + 1

def f(m):
    C = A[:]
    C[0] -= m // 2
    C[-1] -= m // 2
    for i in range(n - 1):
        C[i + 1] -= C[i]
        C[i] = 0
        if C[i + 1] < 0:
            return i % 2 == 1
    if C[-1] == 0:
        return True
    return False
    
while abs(r - l) > 1:
    m = (l + r) // 2
    if f(m * 2):
        r = m
    else:
        l = m

C = A[:]
C[0] -= r
C[-1] -= r
ans = [r * 2]
for i in range(n - 1):
    ans.append(2 * C[i])
    C[i + 1] -= C[i]

print(*ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

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

res = list()
res.append(A_sum - 2 * sum([A[(2*j+1)] for j in range(int((N-1)/2))]))

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

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

Submission status: Accepted

Solution code:


N = int(input())
p = N // 2
A = [int(s) for s in input().split()]
assert len(A) == N
total = sum(A)

ans = [0] * N
core_even = sum(A[i] for i in range(0, N + 1, 2))
core_odd = sum(A[i % N] for i in range(1, N + 1, 2))

for i in range(N):
    new_idx = (2 * p + i) % N
    if i >= 2 and i % 2 == 0:
        core_even += A[new_idx] - A[i - 2]
    if i >= 3 and i % 2 == 1:
        core_odd += A[new_idx] - A[i - 2]

    if i % 2 == 0:
        ans[i] = 2 * core_even - total
    else:
        ans[i] = 2 * core_odd - total

print(*ans)

Submission status: Accepted

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


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    A = read_h()

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

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

    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = [0]*N
tmp = 0
for i in range(N):
    if i % 2 == 0:
        tmp += A[i]
    else:
        tmp -= A[i]
x[0] = tmp
for i in range(1, N):
    x[i] = int(2 * (A[i - 1] - x[i - 1] / 2))

output = ""
for i in range(N):
    output += str(x[i]) + " "
print(output)

Submission status: Accepted

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

s = 0

for i in range(N):
    s = A[i] - s
    # print('A[i]',A[i])
    # print(s)

x = s//2
B = [0]*N

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

print(*B)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
x2 = 0
for i in range(N):
    if i%2 == 0:
        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(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = []
x = 0
for j in range((N - 1) // 2):
	x += A[2 * j + 1]
B.append(S - 2 * x)
for i in range(N - 1):
	x = A[i] * 2 - B[i]
	B.append(x)
C = [str(a) for a in B]
print(' '.join(C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
S = sum(lst)
ans = []

for i in range(2, N, 2):
  S -= 2 *lst[i-1]
  
ans.append(S)

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

s = " ".join([str(n) for n in ans])
print(s)

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
A = [int(n) for n in A]
S = sum(A)
X1 = S
result = []
for i in range(1,N-1,2):
    X1 -= 2*A[i]

result.append(X1)
text = str(X1)

for i in range(N-1):
    result.append(2*A[i]-result[i])
    text += " " + str(result[i+1])

print(text)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
dam = list(map(int, input().split()))
yama = [-1] * n

min_dam = min(dam)
min_dam_arg = np.argmin(dam)

s = sum(dam)
yama[0] = s - 2 * sum(dam[1::2])
for i in range(1, n):
    yama[i] = 2 * (dam[i-1] - yama[i-1]/2)

yama = map(int, yama)
print(' '.join(map(str, yama)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# x1さえ求めてしまえば連立方程式の解は連鎖的にO(N)で求まる
X = list()
x_1 = sum(A)
for i in range(N):
    if i % 2 != 0:
        x_1 -= 2 * A[i]
X.append(x_1)

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

Submission status: Accepted

Solution code:
def d_rain_flows_into_dams(N, A):
    first = sum(A) - 2 * sum(A[1::2])
    ans = [first] + [0] * (N - 1)
    for i in range(N - 1):
        ans[i + 1] = 2 * A[i] - ans[i]
    return ' '.join(map(str, ans))

N = int(input())
A = [int(i) for i in input().split()]
print(d_rain_flows_into_dams(N, A))

Submission status: Accepted

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

x = [0 for _ in range(n)]
_x = 0
for i, _a in enumerate(a):
    if i % 2 == 0:
        _x += _a
    else:
        _x -= _a

x[0] = _x

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

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