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()))
first = a_list[0]

l = 0
r = first
while l <= r:
    mid = (r + l) // 2
    m0 = mid * 2

    arr = [0] * (n + 1)
    arr[0] = m0
    for j in range(0, n):
        curr = arr[j]
        nxt = int((a_list[j] - curr / 2) * 2)
        arr[j + 1] = nxt
    
    mn = arr[n]
    if m0 == mn:
        print(*arr[:n])
        break
    elif mn > m0:
        l = mid + 1
    else:
        r = mid - 1

Submission status: Accepted

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

def check(m0):
    arr = [0] * (n + 1)
    arr[0] = m0
    for j in range(0, n):
        curr = arr[j]
        nxt = int((a_list[j] - curr / 2) * 2)
        arr[j + 1] = nxt
    return arr

r = (0, first)
while r[0] <= r[1]:
    mid = (r[0] + r[-1]) // 2
    m0 = mid * 2
    arr = check(m0)
    mn = arr[n]
    if m0 == mn:
        print(*arr[:n])
        break
    elif mn > m0:
        r = (mid + 1, r[1])
    else:
        r = (r[0], mid - 1)

Submission status: Accepted

Solution code:
#D問題
N = int(input())
A = list(map(int,input().split()))

B = []
for i in range(N):
    if i == N-1:
        B.append(A[0]-A[N-1])
    else:
        B.append(A[i+1]-A[i])
        
X = [0 for i in range(N)]
for i in range(N-1):
    oind = (2*i)%N
    nind = (2*(i+1))%N
    X[nind] = X[oind] + 2*B[oind]
    
SX = sum(X)
SA = sum(A)
d = (SA-SX)//N
for i in range(N):
    X[i]+=d
    print(X[i],end=" ")

Submission status: Accepted

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

M = [0] * N
total_rain = sum(A)
# まずM1を求める
# countは１つおきのダムの水量の総和
count = 0
for i in range(0, N, 2):
    count += A[i]
M[0] = 2 * count - total_rain
for i in range(N-1):
    M[i+1] = 2 * A[i] - M[i]
print(*M)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
x = np.array([0]*N)
sum_A = sum(A)
odd_A = sum(A[0::2])
x[0] = int(odd_A - sum_A/2)
for i in range(1,N):
    x[i] = A[i-1] - x[i-1]
x *= 2
print(*x)

Submission status: Accepted

Solution code:
N = int(input())

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

rain = Asum//2

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

Submission status: Accepted

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

Submission status: Accepted

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

M_1 = 0
for i,val in enumerate(dums):
    i+=1
    if i%2==1:
        M_1 += val
    else:
        M_1 -= val

out_dict = {i+1:0 for i in range(N)}
out_dict[1] = M_1

for i in range(1,N):
    out_dict[i+1] = 2*dums[i-1] - out_dict[i]

print(" ".join(list(map(str, out_dict.values()))))

Submission status: Accepted

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

# main
x = sum(A) - 2*sum([A[i] for i in range(1, N, 2)])
water = [x]

for i in range(N - 1):
  x = 2*A[i] - x
  water.append(x)
  # print("new water: ", water)

# output
print(*water)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [ int(i) for i in input().split() ]
start = 0
for i in range(n-1,-1,-1):
    if i % 2 == 0:
        start += a[i]
    else:
        start -= a[i]

ans = [start]
for i in range(0,n-1):
    ans.append( 2 * a[i] - ans[-1] )
for i in ans:
    print(i,end=" ")
print()

Submission status: Accepted

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

a = sum(An[0::2]) - sum(An[1::2])
output_list = [0] * N
output_list[0] = a
last = An[N-1] * 2 - a
output_list[N-1] = last
for i in range(N -2):
    output_list[N-i-2] = An[N-i-2] * 2 - output_list[N-i-1]
print(' '.join(map(str,output_list)))

Submission status: Accepted

Solution code:
n=int(input())
aList=list(map(int,input().split()))
rList = []
r1 = 0
for i in range(n):
	if i%2 == 0:
		r1 += aList[i]
	else:
		r1 -= aList[i]
rList.append(r1)

for i in range(n-1):
	r = (2 * aList[i]) - rList[i]
	rList.append(r)

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

Submission status: Accepted

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

"""
1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
S = sum(A)
X1 = S − 2(A2 + A4 + ... + AN−1)

2.以降の山も順次求めていく
Xi + Xi+1 = 2Ai 
Xi+1 = 2Ai − Xi
"""

## 1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
X1 = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
ans = [X1]

## 2.以降の山も順次求めていく
for n in range(1,N,1):
  _ = 2 * A[n-1] - ans[n-1]
  ans.append(_)


print(*ans)

Submission status: Accepted

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

X = [0] * (N+1)

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

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
rest = 0
x = input().split()
rest = 0

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

ans = [0]*n
ans[0] = 2 * a
for i in range(1, n):
  #print(int(x[i-1]), " ", ans[i-1]//2)
  ans[i] = 2*(int(x[i-1]) - ans[i-1]//2)
for i in range(n):
  print(ans[i])

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int,input().split()))
ans = [0 for _ in range(n)]

total = sum(lst) // 2
ans[-1] = (total - (sum(lst[::2])) + lst[-1])*2

for i in reversed(range(n-1)):
    ans[i] = (lst[i] - (ans[i+1]//2))*2

print(str(ans).replace('[','').replace(']','').replace(',',''))

Submission status: Accepted

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

Submission status: Accepted

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

A.append(A[0])

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

output = list()
output.append(x)
for i in range(0, N - 1):
    output.append(2 * A[i] - output[i])

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

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
A=list(map(int,input().split())) 
x = [0 for i in range(N)]
S =sum(A)
x[0]=S
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]
ans= map(str,x)
print(' '.join(ans))

Submission status: Accepted

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

while max(a) != min(a):
    for i in range(n):
        a1,a2,a3=a[i-1], a[i], a[(i+1)%n]
        if a2 > a1:
            val=min(a3, a2-a1)
            r[(i+1)%n]+=val*2
            a[i]-=val
            a[(i+1)%n]-=val
        if a2 > a3:
            val=min(a1, a2-a3)
            r[i]+=val*2
            a[i]-=val
            a[i-1]-=val

    for i in range(n)[::-1]:
        a1,a2,a3=a[i-1], a[i], a[(i+1)%n]
        if a2 > a1:
            val=min(a3, a2-a1)
            r[(i+1)%n]+=val*2
            a[i]-=val
            a[(i+1)%n]-=val
        if a2 > a3:
            val=min(a1, a2-a3)
            r[i]+=val*2
            a[i]-=val
            a[i-1]-=val

b=max(a)
print(" ".join(list(map(lambda x: str(x+b), r))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == '__main__':
	N = int(input())
	dam = np.array(list(map(int, input().split())))
	
	index_ = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
	ans = [int(np.dot(dam, index_))]
	for i in range(N-1):
		ans.append(2 * (dam[i] - ans[i]//2))
	ans = [str(i) for i in ans]
	print(' '.join(ans))

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

B = [0]*N

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

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

print(*B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial, ceil, floor # 階乗/切り上げ/切り捨て
from operator import itemgetter as ig
from collections import defaultdict as dd
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

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

    x = sum(A[::2]) - sum(A[1::2])
    r = [x]
    for n in range(N - 1):
        r += [A[n] * 2 - r[-1]]
    print(*r)

main()

Submission status: Accepted

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

s = sum(a)
s1 = 0
for i in range(1,len(a)):
    if i % 2 == 1:
        s1 += a[i]
x = s - 2*s1
ans = [x]
for i in range(len(a)-1):
    ans.append(2*a[i] - x)
    x = 2*a[i] - x
print(*ans)

Submission status: Accepted

Solution code:
def main(n, a):
    x = [0] * n
    # print(a)
    # print(a[1:-1:2])
    x[0] = sum(a) - 2 * sum(a[1:-1:2])
    for i in range(n - 1):
        x[i + 1] = 2 * a[i] - x[i]
    return ' '.join([str(xi) for xi in x])


N = int(input())
A = list(map(int, input().split()))
print(main(N, A))
# print(main(3, [2, 2, 4]))

Submission status: Accepted

Solution code:
num=int(input())
water=list(map(int,input().split()))
ans=[0 for _ in range(num)]
ans[0]=sum([((-1)**i)*a  for i,a in enumerate(water)])//2
for i in range(1,num):
    ans[i]=water[i-1]-ans[i-1]
print(" ".join(list(map(lambda x:str(x*2),ans))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
m1, m2 = 0, 0
for i in range(N):
  if i == 0:
    m1+=alist[i]
    m2+=alist[i]
  elif i%2 == 0:
    m1+=alist[i]
    m2+=-1*alist[i]
  else:
    m1+=-1*alist[i]
    m2+=alist[i]

ans = [m1, m2]
for i in range(2, N-1, 2):
  # index=i
  ans.append(ans[i-2] -2*alist[i-2] + 2*alist[i-1])
  # index=i+1
  ans.append(ans[i-1] - 2*alist[i-1] + 2*alist[i])

ans.append(ans[N-3] - 2*alist[N-3] + 2*alist[N-2])

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
m1, m2 = 0, 0
for i, a in enumerate(alist):
  if i == 0:
    m1+=a
    m2+=a
  elif i%2 == 0:
    m1+=a
    m2+=-1*a
  else:
    m1+=-1*a
    m2+=a    

ans = [m1, m2]
for i in range(2, N-1, 2):
  # index=i
  ans.append(ans[i-2] -2*alist[i-2] + 2*alist[i-1])
  # index=i+1
  ans.append(ans[i-1] - 2*alist[i-1] + 2*alist[i])

ans.append(ans[N-3] - 2*alist[N-3] + 2*alist[N-2])

print(*ans)

Submission status: Accepted

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

def func(dam_num, dam_volumes):
    water_amount = sum(dam_volumes)
    mountains_rain = [0]*dam_num
    mountains_rain[0] = water_amount

    # 最初の山の降水量を計算
    for i in range(dam_num//2):
        mountains_rain[0] -= 2*dam_volumes[2*(i+1)-1]

    # 漸化式　mountains_rain[i+1] = 2*dam_volumes[i] - mountains_rain[i]
    for i in range(dam_num-1):
        mountains_rain[i+1] = 2*dam_volumes[i] - mountains_rain[i]
    
    print(*mountains_rain)
    exit()


def main():
    n = int(input())
    a = [int(i) for i in input().split()] 

    func(n,a)
    
# main関数呼び出し
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC133D - Rain Flows into Dams
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:
# ABC133D - Rain Flows into Dams
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(*X)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

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

a = [0]*N

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

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

Submission status: Accepted

Solution code:
n = int(input())
*A, = map(int, input().split())
X = []
p = sum(A[::2])
q = sum(A[1::2])
for a in A:
    X += [p-q]
    p, q = q+a, p-a
print(*X)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
res = []
s = sum(l)
ts = 0
for i,t in enumerate(l):
    if i %2==1:
        ts+=t
    # print(s,ts)
res.append(s - 2*ts)
for i in range(n-1):
    t = 2*l[i] - res[-1]
    res.append(t)
print(*res)

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 a in A[:-1]:
    x = 2*a - x
    print(x, '', end='')

Submission status: Accepted

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

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

print(' '.join(list(map(str, w))))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

print(*x)

Submission status: Accepted

Solution code:
def rain_volume(A, N):
    X = [0]*N
    X[0] = sum(A)
    for i, a in enumerate(A):
        if i%2 != 0:
            X[0] -= 2*a
    for i in range(1, N):
        if i != 0:
            X[i] = 2*A[i-1] - X[i-1]
    return X

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

    print(' '.join(map(str, rain_volume(A, N))))

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int,input().split()))
X0 = sum(As) - 2 * (sum([As[j] for j in range(1,N-1,2)]))
Xs =[X0]
for i in range(1,N):
    Xs.append(2 * As[i-1]-Xs[i-1])
print(' '.join(list(map(str,Xs))))

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix,linalg
import itertools
n = int(input())
b = np.array([int(i) for i in input().split()])
rows = []
cols = []
for i in range(n):
    rows.append(i%n)
    rows.append(i%n)
    cols.append(i%n)
    cols.append((i+1)%n)

A = csr_matrix((np.ones(n*2,dtype=np.int32),(rows,cols)),(n,n))
x = linalg.spsolve(A,b)
print(*(int(i) for i in 2*x))

Submission status: Accepted

Solution code:

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

'''
M A M A ... A M
1 1 2 2     N 1

 M A M A M A M
 1 1 2 2 3 3 1
 x
 a1-x
 a2-(a1-x) = a2-a1+x
 a3-(a    ) = a3-a2+a1-x x


'''
sum_g = sum(A[1::2])
sum_k = sum(A[::2])

M0 = (sum_k - sum_g)//2
M = [0]* N 
M[0] = M0
for i in range(0,N-1):
    M[i+1] = A[i]-M[i]
    n_before = M[i+1]

text = ""

for m in M:
    text += "{} ".format(m*2)

print(text[:-1])

Submission status: Accepted

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

res = [0] * N
more = 0
for i in range(0, N):
    j = (i+1) % N
    more = int(As[i] - more)
    res[j] = more * 2

if more > 0:
    for i in range(N):
        j = (i+1) % N
        if i % 2:
            res[j] += more
        else:
            res[j] -= more

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

Submission status: Accepted

Solution code:
N=int(input())
a = list(map(int,input().split()))
S = sum(a)
S1 = 0
for i in range(N):
    if i%2 == 1:
        S1 += a[i]
b = [0 for i in range(N)]
b[0] = S - 2*S1
print(b[0],end=' ')
for j in range(1,N):
    b[j] = 2*a[j-1] - b[j-1]
    print(b[j],end=' ')

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

odd = sum([n for i, n in enumerate(x) if i % 2 == 1])
even = sum([n for i, n in enumerate(x) if i % 2 == 0])
y[0] = even - odd

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


str_y = map(str, y)
output = " ".join(str_y)
print(output)

Submission status: Accepted

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

ans = []

sumA = sum(A)
sum_even = 2*sum(A[1 : N : 2])
ans_i = sumA - sum_even
ans.append(ans_i)

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

ans.append(2*A[-1] - ans[0])

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

Submission status: Accepted

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

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

for i in range(n):
  if i == 0:
    print(x)
  else:
    x = 2*(a[i-1]-x//2)
    print(x)

Submission status: Accepted

Solution code:
n=int(input())
L=list(map(int,input().split()))
ans=[0 for i in range(n)]

L=[i*2 for i in L]

m=n//2
a=L[m]

for i in range(1,(n+1)//2):
  a=L[m-i]+L[m+i]-a

ans[0]=a//2

for i in range(1,n):
  ans[i]=L[i-1]-ans[i-1]

print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

sum_odd = sum([v for v in A[1::2]])
x0 = sum(A)-2*sum_odd
ans = [x0]

x = x0
for a in A:
    nex = 2*a-x
    ans.append(nex)
    x = nex
print(*ans[:-1])

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
x_1=sum(a)
for i in range(1,N,2):
    x_1-=2*(a[i])
x=[x_1]
for j in range(1,N):
    x.append(2*a[j-1]-x[j-1])
print(*x)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in  input().split()]
sigma=0
for i in a:
    sigma+=i
sigma/=2
sigma=int(sigma)

x=[sigma for i in range(n)]
g=1

for i in range(int((n-1)/2)):
    sigma-=a[g]
    g+=2
    
x[0]=sigma
for i in range(1,n):
    x[i]=a[i-1]-x[i-1]

        
        
x2=[str(i*2) for i in x]
print(" ".join(x2))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
factor = 1
X = [0] * N
for i in range(N):
  if i == 0:
    factor = 1
    for j in range(N):
      X[0] += A[j] * factor
      factor = -factor
  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()))
rain = [0]*n
rain[0] += 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(n-1):
    rain[i+1] = 2 * (a[i] - rain[i]//2)
print(*rain)

Submission status: Accepted

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

mountains = [0] * N

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

mountains[0] = x2 // 2
for i in range(N-1):
    mountains[i+1] = dam[i] - mountains[i]

print(' '.join([str(x*2) for x in mountains]))

Submission status: Accepted

Solution code:
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]
As=[]
As.append(sum([A[i]*pow(-1, i) for i in range(N)]))
for i in range(1, N):
  As.append(A[i-1]-As[i-1])

x1=As[0]/2
print(int(2*x1), end=' ')

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
x = [0]*a
x1 = sum(b) - (sum(b[1::2]))*2
x[0] = x1
for i in range(1,a):
    x[i] = 2*b[i-1] - x[i-1]
for j in range(len(x)):
    print(x[j],"",end='')

Submission status: Accepted

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

for i in range(n):
  total+=a[i]
a_tot=0
for j in range(n//2):
  a_tot+=a_cycle[2*j+1]
b[0]=total-2*a_tot
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())
d = list(map(int,input().split()))
M = [sum(d[::2])-sum(d[1::2])]
print(M[0],end=" ")
M += [0]*(n-1)
for i in range(n-1):
  ans = 2*d[i]-M[i]
  M[i+1] = ans
  print(M[i+1],end=" ")

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [0 for i in range(N)]
# A_1+A_2+...+A_N = B_1+B_2+...+B_N = S
# (B_i+B_(i+1))/2 = A_i -> B_i+B_(i+1) = 2*A_i
# B_1 = S-(B_2+B_3+...+B_N) = S-2*(A_2+A_4+...+A_(N-1))
# B_(i+1) = 2*A_i-B_i
B[0] = 0
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] = A[i-1]*2-B[i-1]
print(' '.join(map(str, B)))

Submission status: Accepted

Solution code:
def judge(x):
  res = x
  for i in a:
    res = i-res
  else:
    return x-res

def nibutan(n):
  right = n
  left = -1
  while right-left != 1:
    middle = (right+left)//2
    if judge(middle) > 0:
      right = middle
    elif judge(middle) == 0:
      return middle
    else:
      left = middle
  return right

N = int(input())
a = list(map(int,input().split()))
ans = []

tmp = nibutan(a[0])
ans.append(tmp*2)
for i in a:
  tmp = i-tmp
  ans.append(tmp*2)

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

Submission status: Accepted

Solution code:
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
	# 入力
	N = int(input())
	A = list(map(int, input().split()))

	offset = 0
	for a in A:
		offset = a * 2 - offset
	offset //= 2
	for a in A:
		print(offset)
		offset = a * 2 - offset

main()

Submission status: Accepted

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

total = sum(A)//2
x0 = 0
for i in range(len(A)):
  p = (-1)**i
  x0 += (A[i]*p)/2

x0 = int(x0)
ans = [x0*2]
xp = x0
for a in A[:-1]:
  ans += [(a-xp)*2]
  xp = a-xp
result = [str(a) for a in ans]
print(' '.join(result))

Submission status: Accepted

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

total = sum(A)//2
x0 = 0
for i in range(len(A)):
  p = (-1)**i
  x0 += (A[i]*p)/2

x0 = int(x0)
ans = [x0*2]
xp = x0
for a in A[:-1]:
  ans += [(a-xp)*2]
  xp = a-xp
result = [str(a) for a in ans]
print(' '.join(result))

Submission status: Accepted

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

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

B = [0]*N
B[0] = temp
for k in range(1,N):
    B[k] = 2 * A[k-1] - B[k-1]
for j in range(N):
    print(str(B[j]) , end=" ")

Submission status: Accepted

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

Submission status: Accepted

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	s = sum(v)
	t = sum(v[1::2])
	x = [0] * n
	# print(s, t)
	x[0] = s - 2 * t
	for i in range(1, n):
		x[i] = 2 * v[i-1] - x[i-1]
	for i in range(n):
		print("{} ".format(x[i]), end='')
	print("")


if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

result = [0] * N
for i in range(N):
    result[0] += a_list[i] * (1 if i % 2 == 0 else -1)

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

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

Submission status: Accepted

Solution code:
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))

@lru_cache(maxsize=N)
def f(i):
    if i >= 2:
        return f(i - 2) + 2 * A[i - 1] - 2 * A[i - 2]
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = (f(i) for i in range(N))

print(*B)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
rain = []
S = sum(A)
sub = sum(A[1:N:2])
rain.append(S - sub * 2)
while len(rain) != N:
    rain.append(A[len(rain) - 1] * 2 - rain[-1])
for _ in rain:
    print(_)

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()))
x = [0 for i in range(n)]
for i in range(n):
    if i % 2 == 0:
        x[0] += a[i]
    else:
        x[0] -= 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())
d=[int(i) for i in input().split()]
m=[0]*n
s=0
for i in range(n):
    if i%2==0:
        s+=d[i]
    else:
        s-=d[i]
m[0]=s
for i in range(1,n):
    m[i]=2*d[i-1]-m[i-1]
print(*m)

Submission status: Accepted

Solution code:
def main(X,A,N):
    for i in range(N-1):
        X[i+1] = 2*A[i] - X[i]
    return X
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Aoddsum = sum(A[1:N:2])
X1 = S - 2*Aoddsum
X = [0]*N
X[0] = X1
main(X,A,N)
print(" ".join(list(map(str, X))))

Submission status: Accepted

Solution code:
def main(X,A,N):
    for i in range(N-1):
        X[i+1] = 2*A[i] - X[i]
    return X
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Aoddsum = sum(A[1:N:2])
X1 = S - 2*Aoddsum
X = [0]*N
X[0] = X1
main(X,A,N)
for x in X:
    print(x, end=" ")