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 = [int(i) for i in input().split()]
for i in range(N):
    A[i] *= 2
import numpy as np
mat = [[0] * N for _ in range(N)]
for i in range(N):
    j = i + 1
    if j == N:
        j = 0
    mat[i][i] = 1
    mat[i][j] = 1
AB = np.array(mat)
inv_A = np.linalg.inv(AB)
ans = list(np.dot(inv_A,A))
for i in range(N):
    ans[i] = int(ans[i])
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from scipy.sparse.linalg import dsolve
from scipy import sparse
N=int(input())
a=list(map(int, input().split()))
for i in range(N):
  a[i]=a[i]*2
X=[[0 for j in range(N)] for i in range(N)]
for i in range(N-1):
    X[i][i]=1
    X[i][i+1]=1
X[N-1][0]=1
X[N-1][N-1]=1
a=sparse.csr_matrix(a)
X=sparse.csr_matrix(X)
b=dsolve.spsolve(X, a)
for i in range(N):
  print(int(b[i]), end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from scipy.sparse.linalg import dsolve
N=int(input())
a=list(map(int, input().split()))
for i in range(N):
  a[i]=a[i]*2
X=[[0 for j in range(N)] for i in range(N)]
for i in range(N-1):
    X[i][i]=1
    X[i][i+1]=1
X[N-1][0]=1
X[N-1][N-1]=1
a=np.array(a)
X=np.array(X)
b= dsolve.spsolve(X, a, use_umfpack=True)
for i in range(N):
  print(int(b[i]), end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numpy.linalg import solve
N=int(input())
a=list(map(int, input().split()))
for i in range(N):
  a[i]=a[i]*2
X=[[0 for j in range(N)] for i in range(N)]
for i in range(N-1):
    X[i][i]=1
    X[i][i+1]=1
X[N-1][0]=1
X[N-1][N-1]=1
a=np.array(a)
X=np.array(X)
b=solve(X,a)
for i in range(N):
  print(int(b[i]), end=" ")

Submission status: Time Limit Exceeded

Solution code:
def main():
  import numpy as np
  n=int(input())
  rain=[int(i)*2 for i in input().split()]
  
  matrix=[[0]*n for _ in range(n)]
  for i in range(n):
    if i!=n-1:
      matrix[i][i],matrix[i][i+1]=1,1
    else:
      matrix[i][i],matrix[i][0]=1,1
      
  matrix=np.array(matrix,dtype=np.int64)
  print(*list(map(int,np.linalg.solve(matrix,rain))))
 
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
k=N//2
D=list(map(int,input().split()))
DD=D[:]+D[:]
T=sum(D)
ret=[0]*N
for i in range(N):
  ret[i]=T-2*sum(DD[i+1:i+2*k:2])
print(*ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from numpy.linalg import solve

def main():
    N = int(input())
    A = list(map(int,input().split()))
    left = [[0]*(N-2) for _ in range(N)]

    for i in range(N-1):
        left[i][i:i]=[1,1]

    left[N-1].insert(0,1)
    left[N-1].insert(N-1,1)

    ans = list(map(int,2 * solve(left, A)))

    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

    total = sum(A)
    for i in range(N):
        num = i+1
        totali = 0
        for j in range((N-1)//2):
            if num >= N:
                num -= N
            totali += A[num]
            num += 2
        ans= total - 2*totali
        print(ans,end = " ")



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from numpy.linalg import solve

def main():
    N = int(input())
    A = list(map(int,input().split()))
    left = [[0]*(N-2) for _ in range(N)]

    for i in range(N-1):
        left[i].insert(i,1)
        left[i].insert(i,1)

    left[N-1].insert(0,1)
    left[N-1].insert(N-1,1)

    ans = list(map(int,2 * solve(left, A)))

    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x:x * 2, A))


left = [[0] * N for _ in range(N)]
for i in range(N-1):
    for j in range(i, i+2):
        left[i][j] = 1
left[N-1][0] = 1
left[N-1][N-1] = 1

right = A

ans_list = solve(left, right)
ans_list = list(map(lambda x : int(x), ans_list))
print(" ".join(map(str, ans_list)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
S = sum(A)
res = []
for i in range(N):
    a = S
    for j in range((N-1)//2):
        a -= A[((1+i)+2*j)%N]*2
    res.append(a)
print(*res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
T = [[0] * N for i in range(N)]

for i in range(N):
  T[i][(i+1)%N]= 1
arr = np.matrix(T)
E = np.identity(N, dtype=int)
S = E
for i in range(N-1):
  S = S * (arr * (-1)) + E

a = np.matrix(A).reshape(N, 1)
#print(S, a)
rain = (S * a)
print(*[int(i) for i in rain])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
T = [[0] * N for i in range(N)]

for i in range(N):
  T[i][(i+1)%N]= 0.5
  T[i][i] = 0.5
arr = np.matrix(T)
a = np.matrix(A).reshape(N, 1)
#print(arr, a)
rain = np.linalg.solve(arr, a)
print(*[int(i) for i in rain])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
T = [[0] * N for i in range(N)]

for i in range(N):
  T[i][(i+1)%N]= 0.5
  T[i][i] = 0.5
arr = np.matrix(T)
a = np.matrix(A).reshape(N, 1)
#print(arr, a)
rain = (arr**(-1) * a)
print(*[int(i) for i in rain])

Submission status: Time Limit Exceeded

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

B = [0] * n
for i in range(n):
  for j in range(n):
    num = (i + j) % n
    if j % 2 == 0:
      B[i] += A[num]
    else:
      B[i] += -A[num]
print(*B, sep=" ")

Submission status: Time Limit Exceeded

Solution code:
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

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

mat = lil_matrix((N, N))
for i in range(N):
    j = (i + 1) % N
    mat[i, i] = 1
    mat[i, j] = 1
mat = csr_matrix(mat)

ans = (spsolve(mat, A) * 2).astype(int)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

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

mat = lil_matrix((N, N))
for i in range(N):
    j = (i + 1) % N
    mat[i, i] = 1
    mat[i, j] = 1
mat = csr_matrix(mat)

ans = spsolve(mat, A) * 2
ans = list(map(int, ans))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
keisuu = [[0]*n for _ in range(n)]
for i in range(n):
    a[i]*=2
    
    if i+1 <=n-1:
        keisuu[i][i+1] = 1
        keisuu[i][i] = 1
    else:
        keisuu[i][i] = 1
        keisuu[i][0] = 1
keisuu = np.array(keisuu)
avec = np.array(a)
inv_keisuu = np.linalg.inv(keisuu)
x = np.dot(inv_keisuu,avec)
for i in range(n):
    print(int(x[i]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = []
plus = sum(l)
for i in range(n):
    
    minus = 0
    
    for j in range(1,n,2):  
        
        minus += l[(i+j)%n]
    ans.append(plus-2*minus)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = []
for i in range(n):
    plus = 0
    minus = 0
    mod = i%2
    for j in range(n):
        if (i+j) % 2 == mod:
            plus += l[(i+j)%n]
        else:
            minus += l[(i+j)%n]
    ans.append(plus-minus)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = [0 for i in range(N)]
SUM = []
for i in range(N):
    tmp = 0
    for j in range(i+1,i+N-1,2):
        tmp+=2*A[j%N]
    SUM.append(tmp)
for i in range(N):
    ans[i] = sum(A)-SUM[i]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve
import numpy

n = int(input())
dam = list(map(int,input().split()))
rain = [[0 for x in range(n)] for y in range(n)]

for i in range(n):
  rain[i][i] = 1/2
  try:
    rain[i][i+1] = 1/2
  except:
    rain[i][0] = 1/2

temp_ans = solve(rain,dam).tolist()
temp2_ans = list(map(int,temp_ans))
temp3_ans = list(map(str,temp2_ans))
ans = " ".join(temp3_ans)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(0, max(a[0], a[-1])+1, 2):
    m[0] = i
    for j in range(n-1):
        m[j+1] = 2*a[j]-m[j]
    if m[n-1]+m[0] == 2*a[n-1]:
        break
        
print(*m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

matrix = [[0 for i in range(N)] for j in range(N)]

for i in range(N - 1):
    matrix[i][i] = 1
    matrix[i][i+1] = 1

matrix[N-1][N-1] = 1
matrix[N-1][0] = 1

matrix = np.array(matrix)
A = np.array(A)
A = A.T

inv_mat = np.linalg.inv(matrix)

ans = np.dot(inv_mat, A)
ans = np.dot(2, ans)

ans = list(map(int, ans))

print(*ans)

Submission status: Time Limit Exceeded

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

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 sys
sys.setrecursionlimit(10**6)
if sys.platform in ['ios', 'win32', 'darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(x) for x in input().split()]

N = INT()
A = MAP()

R = sum(A)
# print(R)

M = [-1] * N

def solve(i):
	if i<N-1:
		if M[i] != -1:
			mi = M[i]
		else:
			mi = 2*A[i]-solve(i+1)
	else:
		mi = 2*A[i]-solve(0)
	return mi

# print(M)
M[0] = 0
s = 0
for i in range(N):
	s += solve(i)
# print(s)
M[0] += (R-s)

ans = [solve(i) for i in range(N)]
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = list(accumulate([0] + A[1::2] + A[::2] + A[1::2] + A[::2]))
C = [S - 2 * (B[i+N//2] - B[i]) for i in range(N)]
print(*sum(list(map(list, zip(C[:N//2+1], C[N//2+1:]+[0]))), [])[:-1])

Submission status: Time Limit Exceeded

Solution code:
def calculate(arr,S):

    result = []
    even = 0
    for i in range(len(arr)):

        if i % 2 == 0:
            even = S-calculate2(i+1,arr[i+1:])
            result.append(even)
        else:
            odd = arr[i-1]*2-even
            result.append(odd)
            S = S - even - odd

    return result

def calculate2(i,arr):
    # 取偶数项
    return sum(arr[::2])*2

def calculateTotaAmount(arr):
    return sum(arr)

def printArr(arr):
    result = ""
    for i in range(len(arr)):
        result += str(arr[i]) + " "

    return result



N = int(input())

S = input().split(" ")
aArr = [int(s) for s in S]


result = calculate(aArr,calculateTotaAmount(aArr))

print(" ".join([str(s) for s in result]))

Submission status: Time Limit Exceeded

Solution code:
def calculate(arr,S):

    result = []
    even = 0
    for i in range(len(arr)):

        if i % 2 == 0:
            even = S-calculate2(i+1,arr[i+1:])
            result.append(even)
        else:
            odd = arr[i-1]*2-even
            result.append(odd)
            S = S - even - odd

    return result

def calculate2(i,arr):
    # 取偶数项
    result = 0
    for i in range(len(arr)):
        if i % 2 == 0:
            result += arr[i]
    return result * 2

def calculateTotaAmount(arr):
    return sum(arr)

def printArr(arr):
    result = ""
    for i in range(len(arr)):
        result += str(arr[i]) + " "

    return result



N = int(input())

S = input().split(" ")
aArr = [int(s) for s in S]


result = calculate(aArr,calculateTotaAmount(aArr))

print(" ".join([str(s) for s in result]))

Submission status: Time Limit Exceeded

Solution code:
import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    # right = 10**9
    right = max(dams) * 2
    while True:
        center = (left + right) // 2
        if center % 2 == 1:
            center -= 1
        mountains[0] = center
        for i in range(1, n):
            mountains[i] = 2 * dams[i-1] - mountains[i-1]
        temp_dam = (mountains[0] + mountains[-1]) / 2
        if dams[-1] == temp_dam:
            break
        elif dams[-1] < temp_dam:
            right = center
        else:
            left = center
    ans = ' '.join(map(str, mountains))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
P = []
for i in range(N):
    if i == N - 1:
        P.append([0.5] + [0] * (N - 2) + [0.5])
    else:
        P.append([0] * i + [0.5, 0.5] + [0] * (N - 2 - i))
P = np.array(P)
for i in np.dot(np.linalg.inv(P), A):
    print(int(i)," ", end="")

Submission status: Time Limit Exceeded

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

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = [[0 for _ in range(n)]for _ in range(n)]
point = 0
for i in range(n-1):
    lin[i][i] = 0.5
    lin[i][i+1] = 0.5
lin[-1][0] = 0.5
lin[-1][-1] = 0.5
lis = solve(lin,li)
liv = []
for i in lis:
    liv.append(int(i))
print(*liv)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
A = list(map(int,input().split()))
S = sum(A)
ans = []
for i in range(1,n+1):
    aaa = A[i:]+A[:i]
    # print(aaa[:-1:2])
    x = S-(sum(aaa[:-1:2]))*2
    ans.append(x)

[print(a) for a in ans]

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().rstrip().split()])
A_sum = A.sum()
A_sum //= 2
ans = []
for i in range(N):
    temp = A_sum
    flag = 1
    for _ in range((N - 1) // 2):
        if flag:
            i += 1
            flag = 0
        else:
            i += 2
        if i >= N:
            i -= N
        temp -= A[i]
    ans.append(2 * temp)
print(* ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
asum=sum(a)
y=[0]*(n+1)
for i in range(asum+1):
    y[0]=i
    flag=True
    for j in range(1,n+1):
        y[j]=(a[j-1]-y[j-1]//2)*2
        if y[j]<0:
            flag=False
            break
    if flag:
        if y[0]==y[n]:
            y.pop(n)
            print(*y)
            exit()

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

n = ii()
a = li()

total = sum(a)
ans = [0]*n

for i in range(n):
    s = 0
    for j in range(0, n-1, 2):
        s+=a[(j+i+1)%n]*2
    ans[i] += (total - s)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n = int(input())
a = [2*int(_) for _ in input().split()]
s = []
for i in range(n):
    l = [0 for _ in range(n)]
    l[i] = 1
    if i+1 != n:
        l[i+1] = 1
    else:
        l[0] = 1
    s.append(l)
A = np.array(s)
b = np.array(a)
Ainv = np.linalg.inv(A)
x = np.dot(Ainv, b)
for i in range(len(x)):
    print(int(x[i]))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())#奇数
A=[int(x) for x in input().split()]
B=[0]*N
#B[0]はA[0]-A[1]+A[2]-  -A[N-1]+A[N]
A=A*2
for i in range(N):
  for j in range(i,i+N):
    B[i] +=A[j]*((-1)**(j-i))
print(*B)

Submission status: Time Limit Exceeded

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

x = []
for i in range(n):
    sum = 0
    for j in range(i,n+i):
        if (j-i)%2 == 0:
            if 0<=j<n:
                sum += a[j]
            else:
                sum += a[j-n]
        else:
            if 0<=j<n:
                sum -= a[j]
            else:
                sum -= a[j-n]
    x.append(int(sum))
print(' '.join(map(str,x)))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
total = sum(A)
ans = []

from functools import lru_cache
@lru_cache(maxsize=None)
def rec(ind):
    if ind >= N:
        ind -= N
    return A[ind]*2

for i in range(N):
    t = 0
    for j in range(N//2):
        ind = i+1+j*2
        t += rec(ind)
    ans.append(total-t)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
total = sum(A)
ans = []
for i in range(N):
    t = 0
    for j in range(N//2):
        ind = i+1+j*2
        if ind >= N:
            ind -= N
        t += A[ind]*2
    ans.append(total-t)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
ans = []
for i in range(N):
    t = 0
    for j in range(N//2):
        ind = i+1+j*2
        if ind >= N:
            ind -= N
        t += A[ind]*2
    ans.append(total-t)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy as np
left = []
a = []
for i in range(N):
  if (i == 0 or i == 1):
      a.append(0.5)
  else:
    a.append(0)
a = np.array(a)
for i in range(N):
  left.append(np.roll(a, i))
left = np.array(left)
from numpy.linalg import solve
answer = solve(left, A)
answer = list(map(int, answer))
print(*answer)

Submission status: Time Limit Exceeded

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

left = [[] for _ in range(N)]
for i in range(N):
  for j in range(N):
    if (j-i == 0 or j-i == 1) and not i == N-1:
      left[i].append(0.5)
    else:
      left[i].append(0)
left[N-1][0] = 0.5
left[N-1][N-1] = 0.5
from numpy.linalg import solve
answer = solve(left, A)
answer = list(map(int, answer))
print(*answer)

Submission status: Time Limit Exceeded

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))
start_w = a_list[0] * 2

# 一番小さいものから決めていく？
for sw in range(start_w + 1):
    w_list = []
    if a_list[0] < sw // 2:
        continue
    w_list.append(sw)
    for i in range(1, N):
        w_list.append((a_list[i - 1] - w_list[i - 1] // 2) * 2)

    if a_list[-1] == (w_list[0] + w_list[-1]) // 2:
        break

ans = " ".join([str(w) for w in w_list])
print(ans)

Submission status: Time Limit Exceeded

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

answer_list = []

for i in range(N):
    answer = 0
    for j in range(N):
        # print(i, j, i-1-j, A[i-1-j])
        if j % 2 == 0:
            answer += A[i-1-j]
        else:
            answer -= A[i-1-j]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))

Submission status: Time Limit Exceeded

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

minv = 0
maxv = 1000000000

nxt = [0] * (n + 1)
while minv != maxv:
  nxt[0] = (minv + maxv) // 2
  for i in range(n):
    nxt[i+1] = a[i] * 2 - nxt[i]
#  print(nxt)
  if nxt[0] == nxt[n]:
    break
  elif nxt[0] > nxt[n]:
    maxv = nxt[0]
  else:
    minv = nxt[0]
    
for i in range(n):
  print(nxt[i], end=' ')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dam = list(map(int, input().split()))
mt = [0]*n
# a[i]]は山iと山i+1に降った平均
total = sum(dam)
for i in range(n):
    if i-2 < 0:
        mt[i] = total - 2*sum(dam[i+1::2])
    else:
        mt[i] = total - 2*(sum(dam[i-2::-2])+sum(dam[i+1::2]))

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

Submission status: Time Limit Exceeded

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

D=np.array([[0]*N for i in range(N)])
for i in range(N):
  for j in range(N):
    if j==i or j==(i+1)%N:
      D[i][j]=1

X=2*np.dot(np.linalg.inv(D),A)
print(" ".join(map(lambda x:str(int(x)),X)))

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve
n = int(input())
a = list(map(int, input().split()))
ori = [0.5, 0.5] + [0] * (n-2) + [0.5, 0.5] + [0] * (n-2)
cul = []

for i in range(n):
    cul.append(ori[n-i:2*n-i])

x = solve(cul, a)
for i in range(n):
    print(int(x[i]), end=' ')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
for i in range(min(a[0],a[1])):
    b[0]=a[0]-i
    b[1]=i
    for j in range(2,n):
        b[j]=a[j-1]-b[j-1]
        if b[j]<0:
            break
    else:
        if b[n-1]+b[0]==a[n-1]:
            break
def bai(x):
    return 2*x
print(" ".join(list(map(str,(list(map(bai,b)))))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = []
rain = sum(a for a in A)
for i in range(n):
  cost = 0
  if i%2 == 0:
    C = A[:i]
    cost += sum(C[2*k] for k in range(i//2))
    D = A[i:]
    cost += sum(D[2*k+1] for k in range((n-i-1)//2))
    B.append(rain - 2*cost)
  else:
    C = A[:i]
    cost += sum(C[2*k+1] for k in range((i-1)//2))
    D = A[i+1:]
    cost += sum(D[2*k] for k in range((n-i)//2))
    B.append(rain - 2*cost)
L=[str(a) for a in B]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

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

for i in range(A[0]+1):
    ans = []
    x1 = i*2
    ans.append(x1)
    for j in range(len(A)-1):
        x2 = 2*A[j] - x1
        ans.append(x2)
        x1  = x2
    
    ans1 = np.array(ans)
    ans2 = np.array(ans[1:] + [ans[0]])
    ans3 = (ans1 + ans2) / 2
    if sum(A==ans3)==n:
        print(*ans1)

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    m = min(A)
    xi = A.index(m)
    for a in range(0, m*2+1, 2):
        B = A.copy()
        ans = [0]*N
        B[(xi-1)%N] -= a//2
        B[xi] -= a//2
        ans[xi] = a
        for i in range(xi+1, xi+N):
            x = B[(i-1)%N]*2
            if B[i%N]-x//2 < 0:
                break
            B[(i-1)%N] -= x//2
            B[i%N] -= x//2
            ans[i%N] += x
            if sum(B) == 0:
                print(*ans)
                return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split())) * 2
B = [0] * N
for i in range(N):
    B[i] = sum(A[i:i+N:2]) - sum(A[i+1:i+N:2])
print(*B)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=[0]*N
for i in range(N):
  flg=True
  for j in range(i, i+N):
    B[i]+=A[j%N] if flg else (-1)*A[j%N]
    flg=not flg
print(" ".join(str(b) for b in B))

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dams = list(map(int, input().split()))
    smallest_idx = 0
    for i in range(1,N):
        if dams[i] < dams[smallest_idx]:
            smallest_idx = i
    dams = dams[smallest_idx:] + dams[:smallest_idx]

    for i in range(0, dams[0]*2+1, 2):
        mts = [0]*N
        mts[0] = i
        for j in range(1,N):
            mts[j] = (dams[j-1]-mts[j-1]//2)*2
            if mts[j] < 0:
                break
        else:
            if mts[0]//2 + mts[N-1]//2 == dams[N-1]:
                mts = mts[N-smallest_idx:] + mts[:N-smallest_idx]
                print(*mts)
                return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
T = sum(A)
print(T-2*sum(A[1::2]),end=" ")
for i in range(1,N):
    print(T-2*(sum(A[i+1::2])+sum(A[i%2:i-1:2])),end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b_list = list(map(int,input().split()))
b_list+=b_list
c_list = []
for i in range(n):
    sum_num = 0
    for j in range(i,i+n):
        sum_num += b_list[j]*((-1)**(j-i))
    c_list.append(sum_num)
print(" ".join(map(str,c_list)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans =[]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
for i in range(n):
  minus = sum(a_double[i+1:i+n-1:2])
  ans.append(sum_rain-minus)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans =[]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
for i in range(n):
  minus = sum(a_double[i+1:i+n-1:2])
  ans.append(sum_rain-minus)
  
ans_str = [str(i) for i in ans]
print(' '.join(ans_str))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    a=tuple(int(i) for i in input().split())
    chk=a.index(min(a))
    #for i in range(min(a[0],a[-1])*2,-1,-2):
    for i in range(a[chk]*2,-1,-2):
        ans=[0]*n
        ans[chk]=i
        f=1
        for k in range(1,n):
            j=(chk+k)%n
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        #if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
        if f and ans[chk-1]//2+ans[chk-2]//2==a[chk-2] and ans[chk-1]//2+ans[chk]//2==a[chk-1]:
            print(*ans)
            exit()

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    a=tuple(int(i) for i in input().split())
    ans=chk=0
    for i in range(min(a[0],a[-1])*2,-1,-2):
        ans=[0]*n
        ans[0]=i
        f=1
        for j in range(1,n):
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
            print(*ans)
            exit()

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    a=tuple(int(i) for i in input().split())
    ans=chk=0
    for i in range(min(a[0],a[-1])*2,-1,-2):
        ans=[0]*n
        ans[0]=i
        f=1
        for j in range(1,n):
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
            print(*ans)

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
def sol():
    n=int(input())
    a=[int(i) for i in input().split()]
    ans=chk=0
    for i in range(min(a[0],a[-1])*2,-1,-2):
        ans=[0]*n
        ans[0]=i
        f=1
        for j in range(1,n):
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
            print(*ans)

if __name__=="__main__":
    sol()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=chk=0
for i in range(a[-1]*2,-1,-2):
    ans=[0]*n
    ans[0]=i
    f=1
    for j in range(1,n):
        t=(a[j-1]-ans[j-1]//2)*2
        if t>=0 and (t+ans[j-1])//2==a[j-1]:
            ans[j]=t
        else:
            f=0
            break
    if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
        print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
	cnt = 0
	cnt = sum([a[h] if h%2==0 else -a[h] for h in range(n)])
	print(cnt,end=' ')
	a.append(a.pop(0))

Submission status: Time Limit Exceeded

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

for i in range(n):
	cnt = 0
	for h in range(n):
		if h % 2 == 0:
			cnt += a[h]
		else:
			cnt -= a[h]
	print(cnt,end=' ')
	a.append(a.pop(0))

Submission status: Time Limit Exceeded

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

x=[int(sum([A[i]*pow(-1, i) for i in range(N)])/2)]
for i in range(1, N):
  x.append(int(sum([A[j]*pow(-1, j-i) for j in range(i, N)])-x[0]*pow(-1, i)))
  
ans=[int(x[i]*2) for i in range(N)]
print(' '.join(map(str, ans)))