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:
n = int(input())
a = list(map(int, input().split()))
for i in range(a[0] + 1):
  ans = [i]
  ans.append(a[0] - i)
  for j in range(1, n):
    ans.append(a[j] - ans[j])
  if ans[0] == ans[n]:
    ans = [i * 2 for i in ans[0:n]]
    print(" ".join(map(str, ans)))
    break

Submission status: Time Limit Exceeded

Solution code:
import math

def main():
    N = int(input())
    dam_list  = list(map(int, input().split(" ")))
    water_list = []

    for i in range(N):
        sign = 1
        total = 0
        for j in range(i, N+i):
            if j >= N:
                j = j-N
            total = total + dam_list[j] * sign
            sign = sign * -1
        print(total, end=" ")
    
    return


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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

W = np.array(waterlist)
# print(W)

# print(waterlist)
# print(volume)
matrix = [[] for _ in range(N)]
for i in range(N):
    templist = [0 for _ in range(N)]
    templist[i] = 1
    if i == N - 1:
        templist[0] = 1
    else:
        templist[i + 1] = 1
    matrix[i] = templist


A = np.array(matrix)
inv_A = np.linalg.inv(A)
# print(inv_A)

ansmatrix = inv_A.dot(W)*2
# print(ansmatrix)
message = ""
for i in range(N):
    message += str(int(ansmatrix[i]))
    if i == (N - 1):
        break
    message += " "
print(message)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=list(map(int,input().split()))
cc=1
d=[0 for i in range(a)]
d[0]=sum(b[0::2])-sum(b[1::2])
e=str(d[0])
for i in range(1,a):
  d[i]=b[i-1]*2-d[i-1]
  e=e+" "+str(d[i])

print(e)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=list(map(int,input().split()))
cc=1
d=[0 for i in range(a)]
c=sum(b[1::2])*2
d[0]=sum(b)-c
e=str(d[0])
for i in range(1,a):
  d[i]=b[i-1]*2-d[i-1]
  e=e+" "+str(d[i])

print(e)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=list(map(int,input().split()))
cc=1
c=0
d=[0 for i in range(a)]
while cc<a:
  c+=b[cc]*2
  cc+=2
d[0]=sum(b)-c
e=str(d[0])
for i in range(1,a):
  d[i]=b[i-1]*2-d[i-1]
  e=e+" "+str(d[i])

print(e)

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve(N, A):
    def moutain(x):
        sum = 0
        for i in range(N):
            sum += A[(x+i)%N] * (-1) ** (i)
        return sum

    m = [int()] * N
    for i in range(N):
        m[i] = str(moutain(i))

    print(' '.join(m))

def main():
    N = int(input())
    A = list(map(int, input().split()))
    solve(N, A)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

n=int(input())
x=list(map(int, input().split()))
import numpy as np

y=np.array([1,-1]*((n-1)//2))
y=np.append(y,1)

res=[0]*n

for i in range(n):
	res[i]=sum(np.roll(y,i)*x)
	
print(*res)

Submission status: Time Limit Exceeded

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

y=np.array([1,-1]*((n-1)//2))
y=np.append(y,1)

res=[0]*n

for i in range(n):
	res[i]=sum(np.roll(y,i)*x)
	
print(*res)

Submission status: Time Limit Exceeded

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

y=np.array([1,-1]*((n-1)//2))
y=np.append(y,1)

x2=np.array(x).T

res=[0]*n

for i in range(n):
	res[i]=np.dot(np.roll(y,i),x2)
	
print(*res)

Submission status: Time Limit Exceeded

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

y=np.array([1,-1]*((n-1)//2))
y=np.append(y,1)

x2=np.array(x).T

for i in range(n):
	res=np.dot(np.roll(y,i),x2)
	print(res)

Submission status: Time Limit Exceeded

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

y=[1]*n

for i in range(n):
	if i%2!=0:
		y[i]=-1

x2=np.array(x).T

for i in range(n):
	y2=np.roll(y,i)
	res=np.dot(y2,x2)
	print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_rain = sum(a) // 2
a += a
ans_rain = []

for i in range(n):
    rest_rain = 0
    for j in range(i + 1, i + n, 2):
        rest_rain += a[j]
    ans_rain.append((sum_rain - rest_rain) * 2)

print(*ans_rain)

Submission status: Time Limit Exceeded

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

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
    for idx in range(N-1):
        a = A[idx]
        x_next = a - x_values[-1]
        if x_next < 0:
            has_missed = True
            break
        else:
            x_values.append(x_next)
    if (not has_missed) and (x_values[0] + x_values[-1] == A[N-1]):
        break

x_values = [str(2*x) for x in x_values]
print(' '.join(x_values))

Submission status: Time Limit Exceeded

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

x0_half_cands = [a for a in range(A[0]+1)]

for x0_half in x0_half_cands:
    x_values = [x0_half]
    has_missed = False
    for idx in range(N-1):
        a = A[idx]
        x_next = a - x_values[-1]
        if x_next < 0:
            has_missed = True
            break
        else:
            x_values.append(x_next)
    if (not has_missed) and (x_values[0] + x_values[-1] == A[N-1]):
        break
x_values = [str(2*x) for x in x_values]
print(' '.join(x_values))

Submission status: Time Limit Exceeded

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

S = 0
for i in range(N):
   S += A[i]

for i in range(N):
  X = 0
  for j in range(N):
    if j % 2:
       X += A[(i+j)%N]
  print(S-2*X, end=" ")
print()

Submission status: Time Limit Exceeded

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

# 山1に降った雨の量を二分探索する
upper = 2 * (10 ** 9)
lower = 0

ansList = []
while True:
    half = (upper + lower) // 2
    if half % 2 == 1:
        half += (upper + lower) % 2
    tmp = half
    ansList = [half]
    for i, a in enumerate(A):
        tmp = 2 * (a - tmp//2)
        if i == N-1:
            if tmp == ansList[0]:
                break
            else:
                ansList = []
                if i % 2 == 0:
                    upper = half
                else:
                    lower = half
                break
        else:
            if tmp < 0:
                if i % 2 == 0:
                    upper = half
                else:
                    lower = half
                ansList = []
                break
            else:
                ansList.append(tmp)
    if len(ansList) == N:
        break
ansList = [str(a) for a in ansList]
ans = ' '.join(ansList)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int( input())
b = [ int(i) for i in input().split()]

if b[a-1] == 0:
  y=[0]
  
  for i in range (len(b)):
    y.append(2*b[i]-y[i])

for i in range ( 0, 2*b[a-1], 2):
  y = [i]
  c=[]
  
  for j in range (len(b)):
    y.append(2*b[j]-y[j])
    c.append((y[j]+y[(j+1)%len(b)])/2)
    
  if c == b:
    break
    
for i in range (len(b)):
  print(y[i], " ",end="")

Submission status: Time Limit Exceeded

Solution code:
a = int( input())
b = [ int(i) for i in input().split()]

if b[a-1] == 0:
  y=[0]
  
  for i in range (len(b)):
    y.append(2*b[i]-y[i])

for i in range ( 0, 2*b[a-1], 2):
  y = [i]
  c=[]
  
  for j in range (len(b)):
    y.append(2*b[j]-y[j])
  
  for j in range (len(b)):
    c.append((y[j]+y[(j+1)%len(b)])/2)
    
  if c == b:
    break
    
for i in range (len(b)):
  print(y[i], " ",end="")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = A.copy()
for i in range(1, N):
    ans += (-1) ** i * np.concatenate([A[i:].copy(), A[:i].copy()])
ans = list(ans)
print(" ".join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros((N), dtype=np.int)
tmp = np.zeros((N), dtype=np.int)
for i in range(N):
    if i == 0:
        tmp = A.copy()
    else:
        tmp = np.concatenate([A[i:].copy(), A[:i].copy()])
    ans += (-1) ** i * tmp
ans = list(ans)
print(" ".join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for b[0] in range(0,mi*2+1,2) :
    # print(x)
    # b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


# s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


# s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[-0]


for x in range(mi*2, -1,-2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = ""
for i in b :
    s = s + str(i) + " " 


print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split(' ')]
# a = [int(input()) for x in range (n)]

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[-0]


for x in range(0,mi*2+1,2) :
    # print(x)
    b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


s = ""
for i in b :
    s = s + str(i) + " " 


print(s)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=sum(b)
d=[]
for i in range(a):
  x=0
  for j in range(int((a-1)/2)):
    x=x+2*b[(i+2*j+1)%a]    
  d.append(c-x)

for i in d:
  print(i,end=' ')

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

#+++++
		
def main():
	n = int(input())
	water_list=list(map(int, input().split()))
	
	mw=water_list[-1]
	for i in range(mw+1):
		cv = mw - i
		init_cv=cv
		for w in water_list[::-1]:
			#print(w,cv, w-cv)
			cv = w - cv
			if cv < 0:
				break
		else:
			#print('hhh', cv, init_cv, mw)
			if init_cv == cv:
				ret = [0 for _ in range(n)]
				cv=init_cv
				for ii, ww in enumerate(water_list):
					ret[ii] = cv*2
					cv = ww - cv
					#print(ret)
				return ret
				
	return 'hoge'
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(' '.join([str(i) for i in ret]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

matrix = []

for tsumugi in range(n):
  tmp = [0] * n
  for matsuri in range(n):
    if tsumugi == matsuri:
      tmp[matsuri] = 0.5
      if matsuri != n - 1:
        tmp[matsuri + 1] = 0.5
      else:
        tmp[0] = 0.5
  matrix.append(tmp)

matrix_inv = np.linalg.inv(matrix)
fall = np.dot(matrix_inv, a)

print(" ".join(map(str, map(int, fall))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
for i in range(n):
    one_ans = 0
    multiple = -1
    for j in range(n):
        one_ans += x[(i+j)%n] * multiple
        multiple *= -1
    one_ans += 2*x[i]
    ans.append(int(one_ans))
last = ans.pop()
ans.insert(0, last)
print ' '.join(map(str, ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = map(int, raw_input().split())

x = map(int, raw_input().split())
n = n[0]
ans = []

x = np.asarray(x)
for i in range(n):
    a = np.ones(n)
    multiple = -1
    for j in range(n):
        a[(i+j)%n] *= multiple
        multiple *= -1
    a[i] = 1
    ans.append(int(np.dot(x, a)))
last = ans.pop()
ans.insert(0, last)
print ' '.join(map(str, ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

from copy import copy


def min_max_try(n, dams):
    mt_min = [0] * n
    mt_max = copy(dams)

    for _ in range(1000):
        # max -> min
        update = False
        for i in range(n):
            tmp_min = dams[i] - mt_max[i]
            if tmp_min > mt_min[(i+1) % n]:
                mt_min[(i+1) % n] = tmp_min
                update = True
            tmp_min = dams[i] - mt_max[(i+1) % n]
            if tmp_min > mt_min[i]:
                mt_min[i] = tmp_min
                update = True
        if not update:
            return mt_min, mt_max

        # min -> max
        update = False
        for i in range(n):
            tmp_max = dams[i] - mt_min[i]
            if tmp_max < mt_max[(i+1) % n]:
                mt_max[(i+1) % n] = tmp_max
                update = True
            tmp_max = dams[i] - mt_min[(i+1) % n]
            if tmp_max < mt_max[i]:
                mt_max[i] = tmp_max
                update = True
        if not update:
            return mt_min, mt_max

    return mt_min, mt_max


def check_answer(pos, val, n, dams):
    mt = [val] * n
    for i in range(n-1):
        mt[(pos+i+1) % n] = dams[(pos+i) % n] - mt[(pos+i) % n]
    ok = mt[pos] + mt[(pos+n-1) % n] == dams[(pos+n-1) % n]
    return ok, mt


def solv(n, dams):
    # print(dams)
    mt_min, mt_max = min_max_try(n, dams)
    # print(mt_min, mt_max)

    for i in range(n):
        ok, mt = check_answer(i, mt_min[i], n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    idx = 0
    diff = mt_max[0] - mt_min[0]
    for i in range(1, n):
        if mt_max[i] - mt_min[i] < diff:
            diff = mt_max[i] - mt_min[i]
            idx = i

    for val in range(mt_min[idx], mt_max[idx]+1):
        ok, mt = check_answer(idx, val, n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    return 'Error'


if __name__ == '__main__':

    n = int(input())

    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

from copy import copy


def min_max_try(n, dams):
    mt_min = [0] * n
    mt_max = copy(dams)

    for _ in range(1000):
        # max -> min
        update = False
        for i in range(n):
            tmp_min = dams[i] - mt_max[i]
            if tmp_min > mt_min[(i+1) % n]:
                mt_min[(i+1) % n] = tmp_min
                update = True
            tmp_min = dams[i] - mt_max[(i+1) % n]
            if tmp_min > mt_min[i]:
                mt_min[i] = tmp_min
                update = True
        if not update:
            return mt_min, mt_max

        # min -> max
        update = False
        for i in range(n):
            tmp_max = dams[i] - mt_min[i]
            if tmp_max < mt_max[(i+1) % n]:
                mt_max[(i+1) % n] = tmp_max
                update = True
            tmp_max = dams[i] - mt_min[(i+1) % n]
            if tmp_max < mt_max[i]:
                mt_max[i] = tmp_max
                update = True
        if not update:
            return mt_min, mt_max

    return mt_min, mt_max


def check_answer(pos, val, n, dams):
    mt = [val] * n
    for i in range(n-1):
        mt[(pos+i+1) % n] = dams[(pos+i) % n] - mt[(pos+i) % n]
    ok = mt[pos] + mt[(pos+n-1) % n] == dams[(pos+n-1) % n]
    return ok, mt


def solv(n, dams):
    # print(dams)
    mt_min, mt_max = min_max_try(n, dams)
    # print(mt_min, mt_max)

    idx = 0
    diff = mt_max[0] - mt_min[0]
    for i in range(1, n):
        if mt_max[i] - mt_min[i] < diff:
            diff = mt_max[i] - mt_min[i]
            idx = i

    for val in range(mt_min[idx], mt_max[idx]+1):
        ok, mt = check_answer(idx, val, n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    return 'Error'


if __name__ == '__main__':

    n = int(input())

    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

from copy import copy


def min_max_try(n, dams):
    mt_min = [0] * n
    mt_max = copy(dams)

    while True:
        # max -> min
        update = False
        for i in range(n):
            tmp_min = dams[i] - mt_max[i]
            if tmp_min > mt_min[(i+1) % n]:
                mt_min[(i+1) % n] = tmp_min
                update = True
            tmp_min = dams[i] - mt_max[(i+1) % n]
            if tmp_min > mt_min[i]:
                mt_min[i] = tmp_min
                update = True
        if not update:
            return mt_min, mt_max

        # min -> max
        update = False
        for i in range(n):
            tmp_max = dams[i] - mt_min[i]
            if tmp_max < mt_max[(i+1) % n]:
                mt_max[(i+1) % n] = tmp_max
                update = True
            tmp_max = dams[i] - mt_min[(i+1) % n]
            if tmp_max < mt_max[i]:
                mt_max[i] = tmp_max
                update = True
        if not update:
            return mt_min, mt_max


def check_answer(pos, val, n, dams):
    mt = [val] * n
    for i in range(n-1):
        mt[(pos+i+1) % n] = dams[(pos+i) % n] - mt[(pos+i) % n]
    ok = mt[pos] + mt[(pos+n-1) % n] == dams[(pos+n-1) % n]
    return ok, mt


def solv(n, dams):
    # print(dams)
    mt_min, mt_max = min_max_try(n, dams)
    # print(mt_min, mt_max)

    idx = 0
    diff = mt_max[0] - mt_min[0]
    for i in range(1, n):
        if mt_max[i] - mt_min[i] < diff:
            diff = mt_max[i] - mt_min[i]
            idx = i

    for val in range(mt_min[idx], mt_max[idx]+1):
        ok, mt = check_answer(idx, val, n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    return 'Error'


if __name__ == '__main__':

    n = int(input())

    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = sum([dams[x]*(-1)**x for x in range(n)])
out = str(ans)

for i in range(1, n):
  ans = -1 * ans + 2 * dams[i - 1]
  out += " " + str(ans)
  
print(out)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

dams = list(map(int, input().split()))
dams = np.array(dams, dtype = np.int)

ans_list = []

kake = [1*(-1)**x for x in range(n)]
ans_list = [0 for x in range(n)]
kake_temp = kake
out = ""
for i in range(n):
  #print(kake_temp)
  ans = int(np.dot(dams, np.array(kake_temp)))
  out += str(ans) + " " 
  kake_temp = [kake_temp[-1]] + kake_temp[0 : n - 1]
  
print(out[:-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

dams = list(map(int, input().split()))
dams = np.array(dams, dtype = np.int)

ans_list = []

kake = [1*(-1)**x for x in range(n)]
ans_list = [0 for x in range(n)]
kake_temp = kake
for i in range(n):
  ans = 0
  #print(kake_temp)
  ans = int(np.dot(dams, np.array(kake_temp)))
  ans_list[i] = str(ans)
  
  kake_temp = [kake_temp[-1]] + kake_temp[0 : n - 1]
    
print(" ".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans_list = []

for i in range(n):
  ans = 0
  for j in range(i, i + n):
    ans += dams[j % n] * (-1)**(j - i)
  ans_list.append(str(ans))
    
print(" ".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A_vec = [int(_) for _ in input().split()]

matrix = [0] * N

for n in range(N - 1):
    matrix[n] = [0] * (n) + [0.5, 0.5] + [0] * (N - n - 2)
matrix[N - 1] = [0.5] + [0] * (N - 2) + [0.5]

X_vec = map(int, np.dot(np.linalg.inv(np.array(matrix)), A_vec))
print(' '.join(map(str, X_vec)))

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 % 2 == 0:
            x[i] += A[i-(j+1)]
        else:
            x[i] -= A[i-(j+1)]

for i in range(N):
    print(str(x[i]), end="")
    if i != N-1:
        print(" ", end="")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
x = list(map(int,input().split()))
A = np.array([[1 if j == i or j == i + 1 or j ==0 and i == N-1 else 0 for j in range(N)] for i in range(N)])
b = np.array(x)
b = 2 * b
x = np.linalg.solve(A, b)
x = x.astype('int64')
print(' '.join(map(str,x)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
B = np.array(list(map(int, input().split())))
A = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    A[i][i] = A[i][(i + 1) % N] = 1
A = np.array(A)
A_inv = np.linalg.inv(A)
x = np.dot(A_inv, B)
x = list(map(lambda a: str(int(a * 2)), x))
print(' '.join(x))

Submission status: Time Limit Exceeded

Solution code:
_,a=open(0);*a,=map(int,a.split());t=sum(a)-2*sum(a[1::2]);x=t,
for i in a:t=i*2-t;x+=t,
print(*x[:-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
rain_sum = sum(A) // 2
for i in range(N):
    rain_other = 0
    for j in range((N - 1) // 2):
        rain_other += A[(i + 1 + 2 * j) % N]
    print((rain_sum - rain_other) * 2, end = ' ')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
ans = [0] * N
for i in range(N):
    A_copy = A.copy()
    del A_copy[i]
    if i % 2 == 0:
        ans[i] = str(sum([A_copy[t] * (-1) ** ((t + 1) % 2) for t in range(N - 1)]) + A[i])
    else:
        ans[i] = str(sum([A_copy[t] * (-1) ** (t % 2) for t in range(N - 1)]) + A[i])
print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
list1=list(map(int,input().split()))
list2=[]
def calc(n):
    tempsum=0
    for j in range(1,n+1):
        tempsum+=((-1)**(n-j))*list1[j-1]
    return tempsum
list2.append(calc(N))
for i in range(1,N):
    list2.append(2*calc(i)+((-1)**i)*list2[0])
str1=""
for i in range(len(list2)):
    str1+=str(list2[i])
    if i==len(list2)-1:
        print(str1)
    else:
        str1+=" "

Submission status: Time Limit Exceeded

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

sum=0
for i in range(n):
    sum=sum+a[i]

for j in range(1,n,2):
    sum=sum-a[j]*2

ans=[sum]
ch=sum
for i in range(0,n-1):
    ch=a[i]*2-ch
    ans.append(ch)


aaa=str(ans[0])
for i in range(1,n):
    ccd=str(ans[i])
    aaa=aaa+' '+ccd
print(aaa)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=int(input())
ls=list(map(int,input().split()))
ms=[]

#最初の山の値を求める
for i in range(0,10**9,2):
    x=i
    for j in range(n):
        x=(ls[j]-x//2)*2
    if x==0:
        ms.append(i//2)
        break

for i in range(n-1):
    ms.append((ls[i]-ms[-1]//2)*2)
print(*ms)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
setA = set()
water = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams=cur
i = n-1
while(1):
    if i==0:
        if dams+cur== a[0]:
            break
        else:
            water[0]-=cur
            dams=water[0]//2
            cur = dams
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:

            water[0]-=cur
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:
            water[0]-=2
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
setA = set()
water = [0]*n
dams = [0]*n
cur = min(a[0],a[-1])
water[0]=2*min(a[0],a[-1])
dams[0]=cur
i = n-1
while(1):
    if i==0:
        if dams[0]+cur== a[0]:
            break
        else:
            water[0]-=2
            dams[0]=water[0]//2
            cur = dams[0]
            i=n-1
    else:
        need = a[i]-cur
        water[i]= need*2
        cur=need
        i-=1
print(*water)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dam = list(map(int,input().split()))
yama =[0]*n
sum_dam = sum(dam)
dam2 = dam[0]*2 +2
for yama[0] in range(0,dam2,2):
  for i in range(1,n):
    yama[i] = dam[i-1]*2 - yama[i-1] 
    if yama[i] < 0:
      break
  if (yama[n-1] + yama[0])//2 == dam[n-1]:
    joined = " ".join(map(str, yama))
    print(joined)
    break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dam = list(map(int,input().split()))
yama =[0]*n
sum_dam = sum(dam)
dam2 = dam[0]*2 +2
for yama[0] in range(0,dam2,2):
  for i in range(1,n):
    yama[i] = dam[i-1]*2 - yama[i-1] 
    if yama[i] < 0:
      break
  if sum(yama) == sum_dam:
    joined = " ".join(map(str, yama))
    print(joined)
    break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dam = list(map(int,input().split()))
yama =[0]*n
sum_dam = sum(dam)
dam2 = dam[0]*2 +2
for kari in range(0,dam2,2):
  yama[0] = kari
  for i in range(1,n):
    yama[i] = (dam[i-1] - (yama[i-1] // 2))*2
    if yama[i] < 0:
      break
  if sum(yama) == sum_dam:
    joined = " ".join(map(str, yama))
    print(joined)
    break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
total = sum(A)
X = np.zeros(N)
for i in range(total+1):
    X[0] = i
    for j in range(1,N):
        X[j] = 2*A[j-1] - X[j-1]
    if sum(X)==total:
        break

for i in range(N):
    print("{}".format(int(X[i])),end=" ")

Submission status: Time Limit Exceeded

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

n = int(input())
coef = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    if i == n-1:
        coef[i][0] = 1/2
        coef[i][-1] = 1/2
    else:
        coef[i][i] = 1/2
        coef[i][i+1] = 1/2
    
A = np.zeros((n, n))
for i in range(n):
    A[i] = coef[i]

b = np.array([int(x) for x in input().split()])

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

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

Submission status: Time Limit Exceeded

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

IS = lambda: int(input())
IA = lambda: [int(x) for x in input().split()]

N = IS()
A = IA()

h = N//2
ans = []
for i,_ in enumerate(range(N)):
    t = 0
    s = 1
    for j in range(h):
        t += s * (A[(i+j) % N] + A[i-1-j])
        s *= -1
    t += s * A[(i+h) % N]
    ans.append(t)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
coef = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    if i == n-1:
        coef[i][0] = 1/2
        coef[i][-1] = 1/2
    else:
        coef[i][i] = 1/2
        coef[i][i+1] = 1/2
    
A = np.zeros((n, n))
for i in range(n):
    A[i] = coef[i]

b = np.array([int(x) for x in input().split()])

ans = np.linalg.solve(A, b)

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
a1 = a // 2
b1=list(input().split( ))
b=list(map(int, b1))
d=[]
for j in range(a):
    e=b[:]
    for k in range(a1):
        c=(j+1+2*k)%a
        e[c]=e[c]*(-1)
    d.append(sum(e))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
posneg = -1
for i in range(1, N):
	B.append(B[i-1]+posneg*A[i])
	posneg *= -1
ansdiv2 = [B[-1]//2]
posneg = 1
for i in range(0, N-1):
	ansdiv2.append(posneg*(B[i]-ansdiv2[0]))
	posneg *= -1
ans = str(ansdiv2[0]*2)
for i in range(1, N):
	ans = ans + ' ' + str(ansdiv2[i]*2)
print(ans)