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: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

min_ind = 0
min_val = 3e9
for i in range(1, N):
    tmp = A[i]+A[i-1]
    if tmp < min_val:
        min_val = tmp
        min_ind = i

# ダムmin_indから決めていく
rain = [0 for i in range(N)]
start = min_ind
end = (start+N-1)%N
lim = min(A[end], A[start]) * 2
for r in range(lim, -1, -2):
    rain[start] = r
    now = (start+1)%N
    pre = start
    ok = False
    while now != start:
        rain[now] = (A[pre] - rain[pre] // 2) * 2
        if A[now] < rain[now]//2:
            break
        now = (now+1)%N
        pre = (pre+1)%N
    if now == start:
        if rain[now] == (A[pre] - rain[pre]//2) * 2:
            ok = True
    if ok:
        for i in range(N):
            print(rain[i], end="")
            if i != N-1:
                print(" ",end="")
            else:
                print()
        break

Submission status: Time Limit Exceeded

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

S = sum(a_list) / 2

K = N // 2

a=1
new_a_list = []
for i in range(N):
    k = i
    new_a = 0
    for j in range(K):
        new_a += a_list[k]
        k += 2
        k = k % N
    new_a_list.append(str(int((S - new_a)*2)))

lists = new_a_list[1:]+[new_a_list[0]]
print(' '.join(lists))

Submission status: Time Limit Exceeded

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

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    for i in range(n) :
        if dl[i] == max(dl) :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[(i+1)%n]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[i-1]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split(" ")))
A = np.array(A)
t = np.array([1, -1])
w = np.tile(t, [1 + N // 2])[:-1]
r = []
r_append = r.append
for i in range(N):
    r_append(str(np.dot(np.roll(w, i), A)))
print(" ".join(r))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
B=[None for i in range(N)]
res=0
for n in range(N):
	if n%2!=0:res-=A[n]
	else:res+=A[n]
B[0]=res
for i in range(1,N):
	B[i]=int((A[i-1]-(int(B[i-1])/2))*2)

ans=""

for i in B:
	ans=str(ans)+str(i)+" "
	
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())  
A = np.array(input().split(), dtype=np.int64)

sum = int(np.sum(A) / 2)

ans = np.zeros(N)
for i in range(N):
    m = 0
    for j in np.arange(int((N-1)/2)):
        m += A[(i + j*2+1)%N]    
    ans[i] = int((sum - m) * 2)
    
print(*ans.astype(np.int32))

Submission status: Time Limit Exceeded

Solution code:
N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
A.extend(A)
odds = range(0,N,2)
Ans=[-S + 2*sum([s for s,num in zip(A[i:i+N], range(N)) if num in odds] )
     for i in range(N) ]
print(" ".join(map(str,Ans) ))

Submission status: Time Limit Exceeded

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] != None:
            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: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = []
a = 0
for i in range(n):
    if i%2 == 0:
        a += a_list[i]/2
    else:
        a -= a_list[i]/2
out = str(int(a*2))
point = a
for i in range(n-1):
    point = a_list[i]-point
    out += " "+str(int(point*2))
print(out)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * N

ans_tmp = []


for i in range(0, A[0]+1):
    B[0] = A[0] - i
    ans_tmp.append(str(i*2))

    for n in range(1, N):
        B[n] = A[n] - B[n-1]
        ans_tmp.append(str(B[n-1]*2))
    
    if i == B[N-1]:
        break
    
    ans_tmp = []


print(" ".join(ans_tmp))

Submission status: Time Limit Exceeded

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

n = int(input())
a = [int(i)*2 for i in input().split()]

x = []
for i in range(n-1):
    temp = [0]*n
    temp[i] = 1
    temp[i+1] = 1
    x.append(temp)

temp = [0]*n
temp[0] = 1
temp[n-1] = 1
x.append(temp)

x = np.array(x)
a = np.array(a)
#print(x)
#print(a)

y = solve(x, a)
ans = ""
for i in y:
    ans+=str(int(i))+" "

print(ans[0:len(ans)-1])

Submission status: Time Limit Exceeded

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

X = list()
for i in range(N):
    x_i = A[i]
    keisu = -1
    for j in range(1, N):
        x_i += keisu * A[(i + j) % N]
        keisu = keisu * -1
    X.append(str(x_i))
print(' '.join(X))

Submission status: Time Limit Exceeded

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

result = []
for i in range(n):
    r = np.sum(a[0::2]) - np.sum(a[1::2]) 
    result.append(r)
    a = np.concatenate([a[1:], [a[0]]])
    
print(" ".join(map(str, result)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N)]

for i in range(min(A[-1], A[0]) + 1):
	R[0] = i
	fin = 1
	for j in range(1, N):
		R[j] = A[j - 1] - R[j - 1]
		# print(j, R[j])
		if R[j] < 0:
			fin = 0
			break
	# print(R)
	if fin == 1 and R[0] == A[-1] - R[-1]:
		for r in R:
			print(r * 2, end=" ")
		break

Submission status: Time Limit Exceeded

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

a = np.array(a)
mat = []
for i in range(n):
        minimat = [0]*n
        minimat[i] = 1
        minimat[(i+1)%n] = 1
        mat.append(minimat)
inv = np.linalg.inv(mat)
x = np.dot(inv, a)
for j in x:
        print(int(j)*2, end=' ')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
D = list(map(int, input().split()))

argminD = 0#np.argmin(D)
for i in range(0, D[argminD]*2+1, 2):
  first = int(i)
  final = D[argminD]*2 - int(i)
  for j in range(argminD+1, N+argminD):
    j = j % N
    final = D[j]*2-final
    if final < 0:
      break
  if first == final:
    result = [str(first)]
    final = D[argminD]*2 - first
    for j in range(argminD+1, N+argminD):
      j = j % N
      result.append(str(final))
      final = D[j]*2-final
    print(" ".join(result))
    #print(" ".join(result[argminD:]) + " " + " ".join(result[:argminD]))
    sys.exit(0)

Submission status: Time Limit Exceeded

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
    if (i+1) == N:
        tmp[0] = 1
    else:
        tmp[i+1] = 1
    X.append(tmp)
numX = numpy.matrix(X)

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

Submission status: Time Limit Exceeded

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] -= 2*(a[i+1+2*j])
    ls[i] = str(ls[i])
print(" ".join(ls))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
S = np.sum(A)
A = np.concatenate((A, A))
for i in range(N):
    print(S - np.sum(A[i+1:i+N:2])*2, end=' ')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = [None] * n

def solve(idx, m):
    x[idx] = m
    # (x[i] + x[i+1]) / 2 = a[i]
    for i in range(n-1):
        x[i+1] = 2 * a[i] - x[i]

    return sum(x) == sum(a)


#solve(0, 4)
#solve(0, 3)

l = 0
r = 100000000
m = (l + r) // 2

# while l <= r:
#     if solve(0, m):

for i in range(a[0]+a[1] + 1):
    if solve(0, i):
        # print("found!")
        # print(x)
        break

#print('{}'.format([i for i in x]))
print(' '.join([str(i) for i in x]))
#print(x.split())

#if sum(x) == sum(a):
# if solve(0, 5):

Submission status: Time Limit Exceeded

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


left2 = [[0 for i in range(n)] for i in range(n)]

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

right2 = a
tmparr = solve(left2, right2)

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

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

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

for i in range(N):
    num = []
    for j in range(N):
        if j == i or j == (i + 1):
            num.append(1)
        else:
            num.append(0)
        if i == N - 1:
            num[0] = 1
        
    left.append(num)

#print(left)

right = list(x * 2 for x in A)
#print (solve(left, right))

answer = ""
for a in solve(left, right):
    answer += str(int(a))
    answer += " "

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

min_ind = 0
min_val = 3e9
for i in range(1, N):
    tmp = A[i]+A[i-1]
    if tmp < min_val:
        min_val = tmp
        min_ind = i

# ダムmin_indから決めていく
rain = [0 for i in range(N)]
start = min_ind
end = (start+N-1)%N
lim = min(A[end], A[start]) * 2
for r in range(0, lim+1, 2):
    rain[start] = r
    now = (start+1)%N
    pre = start
    ok = False
    while now != start:
        rain[now] = (A[pre] - rain[pre] // 2) * 2
        if A[now] < rain[now]//2:
            break
        now = (now+1)%N
        pre = (pre+1)%N
    if now == start:
        if rain[now] == (A[pre] - rain[pre]//2) * 2:
            ok = True
    if ok:
        for i in range(N):
            print(rain[i], end="")
            if i != N-1:
                print(" ",end="")
            else:
                print()
        break

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N = i_inpl()
A = l_inpl()

ans = []
tmp = 0
for i, Ai in enumerate(A[:N-1]):
    tmp += Ai *(-1)**(i)
a1 = (tmp+A[N-1])
ans.append(a1)
t_ans = []
for i in range(N-1):
    ans.append(2*A[::-1][i]-ans[i])
ans = [ans[0]] + ans[1:][::-1]
print(" ".join([ str(i) for i in ans]))

# L, R = l_inpl()
# L %= 2019
# R %= 2019

# if R<=L:
#     R+=2019

# ans = INF
# for i in range(L, R+1):
#     for j in range(i+1, R+1):
#         print(i, j)
#         ans = min(ans, i*j%2019)

# print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

#mat = np.array([[1.,1.,0.], [0., 1.,1.], [1.,0.,1.]])
#b = np.array([4., 4., 8.])
N = int(input())
a_l = [i*2 for i in list(map(float,input().split(" ")))]
mat_l = []
for i in range(N):
    mat_l.append([1. if (j==i or j==(i+1)%(N)) else 0. for j in range(N)])
mat=np.array(mat_l)
b=np.array(a_l)

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

ans_str=""
for i,ans in enumerate(b):
    if(i!=len(b)-1):
        ans_str+=str(int(ans))+" "
    else:
        ans_str+=str(int(ans))

print(ans_str)

Submission status: Time Limit Exceeded

Solution code:

import scipy.linalg as linalg

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

for i in range(N):
  arr = [0]*N
  if i == N-1:
    arr[i] = 1
    arr[0] = 1
  else:
    arr[i] = 1
    arr[i+1] = 1
  w_arr.append(arr)
  
LU = linalg.lu_factor(w_arr)
ans = linalg.lu_solve(LU, solve_arr)


for i in ans:
  print(str(int(i)) + " ", end ="")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
A=[[0]*n for i in range(n)]
for i in range(n):
        A[i][i]=0.5;
        A[i][(i+1)%n]=0.5;

inv_A=np.linalg.inv(A)
b=list(map(int,input().split()))
res=np.dot(inv_A,b)
for i in range(n):
        print(int(res[i]),end=" ")

Submission status: Time Limit Exceeded

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

N=int(input())
#A=list(map(int, input().split())) 
A=list(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, end=" ")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

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

	ans = [0 for _ in range(N)]
	
	ed = min(A[0]*2, A[-1]*2)
	for i in range(ed, -1, -2):
		fin = True
		for j in range(N):
			if j == 0:
				ans[j] = i
				continue
			tmp = (A[j-1] - (ans[j-1] / 2))*2

			if tmp < 0 or tmp % 2 == 1:
				fin = False
				break
			else :
				ans[j] = int(tmp)
		
		if fin == False:
			pass
		else:
			if (ans[-1] / 2) + (ans[0] / 2) == A[-1]:
				#print("sss")
				break

	ans = [str(a) for a in ans]
	print(' '.join(ans))


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

from collections import deque
dA = deque(A)
ans=[]
for i in range(N):
  Nans = 0
  for itr, val in enumerate(dA):
    if itr % 2 == 0:
      Nans += val
    else:
      Nans -= val
  ans.append(Nans)
  aa = dA.popleft()
  dA.append(aa)
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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(map(int, input().split()))

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i - 1] - ans[i - 1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N - 1] - (ans[N - 1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = N // 2

    while True:
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = jump // 2 + 1
        dprint(x, ret, ans, jump)

    print(" ".join([str(i * 2) for i in ans]))


solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
p = A_list.index(min(A_list))
new_list = A_list[p:N+1]+A_list[0:p]
sum_chk = 0
ans_list = []
for i in range(new_list[0]+1):
    test_water = i *2
    for j in range(N-1):
        test_water = new_list[j+1]*2 -test_water
        if test_water < 0:
            break
    if test_water == (new_list[0]*2-i*2):
        test_water = i*2
        ans_list.append(test_water)
        for j in range(N-1):
            test_water = new_list[j+1]*2 -test_water
            ans_list.append(test_water)
        break
col_list=ans_list[N-p-1:N+1]+ans_list[0:N-p-1]
print(*col_list)

Submission status: Time Limit Exceeded

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

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

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

        if (X[-1] + X[0]) / 2 == A[-1]:
            # Clear
            break
        elif (X[-1] + X[0]) / 2 < A[-1]:
            # Need to increase X[0]
            a = c
            if c == (a + b) // 2:
                c += 1
            else:
                c = (a + b) // 2
        elif (X[-1] + X[0]) / 2 > A[-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: Time Limit Exceeded

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

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

# j=0
for i in range(0,a[0]*2+1,2):
	# temp_i = i
	flag = 0
	ans=[0 for _ in range(n)]
	ans[0]=i
	temp=a[0]-int(ans[0]/2)
	for j in range(1,n):
		# print(i)
		ans[j]=temp*2
		temp=a[j]-int(ans[j]/2)
		if temp < 0:
			break
		if j == n-1:
			if a[j] == int(ans[j]/2)+int(ans[0]/2):
				flag=1

	if flag==1:
		# print(tuple(ans))
		# print(ans)
		print(' '.join(map(str, ans)))
		break

	# j+=1


# print(ans)

Submission status: Time Limit Exceeded

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

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: Time Limit Exceeded

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

def c(index):
    return index%N

total_rain = sum(A) // 2

one = total_rain
for j in range(1, N-1, 2):
    one -= A[j]
rains = [0]*N
rains[0] = one*2

for m in range(1, N):
    rains[m] = (A[m-1] - rains[m-1]//2)*2

ans = ""
for rain in rains:
    ans+=str(rain)
    ans+=" "

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
A=[[0]*n for i in range(n)]
for i in range(n):
        A[i][i]=1;
        A[i][(i+1)%n]=1;

inv_A=np.linalg.inv(A)
b=list(map(int,input().split()))
for i in range(n):
  		b[i]*=2
res=np.dot(inv_A,b)
for i in range(n):
        print(int(res[i]),end=" ")

Submission status: Time Limit Exceeded

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

argminD = 0#np.argmin(D)
for i in range(0, D[argminD]*2+1, 2):
  first = int(i)
  final = D[argminD]*2 - int(i)
  for j in range(argminD+1, N+argminD):
    j = j % N
    final = D[j]*2-final
    if final < 0:
      break
  if first == final:
    result = [str(first)]
    final = D[argminD]*2 - first
    for j in range(argminD+1, N+argminD):
      j = j % N
      result.append(str(final))
      final = D[j]*2-final
    print(" ".join(result))
    sys.exit(0)

Submission status: Time Limit Exceeded

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

# s = [-2*(v%2)+1 for v in range(n)]
# ans = []
k = 0
for i in range(n):
    p = 0
    for j in range(n):
        if ((j-k)% (n)) % 2:
            p -= A[j]
        else:
            p += A[j]
    k += 1
    print(p,end="")
    print(" ",end="")

Submission status: Time Limit Exceeded

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

for i in range(a[0]+1):
    ans = [i*2]
    diff = i

    for rep2 in range(1, n-1):
        dam = a[rep2] - diff
        ans += [dam*2]
        diff = dam
        if diff < 0:
            break

    if a[-1] - ans[-1]//2 == a[0]-i:
        print(*([(a[0]-i)*2] + ans))
        exit()

Submission status: Time Limit Exceeded

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

M = [0] * N
for i in range(N):
    M[i] = min(A[i], A[i-1]) << 1

ans = [-1] * N

for m1 in range(0, M[0]+1, 2):
    ans[0] = m1
    for i in range(1, N):
        m = (A[i-1] - (ans[i-1] >> 1)) << 1
        if 0 <= m <= M[i]:
            ans[i] = m
        else:
            ans = [-1] * N
            break
    if (ans[0] >> 1) + (ans[-1] >> 1) == A[-1]:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())

A=list(map(int,input().split()))
for i in range(N):
    A[i]=A[i]*2
C=[]
for i in range(N-1):
    B = [0] * (N)
    B[i]=0.5
    B[i+1]=0.5
    C.append(B)
B = [0] * (N)
B[0]=0.5
B[N-1]=0.5
C.append(B)

X=np.linalg.solve(C,A)
for i in range(N):
    print(int(X[i]/2),end=" ")

Submission status: Time Limit Exceeded

Solution code:


n = int(input())
Dn = list(map(int, input().split()))#ダム


Mn = [0]*n
M0_max = min(Dn[0],Dn[-1])*2

for i in range(M0_max+1):
    
    Mn[0] = i
    for j in range(1,n):

        Mn[j] = 2*Dn[j-1] - Mn[j-1]
        
    valid = Mn[0] + Mn[-1] == Dn[-1]*2
    #print(i, valid)
    #print(Dn)
    #print(Mn)
    #print()

    if valid:
        print(*Mn)
        break

Submission status: Time Limit Exceeded

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

left=0
right=AL[0]*4
while True:
    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: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mou = [0]*n
mx = 10**10
for i in range(n):
    if a[i] < mx:
        mx = a[i]
        mi =  i
a = a[i:]+a[:i]
for v in range(0,2*(a[0]+1),2):
    mou[0] = v
    for i in range(1,n):
        mou[i] = (a[i-1]-mou[i-1]//2)*2
        if mou[i]<0:
            break
    else:
        if (mou[-1]+mou[0])//2 == a[-1]:
            ans = mou[n-i:]+mou[:n-i]
            break
print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

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

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    for i in range(n) :
        if dl[i] == max(dl) :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[i-2]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[(i+2)%n]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(i) for i in input().split()] * 2
x = []
for i in range(n):
    x.append(str(sum(a[i:i + n:2]) - sum(a[i + 1:i + n:2])) + " ")

print("".join(x))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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="")
# for i in range(len(X)-1):
#     print(X[i], end="")
#     print(" ", end="")
# print(X[-1])

Submission status: Time Limit Exceeded

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

for i in range(0, N) :
    ic = 0
    for j in range(i+1, N, 2):
        ic += A[j]
    for j in range(i-2, -1, -2):
        ic += A[j]
    if i == 0:
        ans = str((sum_all - ic)*2)
    else:
        ans = ans + ' ' + str((sum_all - ic)*2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = (N-1)//2
A = list(map(int, input().split()))
S = sum(A)
S = sum(A)
A += A
X = [S - sum(A[i+1:i+N:2])*2 for i in range(N)]
for x in X:
    print(x, end=' ')

Submission status: Time Limit Exceeded

Solution code:
import numpy

n = int(input())
a = [int(u) for u in input().split(" ")]
v = [[(1 if (v==u or v==u+1 or (v==0 and u==n-1)) else 0) for v in range(n)] for u in range(n)]
w = numpy.linalg.inv(v)
x = list(numpy.dot(w,a))
print(" ".join([str(int(u*2)) for u in x]))

Submission status: Time Limit Exceeded

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

left = [[0 for _ in range(N)] for _ in range(N)]
right = [[] for _ in range(N)]
for i in range(N):
  right[i].append(A[i] * 2)
  for j in range(N):
    if j == i or j == (i + 1) % N:
      left[i][j] = 1

A = np.matrix(left)
Y = np.matrix(right)
ans = np.dot(np.linalg.inv(A), Y)

for i in range(N):
  print(int(round(ans[i,0])), end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = []
a = 0
for i in range(n):
    if i%2 == 0:
        a += a_list[i]/2
    else:
        a -= a_list[i]/2
ans.append(2*a)
point = a
for i in range(n):
    point = a_list[i]-point
    ans.append(point*2)
out = ""
for num in ans[:-1]:
    out += str(int(num)) + " "
print(out[:-1])

Submission status: Time Limit Exceeded

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

N=int(input()) 
A=list(map(int, input().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, end=" ")

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

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

bsp = a[n-1]//2
bst = ceil(a[n-1]/4)

while(True):
  prv=bsp
  ans=[bsp*2]
  for ai in a[:n-1]:
    if ai-prv<0:
      bsp += bst
      bst=ceil(bst/2)
      break
    prv=ai-prv
    ans.append(prv*2)
  else:
    if prv==a[n-1]-bsp:
      s=""
      for ai in ans:
        s+=str(ai)+" "
      print(s)
      break
    elif prv>=a[n-1]-bsp:
      bsp -= bst
      bst=ceil(bst/2)
    else:
      bsp += bst
      bst=ceil(bst/2)

Submission status: Time Limit Exceeded

Solution code:
N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
A.extend(A)
odds = [s for s in range(N) if s%2 ==0]
Ans=[-S + 2*sum([s for s,num in zip(A[i:i+N], range(N)) if num in odds] )
     for i in range(N) ]
print(" ".join(map(str,Ans) ))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
for x in range(n):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    print(((ex-sum)*2),end=" ")