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:
# your code goes here
import numpy as np
n=int(input())
arr=[[0]*n]
arr=arr*n
#print(arr)

A=np.array(arr)
for i in range(n):
	A[i][i]=1
	#print(A)
	A[i][(i+1)%n]=1
#print(A)

B=np.linalg.inv(A)
c=[int(i) for i in input().split()]
C=np.array(c)
x=np.matmul(C,B)
#print(x)
for i in range(-1,x.shape[0]-1):
	print(int(x[i%n]*2),end=" ")

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)])

ans = np.linalg.solve(X, b)

ans1 = np.array([*ans], dtype=np.int64)

ans1 = 2*ans1

print(*ans1)

Submission status: Runtime Error

Solution code:
import math
l,r = list(map(int,input().split()))
f = [0]*2020
x = []
ans = 2020
for i in range(l,r):
    if f[i%2019] == 0:
        x.append(i%2019)
        f[i%2019] = 1
    else:
        break
x.sort()


print(x[0]*x[1])

Submission status: Runtime Error

Solution code:
#! /usr/bin/python3

import numpy as np

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

mat = np.identity(N)

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

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

# X = np.dot(np.linalg.inv(mat), A)

for x in X:
    print(int(2 * x), end = " ")

print("\n")

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:
import numpy as np

N = int(input())

t = [int(x) for x in input().split()]

t = np.array(t).reshape(N, 1)
A = np.eye(N, N)
A[:-1, :] += A[1:, :]
A[N-1, 0] = 1

t = 2*np.dot(np.linalg.inv(A), t)

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

diag = [.5 for i in range(n)]

A = np.diag(diag)
for i in range(n-1):
  A[i][i+1] = .5

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

b = []
for i in range(n):
  b.append([a_list[i]])

x = np.linalg.solve(A, b)
tmp = [str(int(i[0])) for i in x]
print(' '.join(tmp))

Submission status: Runtime Error

Solution code:
#! /usr/bin/python3

import numpy as np

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

mat = np.identity(N)

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


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

for x in X:
    print(int(2 * x), end = " ")

print("\n")

Submission status: Runtime Error

Solution code:
def main():
	import sys
	import numpy as np
	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

	b = 2 * A

	arr_inv = np.linalg.inv(arr)
	x = np.dot(arr_inv, b)
	x = np.array(x, dtype=int)

	print(*x)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

v0 = np.array([0.5]*N)
A0 = np.diag(v0, k=0)
v1 = np.array([0.5]*(N-1))
A1 = np.diag(v1, k=1)
A = A0 + A1
A[N-1][0] = 0.5
Ainv = np.linalg.inv(A)
x = list(np.dot(Ainv, b))
x = [int(xj) for xj in x]
print(*x)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

b = 2 * np.array(list(map(int, input().split())))
A = np.zeros((N, N))

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

Ainv = np.linalg.inv(A)         # A の逆行列を計算
x = np.dot(Ainv, b)             # A の逆行列と b の内積

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

x = np.eye((n))
for i in range(n-1):
    x[i, i+1] = 1
x[n-1, 0] = 1

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

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

Submission status: Runtime Error

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


x = np.roll(np.eye(N),1)
x[0,0]=0
x[N-1,0]=1
x += np.eye(N)
x /= 2


print(" ".join( list(map(str,list(map(int,solve(x,A).tolist()))))))

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][i] = 1
        mat[i][i + 1] = 1
    else:
        mat[i][i] = 1
        mat[i][0] = 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:
N = int(input())
A = list(map(int, input().split()))

import numpy as np
W = np.zeros((N, N))
for i in range(N-1):
    W[i, i] = 0.5
    W[i, i+1] = 0.5
W[N-1, N-1] = 0.5
W[N-1, 0] = 0.5

A = np.array(A)

x = (np.linalg.inv(W).dot(A)+0.1).astype(int)

for xx in x[:-1]:
    print(xx, end=' ')
print(x[-1])

Submission status: Runtime Error

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

arr = np.identity(n)
for i in range(n):
        arr[i][(i+1)%n] += 1

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

ans = ""
for i in range(n):
        if i != n-1:
                print(int(x[i]),end=" ") 
        else:
                print(int(x[i]))

Submission status: Runtime Error

Solution code:
import numpy as np

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

    mA = np.zeros((N, N))
    for i in range(N):
        if i < N - 1:
            mA[i, i] = mA[i, i + 1] = 1
        else:
            mA[i, 0] = mA[i, i] = 1
    ans = np.linalg.inv(mA)
    for i, j in enumerate(ans.dot(A)):
        print(int(j), end="")
        if i == N - 1:
            print()
        else:
            print(" ", end="")

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
tmp=0
fugo=-1
for i in range(N):
    fugo*=-1
    tmp+=fugo*A[i]
ans.append(tmp)

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

for x in ans:
    print(x_, end=' ')
print()

Submission status: Runtime Error

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

import numpy as np
W = np.zeros((N, N))
for i in range(N-1):
    W[i, i] = 0.5
    W[i, i+1] = 0.5
W[N-1, N-1] = 0.5
W[N-1, 0] = 0.5

A = np.array(A)

x = np.linalg.inv(W).dot(A).astype(int)

for xx in x[:-1]:
    print(xx, end=' ')
print(x[-1])

Submission status: Runtime Error

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

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

r = (2 * np.dot(np.linalg.inv(w), A)).astype(np.int64).astype(np.str)
print(" ".join(r))

Submission status: Runtime Error

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

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

r = (2 * np.linalg.inv(w) @ A).astype(np.int64).astype(np.str)
print(" ".join(r))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(lambda x: int(x),input().split())))
X = 0.5*np.eye(N)
Y = np.roll(X, -1, axis=1)
X = X+Y
#for i in range(N):
#    X[i][(N+i-1)%N] = 0.5
#print(X)
#print(np.dot(A,np.linalg.inv(X)))
ans = list(map(lambda x: int(x),list(np.dot(A,np.linalg.inv(X)))))
#print(ans)
print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

v0 = np.array([0.5]*N)
A0 = np.diag(v0, k=0)
v1 = np.array([0.5]*(N-1))
A1 = np.diag(v1, k=-1)
A = A0 + A1
A[0][N-1] = 0.5
Ainv = np.linalg.inv(A)
x = list(np.dot(Ainv, b))
ans = [x[-1]] + x[:N-1]
ans = [int(a) for a in ans]
print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

X = np.eye(n)
for i in range(n - 1):
  X[i, i + 1] = 1

X[n-1, 0] = 1
res = np.linalg.solve(X, 2*a)
for i in range(n):
  print(int(res[i]), end=" ")

print("")

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
list = []
d = 2018
for i in range(L, R+1):
    for j in range(i+1, R+1):
        mal = i * j
        a = mal % 2019
        if a < d:
            list.append(a)
        d = a
if a == 2018:
    print(2018)
print(min(list))

Submission status: Runtime Error

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

arr = np.identity(n)
for i in range(n):
        arr[i][(i+1)%n] += 1

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

ans = ""
for e in x:
       ans += str(int(e))
       ans += " "

print(ans[:-1])

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
list = []
d = 2018
for i in range(L, R+1):
    for j in range(i+1, R+1):
        mal = i * j
        a = mal % 2019
        if a < d:
            list.append(a)
        d = a
print(min(list))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

t = [int(x) for x in input().split()]

t = np.array(t)

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

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

t = 2*np.dot(np.linalg.inv(A), t)

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

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
B_=list(map(lambda x: 2*x,A))
A=np.eye(N,N,1)+np.eye(N,N)
A[N-1][0]=1

x=np.linalg.solve(A, B_)
x=list(map(int,list(x)))

for x_ in x:
    print(x_, end=' ')
print()

Submission status: Runtime Error

Solution code:
import numpy as np

#n= map(int, input().split())
n=input()

f=lambda x:int(x)

a=np.array(list(map(f,input().split())))

#print(n)
#print(a)



x=np.zeros( (len(a),len(a)) )

#print(x)
#print(x.shape)

for i in range( len(a) ):
    if(i== len(a)-1 ):
        x[i][0]=1
        x[i][i]=1
    else:
        x[i][i]=1  
        x[i][i+1]=1

#print(x)
#print(np.linalg.inv(x))

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

#print(ans)

for i in ans:
    print(int(i))

Submission status: Runtime Error

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

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    import numpy as np
    q = np.zeros(shape=(N, N))
    for i in range(N):
        for j in range(N):
            if i == j:
                q[i][j] = 1
            if i == N-1:
                q[i][0] = 1
            else:
                if i+1 == j:
                    q[i][j] = 1

    a = np.array(a_list)
    qinv = np.linalg.inv(q)
    dprint(q)
    x = 2 * np.dot(qinv, a)
    dprint(x)
    x = list(x.astype(int))
    print(" ".join([str(i) for i in x]))

solve()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(lambda x: int(x),input().split())))
X = 0.5*np.eye(N)
for i in range(N):
    X[i][(N+i-1)%N] = 0.5
#print(X)
#print(np.dot(A,np.linalg.inv(X)))
ans = list(map(lambda x: int(x),list(np.dot(A,np.linalg.inv(X)))))
#print(ans)
print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:
import numpy as np

#n= map(int, input().split())
n=input()

f=lambda x:int(x)

a=np.array(list(map(f,input().split())))

#print(n)
#print(a)



x=np.zeros( (len(a),len(a)) )

#print(x)
#print(x.shape)

for i in range( len(a) ):
    if(i== len(a)-1 ):
        x[i][0]=1
        x[i][i]=1
    else:
        x[i][i]=1  
        x[i][i+1]=1

#print(x)
#print(np.linalg.inv(x))

ans = 2 * np.matmul( np.linalg.inv(x) , a )

#print(ans)

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
M = np.eye(N)
for i in range(N):
    M[i][(i + 1) % N] = 1
x = 2 * (np.linalg.inv(M).dot(A))
print(" ".join(map(lambda t: str(int(round(t))), x)))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
C = np.array(C, dtype='int64')
X = 2*np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)

Submission status: Runtime Error

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

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


N=int(input())
a=np.array(acinput())

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

for i in range(N):
    L[i,i]=1
    L[i,(i+1)%N]=1
    
tmp=2*np.dot(inv(L),a)

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
M = np.eye(N)
for i in range(N):
    M[i][(i + 1) % N] = 1
x = 2 * (np.linalg.inv(M) @ A)
print(" ".join(map(lambda t: str(int(round(t))), x)))

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
y=np.array(a)
A=np.eye(n)
for i in range(n):
    A[i-1][i]=1
#print(A)
x=np.linalg.solve(A,y)
for i in range(n):
    print(int(x[i])*2,end=' ')
print()

Submission status: Runtime Error

Solution code:
import numpy as np





n = int(input())
arr = list(map(int,input().split()))
arr = np.array(arr)
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

# print(A)
ans = np.linalg.solve(A, arr)

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

print(int(ans[n-1]))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
*A, = map(int, input().split())
A = np.array(A, dtype='int64')
C = np.diag([1 for _ in range(N)]) + np.diag([1 for _ in range(N-1)], k=1)
C[-1, 0] = 1
X = np.linalg.solve(C, A)
X = list(map(int, X))
print(*X)

Submission status: Runtime Error

Solution code:
import numpy as np


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


x = np.roll(np.eye(N),1)
x[0,0]=0
x[N-1,0]=1
x += np.eye(N)
x /= 2

print(" ".join( list(map(str,list(map(int,np.dot(np.linalg.inv(x),A).tolist()))))))

Submission status: Runtime Error

Solution code:
mod = 2019
l,r = map(int,input().split())

if l==0 or r//mod - (l-1)//mod >= 1:
  print(0)
else:
  print(l*(l+1)%mod)

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][i] = 1
        mat[i][i + 1] = 1
    else:
        mat[i][i] = 1
        mat[i][0] = 1

A = np.array(A)
A *= 2
ret = np.dot(A, np.linalg.inv(mat))
res = []
for r in ret:
    res.append(int(r))

res = [res[-1]] + res[:-1]
for r in res:
    print(r, end=' ')

Submission status: Runtime Error

Solution code:
import numpy as np


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 4
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


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

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

ans = np.linalg.solve(A, arr)

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

print(int(ans[n-1]))

Submission status: Runtime Error

Solution code:
def solve():
  l,r = (int(i) for i in input().split())
  mod = 2019
  l %= mod
  r %= mod
  ans = 10**15
  if l > r :
    print(0)
    exit()
  elif l == 0 or r == 0:
    print(0)
    exit()
  else:
    for i in range(l,r):
      for j in range(l+1,r+1):
        if i<j:
         ans = min(ans,(i*j)%mod)
  print(ans%mod)

solve()

Submission status: Runtime Error

Solution code:
import numpy as np
from math import *
N = int(input())
A = np.matrix([int(a) for a in input().split()]).T
M = np.eye(N) + np.roll(np.eye(N), -1, 0)
x = np.linalg.inv(M) * A

for i in range(N):
    print(int(round(x[i,0]*2)))