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:
# start -> ダム -> 山 -> end で2部グラフを作って最大流を求めれば求まるはず


MAX_V = 100002
used = [False] * MAX_V
edge = [[] for _ in range(MAX_V)]

class Edge():

    def __init__(self, to, cap, rev):
        self.to = to
        self.cap = cap
        self.rev = rev

def init_used():
    for i in range(MAX_V):
        used[i] = False

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def build_graph(N, A, INF=10000000000):
    START = 2 * N
    END = 2 * N + 1
    for i in range(N):
        edge[START].append(Edge(i, A[i], len(edge[i])))
        edge[i].append(Edge(START, 0, len(edge[START])))
    for i in range(N):
        j = N + ((i - 1) % N)
        edge[i].append(Edge(N+i, INF, len(edge[N+i])))
        edge[j].append(Edge(N + j, INF, len(edge[N + j])))
        edge[N+i].append(Edge(N + i, 0, len(edge[i])))
        edge[N+j].append(Edge(N + j, 0, len(edge[j])))
    for i in range(N):
        edge[N+i].append(Edge(END, INF, len(edge[END])))
        edge[END].append(Edge(N+i, 0, len(edge[N+i])))
    return edge, START, END


def dfs(edge, weight, v, t, f=10000000000):
    if v == t:
        return f
    used[v] = True
    for i in range(len(edge[v])):
        to = edge[v][i]
        if not used[to] and weight[v][i] > 0:
            d = dfs(to, t, min(f, weight[v][i]))
            if d > 0:
                weight[v][i] -= d
                edge[v]


def maximum_flow(edge, s, t):
    V = len(edge)
    while True:
        init_used()
        d = dfs(edge, s, t)
        return 0
    

def solve(N, A):
    # 0~N-1: damu, N~2N-1: yama, 2N: s, 2N+1: t
    edge, START, END = build_graph(N, A)
    maximum_flow(edge, START, END)
    return 0


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
sum = 0
x = [-1 for i in range(n)]
for i in range(n):
    if a[i % n] == 0:
        x[i % n] = 0
        x[(i + 1) % n] = 0
i = 0
while (-1 in x):
    if a[i % n] == nun and a[i + 2] != -1:
        x[i] = a[i] * 2 - a[i + 1] * 2 - x[i + 2]
    i += 1
for i in x:
    print(i,end = "")
    print(" ", end = "")

Submission status: Runtime Error

Solution code:
import numpy as np

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

E = np.eye(N)
E[1:,:-1] += np.eye(N - 1)
E[0, -1] += 1
ret = list(np.linalg.solve(E, A))
ret = ret[-1:] + ret[:-1]
print(" ".join([str(int(i) * 2) for i in ret]))

Submission status: Runtime Error

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

import numpy

M = [ [0 for _ in range(N)] for _ in range(N) ]
for i in range(N):
    M[i][i] = 1
    M[i][i-1] = 1

B = numpy.matrix(M)
Y = numpy.matrix(A)
X = list(numpy.linalg.solve(B,Y))

for i in range(N):
    print(X[i])

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

A = np.array(input().split(),np.float32)

A = np.array([A])

An = np.zeros((n,n),np.float32)

for i in range(n):
  An[i][i] = 0.5
  if i == n-1:
    An[i][0] = 0.5
  else:
    An[i][i+1] = 0.5

R = A.T

np.dot(np.linalg.inv(An),A.T,R)

R = R

for i in range(n):
  print(int(R[i][0]))

Submission status: Runtime Error

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

from sympy import Indexed, IndexedBase, Tuple, sqrt, solve

A = IndexedBase('A')
eqs = Tuple()
for i in range(n-1):
    eqs += Tuple(A[i]+A[i+1]-2*a[i])
eqs += Tuple(A[n-1]+A[0]-2*a[n-1])

ans = solve(eqs, eqs.atoms(Indexed))

ans = [x for x in ans.values()]

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

Submission status: Runtime Error

Solution code:
odd = [a[j] for j in range(1, n, 2)]
even = [a[j] for j in range(0, n-1, 2)]
for i in range(0, min(a[0], a[-1])+1):
  x0 = i*2
  xn = x0 + sum(odd) - sum(even)
  if xn == a[-1]:
    x = [x0]
    for j in range(1, n):
      if j % 2 != 0:
        x.append((even.pop(0) - x[j-1]//2)*2)
      elif j % 2 == 0:
        x.append((odd.pop(0) - x[j-1]//2)*2)
    break
for i in range(n-1):
  print(x[i], end=' ')
print(x[-1])

Submission status: Runtime Error

Solution code:
import numpy
N=int(input())
A=input().split()
for i in range(N):
    A[i]=2*int(A[i])
x=[None]*N
for i in range(N-1):
    x[i]=[0]*N
    x[i][i],x[i][i+1]=1,1
x[N-1]=[0]*N
x[N-1][0],x[N-1][N-1]=1,1
y=numpy.linalg.solve(x,A)
for i in range(N):
    print(int(y[i]),end=' ')

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.zeros((N,N),dtype = int)

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

B = np.array(C)

def calc_double(n):
    return n * 2

X = np.linalg.solve(A,B)
Y = map(calc_double,X.tolist())
Z = map(str,map(int,Y))

print(' '.join(Z))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# 整数の入力
N = int(input())
A = [int(input()) for _ in range(N)]

sum_water = sum(A)
A = A[1:] + A[0:N-2]
for i in range(N):
    tmp=sum_water
    for j in range((N-1)//2):
        tmp-=A[i+j*2]*2
    print(tmp, end="")
    print(" ", end="")

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
B = [int(i)*2 for i in input().split()]

#a = [[0]*N for i in range(N)]
A = np.identity(N)
for i in range(N-1):
    #A[i][i] += 1
    A[i][i+1] += 1

A[-1][0] += 1
#A[-1][-1] += 1
#A = np.array(a)
b = np.array(B)

x = np.linalg.solve(A, b)

print(*x.astype(int))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2,2*start+1,2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
ans = map(str,ans)
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array([list(map(int, input().split()))])
m = np.zeros((n, n))
for i in range(n - 1):
    m[i][i] = 0.5
    m[i][i + 1] = 0.5
m[n - 1][0] = 0.5
m[n - 1][-1] = 0.5

mi = np.linalg.inv(m)

ans = mi.dot(a.T)
for i in ans.flatten():
    print(int(i), end=' ')

Submission status: Runtime Error

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

from scipy.optimize import nnls
A = np.array(A)
b = np.array(data)
x, rnorm = nnls(A, b)
x = np.round(x)
x = list(np.array(x, dtype = int))

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
N = int(input())
B = [int(i)*2 for i in input().split()]

#a = [[0]*N for i in range(N)]
A = np.identity(N)
for i in range(N-1):
    #A[i][i] += 1
    A[i][i+1] += 1

A[-1][0] += 1
#A[-1][-1] += 1
#A = np.array(a)
b = np.array(B)

x = np.linalg.solve(A, b)

print(*x.astype(int))

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A=[int(_) for _ in input().split()]
X=np.eye(N)
for i in range(N-1):
    X[i+1][i]=1
X[0][N-1]=1
ans=np.dot(A,np.linalg.inv(X))*2
print(*ans.astype(int))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
M = np.zeros((N, N), dtype='float32')

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

x = np.linalg.solve(M, A) * 2
x = np.array(x, dtype='int32')

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = [int(i) for i in input().split()]
a = np.eye(N)
b = np.roll(a, 1, axis=1)
A = a + b

Y = np.linalg.solve(A, X)

Y = list(map(lambda x: str(int(x*2)), Y))
print(' '.join(Y))

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = (n,n)
M = np.matrix(np.zeros(s))
for i in range(n):
    vec = np.zeros(n)
    vec[i]=1/2
    if i == (n-1):
        vec[0]=1/2
    else:
        vec[i+1]=1/2
    M[i] = vec
ans = (np.linalg.inv(M)*(ans.reshape(-1,1)))
print(' '.join(map(str, ans.T.tolist()[0])))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2*start,1,-2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
ans = map(str,ans)
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
from sympy import *
import math
x=Symbol('x')

N=int(input())
A=list(map(int,input().split()))
X=[0]*(N+1)
X[0]=x
for n in range(1,N+1):
    X[n]=(A[n-1]-(X[n-1]/2))*2
x_ans=solve(X[0]-X[N])
Xans=[0]*N
Xans[0]=int(x_ans[0])
for n in range(1,N):
    Xans[n]=(A[n-1]-(Xans[n-1]/2))*2
ans=[0]*N
for n in range(N):
    ans[n]=str(int(Xans[n]))
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

E = np.eye(N)
E[1:,:-1] += np.eye(N - 1)
E[0, -1] += 1
E /= 2
ret = list(np.linalg.solve(E, A))
ret = ret[-1:] + ret[:-1]
print(" ".join([str(int(i)) for i in ret]))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(raw_input())
A = map(int, raw_input().split(' '))

K = np.zeros([N,N])

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

X = np.linalg.inv(K).dot( np.array(A).T)
VV =map(int, X*2)
print(' '.join(map(str, VV)))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())

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

A=np.array(A)

B=np.identity(N)

for i in range(N-1):
    B[i][i+1]=1
B[N-1][0]=1

B_inv=np.linalg.inv(B)

A=A.reshape((1,N))
X=2*np.dot(B_inv,A.transpose())

X=list(map(int,X))

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

Submission status: Runtime Error

Solution code:
# D
N = int(input())
data = list(map(int, input().split()))
A = np.zeros((N, N))
for i in range(N-1):
    A[i][i] = 1/2
    A[i][i+1] = 1/2
A[N-1][0] = 1/2
A[N-1][N-1] = 1/2

from scipy.optimize import nnls
A = np.array(A)
b = np.array(data)
x, rnorm = nnls(A, b)
x = np.round(x)
x = list(np.array(x, dtype = int))

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

X = np.array([[1 if (j == i or (j < N-1 and j+1 == i) or (j == N-1 and i == 0))
               else 0 for i in range(N)] for j in range(N)])
b = np.array([A[i] for i in range(N)])

LU = np.linalg.lu_factor(X)
cul = np.linalg.solve(LU, b)
ans = np.array(cul, dtype='int64')
ans = 2 * ans

print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
As = [int(i) for i in input().split()]

mat = np.array([np.zeros(N) for _ in range(N)])

for i in range(N-1):
    mat[i][i], mat[i][i+1] = 1, 1

mat[N-1][0], mat[N-1][N-1] = 1, 1

for i in range(N):
    C = mat[i][i]
    As[i] /= C
    for j in range(N):
        mat[i][j] /= C
    for k in range(N):
        if k == i: continue
        D = mat[k][i]
        for j in range(N):
            mat[k][j] -= mat[i][j] * D
        As[k] -= As[i] * D

print(*[int(i)*2 for i in As])

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
ans = []
sum_all = sum(A) / 2

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import copy


def dist2(y, z):
    return np.sum((y - z)**2)


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

    X_sup = [min([A[i], A[(i - 1 + N)% N]]) for i in range(N)]
    head_i = int(np.argmin(X_sup))

    a = 0
    b = X_sup[head_i]
    c = (a + b) // 2

    X = np.zeros(N, dtype=np.int)
    while True:
        X[head_i] = 2 * c
        for i in range(N-1):
            j = (i + head_i) % N
            X[j+1] = 2 * A[j] - X[j]

        if (X[head_i-1] + X[head_i]) / 2 == A[head_i-1]:
            # Clear
            break
        if (X[head_i-1] + X[head_i]) / 2 < A[head_i-1]:
            # Need to increase X[0]
            a = c
            if c == (a + b) // 2:
                c += 1
            else:
                c = (a + b) // 2
        if (X[head_i-1] + X[head_i]) / 2 > A[head_i-1]:
            # Need to decrease X[0]
            b = c
            if c == (a + b) // 2:
                c -= 1
            else:
                c = (a + b) // 2

    ans = ''
    for i in range(N):
        ans += str(int(X[i]))
        if i < N-1:
            ans += ' '
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from numpy.linalg import solve
N=int(input())
A=input().split()
for i in range(N):
    A[i]=2*int(A[i])
x=[None]*N
for i in range(N-1):
    x[i]=[0]*N
    x[i][i],x[i][i+1]=1,1
x[N-1]=[0]*N
x[N-1][0],x[N-1][N-1]=1,1
y=solve(x,A)
for i in range(N):
    print(int(y[i]),end=' ')

Submission status: Runtime Error

Solution code:
def main():
	import sys
	import numpy as np
	# import scipy.linalg as linalg
	from scipy.sparse.linalg import spsolve
	from scipy.sparse import csr_matrix
	input = sys.stdin.readline
	N = int(input())
	A = np.array(list(map(int, input().split())))
	arr1 = np.eye(N)
	arr2 = np.eye(N, k=1)
	arr2[-1, 0] = 1
	arr = arr1 + arr2
	# LU = linalg.lu_factor(arr)

	b = 2 * A

	# arr_inv = np.linalg.inv(arr)
	# print(arr_inv)
	# x = np.dot(arr_inv, b)
	# x = linalg.lu_solve(LU, b)
	arr = csr_matrix(arr)
	x = spsolve(arr, b, use_umfpack=True)

	# x = np.linalg.solve(arr, b)
	x = np.array(x, dtype=int)
	print(*x)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
from numpy.linalg import solve

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

right = np.asarray(a)*2
left = np.zeros([n,n])
for i,_ in enumerate(a):
    if i != n-1:
        left[i,i:i+2] = 1
    else:
        left[i,0] = 1
        left[i,i] = 1
        
out = list(map(int, solve(left, right)))
print(" ".join(map(str, out)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa


A = np.zeros((n, n), dtype=np.int)
exit()
for i in range(n-1):
    A[i][i] = 1
    A[i][i+1] = 1
exit()
A[n-1][n-1] = 1
A[n-1][0] = 1

exit()

Submission status: Runtime Error

Solution code:
import scipy.linalg as linalg

import numpy as np
n = int(input())
b = np.array(list(map(int, input().strip().split())))
b *= 2
A = np.zeros((n,n))
for i in range(n):
    if i == n - 1:
        A[i,0] = 1
        A[i,n-1] = 1
    else:
        A[i,i] = 1
        A[i,i+1] = 1

#Ainv = np.linalg.inv(A)
#x = np.dot(Ainv, b)

#x = np.linalg.solve(A, b)

LU = linalg.lu_factor(A)
x = linalg.lu_solve(LU, b)

s = str(x.astype(int))
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
odd = [a[j] for j in range(1, n, 2)]
even = [a[j] for j in range(0, n-1, 2)]
for i in range(0, min(a[0], a[-1])):
  x0 = i*2
  xn = x0 + sum(odd) - sum(even)
  if xn == a[-1]:
    x = [x0]
    for j in range(1, n):
      if j % 2 != 0:
        x.append((even.pop(0) - x[j-1]//2)*2)
      elif j % 2 == 0:
        x.append((odd.pop(0) - x[j-1]//2)*2)
    break
for i in range(n-1):
  print(x[i], end=' ')
print(x[-1])

Submission status: Runtime Error

Solution code:
# D
N = int(input())
data = list(map(int, input().split()))
A = np.zeros((N, N))
for i in range(N-1):
    A[i][i] = 1/2
    A[i][i+1] = 1/2
A[N-1][0] = 1/2
A[N-1][N-1] = 1/2

from scipy.optimize import nnls
A = np.array(A)
b = np.array(data)
x, rnorm = nnls(A, b)
x = np.round(x)
x = list(np.array(x, dtype = int))
for i in range(N):
    print("{} ".format(x[i]), end="")

Submission status: Runtime Error

Solution code:

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

right = np.asarray(a)*2
left = np.zeros([n,n])
for i,_ in enumerate(a):
    if i != n-1:
        left[i,i:i+2] = 1
    else:
        left[i,0] = 1
        left[i,i] = 1
        
out = list(map(int, solve(left, right)))
print(" ".join(map(str, out)))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
L = [int(x)*2 for x in input().split()]

mat = np.zeros([N, N])
for i in range(N-1):
	mat[i][i]=1
	mat[i][i+1]=1
mat[N-1][0]=1
mat[N-1][-1]=1

result = [str(int(x)) for x in np.linalg.solve(mat, L)]
print(' '.join(result))

Submission status: Runtime Error

Solution code:
import numpy as np

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

arr=np.zeros((n,n))
for i in range(n):
  for j in range(n):
    if((i+j)%2==0 and(i-j)<=0):
      arr[i,j]=0.5
    elif((i+j)%2==1 and(i-j)<=0):
      arr[i,j]=-0.5

for i in range(n):
  for j in range(n):
    if((i+j)%2==0 and(i-j)>0):
      arr[i,j]=-0.5
    elif((i+j)%2==1 and(i-j)>0):
      arr[i,j]=0.5
#print(arr)
x=2*np.dot(arr,A)

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
b = np.array(list(map(int, input().strip().split())))
b *= 2
A = np.zeros((n,n))
for i in range(n):
    if i == n - 1:
        A[i,0] = 1
        A[i,n-1] = 1
    else:
        A[i,i] = 1
        A[i,i+1] = 1

#Ainv = np.linalg.inv(A)
#x = np.dot(Ainv, b)

x = np.linalg.solve(A, b)

s = str(x.astype(int))
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
M = np.zeros((N, N), dtype=int)
for i in range(N - 1):
    M[i][i], M[i][i + 1] = 1, 1
M[N - 1][0], M[N - 1][N - 1] = 1, 1

x = np.linalg.solve(M, A) * 2
x = np.array(x, dtype='int32')

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

Submission status: Runtime Error

Solution code:
import numpy as np


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

A = np.zeros((N, N), dtype='float32')
Y = np.array(Rain).reshape(N, 1)
for i in range(N):
    if i==N-1:
        j = 0
    else:
        j = i+1
    A[i][i] = 1
    A[i][j] = 1

X = np.dot(np.linalg.inv(A), Y)

Ans = []
for x in X:
    Ans.append(int(x)*2)

print(*Ans, sep=" ")

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = (n,n)
M = np.matrix(np.zeros(s))
for i in range(n):
    vec = np.zeros(n)
    vec[i]=1/2
    if i == (n-1):
        vec[0]=1/2
    else:
        vec[i+1]=1/2
    M[i] = vec
ans = (np.linalg.inv(M)*(ans.reshape(-1,1)))
print(' '.join(map(str, map(int, ans.T.tolist()[0]))))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa


A = np.zeros((n, n), dtype=np.int)

for i in range(n-1):
    A[i][i] = 1
    A[i][i+1] = 1
exit()
A[n-1][n-1] = 1
A[n-1][0] = 1

exit()

Submission status: Runtime Error

Solution code:
l, r = [int(i) for i in input().split()]

base = 2019
l_mod = l % base
r_mod = r % base

print(l_mod * (l_mod + 1))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(raw_input())
A = map(int, raw_input().split(' '))

K = np.zeros([N,N])

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

X = np.linalg.inv(K).dot( np.array(A).T)
V=map(int, X*2)
print(*V)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.matrix(list(map(int, input().split()))).T
_a = np.eye(n) + np.roll(np.eye(n),1, axis=1)
ans = map(int, np.linalg.inv(_a) * a * 2)
ans = map(str, ans)
print(" ".join(ans))

Submission status: Runtime Error

Solution code:
# D
N = int(input())
data = list(map(int, input().split()))
A = np.zeros((N, N))
for i in range(N-1):
    A[i][i] = 1/2
    A[i][i+1] = 1/2
A[N-1][0] = 1/2
A[N-1][N-1] = 1/2

from scipy.optimize import nnls
A = np.array(A)
b = np.array(data)

x, rnorm = nnls(A, b)
x = np.round(x)

print(np.array(x, dtype = int))

Submission status: Runtime Error

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

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
a = (x + y) / 2

b = np.array(A)
b = b.reshape((1, N))
b = b.transpose()

ans = np.linalg.solve(a, b)
ans = [int(n) for n in ans]

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.zeros((N,N),dtype = int)

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

B = np.array(C)

X = np.linalg.solve(A,B)
Y = X.tolist()

for j in range(N):
    print(str(int(Y[j]*2)),end=' ')

Submission status: Runtime Error

Solution code:
import numpy as np

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

P = np.zeros((N, N))
for i in range(N):
  P[i,i] = 1
  if i == N-1:
    P[i,0] = 1
  else:
    P[i,i+1] = 1
    
a = np.array(A)
x = 2 * np.linalg.inv(P).dot(a)
print(' '.join(x.astype(int).astype(str)))

Submission status: Runtime Error

Solution code:
N=int(input())
AL=[int(x) for x in input().split()]

cmid=0
left=0
right=AL[0]*4
while True:
    if cmid==mid:
        print('e')
        break
    cmid=mid
    
    flag=True
    mid=(left+right)//2
    k=mid
    L=[k]
    for i,a in enumerate(AL):
        if a<k//2:
            if i%2==0:#midを減らす
                right=mid-1
                flag=False
                break
            else:#midを増やす
                left=mid+1
                flag=False
                break
        else:
            k=(a-k//2)*2
            L.append(k)

    if flag:
        if mid==k:
            print(" ".join([str(x) for x in L[:-1]]))
            break
        elif (k+mid)/2>a:#減らす
            right=mid-1
        else:#増やす
            left=mid+1

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
d = list(map(int, input().split()))
# print(n)
# print(d)
a = np.zeros((len(d),len(d)))
for i in range(n):
    a[i][i] = 1
    a[i][(i+1)%n] = 1
# print(a)
d = np.array(d)
# print(d)
solved = np.dot(np.linalg.inv(a), 2 * d.T)
for i in range(n):
    print(int(solved[i]),end=" ")
print("")

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
A = list(map(int,input().split()))
A=np.array(A)
E = np.zeros((n,n),dtype=int)
for i in range(n):
  for j in range(n):
    if (i==j):
      E[i,j] = 1
    elif i<j:
      if (i+j)%2==0:
        E[i,j] = 1
      else:
        E[i,j] = -1
    else:
      if (i+j)%2==0:
        E[i,j] = -1
      else:
        E[i,j] = 1
out = [str(i) for i in np.dot(E,(A.T))]
print(" ".join(out))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa

A = np.zeros((n, n), dtype=np.int)

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

A[n-1][n-1] = 1
A[n-1][0] = 1

exit()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
mat = np.zeros([N, N])
for i in range(N):
    if i==N-1:
        mat[i][0] = 1
        mat[i][-1] = 1
    else:
        mat[i][i] = 1
        mat[i][i+1] = 1

A = np.array(A)
A *= 2
res = np.dot(A, np.linalg.inv(mat))
for i in range(N):
    if i == 0:
        print(int(res[-1]), end=' ')
    else:
        print(int(res[i-1]), end = ' ')

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa

A = np.zeros((n, n), dtype=np.int)

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

A[n-1][n-1] = 1
A[n-1][0] = 1

exit()
S = np.linalg.solve(A,y)*2

for i in range(n-1):
    print(int(S[i][0]), end=" ")
print(int(S[n-1][0]))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
b = np.array(list(map(int, input().strip().split())))
b *= 2
A = np.zeros((n,n))
for i in range(n):
    if i == n - 1:
        A[i,0] = 1
        A[i,n-1] = 1
    else:
        A[i,i] = 1
        A[i,i+1] = 1

Ainv = np.linalg.inv(A)         # A の逆行列を計算
x = np.dot(Ainv, b)             # A の逆行列と b の内積
s = str(x.astype(int))
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
numbers = np.array(list(map(int, input().split())))
A = np.zeros((N,N))
for i in range(N-1):
    A[i,i] = 0.5
    A[i,i+1] = 0.5
A[N-1,N-1] = 0.5
A[N-1,0] = 0.5
B = np.linalg.inv(A)
C = [B[i].dot(numbers) for i in range(N)]
D = [int(C[i]) for i in range(N)]
E = str(D[0])
for i in range(N-1):
    E += " " + str(D[i+1])
print(E)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
import numpy as np
D = np.array(A)
M = np.zeros((N,N))
for n in range(N):
    M[n][n] = .5
    if n == N-1:
        M[n][0] = 0.5
    else:
        M[n][n+1] = 0.5
X = np.linalg.solve(M,D)
for n in range(N):
    print(int(X[n]), end=" ")

Submission status: Runtime Error

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

m = (n-1)/2

ls = [ans for _ in range(n)]

for i in range(n):
    for j in range(int(m)):
        ls[i] = str(ls[i]-2*(a[i+1+2*j]))

print(" ".join(ls))

Submission status: Runtime Error

Solution code:
# coding: utf-8
l, r = list(map(int, input().split()))
if l // 2019 == r // 2019:
    _l = l % 2019
    n = min(r - l + 1, 2019)
    a = list(range(_l, min(2019, _l + n)))
    a.extend(list(range(0, n - len(a))))
    a.sort()
    a0 = (a[0] * a[1]) % 2019
    a1 = (a[-1] * a[-2]) % 2019
    print(min(a0, a1))
else:
    print(0)

Submission status: Runtime Error

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

    ans = L * R % 2019
    if L // 2019 < R // 2019:
        ans = 0
    else:
        l = L % 2019
        r = R % 2019
        ans = l * r
       for i in range(l+1, r+1):
            ans = min(ans, l*i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools


def rainMt(R):
    W = [0] * len(R)

    for i in range(len(R)):
        W[i] = (R[i] + R[(i + 1) % len(R)]) / 2
    return W


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

totalR = sum(A)

R = [0] * N

r = list(range(0, totalR+1, 2))

for R in list(itertools.permutations(r, N)):
    if (A == rainMt(R)):
        print(R)
        exit(0)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    Mt = [0]*(N+1)

    def is_ok(x,Mt):
        Mt[0]=x
        for i in range(N):
            Mt[i+1] = int(2* (A[i] - (Mt[i]/2)))
            if Mt[i+1] < 0 or Mt[i+1]%2 == 1:
                return False
        return Mt[0] == Mt[-1]

    mini = min(A) + 1
    for i in range(2*mini):
        if is_ok(i,Mt):
            print(*Mt[:-1])
            exit()
    print(A[inf])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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


C = np.zeros(N**2).reshape(N,N)
for i in range(N):
    if i != N-1:
        C[i][i] = 1
        C[i][i+1] = 1
    if i == N-1:
        C[i][i] = 1
        C[i][0] = 1
P = np.matrix(C)

x = np.array(np.dot(np.linalg.inv(P), np.matrix(A).T), np.int64)

ans = (2*x.T).flatten()

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