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(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(VV[0], VV[1], VV[2])

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.eye(N, k=0) + np.eye(N, k=1) + np.eye(N, k=1-N)

a_matrix = np.array(a)
b_matrix = np.array(A)

x = np.linalg.solve(a_matrix,b_matrix)

x = x * 2

for i in range(N):
    print(int(x[i]),end="")
    if(i != N-1):
        print(" ",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)
k = np.zeros((N,N))

k[0,0] = 0.5
k[0,N-1] = 0.5
for i in range(1,N):
    for j in range(i+1):
        if i - j == 0 or i -j == 1:
            k[i,j] = 0.5

k = np.linalg.inv(k)

ans = np.dot(k,A)
for i in range(N):
    print(int(ans[i]),end=" ")

Submission status: Runtime Error

Solution code:
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
import math
import datetime
import numpy
from pprint import pprint
N = int(input())
A = [int(x) for x in input().split()]
import time

mat = numpy.zeros((N,N))
a2 = numpy.array(A).reshape(-1,1)

#pprint(a2)

for i in range(N):
    mat[i,i] = 0.5
    j = i + 1 if i != N -1 else 0
    mat[i,j] = 0.5
#print("mat")
#pprint(mat)
rev_mat = numpy.linalg.inv(mat)
#print("rev")
#print(rev_mat)

ans = numpy.dot(rev_mat,a2)
da = []
for a in ans:
    for b in a:
        da.append(str(int(b)))
print(" ".join(da))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
X = [int(i) for i in input().split()]
print(N)
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 sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    A = list(map(int, input().split())) # 0 ~ N-1 0-indexed
    truesum = sum(A)

    for m_fixed in range(max(A[-1],A[0])): # 0を固定
        if m_fixed%2!=0:
            continue
        if A[-1]-m_fixed//2 < 0 or A[0]-m_fixed//2 < 0:
            continue
        f = False
        mm = [0]*N
        mm[0] = m_fixed
        aa = deepcopy(A)
        aa[-1] -= m_fixed//2
        aa[0] -= m_fixed//2
        if aa[-1] < 0 or aa[0] < 0:
            continue
        for i in range(1,N):
            mm[i] = aa[i-1]*2
            if aa[i] < aa[i-1]:
                f = True
                break
            aa[i] -= aa[i-1]
            aa[i-1] = 0
        if f or truesum != sum(mm):
            continue
        return mm
        


if __name__ == '__main__':
    print(*main(), sep=" ")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from numpy.linalg import solve

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

x = np.identity(n)
x[::][1:] += x[::][:n-1]
x = x.T
x[n-1][0] += 1

print(" ".join(solve(x, a).astype(np.int64).astype('str')))

Submission status: Runtime Error

Solution code:
from numpy.linalg import inv
from numpy import zeros, dot

n = int(input())

x = input().split(' ')

a = [int(v) for v in x]

Z = zeros((n, n))

for i in range(n):
    Z[i, i:i + 1] = 0.5

Z[0, 1] = 0
Z[0, n - 1] = 0.5

N = dot(inv(Z), a).astype('int')

N = [str(p) for p in N]

print(' '.join(N))

Submission status: Runtime Error

Solution code:
import numpy as np

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.zeros((N, N))
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()]
a = np.array(a)
x = np.eye(n)
for i in range(n-1):
    x[i][i+1] = 1
x[n-1][0] = 1
print(*map(int,np.dot(np.linalg.inv(x),a)*2))

Submission status: Runtime Error

Solution code:
N = int(input())

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

def mountain_validation(mountain1, dam_list):
    candidate = [mountain1]
    for i in range(len(dam_list)):
        tmp = dam_list[i] - candidate[i]
        if tmp >= 0:
            candidate.append(tmp)
        else:
            return -1
    if candidate[0] != candidate[-1]:
        return -2
    return candidate

Left = 0
Right = 5 * 10 ** 8 + 1

import math
for _ in range(50):
    mid = math.floor((Left + Right) / 2)
    tmp = mountain_validation(mid, dam_list)
    if tmp == -1:
        Right = mid
    elif tmp == -2:
        Left = mid + 1
    else:
        break;

ans = list(map(lambda x: x * 2, tmp[:-1]))
print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:

L, R = map(int, input().split())
# 2019 = 3*673
p = 673
if R-L>=p:
    print(0)
else:
    ans = 2019
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min((i*j)%2019, ans)
    print(ans)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

ll mod_combi(ll n, ll m){
    ll tmp = mod_mul(fac[n],invfac[n-m]);
    return mod_mul(tmp,invfac[m]);
}

int main(void){

  ll n;
  cin>>n;

  vector<ll> a(n);

  ll sum=0;

  ll sum_o=0;
  ll sum_e=0;

  vector<ll> sum_o_v;
  vector<ll> sum_e_v;

  rep(i,n){
    cin>>a[i];
    sum+=a[i];
    if(i%2==1){
      sum_e+=a[i];
      //sum_e_v.pb(sum_e);
    }
    else{
      //sum_o++;
      sum_o+=a[i];
      //sum_o_v.pb(sum_o);
    }
    sum_e_v.pb(sum_e);
    sum_o_v.pb(sum_o);
    
  }
  /*
  for(auto x:sum_e_v) cout << x << endl;
  cout << endl;
  for(auto x:sum_o_v) cout << x << endl;

  cout << endl;
  cout << sum << endl;
  */

  rep(i,n){
    ll tmp=sum;
    //cout << (sum_e_v[n-1] - sum_e_v[i]  ) << endl;
    //cout << sum_o_v[i-1] << endl;
    //cout << endl;
    if(i%2==0){
      if(i==0){
        tmp= tmp -2*(sum_e_v[n-1] - sum_e_v[i]  );
      }
      else{
        tmp= tmp -2*(sum_e_v[n-1] - sum_e_v[i]  ) - 2*(sum_o_v[i-1]);
      }
      
    }
    else{
      tmp= tmp - 2*(sum_o_v[n-1] - sum_o_v[i]  ) - 2*(sum_e_v[i-1]);
    }

    cout << tmp << " ";
    //cout << endl;
  }
  cout << endl;

  return 0;

}

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.zeros([N,N])
for i in range(N):
  mat[i,i] = 1/2
  if i != N-1:
    mat[i,i+1] = 1/2
  else:
    mat[i,0] = 1/2
solve = np.dot(np.linalg.inv(mat),A)
for j in solve:
  print(int(j))

Submission status: Runtime Error

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

mod = 2019
for i in range(1000):
  if L <= 3**i%(1e9+7) <= R or L <= 673**i%(1e9+7) <= R or L <= 3*673*i%(1e9+7) <= R or L <= 3*i%(1e9+7) <= R or L <= 673*i%(1e9+7) <= R or L <= 3*673**i%(1e9+7) <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))

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)
print(map(int, X*2))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.array(a)
m = np.zeros((n, n))

for i in range(n):
    m[i][i] = 1
    if i + 1 >= n:
        m[i][i + 1 - n] = 1
    else:
        m[i][i + 1] = 1

inv_m = np.linalg.inv(m)
x = np.dot(inv_m, a)

for i in x:
    print(round(float(i*2)), end=" ")

print()

Submission status: Runtime Error

Solution code:
import numpy

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

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:
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
print(ans)

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
for i in range(N - 1):
    print(int(x[i]), end=" ")
print(int(x[N - 1]))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mt = [None] * N

    for s in range(A[0] * 2, -1, -2):
        mt[0] = s
        for n in range(N-1):
            if mt[n] > A[n+1] * 2:
                break
            mt[n+1] = (A[n+1] - mt[n]//2) * 2
        if mt[N-1] //2 + mt[0] // 2 == A[0]:
            print(mt[-1], ' '.join(list(map(str, mt[:-1]))))
            return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from numpy import array
from numpy.linalg import solve
import sys

N=input()
A=map(int, sys.stdin.readline().split())

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print int(ans)*2,

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
#inv_x=np.linalg.inv(x)
#ans=np.dot(inv_x,a)
ans=np.linalg.solve(x,a)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
print(" ".join(ans))

Submission status: Runtime Error

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

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.int32)



print(' '.join(map(str, (2*x.T).flatten())))

Submission status: Runtime Error

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

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

X = []

X.append(X1by2)
for i in range(len(A-1)):
  X.append((A[i]-X[i]/2)*2)

print(" ".join(repr(int(e)) for e in X))

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.zeros([N,N])
for i in range(N):
  mat[i,i] = 1/2
  if i != N-1:
    mat[i,i+1] = 1/2
  else:
    mat[i,0] = 1/2
solve = np.dot(np.linalg.inv(mat),A)
solve = [int(i) for i in solve]
print(solve)

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy.linalg as linalg

n = int(input())
b = [[int(i)] for i in 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

invA = np.linalg.pinv(A)
x = np.dot(invA, b)

tmp = [str(int(round(i[0], 0))) for i in x]
print(' '.join(tmp))

Submission status: Runtime Error

Solution code:
def main():
	import sys
	import numpy as np
	# import scipy.linalg as linalg
	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)
	x = np.linalg.solve(arr, b)
	x = np.array(x, dtype=int).tolist()

	print(*x)


if __name__ == '__main__':
    main()

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

v = np.array([1]*N)
A_inv = np.diag(v, k=0)
for n in range(N):
    A_inv += np.diag(((-1)**(n+1))*v[n:], k=-n)
    A_inv += np.diag(((-1)**n)*v[n:], k=n)
x = list(np.dot(A_inv, b))
x = [int(xj) for xj in x]
print(*x)

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-1):
  arr[i,i]=1
  arr[i+1,i]=1

arr[n-1,n-1]=1
arr[0,n-1]=1

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
inv_x=np.linalg.inv(x)
ans=np.dot(inv_x,a)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
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)
M = np.zeros([N,N])

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

inv_M = np.linalg.inv(M)
R = np.dot(inv_M,A)
Ans = [int(r)*2 for r in R]
for i in range(N):
    if i == N-1:
        print(Ans[i])
    else:
        print(Ans[i],end=" ")

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())


b = np.asarray(list(map(int, input().split(" ")))) * 2

A = np.zeros((N, N))
for i in range(N):
    A[i][i] = 1
    if i == N-1:
        A[i][0] = 1
    else:
        A[i][i+1] = 1
    
x = np.linalg.solve(A, b)
x = np.round(x).astype(int)
out = " ".join([str(elm) for elm in x])
print(out)

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
print(x)

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], dtype=int)
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 = np.linalg.solve(mat, L)
S = ""
for i in range(len(result)-1):
	S+=str(int(result[i])) + " "

S+= str(int(result[-1]))
print(S)

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

cul = np.linalg.solve(X, b)
ans = np.array([*cul], dtype='int32')
ans = 2 * ans

print(*ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
print(f'A:{A}')
x = (sum([A[i] for i in range(N) if i % 2 == 0]) - sum([A[i] for i in range(N) if i % 2 == 1]))
print(x)
for  i in range(N-1):
    x = 2*A[i]-x
    print(x)

Submission status: Runtime Error

Solution code:
import numpy

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

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 = numpy.linalg.solve(B,Y)

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

Submission status: Runtime Error

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

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

mat = np.zeros([N,N])
for i in range(N):
  mat[i,i] = 1/2
  if i != N-1:
    mat[i,i+1] = 1/2
  else:
    mat[i,0] = 1/2
solve = np.dot(np.linalg.inv(mat),A)
print(solve)

Submission status: Runtime Error

Solution code:
import numpy

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

X = []
for i in range(0, N):
    tmp = [0]*N
    tmp[i] = 1
    tmp[i+1] = 1
    # for j in range(0, N):
    #     if i == j or (i+1) == j:
    #         tmp.append(1)
    #     else:
    #         tmp.append(0)
    X.append(tmp)
X[N-1][0] = 1
numX = numpy.matrix(X)

# print(numX)
numA = numpy.matrix(A).T
# print(numA)
ans = numpy.linalg.inv(numX)*numA
# print(ans.tolist())
output = [int(2*x[0]) for x in ans.tolist()]
print(*output)

Submission status: Runtime Error

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

res = []
s = 0
for i in enumerate(range(n)):
    s += a[i] * [-1, 1][i % 2 ==0]
res.append(s)

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
inv_x=np.linalg.inv(x)
ans=np.dot(a.T,inv_x)
ans=np.insert(ans,0,ans[-1])
ans=np.delete(ans,n)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
print(" ".join(ans))

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

cul = np.linalg.solve(X, b)
ans = np.array([*cul], dtype=np.int32)
ans = 2 * ans

print(*ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from numpy.linalg import solve

n = int(input())
a = list(map(int, input().split()))
a = np.array([_a * 2 for _a in a])

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

print(" ".join(solve(x, a).astype('int').astype('str')))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a*2
#a = a.reshape((a.shape[0],1))
#print(n,a)

N = np.zeros((n,n), dtype=int)
for i in range(n):
    N[i,i] = 1
    if i+1 == n:
        N[i,0] = 1
    else:
        N[i,i+1] = 1
#print(N)

ans = np.linalg.solve(N,a)
#ans = ans.reshape((ans.shape[0],))
ans = ans.astype(np.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)

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

arr[n-1,n-1]=1
arr[0,n-1]=1

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a=[[x] for x in a]
a=np.array(a)
k=np.zeros((n,n),dtype="i8")
for i in range(n-1):
    k[i][i]=1
    k[i][i+1]=1
k[n-1][0]=1
k[n-1][-1]=1
k=np.linalg.inv(k)
ka=np.dot(k,a)
ans=[]
for x in ka:
    ans.append(int(x[0])*2)
print(*ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy.linalg as linalg

n = int(input())
b = [[int(i)] for i in 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

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

tmp = [str(int(round(i[0], 0))) for i in x]
print(' '.join(tmp))

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)
m[:n-1,1:] += np.eye(n-1)
m[n-1,0] = 1

d = np.linalg.inv(m) * 2

a = a.reshape(1,n)
ans = np.dot(a,d)[0]

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

Submission status: Runtime Error

Solution code:
L,R=map(int,input().split())
X=2019
for i in range (R-L):
    for j in range(R-L-i):
        if (L+i)*(L+i+j+1)%2019==0:
            X=0
            break
        elif X >(L+i)*(L+i+j+1)%2019:
            X=(L+i)*(L+i+j+1)%2019    
print(X)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A_1 = np.identity(N)
A_2 = np.roll(np.identity(N), 1, axis=1)
A = A_1 + A_2

#print(' '.join(list()))                                                                 
print(' '.join(list(map(str, list(map(int, (np.linalg.solve(A,Y)*2).tolist()))))))

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
print(*[int(x) for x in X])

Submission status: Runtime Error

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

A = np.array(A)
M = np.zeros([N,N],dtype=np.int)

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

inv_M = np.linalg.inv(M)
R = np.dot(inv_M,A)*2
Ans = [int(r) for r in R]
for i in range(N):
    if i == N-1:
        print(Ans[i])
    else:
        print(Ans[i],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 numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = np.array(A)

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

ans = np.linalg.solve(X,B)
for i in range(N):
    print("{}".format(2*int(ans[i])),end=" ")

Submission status: Runtime Error

Solution code:
def main():
	import sys
	import numpy as np
	import scipy.linalg as linalg
	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)
	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())
A = list(map(int, input().split()))

x = np.identity(N)
y = np.identity(N)
y0 = y[0]
y = np.delete(y, 0, 0)
y = np.append(y, y0)
y = np.reshape(y, (N, N))
a = x + y
b = np.array(A)

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
#import scipy as sp

N = int(input())
A = np.array(list(map(lambda x: int(x),input().split())))
X = np.eye(N)
for i in range(1,N):
    X += np.roll((-1)**((i+1)%2)*np.eye(N), i, axis=1)

#print(X)
ans = list(map(lambda x: int(x),list(np.dot(A,X))))
#print(ans)
print(' '.join(map(str, ans)))
#print(np.dot(ans,X))

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
print("done")
X = np.linalg.solve(M,D)
for n in range(N):
    print(int(X[n]), end=" ")

Submission status: Runtime Error

Solution code:
# coding: utf-8
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a*2
a = a.reshape((a.shape[0],1))
#print(n,a)

N = np.zeros((n,n))
for i in range(n):
    N[i,i] = 1
    if i+1 == n:
        N[i,0] = 1
    else:
        N[i,i+1] = 1
#print(N)

inv_N = np.linalg.inv(N)
ans = np.dot(inv_N,a)
ans = ans.reshape((ans.shape[0],))
ans = ans.astype(np.int)
print(*ans)

Submission status: Runtime Error

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

A = np.zeros(n*n).reshape((n, n))
Y = np.empty((n, 1))

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

for i in range(len(a)):
    Y[i][0] = a[i]*2

A = np.asmatrix(A)
Y = np.asmatrix(Y)
ans = np.linalg.inv(A)*Y
print_ans = ""
for i in range(len(ans)):
    if i == len(ans) - 1:
        print_ans += str(int(ans[i]))
    else:
        print_ans += (str(int(ans[i]))+" ")
print(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)

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

arr[n-1,n-1]=1
arr[0,n-1]=1

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

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

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = np.zeros((N, N))
T = np.zeros(N)
for n in range(N):
    if n < N - 1:
        S[n][n] = 1
        S[n][n + 1] = 1
        T[n] = A[n] * 2
    else:
        S[n][n] = 1
        S[n][0] = 1
        T[n] = A[n] * 2

X = np.linalg.solve(S, T)
for x in X:
    print(int(x), end=" ")

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
b = [[int(i)] for i in 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

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

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