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: Runtime Error

Solution code:
import numpy as np

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

C = np.zeros((N, N))

for i in range(N-1):
  C[i][i] = 0.5
  C[i+1][i] = 0.5

C[0][N-1] = 0.5
C[N-1][N-1] = 0.5

Cin = np.linalg.inv(C)
B = np.dot(A , Cin)

print (int(B[0]), end = "")
for i in range(1,N):
  print ( " " + str(int(B[i])), end = "")

Submission status: Runtime Error

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

L=[i for i in L]


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

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

ans[0]=a/2

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

Submission status: Runtime Error

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

result=[]
for i in range(N):
  result.append(mean(A[i:i+2]))
  
print(result)

Submission status: Runtime Error

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

A=[A[-1]]+A[:-1]
result=[]
for i in range(N):
  result.append(mean(A[i:i+2]))
  
print(result)

Submission status: Runtime Error

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

A=[A[-1]]+A[:-1]

for i in range(N):
  print(mean(A[i:i+2]))

Submission status: Runtime Error

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

A=[A[-1]]+A

for i in range(N):
  print(mean(A[i:i+2]))

Submission status: Runtime Error

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

A=[A[-1]]+A

for i in range(N):
  print(mean(A[i:1+2]))

Submission status: Runtime Error

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

A=A[-1]+A

for i in range(N):
  print((A[i]+A[i+1])/2)

Submission status: Runtime Error

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

A=A[-1]+A

for i in range(N):
  print((A[i]+A[i+1])/2)

Submission status: Runtime Error

Solution code:
L, R = (int(i) for i in input().split())  
unko = []
flag = True
if flag:
  for i in range(L,R+1):
    for j in range(i+1,R+1):
      n = (i*j) % 2019
      unko.append((i*j) % 2019)
      if n == 0:
        flag = False
print(min(unko))

Submission status: Runtime Error

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: Runtime Error

Solution code:
n, m, M = (int(_) for _ in input().split())
dp = [[0 for i in range(n + 1)] for j in range(m + 1)]
dp[0][0] = 1
for i in range(1, m + 1):
    for j in range(n + 1):
        if j - i >= 0:
            dp[i][j] = (dp[i - 1][j] + dp[i][j -i]) % M
        else:
            dp[i][j] = dp[i - 1][j]
    print(dp)
print(dp[m][n])

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy import sparse
from scipy.sparse.linalg import inv
N = int(input())
a_list = list(map(int, input().split()))


m = np.zeros((N, N))

for i in range(N):
    m[i, i] = 0.5
    if i+1 == N:
        m[i, 0] = 0.5
    else:
        m[i, i+1] = 0.5

m = sparse.csc_matrix(m)
im = sparse.linalg.inv(m)
print(' '.join(map(str, list(im.dot(np.array(a_list)).astype(int)))))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
a_list = list(map(int, input().split()))

m = np.zeros((N, N))

for i in range(N):
    m[i, i] = 0.5
    if i+1 == N:
        m[i, 0] = 0.5
    else:
        m[i, i+1] = 0.5

inv = np.linalg.inv(m)
print(' '.join(map(str, list(np.dot(inv, np.array(a_list)).astype(int)))))

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] - (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Runtime Error

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

import numpy as np

# v = [8, 3, 3, 4, 10]
# N = len(v)

A = np.zeros((N, N))
for i in range(N):
    A[(i - 1) % N][i] = 1 / 2
    A[i][i] = 1 / 2

ans = np.dot(np.linalg.inv(A), v)
ans = [int(x) for x in ans]
print(*ans)

Submission status: Runtime Error

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

import numpy as np

# v = [8, 3, 3, 4, 10]
# N = len(v)

A = np.zeros((N, N))
for i in range(N):
    A[(i - 1) % N][i] = 1 / 2
    A[i][i] = 1 / 2

ans = np.dot(np.linalg.inv(A), v)
ans = [int(x) for x in ans]
print(ans)

Submission status: Runtime Error

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

import numpy as np

# v = [2,2,4]
# N = len(v)

A = np.zeros((N, N))
for i in range(N):
    A[(i - 1) % N][i] = 1 / 2
    # A[i][(i - 1) % N] = 1 / 2
    A[i][i] = 1 / 2

# print(A)
# print(np.linalg.inv(A))
ans = np.dot(np.linalg.inv(A), v)
ans = [int(x) for x in ans]
print(ans)

Submission status: Runtime Error

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

import numpy as np

# v = [2, 2, 4]
# N = len(v)

A = np.zeros((N, N))
for i in range(N):
    # A[(i - 1) % N][i] = 1
    A[i][(i - 1) % N] = 1 / 2
    A[i][i] = 1 / 2

# print(A)
# print(np.linalg.inv(A))
ans = np.dot(np.linalg.inv(A), v)
ans = [int(x) for x in ans]
print(ans)

Submission status: Runtime Error

Solution code:
import sys

#if sys.platform =='ios':
sys.stdin=open('input133d.txt')

#+++++

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

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

asum = 0
for i in range(n):
    if i % 2 == 1:
        asum += a[i]

x1 = sum - 2 * asum

ret = []
ret.append(x1)

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = input().split() 
A = np.array(A).astype(type(N))

T = np.zeros((N,N))
for i in range(N):
    T[i,i%N] = 1
    T[i,(i+1)%N] = 1
    
inv_T = np.linalg.inv(T)
X = np.dot(inv_T , A.T).astype('int32') *2

for i in X:
    print("{} ".format(i) ,end="")

Submission status: Runtime Error

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

def solve(N: int, A: "List[int]"):
    K = np.eye(N)
    for i in range(N-1):
        K[i, i+1] = 1
    K[N-1, 0] = 1
    A = [2 * a for a in A]
    B = np.dot(np.linalg.inv(K), np.array(A))
    s = ' '.join([str(int(b)) for b in B])
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def D_RainFlowsintoDams():
    import numpy as np
    N = int(input())
    A = [list(map(int, input().split()))]
    A = np.array(A)
    # XB = A のXを求める
    X = (np.eye(N) + np.eye(N, k=1) + np.eye(N, k=-N+1)) * 0.5
    # X^{-1} を求める
    B = np.linalg.solve(X, A.T)
    # 両辺に左からX^{-1}をかける
    for x in range(N):
        print(int(B.T[0][x]), end=" ")

if __name__ == "__main__":
    D_RainFlowsintoDams()

Submission status: Runtime Error

Solution code:
def D_RainFlowsintoDams():
    import numpy as np
    N = int(input())
    A = np.array([list(map(int, input().split()))])
    # XB = A のXを求める
    X = (np.eye(N) + np.eye(N, k=1) + np.eye(N, k=-N+1)) * 0.5
    # X^{-1} を求める
    X = np.linalg.inv(X)
    # 両辺に左からX^{-1}をかける
    B = np.dot(X, A.T)
    for x in range(N):
        print(int(B.T[0][x]), end=" ")

if __name__ == "__main__":
    D_RainFlowsintoDams()

Submission status: Runtime Error

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

l = l+l
xl = []
for i in range(2):
    a = 0
    m = False
    for j in range(i, n+i):
        if m is False:
            a += l[j]
            m = True
        else:
            a -= l[j]
            m = False
    xl.append(a)
    
for i in range(2, n):
    xl.append3(xl[-2] - l[i-2]*2 + l[i-1]*2)
    
print(" ".join(map(str, xl)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 13:50:17 2019

@author: yama
"""

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

l = l+l
xl = []
for i in range(2):
    a = 0
    m = False
    for j in range(i, n+i):
        if m is False:
            a += l[j]
            m = True
        else:
            a -= l[j]
            m = False
    xl.append(a)
    
for i in range(2, n):
    xl.append3(xl[-2] - l[i-2]*2 + l[i-1]*2)
    
print(" ".join(map(str, xl)))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a=[]
a=list(map(int, input().split()))
m=[0]*n
for i in list(reversed(range(a[0])):
  mn=0
  for j in range(n-1):
    if j==0:
      m[n-1]=i*2
      m[j]=(a[j]-m[n-1]/2)*2
    else:
      m[j]=(a[j]-m[j-1]/2)*2

  if m[n-2]/2+m[n-1]/2 ==a[n-1]:
    print(int(m[n-1]),sep=" ",end=" ")
    for i in range(n-1):
      print(int(m[i]),sep=" ",end=" ")


    sys.exit()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array([int(_) for _ in input().split()], dtype=int)


A = 2*A
M = np.zeros((N, N), dtype=int)
for i in range(N):
    M[i, i] = 1
    if i < N-1:
        M[i, i+1] = 1
    else:
        M[i, 0] = 1

x = np.dot(np.linalg.inv(M), A)

ans = [0]*N
for i in range(N):
    ans[i] = str(int(x[i]))
    
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
l = int(((N*N)+1)/2)
b = []
for i in range(l):
    b.append(1)
    b.append(-1)
b = b[:-1]
c = (np.array(b).reshape(N,N)
# print(b)
# c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
g = np.eye(N)
x = 2*(np.dot(inv,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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



a = np.array(A)
l = int(((N**2)+1)/2)



b = np.tile((1,-1),(1,l))

print(1)

# c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# # print(c)
# d = c.reshape(N,N)

# inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)

# x = 2*(np.dot(inv,a))
# print(x)

# ans = list(map(str, list(map(int, list(x)))))
# print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
print(1)
# inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)

# x = 2*(np.dot(inv,a))
# print(x)

# ans = list(map(str, list(map(int, list(x)))))
# print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)
print(1)
# x = 2*(np.dot(inv,a))
# print(x)

# ans = list(map(str, list(map(int, list(x)))))
# print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)
x = 2*(np.dot(inv,a))
# print(x)
print(1)
# ans = list(map(str, list(map(int, list(x)))))
# print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)
x = 2*(np.dot(inv,a))
# print(x)
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = np.delete(b, 2*l-1, axis=None)
d = c.reshape(N,N)
e = np.triu(d)
f = np.tril(d)
g = np.eye(N)

inv = 0.5*(e-(f-g))

x = 2*(np.dot(inv,a))

ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = np.delete(b, 2*l-1, axis=None)
d = c.reshape(N,N)
e = np.triu(d)
f = np.tril(d)
g = np.eye(N)

inv = 0.5*(e-(f-g))

x = 2*(np.dot(inv,a))

print(x)

ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy as np

a = np.array(A)
l = int(((N**2)+1)/2)
b = np.tile((1,-1),(1,l))
c = np.delete(b, 2*l-1, axis=None)
d = c.reshape(N,N)
e = np.triu(d)
f = np.tril(d)
g = np.eye(N)

inv = 0.5*(e-(f-g))

x = 2*(np.dot(inv,a))

ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy as np
a = np.array(A)
b = np.zeros((N,N))
for i in range(N):
    if i < (N-1):
        b[i][i] = 1
        b[i][i+1] = 1
    else:
        b[i][i] = 1
        b[i][0] = 1
c = np.linalg.inv(b)
x = np.dot(2,np.dot(c,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

mat = np.eye(N) + np.eye(N, k=1)
mat[N-1][0] = 1

B = np.dot(np.linalg.inv(mat), A) * 2
ans = np.array(B.reshape(N), dtype=int)

print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A).reshape(N, 1)

mat = np.eye(N) + np.eye(N, k=1)
mat[N-1][0] = 1

B = np.dot(np.linalg.inv(mat), A) * 2
ans = np.array(B.reshape(N), dtype=int)

print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A).reshape(N, 1)

mat = np.eye(N) + np.eye(N, k=1)
mat[N-1][0] = 1

B = np.dot(np.linalg.inv(mat), A) * 2
ans = B.reshape(N)

print(*ans)

Submission status: Runtime Error

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

Ns=[]
N1=0
for i in range(1,N+1):
  N1+=(A[i]*(-1)**(i-1))
Ns.append(N1)
for i in range (2,N+1):
  n=(A[i-1]-Ns[i-1]/2)*2
  Ns.append(n)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A=np.array(input().split(),dtype=float)
A=A.reshape(1,-1).T
P=np.zeros((N,N))
for i in range(N-1):
    P[i][i]=0.5
    P[i][i+1]=0.5
P[N-1][N-1]=0.5
P[N-1][0]=0.5
P=np.linalg.inv(P)
I=np.dot(P,A)
I=I.flatten()
I.tolist()
for i in range(N):
    print(int(I[i]),end=" ")
print()

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A=np.array(input().split(),dtype=float)
A=A.reshape(1,-1).T
P=np.zeros((N,N))
for i in range(N-1):
    P[i][i]=0.5
    P[i][i+1]=0.5
P[N-1][N-1]=0.5
P[N-1][0]=0.5
P=np.linalg.inv(P)
I=np.dot(P,A)
I=I.flatten()
I.tolist()
for i in range(N-1):
    print(int(I[i]),end=' ')
print(int(I[N-1]))

Submission status: Runtime Error

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

D = []

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

D = []
D[0] = x

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

print(' '.join(D))

Submission status: Runtime Error

Solution code:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    a: [i32; n],
    }
    let mut upper: i32 = 2 * (10_i32.pow(9));
    let mut lower = 0;
    let mut ans_list = vec![];
    loop {
        let mut half = (upper + lower) / 2;
        if half % 2 == 1 {
            half += (upper + lower) % 2
        }
        let mut tmp = half;
        ans_list.push(tmp);
        for i in 0..n {
            tmp = 2 * (a[i] - tmp / 2);
            if i == n-1 {
                if tmp == ans_list[0] {
                    break
                } else {
                    ans_list.clear();
                    if i % 2 == 0{
                        upper = half
                    } else {
                        lower = half
                    }
                }
                break
            }
            else {
                if tmp < 0 {
                    if i % 2 == 0 {
                        upper = half
                    } else {
                        lower = half
                    }
                    ans_list.clear();
                    break
                } else {
                    ans_list.push(tmp);
                }
            }
        }
        if ans_list.len() == n {
            break
        }
    }
    for i in 0..n {
        print!("{}", ans_list[i]);
        if i < n-1 {
            print!("{}", " ");
        }
    }
}

Submission status: Runtime Error

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

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
    for idx in range(1, N):
        a = A[idx-1]
        x_next = a - x_values[-1]
        if x_next < 0:
            has_missed = True
            break
        else:
            x_values.append(x_next)
    if x_values[0] + x_values[-1] == A[N]:
        continue
    if not has_missed:
        break
x_values = [str(2*x) for x in x_values]
print(' '.join(x_values))

Submission status: Runtime Error

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

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
    for idx in range(N):
        a = A[idx]
        x_next = a - x_values[-1]
        if x_next < 0:
            has_missed = True
            break
        else:
            x_values.append(x_next)
    if not has_missed:
        break
x_values = [2*x for x in x_values]
print(' '.join(x_values))

Submission status: Runtime Error

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

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
	for idx in range(N):
        a = A[idx]
        x_next = a - x_values[-1]
        if x_next < 0:
            has_missed = True
            continue
        else:
            x_values.append(x_next)
    if not has_missed:
        break
x_values = [2*x for x in x_values]
print(' '.join(x_values))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array([int(a) for a in input().split(' ')])

idx_minA = np.argsort(A)[0]
minA = A[idx_minA]
minA = min(A)

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
	for idx in range(N):
      a = A[idx]
      x_next = a - x_values[-1]
      if x_next < 0:
        has_missed = True
        continue
      else:
        x_values.append(x_next)
    if not has_missed:
      break

print(' '.join(x_values))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.zeros((N, N))
for i, b in enumerate(B):
    b[i:i + 2] = 1 / 2
    if i == len(b) - 1:
        b[0] = 1 / 2
x = np.linalg.solve(B, A).astype(np.int)
print(" ".join(map(str, list(x))))

Submission status: Runtime Error

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] = a[n]

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10**5)


N = int(input())

A_lst = np.array(list(map(int, input().split())))

rain_lst = np.array([0] * N)

def step(A_lst, N, rain_lst, i):
    rain = 0
    if i == N - 1:
        rain = A_lst[i]*2 - rain_lst[-1]
    else:
        rain = A_lst[i]*2 - rain_lst[i+1]
        
    if rain < 0:
        return False
    elif i == -1:
        if rain == rain_lst[-1]:
            return True
        else:
            return False

    rain_lst[i] = rain
    if step(A_lst, N, rain_lst, i-1):
        return True
    return False

for rain in range((A_lst[N-1] + 1)*2):
    rain_lst[:] = 0
    rain_lst[-1] = rain
    if step(A_lst, N, rain_lst, N-1):
        break

output_str = ""
for i in range(N):
    output_str += str(rain_lst[i])
    if i != N:
        output_str += " "

print(output_str)

Submission status: Runtime Error

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]=M[i-1]+2*(M[i]-M[i-1])
  
d=(sum(A)-sum(M))//n
for i in range(n):
  print(M[i]+d)

Submission status: Runtime Error

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

A = np.identity(n)
A += np.eye(n, k=1)
A[n-1][0] = 1

ans = np.linalg.solve(0.5*A,water)
print(" ".join(list(map(lambda x:str(int(x)),ans))))

Submission status: Runtime Error

Solution code:
import scipy.linalg as linalg

N = int(input())
b = np.array(list(map(int, input().split())))

A = np.zeros(N**2).reshape(N, N)
for i in range(N):
    for j in range(N):
        if i == j or i+1 == j:
            A[i, j] = 1
        else:
            continue
A[N-1, 0] = 1
A = A / 2
A_inv = linalg.inv(A)

x = np.dot(A_inv, b)
print(*x)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))
import numpy as np

mat=np.zeros((n, n))
mat2=np.zeros((n, n))

for i in range(n):
	mat[i,i]=1/2
	if i==0:
		mat[i,n-1]=1/2
	else:
		mat[i,i-1]=1/2

for i in range(n):
	if i==0:
		mat2[i,n-1]=1
	else:
		mat2[i,i-1]=1        

mat3=np.linalg.inv(mat)

x2=np.array(x).T

res=np.dot(mat2,np.dot(mat3,x2))

res2=list(map(int,res))

for i in range(n):
	print(res2[i])

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))
import numpy as np

mat=np.zeros((n, n))
mat2=np.zeros((n, n))

for i in range(n):
	mat[i,i]=1/2
	if i==0:
		mat[i,n-1]=1/2
	else:
		mat[i,i-1]=1/2

for i in range(n):
	if i==0:
		mat2[i,n-1]=1
	else:
		mat2[i,i-1]=1        

mat3=np.linalg.inv(mat)

x2=np.array(x).T

res=np.dot(mat2,np.dot(mat3,x2))

res2=list(map(int,res))

print(res2)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))
import numpy as np

mat=np.zeros((n, n))
mat2=np.zeros((n, n))

for i in range(n):
	mat[i,i]=1/2
	if i==0:
		mat[i,n-1]=1/2
	else:
		mat[i,i-1]=1/2

for i in range(n):
	if i==0:
		mat2[i,n-1]=1
	else:
		mat2[i,i-1]=1        

mat3=np.linalg.inv(mat)

x2=np.array(x).T

res=np.dot(mat3,np.dot(mat2,x2))

res2=list(map(int,res))

print(res2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B1 = 0
B = []
for i in range(0,N+1):
    if A[i]%2 == 1:
        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
print(B)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int[i] for i in input().split()]
X = [0]*N
sum = 0
sum_A = 0

# 合計を求める
for i in range(X-1):
    sum = sum + A[i]

# A2からAN-1の合計を求める
for i in range(1, N-2):
    sum_A = sum_A + A[i]

#X1を求める
X[0] = sum - 2*sum_A

#X1を使ってXk+1を求める
for i in range(1, N-1):
    X[i] = 2 * (A[i-1]-X[i-1]/2)

#出力
for i in range(N-1)
    print(X[i], end=" ")

Submission status: Runtime Error

Solution code:
    n=int(input())
    a=list(map(int,input().split()))
     
    sum=0
    for i in range(n):
        sum=sum+a[i]
     
    for j in range(1,n,2):
        sum=sum-a[j]*2
     
    ans=[sum]
    ch=sum
    for i in range(0,n-1):
        ch=a[i]*2-ch
        ans.append(ch)
     
     
    aaa=str(ans[0])
    for i in range(1,n):
        ccd=str(ans[i])
        aaa=aaa+' '+ccd
    print(aaa)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(int(i) for i in input().split())

W = np.zeros((N,N))
for i in range(N):
    for j in range(N):
        ii1 = (N+ j - 1) % N
        ii2 = (N+ j + 0) % N
        W[i,j] = 1 if i == ii1 or i == ii2 else 0

Winv = np.linalg.inv(W)

Ans = 2.0* Winv.dot(A)
Ans = Ans.astype(np.int64)

ss = ""
for i in Ans:
  ss += str(i) + " "
print(ss)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(int(i) for i in input().split())

W = np.zeros((N,N))
for i in range(N):
    for j in range(N):
        ii1 = (N+ j - 1) % N
        ii2 = (N+ j + 0) % N
        W[i,j] = 1 if i == ii1 or i == ii2 else 0

Winv = np.linalg.inv(W)

Ans = 2.0* Winv.dot(A)
Ans = Ans.astype(np.int8)

ss = ""
for i in Ans:
  ss += str(i) + " "
print(ss)

Submission status: Runtime Error

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):
    X[i + 1] = 2 * A[i] - avg[i]

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

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())

module = []
for i in range(L, R):
    for j in range(i+1, R+1):
        print("({} * {}) mod 2019 = {}".format(i, j, (i * j) % 2019))
        if (i * j) % 2019 == 0:
            print("0")
            exit()
        else:
            module.append((i * j) % 2019)

if not module:
    print("0")
else:
    print(min(module))

Submission status: Runtime Error

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

import numpy as np

a = np.zeros((N, N))
for i in range(N-1):
    a[i][i] = 1
    a[i][i+1] = 1
a[-1][-1] = 1
a[-1][0] = 1
b = np.array(A) * 2
X = np.linalg.solve(a, b)
X = map(int, X)
print(" ".join(map(str, X)))

Submission status: Runtime Error

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

import numpy as np

a = np.zeros((N, N))
for i in range(N):
    a[i][i] = 1
    if i + 1 == N:
        a[i][0] = 1
    else:
        a[i][i+1] = 1
b = np.array(A)
X = np.linalg.solve(a, b) * 2
X = map(int, X)
print(" ".join(map(str, X)))

Submission status: Runtime Error

Solution code:
N = int(input())
A = 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(mounts))