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

N = int(input())

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

def judge(x1):
    X = [0] * N
    X[0] = x1
    for i in range(1, N):
        X[i] = A[i-1] - X[i-1]

    if X[0] + X[N-1] == A[N-1]:
        # 正解
        X = map(lambda x: 2*x, X)
        print(' '.join(map(str, X)))
        sys.exit(0)
    elif X[0] + X[N-1] > A[N-1]:
        # x1 が大きすぎた
        return 1
    else:
        # x1 が小さすぎた
        return -1


def getNext(start, end):
    return (end - start) // 2 + start

# x/2 の取りうる範囲
minx = 0
maxx = max(A[0], A[N-1])

current = getNext(minx, maxx)

while True:
    ret = judge(current)
    if ret == 1:
        maxx = current
        current = getNext(minx, current)
    else:
        minx = current
        current = getNext(current, maxx)

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] = str(i)
				continue
			tmp = (A[j-1] - (int(ans[j-1]) / 2))*2

			if tmp < 0 or tmp % 2 == 1:
				fin = False
				break
			else :
				ans[j] = str(int(tmp))
		
		if fin == False:
			pass
		else:
			if (int(ans[-1]) / 2) + (int(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(lambda x: int(x),input().split()))
X = [(-1)**(i) for i in range(N)]
for i in range(N):
    c = 0
    for j in range(N):
        c += A[j]*X[(N+j-i)%N]
    print(c,end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
r = [-1]*N
s = A.index(min(A))

for i in range(A[s]+1):
  r[s] = i*2
  for j in range(1,N):
    k = (s+j)%N
    r[k] = 2*A[k-1]-r[k-1]
  if (r[s] + r[s-1])//2 == A[s-1]:
    print(" ".join(map(str,r)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_ = list(map(int, input().split()))
m = min(a_)
idx = a_.index(m)
a = a_[idx:] + a_[:idx]
for i in range(a[0] + 1):
    result = [0] * (n + 1)
    result[0] = i
    for j in range(1, n + 1):
        result[j] = a[j - 1] - result[j - 1]
    if result[0] == result[n]:
        result.pop()
        rans = result[-idx:] + result[:-idx]
        ans = [n*2 for n in rans]
        print(" ".join(map(str, ans)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
X=list(map(int, input().split()))
Y=[]
Yama=[]
for x in range(0,N):
    if x%2==0:
        Y.append(1)
        Yama.append(0)
    if x%2==1:
        Y.append(-1)
        Yama.append(0)
for x in range(0,N):
    for y in range(0,N):
        Yama[x]=Y[y]*X[y]+Yama[x]
    Y.insert(0,Y[-1])
    del Y[-1]
for s in Yama:
  print(s, end =" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
start = 0
for i in range(1, n):
    if a[i] < a[start]:
        start = i
c = [0 for i in range(n)]
for d in range(a[start]+1):
    b = [0 for i in range(n)]
    i = start-1
    flag = True
    for j in range(n):
        i = (i+1)%n
        c[i] = d
        b[i] += d
        b[i-1] += d
        d = a[i]-b[i]
        if d < 0:
            flag = False
            break
    if flag and a[i]==b[i]:
        break
for a in c:
    print(a*2, end=' ')
print()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
all_rain = sum(l)
ans = []

for i in range(n):
    now = (i+2)%n
    others = 0
    while now%n != (i+1)%n:
        others += l[(now-1)%n]
        now = (now+2)%n
    ans.append(str(all_rain-others*2))

print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
amini = a.index(min(a))
a = a[amini:]+a[:amini]


for i in range(a[0]+1):
    b = [i*2]
    for j in range(1,n):
        c = a[j-1]*2-b[-1]
        if not (c<0):
            b.append(c)
        else:
            break
    if len(b)==n and (b[0]+b[-1] == a[-1]*2):
        b = b[-amini:]+b[:-amini]
        print(*b)
        exit(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
A = []
for i in range(n):
    c = [0] * n
    if i != n-1:
        c[i], c[i+1] = 0.5, 0.5
    else:
        c[0], c[n-1] = 0.5, 0.5
    A.append(c)

A = np.array(A)
b = np.array(a)
ans = list(np.linalg.solve(A, b))
ans = map(int, ans)
ans = map(str, ans)
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_matrix = []
for i in range(N):
    m = [0] * N
    if i != N - 1:
        m[i] = m[i+1] = 0.5
    else:
        m[i] = m[0] = 0.5
    A_matrix.append(m)

A_matrix = np.array(A_matrix)
A = A.T
A_inv = np.linalg.inv(A_matrix)
ans = np.dot(A_inv, A)
ans = ans.astype(int)
print(" ".join(str(n) for n in ans))

Submission status: Time Limit Exceeded

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

Alists=list(map(int, input().split()))
Ylists=[[i] for i in Alists]

xlists=[]
for i in range(N):
  lists=[0 for j in range(N)]
  if(i<N-1):
    lists[i]=lists[i+1]=1
  if(i==N-1):
    lists[0]=lists[i]=1
    
  xlists.append(lists)

A=np.matrix(xlists)
Y=np.matrix(Ylists)

ret=np.linalg.solve(A,Y)
result=[str(int(2*ret[i][0])) for i in range(len(ret))]
#result=[str(int(result[i])) for i in range(len(result))]
print(' '.join(result))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

a=int(input())
b=list(map(int,input().split()))
b=2*np.array(b)
c=[[0 for s in range(a)] for _ in range(a)]
aa=0
for i in c:
    if aa==a-1:
        i[0]=1
        i[aa]=1
    else:
        i[aa+1]=1
        i[aa]=1
    aa+=1
c=np.array(c)

x=np.linalg.solve(c,b)
x=list(x)
for j in range(len(x)):
    x[j]=int(x[j])
print(" ".join(repr(e) for e in x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
argmn = np.argmin(A)
mn = A[argmn]
for m in range(mn+1):
  B = np.zeros(len(A))
  B[argmn] = m * 2
  for i in range(len(A)):
    idx = (i + argmn)%len(A)
    B[(idx+1)%len(A)]  += A[idx] * 2  - B[idx]
  B[argmn] -= m * 2
  if (B[argmn]+B[(argmn+1)%len(A)]==(A[argmn]*2)):
    print (" ".join(B.astype(np.int).astype(np.str)))
    exit()

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 :
    m = max(dl)
    for i in range(n) :
        if dl[i] == m :
            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(" ")))
A2 = []
M = []
for i in A:
    A2.append(i * 2)
RM = []
count = 1
for i in range(N):
    a = [0.5] * N
    for i in range(int(N/2)):
        target = (count + i*2) % N
        a[target] *= -1
    count += 1
    RM.append(a)
ans = np.dot(RM,A2)
print(' '.join(map(lambda x:str(int(x)),ans)))

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)
	s = 0
	if ed > 1000000 * 2:
		s = 100000000
	for i in range(s, 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:
import numpy as np

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

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

y = []
for x in b:
    y.append(x*2)

ans = np.linalg.solve(A, y)
x = []
for a in ans:
    x.append(int(a))

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

Submission status: Time Limit Exceeded

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

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

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

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

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

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
ans=0
x=[]
for i in range(n):
    for j in range(n):
        if (i+j)>n-1:
            b=i+j-n
        else:
            b=i+j
        ans+=a[b]*pow(-1, j)
    x.append(str(ans))
    ans=0
print(' '.join(x))

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)
	s = 0
	if ed > 1000000 * 2:
		s = 100000
	for i in range(s, 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:
import copy
N=int(input())
A=list(map(int,input().split()))

MAX=A[0]
MIN=0
MID=(MAX+MIN+1)//2
#print(MID)
for i in range(100):
    B=copy.deepcopy(A)
    B[0]-=MID
    B[N-1]-=MID
    #print(B)
    for j in range(N):
        B[(j+1)%N]-=B[j]
        B[j]=0
    #print(B)
    if B[0]==0:
        C=copy.deepcopy(A)
        ANS=[0 for i in range(N)]
        C[0]-=MID
        C[N-1]-=MID
        ANS[0]+=MID*2
        #ANS[N-1]+=MID
        for j in range(N):
            C[(j+1)%N]-=C[j]
            ANS[(j+1)%N]+=C[j]*2
            #ANS[j]+=C[j]
            C[j]=0
            #print(C)
            #print(ANS)
        ans=str(ANS[0])
        for i in range(1,len(ANS)):
            ans+=" "+str(ANS[i])
        print(ans)
        exit()
    elif B[0]<0:
        MIN=MID
        if i%2==0:
            MID=(MIN+MAX)//2
        else:
            MID=(MIN+MAX+1)//2
    elif B[0]>0:
        MAX=MID
        if i%2==0:
            MID=(MIN+MAX)//2
        else:
            MID=(MIN+MAX+1)//2

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())

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

def judge(x1):
    X = [0] * N
    X[0] = x1 * 2
    for i in range(1, N):
        X[i] = 2*A[i-1] - X[i-1]

    if X[0] + X[N-1] == 2*A[N-1]:
        # 正解
        print(' '.join(map(str, X)))
        sys.exit(0)
    elif X[0] + X[N-1] > 2*A[N-1]:
        # x1 が大きすぎた
        return 1
    else:
        # x1 が小さすぎた
        return -1


def getNext(start, end):
    return (end - start) // 2 + start

# x/2 の取りうる範囲
minx = 0
maxx = max(A[0], A[N-1])

current = getNext(minx, maxx)

while True:
    prev = current
    ret = judge(current)
    if ret == 1:
        maxx = current
        current = getNext(minx, current)
    else:
        minx = current
        current = getNext(current, maxx)

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
ans=str(str(res)+" ")
for i in range(1,N):
	B[i]=int((A[i-1]-(int(B[i-1])/2))*2)
	ans=str(ans)+str(B[i])+" "

print(ans)

Submission status: Time Limit Exceeded

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

cmid=0
mid=AL[0]*4
left=0
right=AL[0]*4
while True:
    flag=True
    cmid=mid
    mid=(left+right)//2
    if cmid==mid:
        mid-=1
    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:
from numpy.linalg import solve

N = int(input())
right = list(int(x) * 2 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)

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

yama = [10**8 for _ in range(n)]

ans = [10**8 for _ in range(n)]

for i in range(n):
    if i == 0:
        yama[i] = min(dam[i], dam[-1]) * 2
    else:
        yama[i] = min(dam[i-1], dam[i]) * 2


for i in range(0,yama[0]+1,2):
    for j in range(n):
        if j == 0:
            ans[j] = i
        else:
            ans[j] = (dam[j-1] - ans[j-1]//2) * 2
            if ans[j] > yama[j]:
                break
    else:
        if (ans[0] + ans[-1])//2 == dam[-1]:
            print(*ans)
            exit()

Submission status: Time Limit Exceeded

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

for i in range(n):
  wa=0
  cnt=0
  for j in range(i,n+i):
    b=j
    cnt+=1
    if b>=n:
      b=b%n
    if cnt%2==1:
      wa+=a[b]
    else:
      wa-=a[b]
  print(wa)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
c=deque([1 if i%2==0 else -1 for i in range(n)])

ans=[]
for loop in range(n):
    t=sum([i*j for i,j in zip(a,c)])
    ans.append(str(t))
    c.rotate(1)


print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_r = 0
# print(A[0::2])
# print(A[1::2])
sum_odd = 0
sum_even = 0
for i in range(N):
    a = A[i]
    sum_r += a
    if i % 2 == 0:
        sum_odd += a
    else:
        sum_even += a

ans = ''
rolling_even = sum_even 
rolling_odd = sum_odd - A[0]
#print(sum_r,sum_even)
ans += str(sum_r - 2 * rolling_even) + ' ' + str(sum_r - 2 * rolling_odd)
mepo = A[1]
mope = A[0]
for i in range(2,N):
    tmp = sum_r

    if i % 2 == 0:
        # rolling_even += A[(i-2)%N] - A[(i-1)%N]
        mepo = A[(i-1)%N]
        rolling_even += mope - mepo
        tmp = sum_r - 2 * rolling_even
    else:
        mope = A[(i-1)%N]
        rolling_odd += mepo - mope
        tmp = sum_r - 2 * rolling_odd
    ans += ' ' + str(tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
A=list(map(int,input().split()))
anp=np.array(A)
anp*=2
for i in range(len(A)):
    x=anp[i]
    flag=1
    for j in range(i+1,i+len(A)):
        k=j%len(A)
        if flag:
            x-=anp[k]
            flag=0
        else:
            x+=anp[k]
            flag=1
    x/=2
    print(int(x),end=" ")
print()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    min_index = As.index(min(As))
    new_As = As[min_index:] + As[:min_index]
    # print(new_As)
    for i in range(new_As[0] + 1):
        xxx = []
        tmp = i
        for x in new_As:
            xxx.append((tmp, x - tmp))
            tmp = x - tmp
            if tmp < 0:
                break
        else:
            if xxx[0][0] == xxx[-1][1]:
                # print(xxx)
                yyy = []
                for i, item in enumerate(xxx[:-1]):
                    yyy.append(item[1] + xxx[i + 1][0])
                yyy.append(xxx[0][0] + xxx[-1][1])
                yyy = yyy[-1:] + yyy[0:-1]
                # print(yyy)
                yyy = yyy[-min_index:] + yyy[:- min_index]
                # print(yyy)
                for z in yyy[:-1]:
                    print(z, end=' ')
                print(yyy[-1])
                return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

fin_flag = 0
rain = np.zeros(n,dtype=int)
for i in range(a[0]*2//2+1):
    # mount1
    rain[0] = 2*i
    #print("rain[0]",rain[0])
    for j in range(1,n):
        rain[j] = (a[j-1]-rain[j-1]/2)*2
        #print("j,rain[j]",j,rain[j])
        if rain[j] < 0:
            break
        if j == n-1:
            if rain[0]/2 + rain[j]/2 == a[j]:
                fin_flag = 1
    if fin_flag == 1:
        break
print(*rain)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A_list = [int(i) for i in input().split()]
A_matrix = np.matrix(A_list)
N_matrix_list=[]
for i in range(N):
    tmp = [0]*N
    tmp[i]=1
    if i == N-1:
        tmp[0]=1
    else:
        tmp[i+1]=1
    N_matrix_list.append(tmp)
N_matrix = np.matrix(N_matrix_list)
N_matrix_inv = N_matrix.I
X_matrix = N_matrix_inv * A_matrix.T *2
ans = X_matrix.T.astype(int).tolist()[0]
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a_list = list(map(int,input().split()))
    a = 0
    end = 0
    for i in range(n):
        if i%2 == 0:
            a += a_list[i]*0.5
        else:
            a -= a_list[i]*0.5

    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)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
arg0 = list(map(int, input().split()))
dam = list(map(int, input().split()))

for i in range(len(dam)):
  dam[i] = dam[i] * 2
  
rain = [0] * (len(dam)+1)

for i in range(max(dam)):
  rain[0] = i
  for j in range(len(dam)):
    rain[j+1] = dam[j] - rain[j]
  if rain[0] == rain[-1]:
    break
    
for i in range(len(rain)-1):
  print(rain[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
S=sum(A)
ans=[]
for i in range(0,N):
    if i % 2 ==0 :
        #print("###%d" % i)
        #print(A[i+1:N:2])
        #print(A[0:i:2])
        ans.append(S-2*(sum(A[i+1:N:2])+sum(A[0:i:2])))
        
    if i % 2 !=0:
        #print("###%d" % i)
        #print(A[i+1:N:2])
        #print(A[1:i:2])
        ans.append(S-2*(sum(A[i+1:N:2])+sum(A[1:i:2])))
        
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
Base1 = 0
Base2 = 0
for x in range(N):
    if x % 2 == 0:
        Base1 += A[x]
        Base2 -= A[x]
    else:
        Base1 -= A[x]
        Base2 += A[x]

for i in range(N):
    if i % 2 == 0:
        tmp1 = Base1
        for j in range(i):
            if j % 2 == 0:
                tmp1 -= 2*A[j]
            else:
                tmp1 += 2*A[j]
        print(tmp1)
    if i % 2 == 1:
        tmp2 = Base2
        for j in range(i):
            if j % 2 == 0:
                tmp2 += 2*A[j]
            else:
                tmp2 -= 2*A[j]

        print(tmp2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

print("".join(x))

Submission status: Time Limit Exceeded

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

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

# ダムmin_indから決めていく
rain = [0 for i in range(N)]
start = 0
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:
from numpy.linalg import solve
N=int(input())
A=input().split()
for i in range(N):
    A[i]=2*int(A[i])
x=[None]*N
for i in range(N-1):
    x[i]=[0]*N
    x[i][i],x[i][i+1]=1,1
x[N-1]=[0]*N
x[N-1][0],x[N-1][N-1]=1,1
y=solve(x,A)
for i in range(N):
    print(int(y[i]),end=' ')

Submission status: 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(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] = -1
            break
    if (ans[0] >> 1) + (ans[-1] >> 1) == A[-1]:
        break

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

Submission status: Time Limit Exceeded

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

total_rain = sum(A) // 2

one = total_rain
for j in range(1, N-1, 2):
    one -= A[j]
rain = one*2
ans = str(rain)
prerain = rain

for m in range(1, N):
    rain = (A[m-1] - prerain//2)*2
    ans+=" "
    ans+=str(rain)
    prerain = rain

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

X = []
for i in range(N):
    x = [0 for _ in range(N)]
    for j in range(i, i+2):
        if j >= N:
            continue
        x[j] = 1
    if i == N - 1:
        x[0] = 1
    X.append(x)

Y = A
X = np.matrix(X)
Y = np.matrix(Y).reshape(-1, 1)
ans = np.linalg.solve(X,Y) * 2
ans = list(map(lambda x: str(int(x)), ans))
print(' '.join(ans).strip())

Submission status: Time Limit Exceeded

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

Alists=list(map(int, input().split()))
Ylists=[[i] for i in Alists]

xlists=[]
for i in range(N):
  lists=[0 for j in range(N)]
  if(i<N-1):
    lists[i]=lists[i+1]=1
  if(i==N-1):
    lists[0]=lists[i]=1
    
  xlists.append(lists)

A=np.matrix(xlists)
Y=np.matrix(Ylists)

ret=np.linalg.solve(A,Y)
retlists=[2*ret[i][0] for i in range(len(ret))]
result=[np.squeeze(np.asarray(retlists[i])) for i in range(len(retlists))]
result=[str(int(result[i])) for i in range(len(result))]
print(' '.join(result))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    for s in range(A[0] * 2, -1, -2):
        mt = [None] * N
        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:
import numpy as np
n = int(input())
A = [int(i) * 2 for i in input().split()]

L1 = [[0] * n for _ in range(n)]
for i in range(n):
    if i + 1 <= n-1:
        L1[i][i] = 1
        L1[i][i+1] = 1
    else:
        L1[i][i] = 1
        L1[i][0] = 1
        
L1 = np.linalg.inv(L1)
L2 = np.array(A)
ans = list(np.dot(L1, L2))
print(" ".join([str(int(n)) for n in ans]))