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:
n = int(input())
a = list(map(int, input().split()))
a = [a[-1]] + a[:-1]
import numpy as np
from numpy.linalg import lstsq
field = np.zeros((n,n))
for i in range(n):
  field[i][i-1],field[i][i] = 1,1
#print(field,a)
[print(int(round(i)*2),end=" ") for i in lstsq(field,a)[0]]

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [a[-1]] + a[:-1]
import numpy as np
from numpy.linalg import solve
field = np.zeros((n,n))
for i in range(n):
  field[i][i-1],field[i][i] = 1,1
#print(field,a)
[print(int(round(i)*2),end=" ") for i in solve(field,a)]

Submission status: Runtime Error

Solution code:
import sys
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    va = np.array(a)
    m = np.identity(n, dtype=int)
    for i in range(n):
        if i < n - 1:
            m[i][i + 1] = 1
        else:
            m[i][0] = 1
    vx = np.linalg.solve(m, va).astype(np.int) * 2
    print(*vx)


main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [a[-1]] + a[:-1]
import numpy as np
from numpy.linalg import solve
field = np.zeros((n,n))
for i in range(n):
  field[i][i-1],field[i][i] = 1,1
field = field + np.identity(n)*1e-9
[print(int(round(i)*2),end=" ") for i in solve(field,a)]

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [a[-1]] + a[:-1]
import numpy as np
from numpy.linalg import solve
field = np.zeros((n,n))
for i in range(n):
  field[i][i-1],field[i][i] = 1,1
  
[print(int(i*2),end=" ") for i in solve(field,a)]

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

exit()

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

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

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

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

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

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

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

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

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:
N = int(input())
lst = list(map(int, input().split()))
S = sum(lst)
ans = []

for i in range(2, N, 2):
  S -= 2 *lst[i-1]
  
ans.append(S)

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

Submission status: Runtime Error

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

for i in range(1, n):
  x[i] = -x[i-1] + 2*a[i-1]
  
o = " ".join(x)
print(o)

Submission status: Runtime Error

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

for i in range(1, n):
  x[i] = -x[i-1] + 2*a[i-1]
  
o = " ".join(x)
print(o)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)*2
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] = 1
        M[i][i] = 1
R = np.linalg.solve(M,A).astype(np.int)
print(' '.join(map(str, R)))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

n = int(input())
a = list(map(int,input().split()))
b = [1 for i in range(n)]
c = [1 for i in range(n-1)]
left = np.diag(b) + np.diag(c,k=1)
left[n-1][0] +=1
g = np.linalg.inv(left)
aa = np.dot(g,a)
aa = [int(aa[i]*2) for i in range(n)]

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

Submission status: Runtime Error

Solution code:
n = int(input())
b = np.array(list(map(int, input().strip().split())))
s = sum(b)
x = []

for i in range(n):
    y = s
    k = i + 1
    for j in range(int((n-1)/2)):
        y -= 2*b[k%n]
        k += 2

    x.append(y)

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

Submission status: Runtime Error

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

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

print(*Y)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = [int(c) for c in input().split(' ')]

gyoretu = np.zeros((n, n))
uhen = np.array(a)

for i in range(n):
    gyoretu[i,i] = 1
    gyoretu[i,(i+1+n) % n] = 1

rev = np.linalg.inv(gyoretu) * 2

#print(gyoretu)
#print(rev)
#print(uhen)

result = (np.dot(rev, uhen))

for i in range(n):
    if i < n-1:
        print(int(result[i]), '', end="")
    else:
        print(int(result[i]))
#print(np.dot(rev, gyoretu))

Submission status: Runtime Error

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

sum = 0
for i in range(N):
  sum+=A[i]
X =[0 for x in range(N)]
sum2=0
i=1
while i < N:
  sum2+=A[i]
  i+=2
X[0]=sum-sum2

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

Submission status: Runtime Error

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

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

print(*Y)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
X=list(map(int, input().split()))
Xo=np.array(X)
Y=[]
Yama=[]
for x in range(0,N):
    if x%2==0:
        Y.append(1)
    if x%2==1:
        Y.append(-1)
Yo=np.array(Y)
for x in range(0,N):
    Yama.append(np.dot(Xo,Yo))
    Yo.insert(0,Y[-1])
    del Yo[-1]

for s in Yama:
  print(s, end =" ")

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

n = int(input())
a = list(map(int,input().split()))
b = [1 for i in range(n)]
c = [1 for i in range(n-1)]
left = np.diag(b) + np.diag(c,k=1)
left[n-1][0] +=1
tmparr = np.linalg.solve(left, a)
tmparr = [int(tmparr[i]*2) for i in range(n)]

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

L, R = list(map(int, input().split()))

if R-L >= 2019:
    print(0)
else:
    tmp = []
    for i in range(L, R):
        for j in range(i+1, R+1):
            tmp.append((i * j) % 2019)
    print(min(tmp))

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    # [NumPyで全要素を同じ値で初期化した配列ndarrayを生成 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-zeros-ones-full/)
    A = np.zeros((N, N), np.int8)
    for i in range(N):
        if i == N - 1:
            A[i][0] = 1
            A[i][i] = 1
        else:
            A[i][i] = 1
            A[i][i+1] = 1

    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

    int_ans = [str(int(x) * 2) for x in ans]
    print(' '.join(int_ans))

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])+np.diag(np.zeros(n)+0.1**10)

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

y = a

ans = np.linalg.solve(x,y)
ans = list(map(str,np.round(ans).astype(np.int)))

print(" ".join(ans))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N;
const int MAX_N = 1.0e5 + 100;
ll A[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<ll> x;
    ll S = 0;
    for (int i = 0; i < N; i++) {
        S += A[i];
    }

    ll x0 = S;
    for (int i = 1; i < (N+1)/2; i++) {
        x0 -= 2*A[2*i - 1];
    }

    x.push_back(x0);

    for (int i = 1; i < N; i++) {
        ll x_i = 2*A[i-1] - x[i-1];
        x.push_back(x_i);
    }

    for (int i = 0; i < N; i++) {
        cout << x[i] << " ";
    }
    cout << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np


N = int(input())
A = np.zeros((N,1))

input_line = input().split(' ')
for i in range(N):
    A[i] = int(input_line[i])

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

A = np.array([2,2,4])
x = np.linalg.solve(M,A)
x = x*2
x_int = list(map(int,x))
L = [str(s) for s in x_int]
L = ' '.join(L)
print(L)

Submission status: Runtime Error

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

if R - L >= 2050:
    print(0)
else:
    ans = 20000000
    for i in range(L, R+1):
        for j in range(i, R+1):
            ans = min(ans, (i * j) % 2019)
    print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(_) for _ in input().split()]
ans=[0]*N
ans[0]=sum(A)//2-sum(A[1::2])
for i in range(N-１):
    ans[i+1]=A[i]-ans[i]
print(' '.join(str(2*a) for a in ans))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(_) for _ in input().split()]
ans=[0]*N
ans[0]=sum(A)//2-sum(A[1::2])
for i in range(N-):
    ans[i+1]=A[i]-ans[i]
print(' '.join(str(2*a) for a in ans))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
S = 0
inv = [1,-1]*(n//2) + [1]
for q in range(n):
  S += A[q]*inv1[q]
ans = [0]*n
for q in range(n):
  ans[q] = S
  S = 2*A[q]-S
print ' '.join(map(str, ans))

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    # [NumPyで全要素を同じ値で初期化した配列ndarrayを生成 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-zeros-ones-full/)
    A = np.zeros((N, N))
    for i in range(N):
        if i == N - 1:
            A[i][0] = 0.5
            A[i][i] = 0.5
        else:
            A[i][i] = 0.5
            A[i][i+1] = 0.5

    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

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

Submission status: Runtime Error

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

left = np.zeros((n, n))

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

tmparr = solve(left, a)

tmparr = [int(tmparr[i]*2) for i in range(n)]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

listX = []
for i in range(1, 990590):
  listX.append(i*2019)

sw = 0
for n in range(len(listX)):
  if L < listX[n] and R > listX[n]:
    sw += 1

if sw > 0:
  print(0)

elif sw == 0:      
  L_1 = L % 2019
  R_1 = R % 2019
  
  idx1 = 0
  listA = []
  for idx1 in range(L_1, R_1):
    for idx2 in range(idx1 + 1, R_1 + 1):
      listA.append(idx1 * idx2)
 
  print(min(listA))

Submission status: Runtime Error

Solution code:
import numpy as np

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


Q, R = linalg.qr(x)
t = np.dot(Q.T, A)
x = linalg.solve(R, t)

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mountain = [0 for _ in range(len(a))]

while sum(a) != 0:
    i_sort = sorted(range(len(a)), key=lambda k: a[k], reverse=1)
    i_max = i_sort[0]
    # print(f'imax : {i_max}')
    if i_max == 0:
        i_second = max(-1, i_max+1, key=lambda x:a[x])
    elif i_max == len(a):
        i_second = max(i_max-1, 0, key=lambda x:a[x])
    else:
        i_second = max(i_max-1, i_max+1, key=lambda x:a[x])
    # print(f'isecond : {i_second}')
    mountain[(i_max+i_second)//2] = max((a[i_second]//2)*4,2)
    a[i_max] -= max((a[i_second]//2)*2,1)
    a[i_second] -= max((a[i_second]//2)*2,1)
    # print(a)
print(mountain[-1], end=' ')
[print(i, end=' ') for i in mountain[:-1]]
print()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
mod = 10**9 + 7
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def p(n, k):
    x = 1
    for i in range(k):
        x *= n - i
        x %= mod
    return x
def f(x, par):
    L = len(G[x])
    if x == par:
        if L <= K-1:
            ans = K*p(K-1,L) % mod
        else:
            return 0
    elif x != par:
        if L-1 <= K-2:
            ans = p(K-2,L-1)
        else:
            return 0
    for i in G[x]:
        if i != par:
            ans *= f(i, x)
            ans %= mod
    return ans
print(f(0, 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

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

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 sympy

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


symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()

Submission status: Runtime Error

Solution code:
import sympy

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

symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()

Submission status: Runtime Error

Solution code:
5
3 8 7 5 5

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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:
mod = 2019
l,r = map(int,input().split())

cnt = 0
tank = []
for i in range(l,r+1):
    tank.append(i%mod)
    cnt += 1
    if cnt >= 2020:
        break

res = 2019

n = len(tank)
for i in range(n):
    for j in range(i+1,n):
        res = min(res,tank[i]*tank[j]%mod)
print(res)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""

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

    
def main():
    m = [0]*N
    sgn = (-1)
    Atot=0
    for n in range(N):
        Atot += sgn**(n)*A[n]
    m[0] = Atot//2
    for n in range(1,N):
        m[n] = A[n-1]-m[n-1]
    for n in range(N):
        m[n] = m[n]*2
    
        
    print(", ".join(m))
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sympy

N = 3
Y = list(map(int,input().split(' ')))


symbols = []
for i in range(N):
    symbols.append(sympy.Symbol('x' + str(i)))

equation = []
for i in range(N):
    i1 = i
    i2 = i + 1 
    if i2 >= N:
        i2 = 0
    equation.append(0.5*symbols[i1] + 0.5*symbols[i2] - Y[i])

for i in range(N):
    print(str(int(sympy.solve(equation)[symbols[i]])) + " " , end="")
print()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().strip().split()))
X = []
X = X.append(sum(A[0::2])-sum(A[1::2]))
for k in range (N-1):
  X = X.extend(2*A[k] - X[k])
print(X)

Submission status: Runtime Error

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

import numpy as np

Y = [1]*N
for i in range(N):
  if A[i] == (Y[i]+Y[i+1])/2:
    continue
  else:
    Y[i] += A[i]-(Y[i]+Y[i+1])/2

for i in Y:
print(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-2,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:
    A[max_idx] -= b

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 = np.array(x, dtype = int)

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array([2 * int(i) for i in input().split()]).reshape(N, 1)
B = np.zeros((N, N))
for i in range(N - 1):
    B[i][i] = 1
    B[i][i + 1] = 1
B[N - 1][0] = 1
B[N - 1][N - 1] = 1

X = np.linalg.solve(B, A)
for i in range(N):
    print(int(X[i]))

Submission status: Runtime Error

Solution code:
import numpy as np

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

for i in range(N - 1):
    M[i][i + 1] = 1
M[N - 1][0] = 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)
A = a + np.roll(a, 1, axis=1)

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:
N = int(input())
A = [int(i) for i in input().split()]
import numpy as np
D = np.array(A)
M = np.identity(N)/2 + np.roll(np.identity(N)/2, 1, axis=1)
X = np.linalg.solve(M,D)
for n in range(N):
    print(int(X[n]), end=" ")

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)

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

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)
        elif i % 2 == 1:
            return -2
        else:
            return -1
    if candidate[0] < candidate[-1]:
        return -1
    if candidate[0] > candidatet[-1]:
        return -2 
    return candidate

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

import math
while True:
    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:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

# solve "mat * x = b" about x
x, y = np.identity(N), np.identity(N)
y0 = y[0]
y = np.reshape(np.append(np.delete(y, 0, 0), y0), (N, N))
mat = (x + y) / 2

b = np.array(A)

for i in range(len(mat) - 1):
    for j in range(i + 1, len(mat)):
        coef = mat[j][i] / mat[i][i]
        mat[j] -= mat[i] * coef
        b[j] -= b[i] * coef

for i in range(len(mat) - 1, 0, -1):
    b[i] /= mat[i][i]
    mat[i] /= mat[i][i]
    for j in range(i):
        b[j] -= b[i] * mat[j][i]
        mat[j][i] = 0

b = [int(n) for n in b]
b[0] += 1
print(" ".join(map(str, b)))

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 range(n):
    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

n = int(input())
inp = input().split()
dams = [int(s) for s in inp]

def make_keisu(int_n):
    result = []
    for i in range(int_n):
        result.append(0.5)

    return result

keisu_mat = numpy.matrix([
    make_keisu(n)
])

#gyaku = numpy.linalg.inv(keisu_mat)

mizu_mat = numpy.matrix([
    dams
])

print(numpy.linalg.inv(keisu_mat)*mizu_mat)

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 = 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:
N = int(input())
A = [int(i) for i in input().split()]
import numpy as np
D = np.array(A)
M = np.identity(N)/2 + np.roll(np.identity(N)/2, 1, axis=1) + .00000001
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())

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)
        elif i % 2 == 1:
            return -2
        else:
            return -1
    if candidate[0] < candidate[-1]:
        return -2
    if candidate[0] > candidatet[-1]:
        return -1 
    return candidate

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

import math
while True:
    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)))