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 numpy as np
N = int(input())
A = list(map(int,input().split(" ")))
A2 = []
M = []
for i in A:
    A2.append(i * 2)
for i in range(N):
    a = [0] * N
    a[i] = 1
    a[(i+1)%N] = 1
    M.append(a)
RM = np.linalg.inv(M)
ans = np.dot(RM,A2)
print(' '.join(map(lambda x:str(int(x)),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

    # i = 0
    while True:
        # i += 1
        # if i > 10:
        #     break
        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 = max(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:
from numpy.linalg import solve

mount_num = int(input())
dam_accumulate = list(map(lambda x: x * 2, list(map(int, input().split()))))

left = []
for i in range(mount_num):
    left.append([0] * mount_num)
    left[i][i % mount_num] = 1
    left[i][(i+1) %  mount_num] = 1

print(*list(map(int, solve(left, dam_accumulate))))

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

a = []
for i in range(n):
    line = [0 for j in range(n + 1)]
    line[i] = 1
    if i + 1 >= n:
        i = -1
    line[i + 1] = 1
    line[n] = d[i] * 2
    a.append(line)
#print(a)

for k in range(n):
    p = a[k][k]
    for j in range(k, n + 1):
        a[k][j]  = a[k][j] / p
    for i in range(n):
        if i != k:
            d = a[i][k]
            for j in range(k, n + 1):
                a[i][j] = a[i][j] - d * a[k][j]
ans = []
for i in range(n):
    ans.append(str(int(a[i][-1])))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
B=[]
res=0
for m in range(N):

	for i in range(N):
		n=(i+m)%N
		if n%2!=0:res-=A[n]
		else:res+=A[n]
	B=B+[res]
	res=0
	zero=A[0]
	for s in range(N-1):
		A[s]=A[s+1]		
	A[N-1]=zero
ans=""

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

a=int(input())
b=list(map(int,input().split()))
b=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/2
        i[aa]=1/2
    else:
        i[aa+1]=1/2
        i[aa]=1/2
    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:
n = int(input())
l = list(map(int,input().split()))
#print(n,l)

flag = 0   
for x in range(0,l[0]+1):
    #xはx1のこと
    #print(x)
    if flag == 1:
        break
    ans = [0]*n
    flag = 0
    ans[0] = 2*x
    ans[1] = 2*(l[0]-x)
    for i in range(2,n):
        ans[i] =2*l[i-1]-ans[i-1]
    if (ans[n-1]+ans[0])//2 == l[n-1]:
        flag = 1
        break
for i in range(n):
    print(ans[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
n = int(input())
a = list(map(int, input().split()))

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

cur = 0
x = 0
while True:
    pre = cur
    ans = [0 for _ in range(n)]
    ans[0] = cur
    for i in range(n-1):
        cur = a[i] * 2 - cur
        ans[i+1] = cur
        if cur < 0:
            break
    if a[-1] * 2 == cur + pre:
        print(" ".join(list(map(str, ans))))
        break
    x += 1
    cur = x * 2

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])
  for j in range(N):
    if j == i or j == (i + 1) % N:
      left[i][j] = 0.5

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

N = int(input())
A = np.array(list(map(lambda x: int(x),input().split())))
X = np.array([(-1)**i for i in range(N)])
for i in range(N):
    print(int(np.dot(A,np.roll(X,i).T)),end=" ")

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

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

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

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.inv(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:
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(invnumX, 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()))

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

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

ans = ''
temp = (A[1] - A[0])*2
for i in range(N)[2:]:
    temp = A[i]*2 - temp
a = int(temp/2)
ans = ans + str(a) + ' '

temp = a
for i in range(N-1):
    temp = A[i]*2 - temp
    ans = ans + str(temp) + ' '

print(ans.rstrip())

Submission status: Time Limit Exceeded

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

Y = [0] * N

pattern = A[0] + 1

for i in range(pattern):
    Y[0] = i * 2
    # print("pattern", Y[0])
    for k in range(1, N):
        # print("k", k)
        Y[k] = 2 * A[k - 1] - Y[k - 1]
        # print("Y:", Y[k])
        if Y[k] < 0:
            break
        if k == N - 1 and (Y[k] + Y[0]) / 2 == A[k]:
            ans = ' '.join([str(n) for n in Y])
            print(ans)
            exit()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
water = np.array([int(i)*2 for i in input().split()])
A = np.array([[0 for i in range(n)] for j in range(n)])

for i in range(n):
	for j in range(i,i+2):
		if j >= n:
			j = 0
		A[i][j] = 1
		
inv_A = np.linalg.inv(A)
ans = np.dot(inv_A,water)
ans = [str(int(i)) for i in ans]
print(" ".join(ans))

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=[]
for i in range(N):
    sum_i = sum([s for s,num in zip(A[i:i+N], range(N)) if num in odds] )

    Ans.append( 2*sum_i -S )    
print(" ".join(map(str,Ans) ))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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)

#for i in x:
#    print(int(i), end=" ")
print(*x.astype(int))

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(2 * A[i] + 2 * A[(i + 1) % N])
  for j in range(N):
    if j == i or j == (i + 2) % N:
      left[i][j] = 1
    if j == (i + 1) % N:
      left[i][j] = 2

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

input = sys.stdin.readline

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

X = [0 for _ in range(N)]



X = np.array(X)
A = np.array(A)
for i in range(N):
    B  = np.hstack((A[i:N+i], A[:i]))
    X = X + (-1)**i * B
 
print(*X)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_r = sum(A)
# print(A[0::2])
# print(A[1::2])
sum_odd = sum(A[0::2])
sum_even = sum(A[1::2])

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)
for i in range(2,N):
    tmp = sum_r
    # for j in range(N//2):
    #     #print((i+1+j*2)%N)
    #     amount -= A[(i+1+j*2)%N]*2
    if i % 2 == 0:
        #print(i,rolling_odd, A[(i-2)%N], A[(i-1)%N])
        rolling_even += A[(i-2)%N] - A[(i-1)%N]
        tmp = sum_r - 2 * rolling_even
    else:
        rolling_odd += A[(i-2)%N] - A[(i-1)%N]
        tmp = sum_r - 2 * rolling_odd
    ans += ' ' + str(tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

mount_num = int(input())
dam_accumulate = list(map(int, input().split()))

left = []
for i in range(mount_num):
    left.append([0] * mount_num)
    left[i][i % mount_num] = 1
    left[i][(i+1) %  mount_num] = 1

right = list(map(lambda x: x * 2, dam_accumulate))

print(*list(map(int, solve(left, right))))

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(2 * A[i] + 2 * A[(i + 1) % N])
  for j in range(N):
    if j == i or j == (i + 2) % N:
      left[i][j] = 1
    if j == (i + 1) % N:
      left[i][j] = 2

A = np.matrix(left)
Y = np.matrix(right)
ans = 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_i たまった水
A = list(map(int,input().split()))

A_total = sum(A)

ans = []
for i in range(N):
    tmp_sum = 0
    for j in range((N - 1) // 2):
        tmp_sum += (2 * A[(i+1 + (j * 2)) % N])
    ans.append(A_total - tmp_sum)

ans_s = str(ans[0])
for a_i in ans[1:]:
    ans_s = ans_s + " " + str(a_i)
print(ans_s)

Submission status: Time Limit Exceeded

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

rains = [0] * N
for rain1 in range(0, strage[0]*2 + 1, 2):
    rains[0] = rain1
    for i in range(1, N):
        rains[i] = (strage[i-1] - rains[i-1]/2) * 2
    if (rains[0] + rains[-1]) /2 == strage[-1]:
        break
    else:
        rains = [0] * N

for rain in rains:
    print(int(rain))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dam = list(map(int, input().split()))
yama = [0] * n
yama_copy = [0] * n

min_dam = min(dam)
min_arg = dam.index(min(dam))

yama_bf = min_arg
yama_i = min_arg
for i in range(0, min_dam * 2 + 1, 2):
    yama_copy[yama_i] = i
    yama_i = (yama_i + 1) % n
    for j in range(n-1):
        yama_copy[yama_i] = (dam[yama_bf] - yama_copy[yama_bf]/2) * 2
        yama_bf = yama_i
        yama_i = (yama_i + 1) % n
    if dam[yama_bf] == yama_copy[yama_bf]/2 + yama_copy[min_arg]/2:
        break
    yama_copy = [0] * n
    yama_bf = min_arg
    yama_i = min_arg
yama_copy = map(int, yama_copy)
print(' '.join(map(str, yama_copy)))

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
def input_from_console():
    n = int(input())
    a_list = list(map(int, input().split()))
    return n, a_list


def solve(n, a_list):
    row = [0] * (n)
    matrix = []
    row[0] = 0.5
    row[n - 1] = 0.5
    # print(row)
    for i in range(n):
        matrix.append(row.copy())
        row.insert(0, row[-1])
        row = row[:n]
    y = np.array(matrix)
    x = np.array(a_list)
    dam_list = list(map(str, map(int, np.linalg.solve(y, x))))
    dam_list = [dam_list[n - 1]] + dam_list[:n - 1]
    result = ' '.join(map(str, dam_list))
    return result


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

print(*ans)

Submission status: Time Limit Exceeded

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

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

w_arr = []

for i in range(N):
  arr = [0]*N
  if i == N-1:
    arr[i] = 1/2
    arr[0] = 1/2
  else:
    arr[i] = 1/2
    arr[i+1] = 1/2
  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:
N = int(input())
A = list(map(int, input().split()))

def c(index):
    return index%N

total_rain = sum(A) // 2

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

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

print(ans)

Submission status: Time Limit Exceeded

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

cnum=0

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 = [int(i) for i in input().split()]
B = [0]*len(A)
flag = False
for i in range(A[0]+1):
    tmp = i
    B[0] = tmp*2
    for j in range(1,N+1):
        tmp = (A[j-1] - (B[j-1]//2))*2
        if tmp < 0:
            break
        if j == N:
            if tmp == B[0]:
                flag = True
            break
        B[j] = tmp
    if flag:
        break
ans = " ".join(map(str, B))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
#print(n,l)

flag = 0   
for x in range(0,l[0]+1):
    #xはx1のこと
    #print(x)
    if flag == 1:
        break
    ans = [0]*n
    flag = 0
    ans[0] = 2*x
    ans[1] = 2*(l[0]-x)
    for i in range(2,n):
        ans[i] = 2*l[i-1] - ans[i-1]
        if ans[i]%2 != 0:
            break
        if i == n-1:#Aiについて成り立つかどうか
            total = (ans[n-1] + ans[0])
            if total//2 == l[n-1]:
                flag = 1
                break
for i in range(n):
    print(ans[i],end=" ")

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 for _ in range(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]))

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 = []
for i in range(n):
    p = sum([v*x for v,x in zip(s,A)])
    # print(s)
    s = s[-1:]+s[:-1]
    print(p,end="")
    print(" ",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)

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

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

d = np.array(d)

ans = np.dot(np.linalg.inv(d), A.T)
ans = np.array(ans, dtype="int")
ans = (ans.T).tolist()

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

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

mountains = []

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

print(' '.join([str(int(x)) for x in solve(mountains, dam)]))

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

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

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

Submission status: Time Limit Exceeded

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

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

r = []
for i in range(N):
    if i%2 == 0:
        tmp = sum(A[i::2])
        tmp -= sum(A[i+1::2])
        tmp -= sum(A[0:i:2])
        tmp += sum(A[1:i:2])
    else:
        tmp = sum(A[i::2])
        tmp -= sum(A[i+1::2])
        tmp -= sum(A[1:i:2])
        tmp += sum(A[0:i:2])

    r.append(str(tmp))

print(" ".join(r))

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)
        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;
        
tmp.pop(-1)

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

Submission status: Time Limit Exceeded

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

half_sum_water = sum(water) // 2

ans = []

m = n // 2
for i in range(n):
    mount = half_sum_water
    for j in range(m):
        mount = mount - water[(i + 1 + (j * 2)) % n]
    print(mount * 2,end = ' ')

print()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
total_water = sum(a)
result_list = []


def double(n):
    return n * 2

# b = [a[i]*2 for i in range(n)] * 2
b = list(map(double, a)) * 2

t = n//2

for i in range(1, n+1):
    s = sum(b[i : i + t*2 : 2])
    print(total_water - s, end = ' ')

Submission status: Time Limit Exceeded

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

ls = []
for i in range(n):
  x = A[0]
  for j, a in enumerate(A[1:]):
    if j%2==0:
      x -= a
    else:
      x += a
  A.insert(n, A[0])
  A.pop(0)
  print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = [a[i] if (i % 2 == 0) else -1 * a[i] for i in range(n)]
b = []
for i in range(n):
    t = a[i:] + a[:i]
    ttt = sum([t[i] if (i % 2 == 0) else -1 * t[i] for i in range(n)])
    b.append(str(ttt))
print(" ".join(b))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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)

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

Submission status: Time Limit Exceeded

Solution code:
size = int(input())
waters = list(map(int, input().split()))

# 奇数の場合のみ、たとえば size = 5 なら、
# m1 = d1 - d2 + d3 - d4 + d5 のように求められる

# 各山に振った水量を、mとする
m = [0]*size
m[0] = sum(waters[::2]) - sum(waters[1::2])

for i in range(1, size):
    m[i] = 2 * (waters[i-1]) - m[i - 1]

ans_msg = str(m[0])
for ans_i in m[1:]:
    ans_msg = ans_msg + " " + str(ans_i)

print(ans_msg)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

X = [0]*N

for i in range(N):
    for j in range(N):
        if j+i < N:
            tmp_A = (-1)**(j+i)*A[j+i]
        else:
            tmp_A = (-1)**(j+i)*A[j+i-N]
        X[i] += tmp_A
    if i % 2 != 0:
        X[i] *= -1
print(" ".join(map(str, X)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[0 for x in range(n)]
for i in range(n):
    for j in range(i,i+n):
        x[i]+=a[j%n]*((-1)**j)
for i in range(n):
    print("{}".format(abs(x[i])),end=" ")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
suma=sum(a)//2
for i in range(n):
  minus=0
  for j in range(n//2):
    minus+=a[(i+2*j+1)%n]
  print(2*(suma-minus),end=' ')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [0]*len(A)
flag = False
for i in range(A[0]+1):
    tmp = i
    B[0] = tmp*2
    for j in range(1,N+1):
        tmp = (A[j-1] - (B[j-1]//2))*2
        if tmp < 0:
            break
        if j == N:
            if tmp == B[0]:
                flag = True
            break
        B[j] = tmp
    if flag:
        break
ans = ""
for i in B:
    ans += str(i) + " "
print(ans[:-1])

Submission status: Time Limit Exceeded

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

t = np.array([1, -1])
w = np.tile(t, [1 + N // 2])[:-1]
W = []
W_append = W.append
for i in range(N):
    W_append(np.roll(w, i))

W = np.array(W)
r = np.dot(W, A).astype(np.str).tolist()
print(" ".join(r))

Submission status: Time Limit Exceeded

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

x[0]=sum//2

for i in range(1, n):
    x[i]=a[i-1]-x[i-1]

ans=""
for i in range(n):
    ans=ans+str(x[i]*2)+" "
print(ans)

Submission status: Time Limit Exceeded

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

water = A[:]
#print(water)

ans = []
for x in range(0, max(water[0], water[-1])*2+1, 2):
    #print(x)
    ans = [x]
    for i, a in enumerate(water):
        y = 2*a - x
        #print(y)
        if y % 2 == 1:
            break
        ans.append(y)
        x = y
    if len(ans) == N+1 and ans[0] == ans[-1]:
        #print(len(ans), N)
        break
print(' '.join(list(map(str, ans[:-1]))))

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=[]
for i in range(N):
    sum_i=0
    for odd in odds:
        sum_i += A[i+odd] 
    Ans.append( 2*sum_i -S )    
print(" ".join(map(str,Ans) ))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for i in range(n):
        f = s
        for j in range(a):
            f -= 2 * al[(i - (1 + 2 * (j + 1)) + n) % n]
        ans[i] = str(f)
    print(" ".join([i for i in ans[1:]]) + " " + ans[0])

if __name__=="__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
dam = list(map(int, input().split()))
yama = [0] * n
yama_copy = [0] * n

min_dam = min(dam)
min_arg = np.argmin(dam)

yama_bf = min_arg
yama_i = min_arg
for i in range(0, min_dam * 2 + 1, 2):
    yama_copy[yama_i] = i
    yama_i = (yama_i + 1) % n
    for j in range(n-1):
        yama_copy[yama_i] = (dam[yama_bf] - yama_copy[yama_bf]/2) * 2
        yama_bf = yama_i
        yama_i = (yama_i + 1) % n
    if dam[yama_bf] == yama_copy[yama_bf]/2 + yama_copy[min_arg]/2:
        break
    yama_copy = [0] * n
    yama_bf = min_arg
    yama_i = min_arg
yama_copy = map(int, yama_copy)
print(' '.join(map(str, yama_copy)))