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(0,a[0]*2+1,2):
    ans = [0]*n
    ans[0] = i
    for j in range(1,n):
        tmp = (a[j-1]-ans[j-1]//2)*2
        ans[j] = tmp
    if (ans[-1]/2 + ans[0]/2) == a[-1]:
        print(*ans)
        exit()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(0,a[0]*2+1,2):
    ans = [i]
    for j in range(1,n):
        tmp = (a[j-1]-ans[j-1]//2)*2
        if tmp%2 == 0:
            ans.append(tmp)
        else:
            break
    if (ans[-1]//2 + ans[0]//2) == a[-1]:
        print(*ans)
        exit()

Submission status: Time Limit Exceeded

Solution code:
'''
        2 A1 = M_1 + M_2
        2 A2 = M_2 + M_3
        2 A3 = M_3 + M_4
        2 A4 = M_4 + M_5
        2 A5 = M_5 + M_1
A1 + A2 + A3 = M_1 + M_2 + M_3

M_1 = (A1 + A2 + A3) - (M_2 + M_3 + M_4 + M_5)
M_2 = (A1 + A2 + A3) - (M_3 + M_4 + M_5 + M_6)
M_3 = (A1 + A2 + A3) - (M_4 + M_5 + M_6 + M_7)
'''

n    = int(input())
ai   = list(map(int, input().split()))
aix2 = list(map(lambda x: x * 2, ai))

sum_a = sum(ai)

def ring_get(xs, s, e, mod):
    ys = []
    i  = s % mod

    while i != (e % mod):
        ys.append(xs[i])
        i = (i + 2) % mod

    return ys

for i in range(1, n):
    print(sum_a - sum(ring_get(aix2, i, i + (n - 1), n)))

print(sum_a - sum(ring_get(aix2, 0, 0 + (n - 1), n)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
r = np.array(list(map(int,input().split())))

pm = np.array([1,-1] * (n//2) + [1])


d = []
for i in range(n):
    tmp = r * pm
    d.append(str(sum(tmp)))
    r0 = r[0]
    r = r[1:]
    r = np.append(r, r0)

print(' '.join(d))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
arr=list(map(int,input().split()))
total=sum(arr)
mt=[0]*N


for i in range(total+1):
    mt[0]=i
    for j in range(N-1):
        mt[j+1]=arr[j]*2-mt[j]
    if sum(mt)==total:
        break
    
print(*mt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
num = sum(A)//2
A = A+A
ans = [0]*N
for i in range(N):
    tmp = num
    for j in range(i,i+N-2,2):
        tmp -= A[j]
    ans[i-1] = tmp*2
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))

N = i()
A = l()
num = sum(A)//2
A += A
ans = []
for i in range(N):
    num2 = 0
    for j in range(0,N,2):
        num2 += A[i+j]
    ans.append(abs((num-num2))*2)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
A += A
num = sum(A)//4
ans = []
for i in range(N):
    num2 = 0
    for j in range((N-1)//2):
        num2 += A[i+1+2*j]
    ans.append((num-num2)*2)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from itertools import islice
def main():
    n = int(input())
    A = deque(list(map(int, input().split())))
    ans = [0] * n
    for i in range(n):
        ans[i] = sum(islice(A, 0, n, 2)) - sum(islice(A, 1, n, 2))
        A.rotate(-1)
    print(' '.join(list(map(str, ans))))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

A = [[0]*n for _ in range(n)]

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

X = [[0]*n for _ in range(n)]
for i in range(n):
    X[i][i] = 1

def Inv(A):
    """逆行列をnumpyを使わず求める"""
    
    #まずAを上三角行列にする。
    for p in range(len(A)):
        pivot = A[p][p]
        for j in range(p+1, len(A)):
            coef = A[j][p] / pivot
            A[j] = [aj-ap*coef for aj,ap in zip(A[j],A[p])]
            X[j] = [xj-xp*coef for xj,xp in zip(X[j],X[p])]

    #対角成分を1にする。
    for i in range(len(A)):
        X[i] = [xi/A[i][i] for xi in X[i]]
        A[i] = [ai/A[i][i] for ai in A[i]]

    #答えを出す。
    for i in range(len(A)-1,0,-1):
        for j in range(i):
            X[j] = [xj-xi*A[j][i] for xj,xi in zip(X[j],X[i])]
            A[j][i] = 0
    return X

InvA = Inv(A)

ans = [0]*n

for i in range(len(A)):
    ans[i] = int(sum([a*b for a,b in zip(InvA[i], B)])) * 2
    
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
X = []
A_sum = sum(A)

for i in range(n):
    temp = A_sum
    for j in range(i+1,n+i,2):
        temp -= 2*A[j % n]
    X.append(temp)

for i,x in enumerate(X):
    if i == n-1:
        print(x)
    else:
        print(x,end=" ")

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    import numpy as np
    from scipy import linalg
    input = stdin.readline

    n = int(input())
    a = [[] for _ in range(n)]
    for i in range(n - 1):
        a[i] = [0] * i + [1, 1] + [0] * (n - i - 2)
    a[n - 1] = [1] + [0] * (n - 2) + [1]
    A = np.array(a)
    b = np.array(list(map(int, input().split())))
    LU = linalg.lu_factor(A)
    x = linalg.lu_solve(LU, b) * 2
    print(' '.join(map(str, map(int, x))))
main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    import numpy as np
    input = stdin.readline

    n = int(input())
    a = [[] for _ in range(n)]
    for i in range(n - 1):
        a[i] = [0] * i + [1, 1] + [0] * (n - i - 2)
    a[n - 1] = [1] + [0] * (n - 2) + [1]
    A = np.array(a)
    b = np.array(list(map(int, input().split())))
    x = np.linalg.solve(A, b) * 2
    print(' '.join(map(str, map(int, x))))
main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    x_sum = sum(a) // 2
    x = [0] * n
    for i in range(n):
        tmp = x_sum
        idx = (i + 1) % n
        for _ in range((n - 1) // 2):
            tmp -= a[idx]
            idx += 2
            idx %= n
        x[i] = 2 * tmp
    print(*x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

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

ans = [0]*N
for i in range(N):
    if i%2 == 0:
        ans[i] = sum(A[0:i:2])-sum(A[1:i:2])+A[i]+sum(A[i+1::2])-sum(A[i+2::2])
    else:
        ans[i] = -sum(A[0:i:2])+sum(A[1:i:2])+A[i]+sum(A[i+1::2])-sum(A[i+2::2])
ans.insert(0, ans.pop(-1))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
y = [0 for _ in range(n)]
suma = sum(a)
ans = []
for i in range(n):
	t = 2*sum([a[j%n] for j in range(i, i+n, 2)])-suma
	ans.append(str(t))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve
n = int(input())
a = list(map(int,input().split()))
l = [[0 for j in range(n)] for _ in range(n)]

for i in range(n):
	if i != n-1:
		l[i][i], l[i][i+1] = 1/2, 1/2
	else:
		l[i][0], l[i][i] = 1/2, 1/2

left = l
right = a

ans = solve(left,right)
print(" ".join(list(map(str,list(map(int,ans))))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

tmp = [[0 for i in range(N)] for i in range(N)]
for i in range(N):
    tmp[i][i] = 1
    tmp[i][(i+1)%N] = 1

A = np.matrix(tmp)
Y = np.matrix(W).T

ans = np.linalg.solve(A, Y)*2

tmp = []
for a in ans:
    tmp.append(str(int(a)))

print(" ".join(tmp))

Submission status: Time Limit Exceeded

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

import numpy as np
d=deque(A)
ans=np.array([0]*n)

for i in range(n):
    if i%2==0:
        ans+=np.array(d)
    else:
        ans-=np.array(d)
    d.append(d.popleft())
print(*ans)

Submission status: Time Limit Exceeded

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

d=deque(A)
ans=[]
for i in range(n):
    c=sum(d[i]*((-1)**i) for i in range(n))
    ans.append(c)
    d.append(d.popleft())
print(*ans)

Submission status: Time Limit Exceeded

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

left=[]
for i in range(n-1):
    c=[0]*n
    c[i]=1
    c[i+1]=1
    left.append(c)
left.append([1]+[0]*(n-2)+[1])

from numpy.linalg import solve
 
A2=[2*i for i in A]
 
ans=solve(left, A2)
ans2=[int(i) for i in ans]
print(*ans2)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    m=n//2
    a=list(map(int,readline().split()))

    s=sum(a)//2
    ans=[0]*n
    k=n-1
    for i in range(n):
        t=0
        for j in range(m):
            t+=a[i]
            i+=2
            i%=n
        ans[k]=(s-t)*2
        k+=1
        k%=n

    print(*ans)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
t = 0
while True :
    t += 1
    if t > n :
        exit()
    print(All-sum(a2[1::2]))
    a2.append(a2[0])
    del a2[0]

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

target = sum(a)//2

a = np.array(a)
a = np.concatenate((a, a))
ans = []

for i in range(n):
    num = target
    b = a[i+1:i+n:2]
    num -= np.sum(b)
    ans.append(num*2)

for i in range(n):
    print(ans[i], end=' ')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

target = sum(a)//2

a = np.array(a)
a = np.concatenate((a, a))

for i in range(n):
    num = target
    for j in range(n//2):
        num -= a[i + 2*j + 1]
    print(num*2)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=np.array([int(_) for _ in input().split()])
    B=np.zeros(n,dtype=int)
    while True:
        for i in range(1,n):
            B[i]=A[i-1]-B[i-1]
        B[1::]=A[:-1:]-B[:-1:]
        if B[0]==A[-1]-B[-1]:
            print(*[2*x for x in B])
            break
        B[0]+=1
    

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    B=[0]*n
    while True:
        for i in range(1,n):
            B[i]=A[i-1]-B[i-1]
        if B[0]==A[-1]-B[-1]:
            print(*[2*x for x in B])
            break
        B[0]+=1
    

if __name__=='__main__':
    main()

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

l=[[0]*n for _ in range(n)]
k=0
for i in range(n-1):
    l[i][k]=1
    l[i][k+1]=1
    k+=1
l[n-1][0]=1
l[n-1][n-1]=1
p=[[0] for _ in range(n)]
for i in range(n):
    p[i]=a[i]*2
for i in solve(l,p):
  print(int(i), end=" ")

Submission status: Time Limit Exceeded

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

def solver(k):
    global ans
    ans = [k]
    if k % 2 == 1:
        return False
    b = k
    for i in range(N - 1):
        b = 2 * A[i] - b
        ans.append(b)
        if b % 2 == 1 or b < 0:
            return False
    if ans[0] + ans[-1] == 2 * A[-1]:
        return True
    else:
        return False

for i in range(total // 2 + 1):
    if solver(2 * i):
        print(" ".join(map(str, ans)))
        exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
X = [0]*(N+1)
S = sum(A)

even_list = deque([A[i] for i in range(1, N) if (i+1) % 2 == 0])
odd_list = deque([A[i] for i in range(1, N) if (i+1) % 2 != 0])

X[1] = S - 2 * sum(even_list)
X[2] = S - 2 * sum(odd_list)
even_idx = N-1
odd_idx = N
for i in range(3, N+1):
  if i%2:
    even_idx += 2 
    even_idx %= N
    even_list.popleft()
    even_list.append(A[even_idx-1])
    X[i] = S - 2 * sum(even_list)
  else:
    odd_idx += 2
    odd_idx %= N
    odd_list.popleft()
    odd_list.append(A[odd_idx-1])
    X[i] = S - 2 * sum(odd_list)

for i in range(1, N+1):
  print(X[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=int(input())
  a=list(map(int,input().split()))
  ans=[0]*n
  ans[0]=sum([a[i]*(-1)**i for i in range(n)])
  for i in range(1,n):
    ans[i]=sum((a[j]*(-1)**(i+j+1) if j<i else a[j]*(-1)**(i+j) for j in range(n)))
  print(*ans)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(n)]
for i in range(n):
    if i%2 == 0:
        l[i] = 2*(sum(a)//2 - sum(a[i+1::2]) - sum(a[:i:2]))
    else:
        l[i] = 2*(sum(a)//2 - sum(a[i+1::2]) - sum(a[1:i:2]))
print(" ".join(map(str, l)))

Submission status: Time Limit Exceeded

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

rslt = []
ttl = sum(ns)
for i in range(n):
    rslt.append(ttl - 2 * sum(ns[i % 2:max(i - 1, 0):2] + ns[i + 1::2]))
print(*rslt)

Submission status: Time Limit Exceeded

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

import numpy as np
K = np.array([[0] * N for _ in range(N)])
for i in range(N):
    K[i][i] = 1
    if i != N - 1:
        K[i][i + 1] = 1
    else:
        K[i][0] = 1
        
X = np.linalg.solve(K, A)
X = [str(int(2 * x)) for x in X]
ans = " ".join(X)
print(ans)

Submission status: Time Limit Exceeded

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

x_sum = sum(A) / 2
x_list = []
x_even = [A[j] for j in range(1, N, 2)]
x_odd = [A[j] for j in range(2, N, 2)]
for i in range(N):
    if i % 2 == 0:
        x_rem = x_list + x_even[(i//2):]
    else:
        if i == 1:
            x_rem = x_odd
        else:
            x_rem = x_list[1:] + x_odd[(i//2):]
    x = x_sum - sum(x_rem)
    x_list.append(x)

ans = [int(x_list[x] * 2) for x in range(N)]
print(*ans)

Submission status: Time Limit Exceeded

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

x_sum = sum(A) / 2
x_list = []
for i in range(N):
    if i % 2 == 0:
        x_rem = x_list + [A[j] for j in range(i+1, N, 2)]
    else:
        if i == 2:
            x_rem = [A[j] for j in range(i+1, N, 2)]
        else:
            x_rem = x_list[1:] + [A[j] for j in range(i+1, N, 2)]
    x = x_sum - sum(x_rem)
    x_list.append(x)

ans = [int(x_list[x] * 2) for x in range(N)]
print(*ans)

Submission status: Time Limit Exceeded

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

for i in range(0, min(A[0], A[-1]) * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            # print('M', M)
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる

Submission status: Time Limit Exceeded

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

for i in range(0, A[0] * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            # print('M', M)
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
D = np.zeros(N + 1, dtype='int')
D[:-1] = A // 2
D[1:] = A // 2
# print(D)

idx = A.argmin()
A = np.append(A[idx:], A[:idx])
# print('A', A)
# print('idx', idx)

for i in range(0, A[0] * 2 + 1, 2):
    M = [i]
    for j in range(N):
        v = 2 * A[j] - M[-1]
        M.append(v)
        if v < 0:
            break
    else:
        if M[0] == M[-1]:
            M = M[:-1]
            M = np.array(M)
            # print('M', M)
            idx2 = len(M) - idx
            # print('idx2', idx2)
            M = np.append(M[idx2:], M[:idx2])
            print(*M, sep=' ')
            exit()

# 一番小さいi値を 0, 2, 4, .... 2 * M[i]まで総当たりでやってみる

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input()) 
A=list(map(int,input().split()))
count=0
allcount=0
matrix=[]
ans=[0]*N
for i in range(N):
    buf=[0]*N
    if i==N-1:
        buf[0]=1
        buf[N-1]=1
    else:
        buf[i]=1
        buf[i+1]=1
    matrix.append(buf)
matrix=np.matrix(matrix)
A=np.array(A)
A=np.reshape(A,(1,N))
right=A.T
#print(right)
#print(matrix)
#print(np.linalg.inv(matrix))
rev=np.linalg.inv(matrix)
B=rev*right
#print(B)
B=np.reshape(B,(1,N))
B=B.tolist()
#print(B)
for i in range(N):
    ans[i]=int(2*B[0][i])
print(*ans,sep=" ")

Submission status: Time Limit Exceeded

Solution code:
#連立方程式を解くライブラリ
from numpy.linalg import solve

#山の数の取得
Y = int(input())
#ダムの貯水量の取得
A = input().split()
#連立方程式のリスト
left0 = []
left = []
right = []

for i in range(Y):
  for j in range(Y):
    if i == Y - 1:
      if j == 0 or j == Y - 1:
        left0.append(1)
      else:
        left0.append(0)
    elif j == i or j == i + 1:
      left0.append(1)
    else:
      left0.append(0)
  left.append(left0)
  right.append(int(A[i]))
  left0 = []
  
#left = [[2, 1], [4, 1]]
#right = [3, 6]

S = solve(left, right)
for s in S:
  print(2 * int(s), end =" ")

Submission status: Time Limit Exceeded

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

for i in range(N):
  a = 0
  for j in range(N//2):
    a += A[(i+j*2+1)%N]
  print(s-a*2, end=" ")
  
print("")

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve
n = int(input())
a = list(map(int, input().split()))

left = [[0] * n for _ in range(n)]
right = list(map(lambda x: x * 2, a))
for i in range(0, n):
    left[i][i] = 1
    left[i][(i+1)%n] = 1
b = solve(left, right)
print(*list(map(int, b)))

Submission status: Time Limit Exceeded

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    xs = sum(a) // 2
    res = [0] * n

    for i in range(n):
        sub = 0
        for j in range(n // 2):
            sub += a[(i + 1 + j * 2) % n]
        res[i] = 2 * (xs - sub)

    print(*res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l1 = [] #odd *-1
l2 = [] #even *-1
ans = []
for i in range(n):
    if i%2:
        l1.append(-1*l[i])
    else:
        l1.append(l[i])

for j in range(n):
    if j%2:
        l2.append(l[j])
    else:
        l2.append(-1*l[j])

for k in range(n):
    if k%2:
        ans.append(sum(l2[k:])+sum(l1[:k]))
    else:
        ans.append(sum(l1[k:])+sum(l2[:k]))

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

Submission status: Time Limit Exceeded

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

def check(si,xi):
    X = [-1] * N
    X[si] = xi
    for i in range(N-1):
        ci = (si+i+1)%N-1
        X[ci+1] = 2*A[ci] - X[ci]
    if X[si] == 2*A[si-1] - X[si-1]:
        return X
    return []

mm = 10**10
mi = -1
for i,a in enumerate(A):
    if a < mm:
        mm = a
        mi = i

for xi in range(2*mm+1):
    X = check(mi, xi)
    if X:
        print(*X)
        exit()

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

N = int(input())
A = list(map(int, input().split()))
mat = [[0]*N for _ in range(N)]
A = [2*n for n in A]

for i in range(N):
    mat[i][i] = 1
    mat[i][(i+1)%N] = 1

ans = list(map(int, solve(mat, A)))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# たまっている水の合計…の半分
s = sum(As) // 2

ans_list = []

for i in range(len(As)):
    ans = s
    for j in range(i-2, -1, -2):
        ans -= As[j]

    for j in range(i+1, len(As), 2):
        ans -= As[j]

    ans_list.append(str(ans*2))

print(' '.join(ans_list))

Submission status: Time Limit Exceeded

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

b=[0]*(N+1)
for b0 in range(2*a[0]+1):
    b[0] = b0
    for i in range(1,N+1):
        b[i] = 2*a[i-1] - b[i-1]
    if b[0] == b[N]: break
print(*b[:N])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = list(map(int, input().split()))
a = n // 2
res = sum(lis)


def dams(i, a, lis):
    su = 0
    for j in range(a):
        b = (i + (2 * j + 1)) % len(lis)
        su += lis[b]
    return su


ans = []
for i in range(n):
    ans.append(res - 2 * dams(i, a, lis))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)
MIN = min(A)
start = A.index(MIN)

for odd in range(0, 10**9+1, 2):
    dp = [0]*n
    dp[start] = cnt = odd
    for i in range(start+1, n):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]
    else:
        for i in range(start):
            dp[i] = 2*A[i-1]-dp[i-1]
            cnt += dp[i]
    if cnt == SUM:
        break
print(*dp)

Submission status: Time Limit Exceeded

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

for odd in range(0, 10**9+1, 2):
    dp = [0]*n
    dp[0] = odd
    cnt = dp[0]
    for i in range(1, n):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]
    if cnt == SUM:
        break
print(*dp)

Submission status: Time Limit Exceeded

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from numpy.linalg import solve

N =ii()
left = dp2(0, N, N)
for i in range(N-1):
    left[i][i] = left[i][i+1] = 0.5
left[N-1][N-1] = left[N-1][0] = 0.5

right = li()

for i in solve(left, right):
    print(int(i), end='')
    print(' ', end='')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# D
n = int(input())
y = list(map(int, input().split()))
ans = [0 for i in range(n)]
for i in range(n):
    count=0
    for j in range(i,n+i):
        if (j-i) % 2 == 0:
            count += y[j%n]
        else:
            count -= y[j%n]
    ans[i] = count
print(*ans, sep=' ')

Submission status: Time Limit Exceeded

Solution code:

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    sval = sum(a)
    for k in range(1, n+1):
        a_s = 0
        for l in range(n//2):
            a_s += a[((k+1)+(2*l))%n-1]
        ans = sval - 2 * a_s
        print(ans, end=' ')
main()

Submission status: Time Limit Exceeded

Solution code:
#python3

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    sval = sum(a)
    for k in range(1, n+1):
        a_s = 0
        for l in range(n//2):
            a_s += a[((k+1)+(2*l))%n-1]
        ans = sval - 2 * a_s
        print(ans, end=' ')
main()

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

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

right = A
res = solve(left, right)

for i in res:
    print(i.astype(int))

Submission status: Time Limit Exceeded

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

MaxX1=min(A[-1],A[1])*2

for i in range(0,MaxX1+2,2):
    X=[i]*N
    for j in range(N-1):
        X[j+1]=2*A[j]-X[j]
        AJ=[0]*N
        for k in range(N):
            AJ[k-1]=X[k-1]/2+X[k]/2
        if AJ==A:
            print(" ".join(map(str,X)))
            exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ms = list(map(int, input().split()))
for i in range(0, 1000000001, 2):
  a = i
  for m in ms:
    a = 2 * m - a
  if i == a:
    result = i
    break

vv = ['%d' % a]
for m in ms[:-1]:
  a = 2 * m - a
  vv.append('%d' % a)
print(' '.join(vv))

Submission status: Time Limit Exceeded

Solution code:
# pencil and paper !
# n = 3 (x, y, z = 山, a, b, c = ダム)
# x = a - b + c
# y = a + b - c
# z = -a + b + c
# 
# n = 5
# x = a - b + c - d + e
# 両隣は + , それ以降は -, +, -, +
n = int(input())
aaa = list(map(int, input().split(' ')))
ans = []
for i in range(n):
    r = 1
    temp = 0
    for j in range(n):
        temp += (aaa[(i+j) % n ] * r)
        r *= -1
    ans.append(str(temp))
print(' '.join(ans))