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()))
b, c, d = 0, 0, 0
e = []
while(True):
    c = d
    for i in range(n):
        b = 2 * a[i] - c
        e.append(c)
        c = b
    if d == b:
        break
    d += 1
    e.clear()
for i in e:
    print(i, end = " ")

Submission status: Time Limit Exceeded

Solution code:


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


memo = 0 # M_n = M_0
for i in range(n):
    memo += Dn[i]*(-1 if i%2==0 else 1)

memo *= -1

#print(memo)



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

for i in range(0, M0_max+1, 2):
    
    valid = i == memo 
    
#    print(i, memo, valid)
#    print(Dn)
#    print()

    if valid:
        Mn0 = i
        break

Mn = [0]*n
Mn[0] = Mn0
for i in range(1,n):
    Mn[i] = 2*Dn[i-1]-Mn[i-1]

print(*Mn)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ax=max(a)
dx=a.index(ax)

for i in range(ax*2,-1,-2):
    ans=[0]*n
    ans[dx]=i
    t=[x for x in a]
    for j in range(n):
        p=(dx+j)%n
        o=ans[p]//2
        t[p]-=o
        if j!=n-1:
            ans[(p+1)%n]=t[p]*2
        t[p-1]-=o
        if t[p]<0 or t[p-1]<0: break
    t=set(t)
    if len(t)==1 and 0==t.pop():
        print(*ans)
        exit()

Submission status: Time Limit Exceeded

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

for i in range(A[0]+1):
  answer_list = []
  answer_list.append(i)
  answer = i
  for j in A:
    if (j - answer) < 0:
      break
    answer = j - answer
    answer_list.append(answer)
  if answer_list[0] == answer_list[-1] and len(answer_list) == N+1:
    print(' '.join([str(i*2) for i in answer_list[:N]]))
    exit()

Submission status: Time Limit Exceeded

Solution code:
### ABC133-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
l=0
r=A[-1]
m=(l+r)//2
sA=sum(A)
x0=0
while l<r:
    x0=m
    xm=m
    sx=2*xm
    for i in range(n-1):
        xm=A[i]-xm
        sx+=2*xm
    if sA==sx:
        break
    elif sx<sA:
        l=m
        m=(l+r)//2
    else:
        r=m
        m=(l+r)//2
print(2*x0,end=" ")
xm=x0
for i in range(n-1):
    xm=A[i]-xm
    print(2*xm,end=" ")
print()

Submission status: Time Limit Exceeded

Solution code:
# ABC133-D

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy,numpy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  left=[]
  a=[0]*n
  for i in range(n):
    b=copy.deepcopy(a)
    b[i]=1
    b[(i+1)%n]=1
    left.append(b)

  right=[]
  for x in l:
    right.append(x*2)

  return ' '.join(str(int(x)) for x in list(numpy.linalg.solve(left,right)))

print(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
inverse_matrix = np.array([[(-1)**((i-j)%N) for i in range(N)] for j in range(N)])
solution_list = inverse_matrix.dot(numbers)
solution_string = str(solution_list[0])
for i in range(1,N):
    solution_string += " " + str(solution_list[i])
print(solution_string)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
A.extend(A)
B = []
for i in range(N):
	x = 0
	for j in range((N - 1) // 2):
		x += A[i + 2 * j + 1]
	B.append(S - 2 * x)
C = [str(a) for a in B]
print(' '.join(C))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
solution_list = [sum([numbers[(i+j)%N]*(-1)**i for i in range(N)]) for j in range(N)]
solution_string = str(solution_list[0])
for i in range(1,N):
    solution_string += " " + str(solution_list[i])
print(solution_string)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
s = sum(d)
for i in range(n):
    ans = int(s)
    for j in range(0,n-2,2):
        j = (i+j+1)%n
        ans -= d[j] * 2
        
    print(ans,end=" ")

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math

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

res = [0 for i in range(N)]

for i in range(N):
    res[i] = A_sum - 2 * sum([A[(i+(2*j+1)) % N] for j in range(int((N-1)/2))])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
X=list(map(int, input().split()))
Xo=np.array(X)
Yo=np.array([])
Yama=[]
for x in range(0,N):
    if x%2==0:
        Yo=np.append(Yo,1)
    if x%2==1:
        Yo=np.append(Yo,-1)
for x in range(0,N):
    NNN=int(np.dot(Xo,Yo))
    Yama.append(NNN)
    Yo=np.insert(Yo,0,Yo[N-1])
    Yo=np.delete(Yo,N)

Yama = map(str, Yama)
print(" ".join(Yama))

Submission status: Time Limit Exceeded

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

    I = a.index(min(a))
    for i in range(a[I]*2+1):
        ans = a.copy()
        tmp = (ans[I]*2 - i)/2
        ans[I] = ans[I]*2 - i
        for j in range(1, n):
            ans[I-j] -= tmp
            tmp = ans[I-j]
            ans[I-j] = int(ans[I-j]*2)
        if tmp*2==i: break
    print(" ".join(list(map(str, ans))))

if __name__=="__main__": main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
X=list(map(int, input().split()))
Xo=np.array(X)
Y=[]
Yama=[]
for x in range(0,N):
    if x%2==0:
        Y.append(1)
    if x%2==1:
        Y.append(-1)
Yo=np.array(Y)
for x in range(0,N):
    Yama.append(np.dot(Xo,Yo))
    Yo=np.insert(Yo,0,Yo[N-1])
    Yo=np.delete(Yo,N)

for s in Yama:
  print(s, end =" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b = list(map(int, input().strip().split()))
s = sum(b)
x = []
for i in range(n):
    y = s
    k = i + 1
    for j in range(int((n-1)/2)):
        y -= 2*b[k%n]
        k += 2
    x.append(y)
s = str(x)
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
mat = np.array([])

for i in range(n):
    zeros = np.zeros(n)
    zeros[i] = 1
    if i + 1 > n - 1:
        zeros[0] = 1
    else:
        zeros[i + 1] = 1

    mat = np.hstack((mat, zeros))
b = a * 2
mat = np.reshape(mat, (n, n))

for i in range(len(mat) - 1):
    for j in range(i + 1, len(mat)):
        coef = mat[j][i] / mat[i][i]
        mat[j] -= mat[i] * coef
        b[j] -= b[i] * coef

for i in range(len(mat) - 1, 0, -1):
    b[i] /= mat[i][i]
    mat[i] /= mat[i][i]
    for j in range(i):
        b[j] -= b[i] * mat[j][i]
        mat[j][i] = 0

print(*(b.tolist()))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mountain = [0 for _ in range(len(a))]

while sum(a) != 0:
    i_max = max(range(len(a)), key=lambda x:a[x])
    if i_max == 0:
        i_second = max(-1, i_max+1, key=lambda x:a[x])
    elif i_max == len(a)-1:
        i_second = max(i_max-1, 0, key=lambda x:a[x])
    else:
        i_second = max(i_max-1, i_max+1, key=lambda x:a[x])
    res = max((a[i_second]//2)*4,2)
    mountain[(i_max+i_second)//2] = res
    a[i_max] -= res//2
    a[i_second] -= res//2

[print(i, end=' ') for i in list([mountain[-1]]) + mountain[:-1]]
print()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
solution_list = [[numbers[(i+j)%N]*(-1)**i for i in range(N)]for j in range(N)]
solution_string = str(sum(solution_list[0]))
for i in range(1,N):
    solution_string += " " + str(sum(solution_list[i]))
print(solution_string)

Submission status: Time Limit Exceeded

Solution code:
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, n):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = str(int(res[x] / 2))
    print(' '.join(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mina = min(a)
minaindex = a.index(min(a))
if minaindex + 2 <= n:
    ansstartmax = a[minaindex] + a[minaindex+1]
    start = minaindex+1
else:
    ansstartmax = a[minaindex] + a[minaindex-1]
    start = minaindex-1

ans = [0]* (n+1)

for i in range(ansstartmax//2+1):
    ans[start] = i*2
    for j in range(start+1, n+1):
        ans[j] = (a[j-1] - ans[j-1]//2)*2
    
    for j in reversed(range(start)):
        ans[j] = (a[j] - ans[j+1]//2)*2

    
    if ans[0] == ans[-1]:
        print(*ans[:-1])
        break

Submission status: Time Limit Exceeded

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

T = ( sum(map(lambda t: (-1)**(t[0]%2+1) * t[1], enumerate(As[:-1])) ) + As[-1] ) / 2

for i in range(N-1):
    U = sum(map(lambda t: (-1)**(t[0]%2) * t[1], enumerate(As[i:-1])) )
    U += (-1)**(i%2) * T
    print(int(U)*2, end=" ")

print(int(T)*2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

V = [0 for i in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            V[j] += A[i]
        elif i > j and (i + j) % 2 == 0:
            V[j] += A[i]
        elif i < j and (i + j) % 2 == 1:
            V[j] += A[i]
        else:
            V[j] -= A[i]

for volume in V:
    print(volume, end=' ')
print()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

S = sum(A)
ans = []
s = 0
for k in range(int((N - 1) / 2)):
    s += A[2 * k + 1] * 2
ans.append(S - s)
for k in range(N - 1):
    ans.insert(0, A[k] * 2 - ans[0])
ans.reverse()
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, n):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x):
            mod_i = i % n
            count += 1
            if count % 2 == 0:
                res[x] = res[x] - a[mod_i]
            else:
                res[x] = res[x] + a[mod_i]
        res[x] = str(int(res[x] / 2))
    print(' '.join(res))

Submission status: Time Limit Exceeded

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

x_list = [0]*N
# print(A_list)
# print(x_list)

A = sum(A_list)
for j in range(A):
    x_list[0] = j
    X = x_list[0]
    for i in range(N-1):
        x_list[i+1] = 2*A_list[i] - x_list[i]
        X += x_list[i+1]
        if(X > A):
            break
    if(A == sum(x_list)):
        break

# print(','.join(x_list))
for _ in range(N):
    sys.stdout.write(str(x_list[_]) + ' ')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
X=list(map(int, input().split()))
Y=[]
Yama=[]
for x in range(0,N):
    if x%2==0:
        Y.append(1)
    if x%2==1:
        Y.append(-1)

for x in range(0,N):
    Yama.append(0)
    for y in range(0,N):
        Yama[x]=X[y]*Y[y]+Yama[x]
    Y.insert(0,Y[N-1])

for s in Yama:
  print(s, end =" ")

Submission status: Time Limit Exceeded

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

x_list = [0]*N
# print(A_list)
# print(x_list)

A = sum(A_list)

for j in range(A):
    x_list[0] = j
    for i in range(N-1):
        x_list[i+1] = 2*A_list[i] - x_list[i]
    if(A == sum(x_list)):
        break

# print(','.join(x_list))
for _ in range(N):
    sys.stdout.write(str(x_list[_]) + ' ')

Submission status: Time Limit Exceeded

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


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    A = read_h()

    import numpy as np

    a = np.asarray([[1 if i == j or i - 1 == j or i + N - 1 == j else 0
                     for j in range(N)]
                    for i in range(N)])
    b = np.asarray(A) * 2
    inv_a = np.linalg.pinv(a)
    x = list(map(int, map(np.round, np.dot(inv_a, b))))

    print(x[-1], *x[:-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

x_list = [0]*N
# print(A_list)
# print(x_list)

for j in range(sum(A_list)):
    x_list[0] = j
    for i in range(N-1):
        x_list[i+1] = 2*A_list[i] - x_list[i]
    if(sum(A_list) == sum(x_list)):
        break

# print(','.join(x_list))
for _ in range(N):
    sys.stdout.write(str(x_list[_]) + ' ')

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
N = int(input())
A = [int(i) for i in input().split()]
B = deepcopy(A)
num = sum(A)
for i in B:
    A.append(i)
ans = []
if N%4 == 1:
    for i in range(N):
        a = 0
        for j in range(int(N/2)):
            a += 2*A[2+2*j+i]
        ans.append(num-a)
    b = [ans[-1]] + ans[:-1]
else:
    for i in range(N):
        a = 0
        for j in range(int(N/2)):
            a += 2*A[1+2*j+i]
        ans.append(num-a)
    b = ans
print(*b)

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(1,n):
        if i+j<n:
            l[i]+=((-1)**j)*line[i+j]
            # print('i:' + str(i))
            # print(line[i+j])
            # print(l[i])
        else:
            l[i]+=((-1)**j)*line[i+j-n]
            # print('i:' + str(i))
            # print(line[i+j-n])
            # print(l[i])


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

V = []
for i in range(N):
    volume = 0
    for j in range(N):
        k = i + j
        if k >= N:
            k -= N
        if j % 2 == 0:
            volume += A[k]
        else:
            volume -= A[k]
    print(volume ,end=' ')

print()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = [0 for i in range(N)]
for i in range(min(A[N-1],A[0])+1):
    ans[0] = i*2
    j = 1
    while j <= N-1:
        ans[j] = A[j-1]*2-ans[j-1]
        j += 1
    if ans[0]//2 == A[N-1]-ans[N-1]//2:
        a = str(ans[0])
        for i in range(1,N):
            a += " " + str(ans[i])
        print(a)
        break
    else:
        ans = [0 for i in range(N)]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
first_water = [i for i in range(A[0]+1)]
a = []
for w in first_water:
    ans = []
    ans.append(2*w)
    for i in range(N-1):
        w = A[i]-w
        if w<0:
            continue
        else:
            ans.append(2*w)
    if (ans[-1]+ans[0])/2 == A[-1]:
        a.append(ans)
print(*a[0])

Submission status: Time Limit Exceeded

Solution code:

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

maxx = [min(A[i],A[i-1]) for i in range(N)]
w = [0 for i in range(N) ]

for init  in range(0,maxx[0]*2+1,2):
    w[0] = init
    for i in range(1,N):
        w[i] = 2*(A[i-1]-w[i-1]//2)

    if A[-1] == w[0]//2 + w[-1]//2:
        break
    else:
        w = [0 for i in range(N) ]

res=" ".join(map(str,w))
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

V = []
for i in range(N):
    volume = 0
    for j in range(N):
        if j % 2 == 0:
            volume += A[(i + j) % N]
        else:
            volume -= A[(i + j) % N]
    print(volume ,end=' ')

print()

Submission status: Time Limit Exceeded

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

for i in range(N):
  ans = 0
  for j in range(i, N + i):
    if (j - i) % 2 == 0:
      ans += A[j % N]
    else:
      ans -= A[j % N]
  print(ans ,end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  ans = 0
  for j in range(i, N + i):
    if (j - i) % 2 == 0:
      ans += A[j % N]
    else:
      ans -= A[j % N]
  print(ans ,end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    a = list()
    for i in range(N):
        tmp = [0] * N
        if i == N - 1:
            tmp[0] = 0.5
            tmp[i] = 0.5
        else:
            tmp[i] = 0.5
            tmp[i+1] = 0.5

        a.append(tmp)

    A = np.array(a)
    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

    int_ans = [str(int(x)) for x in ans]
    print(' '.join(int_ans))

Submission status: Time Limit Exceeded

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

result = []

length = len(As)
for i in range(length):
	res = 0
	for j in range(length):
		if (i+j)%2 == 0:
			res += As[(i+j)%length]
		else:
			res -= As[(i+j)%length]
	result.append(str(abs(res)))

print(" ".join(result))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A = list(map(int,input().split()))
A = A+A
E = [1]*n
A = np.array(A)
E = np.array(E)
for i in range(n):
  if i%2==1:
    E[i] = -1
out = []
for i in range(n):
  out.append(str(np.dot(A[i:(i+n)],E)))
print(" ".join(out))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

b = np.array(d)

Ainv = np.linalg.inv(a)         # A の逆行列を計算
x = np.dot(Ainv, b) 

# 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):
#         print(a[i])
#     print("-------------")
#     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(x[i])))
print(" ".join(ans))

Submission status: Time Limit Exceeded

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

num_list = [0 for i in range(N)]
while True:
  x = A.index(max(A))
  if max(A) == 2 or max(A) == 1:
    break
  if x == 0:
    if A[x+1] >= A[N-1]:
      num_list[x+1] += (A[x+1] - 1) * 2
      A[x] -= A[x+1] - 1
      A[x+1] = 1
    else:
      num_list[x] += (A[N-1] - 1) * 2
      A[x] -= A[N-1] - 1
      A[N-1] = 1
  elif x == N-1:
    if A[0] >= A[N-2]:
      num_list[0] += (A[0] - 1) * 2
      A[x] -= A[0] - 1
      A[0] = 1
    else:
      num_list[x] += (A[N-2] - 1) * 2
      A[x] -= A[N-2] - 1
      A[N-2] = 1
  else:
    if A[x-1] > A[x+1]:
      num_list[x] += (A[N-2] - 1) * 2
      A[x] -= A[x-1] - 1
      A[x-1] = 1
    else:
      num_list[x+1] += (A[x+1] - 1) * 2
      A[x] -= A[x+1] - 1
      A[x+1] = 1
      
x = A.index(max(A))

while True:
  if max(A) == 0:
    break
  if A[x] == 0:
    if x == N-1:
      x = 0
    else:
      x += 1
    continue
  if x == N-1:
    num_list[0] += 2
    A[x] -= 1
    A[0] -= 1
    x = 0
  else:
    num_list[x+1] += 2
    A[x] -= 1
    A[x+1] -= 1
    x += 1
  
for s in num_list:
  print(s, end =" ")

Submission status: Time Limit Exceeded

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


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

for water in range(a[0], -1, -1):
    flag = True
    m[0] = water*2
    for i in range(n):
        m[i+1] = (a[i] - (m[i]//2))*2
    for j in range(n-1):
        if a[j] != (m[j]+m[j+1])//2:
            falg = False
    if a[n-1] != (m[n-1]+m[0])//2:
        flag = False
    if flag:
        break

m.pop()
print(' '.join(list(map(str, m))))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
X=list(map(int, input().split()))
Y=[]
Yama=[]
for x in range(0,N):
    if x%2==0:
        Y.append(1)
    if x%2==1:
        Y.append(-1)

for x in range(0,N):
    Yama.append(0)
    for y in range(0,N):
        Yama[x]=Y[y]*X[y]+Yama[x]
    Y.insert(0,Y[-1])
    del Y[-1]

for s in Yama:
  print(s, end =" ")

Submission status: Time Limit Exceeded

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

A = np.array([[0]*n for i in range(n)])
for i in range(n):
    A[i][i] = 1
    if i == n-1:
        A[i][0] = 1
    else:
        A[i][i+1] = 1
B =np.matrix(A)
X = np.array([[l[i]] for i in range(n)])
Y = np.matrix(X)
C = np.linalg.inv(B)*Y

for i in range(n):
  print(int(C[i][0])*2,end=" ")

Submission status: Time Limit Exceeded

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

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

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

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):
    a1 = a[i:n]+a[0:i]
    x[i]=sum(a1[0::2])-sum(a1[1::2])
for i in range(n):
    print("{}".format(abs(x[i])),end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=list(map(int, input().split()))
all=int(sum(A)/2)
ans=[]
for i in range(N):
    index=[]
    for j in range(int(N/2)):
        k=(i+1+2*j)%N
        index.append(A[k])
    x=sum(index)
    ans.append((all-x)*2)
for a in ans:
  print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

ans = np.array([-1] * N)

ans[0]
for i in range(1, N):
    ans[i] = (A[i-1] - (ans[i-1] >> 1)) << 1

d = np.array([2] * N)
for i in range(1, N, 2):
    d[i] = -2


while True:
    if np.any(ans < 0):
        ans = ans + d
    else:
        print(" ".join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

N = int(input())
right = list(int(x) * 2 for x in input().split())
 
left = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    left[i][i] = 1
    if i < N - 1:
        left[i][i + 1] = 1
    
left[N - 1][0] = 1

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

#print(left)

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

print(answer)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    min_A = min(A)
    min_A_idx = A.index(min_A)
    A = A[min_A_idx:] + A[:min_A_idx]
    
    for s in range(A[0] * 2, -1, -2):
        mt = [None] * N
        mt[0] = s
        for n in range(N-1):
            if mt[n] > A[n+1] * 2:
                break
            mt[n+1] = (A[n+1] - mt[n]//2) * 2

        if mt[N-1] != None:
            if mt[N-1] //2 + mt[0] // 2 == A[0]:
                if min_A_idx == 0:
                    print(mt[-1], ' '.join(list(map(str, mt[:-1]))))
                    return
                print(' '.join(list(map(str, mt[N-min_A_idx-1:]))), ' '.join(list(map(str, mt[:N-min_A_idx-1]))))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
sum = 0
x = [-1 for i in range(n)]
for i in range(n):
    if a[i % n] == 0:
        x[i % n] = 0
        x[(i + 1) % n] = 0
i = 0
while (-1 in x):
    if a[i % n] == -1 and a[i + 2] != -1:
        x[i] = a[i] * 2 - a[i + 1] * 2 - x[i + 2]
    i += 1
for i in x:
    print(i,end = "")
    print(" ", end = "")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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