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())
li = list(map(int,input().split()))
sum = 0
ans = []
for i in li:
    sum += i

x1_a = 0
count = 1
for i in li:
    if(count % 2 == 0):
        x1_a += i
    count += 1
x1 = sum - 2 * x1_a
ans.append(x1)

for i in range(1,n):
    ans.append(2*li[i-1]-ans[i-1])
print(" ".join([str(n) for n in ans]))

Submission status: Accepted

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

x = 0

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

ans = [x]

tmp = x

for i in range(n-1):
    s = 2*li[i] - tmp
    ans.append(s)
    tmp = s
    
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
_a = input().split()

a = []

x = []

for i in range(n):
  a.append(2*int(_a[i]))
  x.append(0)
  
for i in range(1, n):
  a[i] -= a[i-1]

x[n-1] = a[n-1] // 2

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

print(ans[:-1])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
X = [0]*N
S = sum(A)
X[0] = S - 2*sum(A[1::2])

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=[int(i) for i in input().split()]
SumOdd=[0 for i in range(N+1)]
SumEven=[0 for i in range(N+1)]
for i in range(N):
    if i%2==1:
        SumOdd[i+1]=SumOdd[i]+A[i]
        SumEven[i+1]=SumEven[i]
    else:
        SumOdd[i+1]=SumOdd[i]
        SumEven[i+1]=SumEven[i]+A[i]
Sum=sum(A)
ans=[0 for i in range(N)]
for i in range(N):
    if i%2==0:
        ans[i]=Sum-2*(SumOdd[N]-SumOdd[i]+SumEven[i])
    else:
    	ans[i]=Sum-2*(SumEven[N]-SumEven[i]+SumOdd[i])
print(" ".join([str(i) for i in ans]))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A_cs = np.array([(-1)**i * int(x) for i,x in enumerate(input().split())]).cumsum()
print(*(np.array( [ (A_cs[N-1]-A_cs[i-1]-A_cs[i-1] if i!=0 and i%2==0 else -A_cs[N-1]+A_cs[i-1]+A_cs[i-1] ) for i in range(N) ] )))

Submission status: Accepted

Solution code:
# 最初に入れておくとinputが早くなる
import sys
import numpy as np
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

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

tempa = [0]*n
for j in range(n):
    tempa[j] = ans[j % n] // 2
    if(j+1 != n):
        ans[(j + 1) % n] = (a[j] - tempa[j]) * 2
    #print(a, tempa, ans)
print(*ans)

Submission status: Accepted

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

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

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

print(*x)

Submission status: Accepted

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

# B0を決定する
# B0 = a0 + a1 + .. - (a1 + a3 + ... ) * 2
b0 = sum(a)
for i in range(1, n, 2):
    b0 -= a[i] * 2

# a0 = b0 / 2 + b1 / 2
#   <=> b1 = a0 * 2 - b0
b = [None] * n
b[0] = b0
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:
N = int(input())
l_a = list(map(int,input().split()))
b_x = sum(l_a) - sum(l_a[1::2])*2
l_x =[b_x]
for s in range(N-1):
    x = l_a[s]*2 - b_x
    l_x.append(x)
    b_x = x
print(*l_x)

Submission status: Accepted

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

d.pop()
print(*d)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

x[0]=s-y

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

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

Submission status: Accepted

Solution code:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
double_x = 2 * x
x0 = 0
multiple = 1
for j in range(n):
    x0 += x[j] * multiple
    multiple *= -1
ans.append(x0)
for i in range(0, n-1):
    ans.append(double_x[i] - ans[i])

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

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split(" "))

y1 = 0
for i in range(0, len(a)):
    if i % 2 == 0:
        y1 += a[i]
    else:
        y1 -= a[i]

y = []
y.append(y1)

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

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

Submission status: Accepted

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

all_ = sum(a)

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

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

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

Submission status: Accepted

Solution code:
dom_num = int(input())
dom_rain = [int(i) for i in input().split(" ")]
mou_rain = []
a = 0
is_plus = 1
for i in dom_rain:
    if is_plus:
        a += i
    else:
        a -= i
    is_plus = 1 - is_plus
mou_rain.append(a)
for i in range(0, dom_num - 1):
    mou_rain.append(2 * dom_rain[i] - mou_rain[- 1])
print(" ".join([str(i) for i in mou_rain]))

Submission status: Accepted

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

Submission status: Accepted

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

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

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

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

Submission status: Accepted

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

Submission status: Accepted

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

x = [-1] * N
sa = sum(A)
sx = sa // 2

t = 0
for i in range(0, N, 2):
    t += A[i]
x[0] = t - sx

for i in range(N-1):
    x[i+1] = A[i] - x[i]

print(*[2 * xx for xx in x], sep=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
M=[0]*n
K=[k for k in range(n)][1::2]+[k for k in range(n)][::2]
for i in K:
  M[(i+1)%n]=M[i-1]+2*(A[i%n]-A[i-1])
  
d=(sum(A)-sum(M))//n
for i in range(n):
  print(M[i]+d)

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve

N = int(input())
b = np.array(input().split()).astype(int)

rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

A = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))

x = (spsolve(A, b) * 2).astype(int)

print(*x)

Submission status: Accepted

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

x = 0
for i in A:
    x = i - x
B = [x]
x = x//2
for i in A[:N-1]:
    x = i - x
    B += [x*2]
print(*B)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
l=A[0]/2.0
tmp=l
for a in A[1:]:
  tmp=a-tmp
ans=[int(l+tmp)]
for i in range(N-1):
  ans.append( int( (A[i]-ans[i]/2)*2 ) )
print(str(ans[0]),end='')
for a in ans[1:]:
  print(' '+str(a),end='')

Submission status: Accepted

Solution code:
_,a=open(0);*a,=map(int,a.split());t=sum(a)-2*sum(a[1::2]);x=[t]
for i in a:t=i*2-t;x+=t,
print(*x[:-1])

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = input().split()
    S = 0
    for n in range(N):
        A[n] = int(A[n])
        S += A[n]
    ans = S
    for n in range(N)[1::2]:
        ans -= 2 * A[n]
    prev = ans
    print(str(ans) + " ", end="")
    for n in range(N)[1:]:
        ans = 2 * A[n - 1] - prev
        prev = ans
        if n == N - 1:
            print(ans)
        else:
            print(str(ans) + " ", end="")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = input().split()
    S = 0
    ans = []
    for n in range(N):
        ans.append(0)
        A[n] = int(A[n])
        S += A[n]
    ans[0] = S
    for n in range(N)[1::2]:
        ans[0] -= 2 * A[n]
    for n in range(N)[1:]:
        ans[n] = 2 * A[n - 1] - ans[n - 1]
    for n in range(N):
        if n == N - 1:
            print(ans[n])
        else:
            print(str(ans[n]) + " ", end="")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum = 0
B = []

for index,value in enumerate(A):
    index += 1

    if index % 2 == 0:
        sum -= value
    else:
        sum += value

B.append(sum)

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

print(*B)

Submission status: Accepted

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

sum_water = sum(water)
r_1 = sum_water
for i in range(1,int((n-1)/2+1)):
    r_1 -= water[2*i-1]*2
    #print(water[2*i])

ans = [r_1]
for i in range(n-1):
    ans.append(water[i]*2-ans[-1])
    #print(ans)

print(" ".join(map(lambda x:str(int(x)),ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,a=open(0)
*a,=map(int,a.split())
t=sum(a)-2*sum(a[1::2])
x=[t]
for i in a:
  t=i*2-t
  x+=t,
print(*x[:-1])

Submission status: Accepted

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0 for _ in range(n)]

    for index, ai in enumerate(a):
        if index % 2 == 0:
            ans[0] += ai
        else:
            ans[0] -= ai

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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] = A[i-1] * 2 - ans[i-1]

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

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))	
res = 0
for i in range (0,N+1,2):
    res += li[i]
for i in range(1,N,2):
    res -= li[i]
a = res 
ans = [a]
for i in range(N-1):
    b = int(2 * (li[i] - a / 2))
    ans.append(b)
    a = b
for s in ans:
  print(s, end =" ")

Submission status: Accepted

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


def find_mountain_rain_amount(N, A):
    for i in range(N):
        A[i] = A[i] * 2

    offset = 0
    for i in range(N):
        offset = A[i] - offset

    x = offset // 2

    cur = x
    ans = []
    for i in range(N):
        ans.append(cur)
        cur = A[i] - cur

    return ans


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = find_mountain_rain_amount(N, A)
    for num in ans:
        print(num, end=" ")


main()

Submission status: Accepted

Solution code:
num = int(input())
a = input().split()
b = list(map(int, a))
sum = sum(b)

X = [0]*num
X1 = 0
for i in range(num):
  if((2*i+1) >= num):
    break
  X1 = b[2*i+1] + X1
X[0] = sum - 2 * X1

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

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

x = [i * 2 for i in x]

print(*x)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = sum([dams[x]*(-1)**x for x in range(n)])
out = str(ans)

ansList = [0 for x in range(n)]

ansList[0] = ans

for i in range(1, n):
  ans = -1 * ans + 2 * dams[i - 1]
  ansList[i] = ans
  
print(*ansList)

Submission status: Accepted

Solution code:
n = int(input())

dams = list(map(int, input().split()))
ans_list = [0 for x in range(n)]

ans_list[0] = sum([dams[x]*(-1)**x for x in range(n)])

for i in range(1, n):
  ans_list[i] = -ans_list[i-1] + 2 * dams[i - 1]

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

#print(*ans_list)

Submission status: Accepted

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

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

Submission status: Accepted

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


t = sum(A) 
x = [0] * N

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

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

print(*x)

Submission status: Accepted

Solution code:
n = int(input())
dam = list(map(int,input().split()))
mountain =[0]*n
all_water = sum(dam)
def dam_water(num):
  sum_dam = 0
  for i in range(num,n,2):
    sum_dam += dam[i]
  return sum_dam

mountain[0] = all_water - 2 * (dam_water(1))

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

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

# x_1 = (A_1 - A_2 + A_3 - A_4 + ... + A_N) / 2 である
# x_2 以降は代入しながら求めればよい
ans = ' '.join(
    str(2 * x)
    for x in accumulate(
        [(sum(A[::2]) - sum(A[1::2])) // 2] + A[:-1],
        lambda acc, a: a - acc
    )
)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

# x_1 = (A_1 - A_2 + A_3 - A_4 + ... + A_N) / 2 である
# x_2 以降は代入しながら求めればよい
ans = ' '.join(
    str(2 * x)
    for x in accumulate(
        [sum((-1)**i * A[i] for i in range(N)) // 2] + A[:-1],
        lambda acc, a: a - acc
    )
)

print(ans)

Submission status: Accepted

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

S = sum(A)
X = 0
Y = 0
M = [0] * (N+1)

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

for i in range(1,N+1,2):
    #print(i,X,Y)
    M[i] = S - X - Y
    if i != N:
        X += 2*A[i]
        Y -= 2*A[i+1]

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

M.pop(0)
print(' '.join(map(str,M)))

Submission status: Accepted

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

s = 0
for a in a_list:
  s += a
  
x1 = s - (2 * sum(a_list[1::2]))

result = []
# result.append(x1)
print(x1)
xi = x1
for i in range(n-1):
    hoge = (a_list[i] * 2) - xi
    # result.append(hoge)
    print(hoge)
    xi = hoge
# print(result)

Submission status: Accepted

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

s = 0
for a in a_list:
  s += a

hoge = 0
for i in range(n-1):
  if i%2 == 0:
    continue
  hoge += a_list[i]
  
x1 = s - (2 * hoge)

result = []
# result.append(x1)
print(x1)
xi = x1
for i in range(n-1):
    hoge = (a_list[i] * 2) - xi
    # result.append(hoge)
    print(hoge)
    xi = hoge
# print(result)

Submission status: Accepted

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

x_1 = 0
for i, a in enumerate(l):
    if i % 2 == 0:
        x_1 += a
    else:
        x_1 -= a
ans = x_1

for a in l:
    print(ans)
    ans = 2 * a - ans

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
temp = sum(a)
for i in range(n):
    if i%2 == 1:
        temp -= 2*a[i]
x.append(temp)
for i in range(n-1):
    x.append(2*a[i]-x[i])
for i in range(n):
    if i != n-1:
        print(x[i],end=" ")
    else:
        print(x[i])

Submission status: Accepted

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

x = [0]*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] = int( 2 * ( A[i-1] - x[i-1] / 2 ) )

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

Submission status: Accepted

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

x = 0

wa_list = []


for i in range(0,N):
    wa_list.append(x)
    x = a[i]-x


x = x//2

# print(x,wa_list)

for i in range(0,N):
    print(2*(x+wa_list[i]),'',end='')
    x *= -1

Submission status: Accepted

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

total_rain = sum(ai)
rain_x1 = 0   # tatal rain except last one
for r in ai[1:-1:2]: # A1 contains sum of Mn and M1, so start from A2->ai[1]
    rain_x1 += r
    
# print(total_rain, rain_x1)
rain_mn = total_rain - rain_x1*2

rain_mx = list()
prev = rain_mn

for r in ai:
    rain_mx.append(prev)
    prev = r*2-prev

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve

N = int(input())
A = 2 * np.array(list(map(int, input().split())))
r, c, v = [None] * 2 * N, [None] * 2 * N, [None] * 2 * N
for n in range(N):
  r[2 * n] = n
  r[2 * n + 1] = n
  c[2 * n] = n
  c[2 * n + 1] = n + 1 if n != N - 1 else 0
  v[2 * n] = 1
  v[2 * n + 1] = 1
C = csr_matrix((v, (r, c)), shape=(N, N))
a = list(map(int, spsolve(C, A)))
for aa in a:
  print(aa, end=' ')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = 0
	for i, val in enumerate(A):
		if i == 0:
			tmp += 2*val
			continue
		if i % 2 == 1:
			tmp -= 2*val
		else:
			tmp += 2*val
	
	x = tmp / 2
	
	ans = []
	ans.append(int(x))
	for i, val in enumerate(A):
		tmp = (val - (ans[i]/2)) * 2
		ans.append(int(tmp))
	
	ans = ans[:-1]
	ans = [str(s) for s in ans]
	print(" ".join(ans))
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

X_1 = S
i = 0
while 2*i+1 < n:
    X_1 -= 2 * A[2*i+1]
    i += 1

X = [0] * n
X[0] = X_1

for i in range(n-1):
    X_i_1 = 2 * A[i] - X[i]
    X[i+1] = X_i_1
    
print(" ".join(map(str, X)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Submission status: Accepted

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

#一つ飛ばしで合計から引いていく。
#X1 = S − (X2 + ... + XN ) = S − 2(A2 + A4 + ... + AN−1)がtmp
for r in a[:-1:2]:
  tmp -= r*2
  

#tmp=XN+1なのでX1も漸化式から計算
ans[-1] = tmp
ans[0] = a[-1] * 2 - tmp

tmp = ans[0]
#Xi+1 = 2Ai − Xi で他を求める
#i=n-1の時に最後もちゃんと更新される
for i in range(1, n-1):
    ans[i] = 2 * a[i-1] - ans[i-1]

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
All = sum(As)
odd = 0
for i in range(0, N+1, 2):
    odd += As[i]
iprv = (odd-All//2)*2
ans = []
ans.append(iprv)
for j in range(N-1):
    ik = (As[j]-iprv//2)*2
    iprv = ik
    ans.append(iprv)
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
res=[0 for i in range(n)]
now=0
for i in range(n-1):
    now=l[i]-now
    res[i+1]=now
diff=(res[-1]+res[0]-l[-1])//2
for i in range(n):
    if i%2==0:
        print(2*(res[i]-diff),end=" ")
    else:
        print(2*(res[i]+diff),end=" ")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

r_0 = res/2
rs = [r_0]
for i in range(1, N)[::]:
    r = a[i-1] - rs[i - 1]
    rs.append(r)

ans = ""
for r in rs:
    ans += str(int(2*r)) + " "
print(ans)

Submission status: Accepted

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

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

X[0] = x

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_lis = list(map(int, input().split()))
X_lis = []
S = sum(A_lis)
x0 = S - sum(map(lambda x:A_lis[x], list(range(1,len(A_lis),2))))*2
X_lis.append(x0)

for i in range(1,N):
	xi = 2*A_lis[i-1] - X_lis[i-1]
	X_lis.append(xi)
print(" ".join(map(str,X_lis)))

Submission status: Accepted

Solution code:
import numpy as np
import sys

n = int(input())

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

a_sum = sum(a)
# x[i]はi番目のダムに溜まった水の半分
x = []

x_0 = int(a_sum/2)

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

x.append(x_0)
x_tmp = x_0

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

x = list(map(lambda y: y*2, x))

print(*x, sep=' ')

Submission status: Accepted

Solution code:
import numpy as np
import sys

n = int(input())

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

a_sum = sum(a)
# x[i]はi番目のダムに溜まった水の半分
x = []

x_0 = int(a_sum/2)

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

x.append(x_0)
x_tmp = x_0

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

for wa in x:
    print(wa*2, end=' ')

Submission status: Accepted

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

B = []

# b1 = A1 - B1 + A2 ... - AN (奇数個) が式変形で求められる
b1 = 0
for i in range(len(A)):
    if i % 2 == 0:
        b1 += A[i]
    else:
        b1 -= A[i]

B.append(b1)

# B[i] = 2 * A[i-1] - B[i-1] (式変形により)
for i in range(1, N):
    bi = 2 * A[i-1] - B[i-1] 
    B.append(bi)

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

Submission status: Accepted

Solution code:
_,a=open(0)
*a,=map(int,a.split())
t=sum(a)-2*sum(a[1::2])
x=[t]
for i in a:
  t=i*2-t
  x+=t,
print(*x[:-1])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
a = 0
for i, x in enumerate(A):
    if (i % 2 == 0):
        a += x
    else:
        a -= x
for x in A:
    print(int(a), end=" ")
    a = x*2 - a
print("")

Submission status: Accepted

Solution code:

#!/bin/env python3
"""
1つ飛ばしで各ダムのsumを
"""
def main():
  n = int(input())
  a = list(map(int,input().split()))
  res = [0] * n
  sum_a = sum(a) #total rain 
  sum_odd = 0
  sum_even = 0
  for i in range(n):
    if i%2 == 1:
      sum_odd += a[i]
    else:
      sum_even += a[i]
  for i in range(n):
    if i == 0:
      res[i] = sum_a - (sum_even - a[i])*2
    else:
      res[i] = a[i]*2-res[i-1]
  for i in range(n):
    print(res[(i+n-1)%n],end=" ")
  print()
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
rain_sum = sum(A) // 2
rain_other = 0
for i in range((N - 1) // 2):
    rain_other += A[(2 * i + 1) % N]
rain_before = (rain_sum - rain_other) * 2
print(rain_before, end = ' ')
for i in range(N - 1):
    rain_before = 2 * A[i] - rain_before
    print(rain_before, end = ' ')

Submission status: Accepted

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

for mi in m[:-1]:
  print(mi,end=' ')
print(m[-1],end='')

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(r_list)):
    if i == 0:
        a = sum(r_list)
        for j in range(1, len(r_list)):
            if j % 2 == 1:
                a -= r_list[j] * 2
    else:
        a = (2 * r_list[i-1]) - ans_list[i-1]
    ans_list.append(a)

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

Submission status: Accepted

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

for i in range(len(r_list)):
    if i == 0:
        a = sum(r_list)
        for j in range(1, len(r_list)):
            if j % 2 == 1:
                a -= r_list[j] * 2
    else:
        a = (2 * r_list[i-1]) - ans_list[i-1]
    ans_list.append(a)

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve

N = int(input())
b = np.array(input().split())

rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

A = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))

x = (spsolve(A, b) * 2).astype(int)

print(*x)

Submission status: Accepted

Solution code:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve

N = int(input())
b = np.array(input().split())

rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

A = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))

x = (spsolve(A, b) * 2 + .5).astype(int)

print(*x)

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import islice

IS = lambda: int(input())
IA = lambda: [int(x) for x in input().split()]

N = IS()
A = IA()

h = N//2

a1 = 0
s = 1
for x,y in islice(zip(A, reversed(A)), h):
    a1 += s * (x + y)
    s *= -1
a1 += s * A[h]

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

print(*ans)

Submission status: Accepted

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

totalRain = sum(A)

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


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

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

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:N-1:2])
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()))

x = [0] * 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(*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(1, n, 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()))

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

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

Submission status: Accepted

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

x2 = 0
for i in range(N):
    if i%2:
        x2 -= a[i]
    else:
        x2 += a[i]
ans = [0 for i in range(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

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

Submission status: Accepted

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

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