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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    mi = (0, -1)
    for i in range(N):
        mi = max(mi, (A[i-1] + A[i], i, A[i-1], A[i]))


    s = min(mi[2], mi[3])*2

    si = mi[1]
    while True:
        ans = [0] * N
        ans[si] = s
        a = A[:]
        a[si-1] -= s//2
        a[si] -= s//2
        for i in range(1, N):
            ans[(si+i)%N] = a[(si+i-1)%N] * 2
            a[(si+i) % N] -= a[(si+i-1) % N]
            a[(si+i-1) % N] = 0
        
        if a[(si+i) % N] == 0:
            break
        s -= 2
        if s < 0:
            break

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


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    tmp=0
    for j in range(n-i):
        tmp+=((-1)**(j))*a[j+i]
    if(i>0):
        j+=1
        tmp+=((-1)**(j))*ans[0]/2
        ans.append(tmp*2)
    else:
        ans.append(tmp)
        continue

for i in ans:
    print(int(i),end=' ')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
B = [int(i)*2 for i in input().split()]

a = [[0]*N for i in range(N)]

for i in range(N-1):
    for j in range(N):
        if j == i:
            a[i][j] += 1
        if j == i+1:
            a[i][j] += 1

a[-1][0] += 1
a[-1][-1] += 1

A = np.array(a, dtype=np.int)
b = np.array(B, dtype=np.int)

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
tmp = A[0]
for i in range(1, N):
  if i % 2 == 0:
    tmp = tmp + A[i]
  else:
    tmp = tmp - A[i]
X = [tmp]*N
print_str = str(tmp)
for i in range(0, N-1):
  X[i+1] = (A[i] - X[i] // 2) * 2
  print_str = print_str + " " + str(X[i+1])
print(print_str)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
#v =  np.array([n*2 for n in a])
#print(v)
#x = []
for i in range(n):
	#s = 0
	#print(v)
	print((sum(v[0::2]) - sum(v[1::2])))
	#for j in range(n):
	#	s += pow(-1, j)*v[j]
		#print(s)
	#x.append(s)
	v = np.roll(v, -1)
	#print(int(s/2))
#print(np.array([int(n/2) for n in x]))

Submission status: Time Limit Exceeded

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

ans = [0]*(n+1)
for i in range(0, a[0]*2+1, 2):
    ans[0] = i
    for j in range(n):
        ans[j+1] = (a[j] - ans[j]//2) *2
    if ans[0] == ans[n]:
        print(' '.join(map(str, ans[0:len(ans)-1])))
        exit(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
for i in range(n):
    ans = 0
    k = 0
    for j in range(i,n+i):
        ans += a[j]*(-1)**k
        k += 1
    print(ans,end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a = []
for i in range(N):
    ai = []
    for j in range(N):
        k = i+1 if i+1 < N else 0
        if(j == i or j == k):
            ai.append(1)
        else:
            ai.append(0)
    a.append(ai)

a_matrix = np.array(a)
b_matrix = np.array(A)

x = np.linalg.solve(a_matrix,b_matrix)

x = x * 2

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

Submission status: Time Limit Exceeded

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

all_mount = sum(A)
mounts = []
for i in range(N):
  mount = all_mount
  for j in range(0, N-1, 2):
    mount -= 2 * A[(i+j+1)%N]
  mounts.append(mount)
    
print(" ".join(map(str,mounts)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
water = [int(x) for x in input().split()]
rain = [0]*N
sum = 0
for i in water:
    sum += i

for k in range(N):
    sa = 0
    numofloop = 0
    ite = k + 1
    if (ite >= N):
        ite -= N
    while (numofloop < (N - 1) / 2):
        sa += water[ite]
        ite += 2
        if (ite >= N):
            ite -= N
        numofloop += 1
    sa *= 2
    rain[k] = sum - sa

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

Submission status: Time Limit Exceeded

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

t = n//2

for i in range(1, n+1):
    s = sum(b[i : i + t*2 : 2])
    result_list.append(total_water - s)

for item in result_list:
    print(item, end = ' ')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

X = [0]*N

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

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

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

for i, mount in enumerate(mountains):
    if i != N - 1:
        mount[i] = 0.5
        mount[i+1] = 0.5
    else:
        mount[0] = 0.5
        mount[i] = 0.5

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy

n = int(input())
a = list(map(lambda x: [int(x)], input().split()))

met = []

for i in range(0, n):
    row = [0 for _ in range(0, n)]
    row[i] = 1
    if (i == n-1):
        row[0] = 1
    else:
        row[i+1] = 1
    met.append(row)
A = numpy.matrix(met)
Y = numpy.matrix(a)

ans = []
for j in numpy.linalg.inv(A)*Y:
    ans.append(str(int(j) * 2))

print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
res = []
for i in range(n):
    s = 0
    for pm, j in enumerate(range(i, i+n)):
        s += a[j%n] * [-1, 1][pm %2 ==0]
    res.append(s)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

N = int(input().strip())
As = list(map(int, input().strip().split(' ')))

xs = [0] * N
for n in range(N):
    rotate = As[n:] + As[:n]
    xs[n] = sum(rotate[0::2]) - sum(rotate[1::2])
print(" ".join(map(str, xs)))

Submission status: Time Limit Exceeded

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

ans = [None] * N
for i in range(N):
    if i < 2:
        ans[i] = str(sumA - 2 * sum(A[i + 1::2]))
    else:
        ans[i] = str(sumA - 2 * sum(A[i - 2::-2]) - 2 * sum(A[i + 1::2]))

print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

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

for i in range(N):
    j = i
    f = 1
    while j < N+i:
        X[i] += f * A[j % N]
        j += 1
        f *= -1

print(*X)

Submission status: Time Limit Exceeded

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

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

if __name__=="__main__":
    solve()

Submission status: Time Limit Exceeded

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

left = [[0 for _ in range(N)] for _ in range(N)]
right = []
for i in range(N):
  right.append(2 * A[i] + 2 * A[(i + 1) % N])
  for j in range(N):
    if j == i or j == (i + 2) % N:
      left[i][j] = 1
    if j == (i + 1) % N:
      left[i][j] = 2

ans = solve(left, right)
for i in range(N):
  print(int(round(ans[i])), end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

w_arr = []

for i in range(N):
  arr = [0]*N
  if i == N-1:
    arr[i] = 1/2
    arr[0] = 1/2
  else:
    arr[i] = 1/2
    arr[i+1] = 1/2
  w_arr.append(arr)
  
ans = solve(w_arr, solve_arr)
for i in ans:
  print(str(int(i)) + " ", end ="")

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

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

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

for i, mount in enumerate(mountains):
    if i != N - 1:
        mount[i] = 0.5
        mount[i+1] = 0.5
    else:
        mount[0] = 0.5
        mount[i] = 0.5

ans = solve(mountains, dam)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
v =  np.array([n*2 for n in a])
#print(v)
#x = []
for i in range(n):
	s = 0
	#print(v)
	for j in range(n):
		s += pow(-1, j)*v[j]
		#print(s)
	#x.append(s)
	v = np.roll(v, -1)
	print(int(s/2))
#print(np.array([int(n/2) for n in x]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [int(x) for x in input().split()]
for i in range(A_list[0]+1):
    now = i * 2
    # print(now)
    for a in A_list:
        now = (a - now//2) * 2
        if (now<0):
            break
        # print(now)
    if (i == now//2):
        break
now = i * 2
ans = [str(now)]
for a in A_list[:-1]:
    now = (a - now//2) * 2
    ans.append(str(now))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from numpy.linalg import solve

n = int(input())
a = list(map(int, input().split()))
a = [_a * 2 for _a in a]

x = [[0]*n for _ in range(n)]
for i in range(n-1):
    x[i][i] = 1
    x[i][i+1] = 1
x[n-1][n-1] = 1
x[n-1][0] = 1

print(" ".join(map(str, map(int, list(solve(x, a))))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
for x in range(A[0]+1):
    t = x
    B = [x]
    for i in range(n-1):
        B.append(A[i]-t)
        t = B[-1]
    if 2*sum(B)==sum(A):
        break
ans = [i*2 for i in B]
print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
M = [0 for i in range(N)]

for i in range(A[0]+1):
    M[0] = i*2
    for j in range(N-1):
        M[j+1] = (A[j] - int(M[j]//2)) * 2
    if A[N-1] == int((M[0]//2) + ((M[N-1])//2) ):
        break;

for i in range(N):
    print(M[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

# A = list(map(int, input().split()))
# print(N, A)
A = []
l = input().split()
total = 0
sub = 0
for i in range(len(l)):
    v = int(l[i])
    A.append(v)
    total += v
    if i % 2 == 1:
        sub += v

M = [0]*N
# total = sum(A)
# sub = 0
# for i in range((N-1)//2):
#     sub += A[2*i + 1]
# print(total, sub)
M[0] = total - 2 * sub
ans = "{} ".format(M[0])
for i in range(1, N):
    m = 2 * A[i - 1] - M[i - 1]
    M[i] = m
    ans += str(m) + " "
# print(M)
print(ans[0:-1])

Submission status: Time Limit Exceeded

Solution code:
# 最初に入れておくとinputが早くなる
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n

for i in range(0, a[0]*2+1, 2):
    ans[0] = i
    tempa = a.copy()
    for j in range(n):
        tempa[j % n] = ans[j % n] // 2
        if(j+1 != n):
            ans[(j+1) % n] = (a[j]-tempa[j])*2
    if (ans[0] == (a[n - 1] - tempa[n - 1]) * 2):
        break
# tempa[1 % 3] = ans[1 % 3]/2
# ans[2 % 3] = (a[1]-tempa[1])*2
# tempa[2 % 3] = ans[2 % 3]/2
# ans[3 % 3] = (a[2 % 3]-tempa[2 % 3])*2
# tempa[3 % 3] = ans[3 % 3] / 2
# print(a)
# print(tempa)
print(*ans)

Submission status: Time Limit Exceeded

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

import numpy

mat = []
for q in range(n-1):
  mat.append( [0]*q + [0.5,0.5] + [0]*(n-q-2) )
mat.append([0.5] + [0]*(n-2) + [0.5])

X = numpy.matrix(mat)

mat2 = []
for q in A:
  mat2.append([q])
Y = numpy.matrix(mat2)
ans = numpy.linalg.solve(X,Y)
ans = map(int,ans)
print ' '.join(map(str, ans))

Submission status: Time Limit Exceeded

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

t = n//2

for i in range(1, n+1):
    s = 0
    for j in range(t):
        s += b[(i + 2*j)%n]
    result_list.append(total_water - s)

for item in result_list:
    print(item, end = ' ')

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split()))
M = [0] * N
for i in range(N):
    op = 1
    for j in range(N):
        jj = (i + j) % N
        M[i] = M[i] + A[jj] if op == 1 else M[i] - A[jj]
        op = 1 - op
print(*M)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa = a+a
g = sum(a)//2
ans = []
for i in range(n):
    temp = sum([aa[i+1+j*2] for j in range(n//2)])
    ans.append(g-temp)
for k in ans:
    print(2*k,end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    ans = 0
    for j in range(n):
        if j == i:
            ans += a[j % n]
        elif (j == i-1) | (j == n+i-1):
            ans += a[j % n]
        elif (j > i):
            if j % 2 != i % 2:
                ans -= a[j % n]
            else:
                ans += a[j % n]
        elif (j < i):
            if j % 2 != i % 2:
                ans += a[j % n]
            else:
                ans -= a[j % n]
    b.append(str(ans))
print(" ".join(b))

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    x = [0] * N
    xsum = sum(A)
    for i in range(N):
        if i % 2 == 0:
            x[i] = xsum - (sum(A[i+1::2]) + sum(A[:i:2]))*2
        else:
            x[i] = xsum - (sum(A[i+1::2]) + sum(A[1:i:2]))*2
    print(*x)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(_) for _ in input().split()]
X=[]
for i in range(N):
    x=0
    for j in range(N):
        if ((j-i)%N)%2==0:
            x+=A[j]
        else:
            x-=A[j]
    X.append(x)
print(' '.join(map(str, X)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

sum_even = sum(A[::2])
sum_odd = sum(A[1::2]) + A[0]
ANS = A[:]
A = deque(A)
minus = False
for _ in range(n - 1):
    A.rotate(-1)
    for i in range(n):
        if minus:
            ANS[i] -= A[i]
        else:
            ANS[i] += A[i]
    minus = not minus
ANS = deque(ANS)
ANS.rotate()
print(*ANS)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) * 2 for i in input().split()]
assert len(A) == n
S = sum(A) // 2
A += A
for i in range(n):
    ans = S
    for j in range(i + 1, i + n, 2):
        ans -= A[j]
    print(ans, end=' ')
print()

Submission status: Time Limit Exceeded

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

water = A[:]
#print(water)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
c=np.array([1 if i%2==0 else -1 for i in range(n)])

ans=[]
for _ in range(n):
    rain=sum([i*j for i,j in zip(a,c)])
    tmp=a.popleft()
    a.append(tmp)
    ans.append(str(rain))
    


print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a1 = np.roll(a, -1)

for i in range(1, (n - 1) // 2):
  a1 += np.roll(a, -1 - 2 * i)

ans_list = map(str, (np.sum(a) - a1 * 2).tolist())
print(" ".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
S=sum(a)
ans=[]
for i in range(n):
    rmv=0
    for j in range(n//2):
        k=(i+2*j+1)%(n)
        rmv+=a[k]
    ans.append(str(S-rmv*2))
print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = [0] * N
for i in range(N):
    x = 1
    for j in range(N):
        if x == 1:
            ans[i] += A[(i+j)%N]
        else:
            ans[i] -= A[(i+j)%N]
        x ^= 1


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa = []
for s in a:
    aa.append(s)
for s in a:
    aa.append(s)
g = sum(a)//2
ans = []
for i in range(n):
    temp = sum([aa[i+1+j*2] for j in range(n//2)])
    ans.append(g-temp)
for k in ans:
    print(2*k,end=" ")

Submission status: Time Limit Exceeded

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

A_all = sum(As)//2

ans = []
for i in range(N):
    cnt = 0
    for j in range(N//2):
        index = i+2*j
        cnt += As[index%N]
    ans.append((A_all-cnt)*2)
 
a = ""
for i in range(1,N+1):
    a += str(ans[i%N])+" "
print(a)

Submission status: Time Limit Exceeded

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

S = sum(A)
ans = []
for i in range(N):
    v = S
    for j in range((N-1)//2):
        v -= 2 * A[(2*j+1+i) % N]
    ans.append(v)

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

Submission status: Time Limit Exceeded

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

#a = [x * 2 for x in a]
sol = []

for i in range(n):
    b = 1
    temp = 0
    for j in range(n):
        temp += a[j] * b
        b = b * -1
    sol.append(temp)
    x = a.pop(0)
    a.append(x)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)//2
A += A
X = [(S - sum(A[i+1:i+N:2]))*2 for i in range(N)]
X = list(map(str, X))
print(' '.join(X))

Submission status: Time Limit Exceeded

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

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

r = []
for i in range(N):
    flag = True
    tmp = 0
    for j in range(N):
        if flag: tmp += A[(i+j)%N]
        else: tmp -= A[(i+j)%N]
        flag = not flag
    r.append(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ["0"]*N
	mat = [[1 for _ in range(N)] for _ in range(N)]
	for i in range(N):
		for j in range(1, N, 2):
			mat[i][(i+j)%N] = -1
	for i in range(N):
		this_ans = 0
		for j in range(N):
			this_ans += mat[i][j]*A[j]
		ans[i] = str(this_ans)
	print(" ".join(ans))


if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
dam=[int(x)*2 for x in input().split()]
a=[[0]*n for x in range(n)]
for i in range(n):
    a[i][i],a[i][(i+1)%n]=1,1
# a=np.array(a)
# dam=np.array(dam)
ans=np.linalg.solve(a,dam)
print(" ".join([str(int(ans[i])) for i in range(n)]))

Submission status: Time Limit Exceeded

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

M = [0]*N
total = sum(A)
sub = 0
for i in range((N-1)//2):
    sub += A[2*i + 1]
# print(total, sub)
M[0] = total - 2 * sub
for i in range(1, N):
    M[i] = 2 * A[i - 1] - M[i - 1]
# print(M)
ans = ""
for m in M:
    ans += str(m) + " "
print(ans[0:-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(raw_input())
a = map(int,raw_input().split())
#print (a)
k = 0
w = []
for i in range(len(a)):
	Ans = np.zeros(len(a))
	for j in range(len(a)):
		if (j==k):
			Ans[j%n]=1
			Ans[(j+1)%n]=1
	w.append(Ans)
	#print (Ans)
	k+=1
#print (w)
b = a
for i in range(len(b)):
	b[i]=b[i]*2
#print (b)
ans = np.linalg.solve(w,b)
for i in ans:
	print int(i),

Submission status: Time Limit Exceeded

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

ans = [0]*N
for i in range(N):
    if i < 2:
        ans[i] = sumA - 2 * sum(A[i+1::2])
    else:
        ans[i] = sumA - 2 * sum(A[i-2::-2]) - 2 * sum(A[i+1::2])

Ans = str(ans)[1:-1].replace(", ", " ")
print(Ans)

Submission status: Time Limit Exceeded

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

ki_idx = [i for i in range(N) if i % 2 == 1]

A_sum = sum(A)

ans = []
for idx, dam in enumerate(A):
    ans.append(str(A_sum - 2*sum(A[ki_idx])))
    
    A = np.roll(A, -1)
    
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
A = [[0]*n for _ in range(n)]
for i in range(n-1):
  A[i][i]=A[i][i+1]=1
A[n-1][0]=A[n-1][n-1]=1
b = list(map(lambda x:int(x)*2,input().split()))
A = np.array(A)
b = np.array(b)
x = np.linalg.solve(A,b)
for i in x:
  print(int(i),end=" ")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
S=sum(a)
for i in range(n):
    a[i]*=2
ans=[]
for i in range(n):
    rmv=0
    for j in range(n//2):
        k=(i+2*j+1)%(n)
        rmv+=a[k]
    ans.append(S-rmv)
for i in range(n):
    ans[i]=str(ans[i])
print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import scipy.linalg as linalg
import numpy as np
N = int(input())
A = list(map(int,input().split()))
#
b = np.array([a*2 for a in A])
A = []
for i in range(N):
    a = [0]*N
    if i==N-1:
        a[0]=1
        a[N-1]=1
    else:
        a[i]=1
        a[i+1]=1
    A.append(a)
A = np.array(A)
LU = linalg.lu_factor(A)
x = linalg.lu_solve(LU,b)
x = [int(a) for a in x]
print(*x)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
from copy import deepcopy

N = int(input())
inputs = np.array([int(s) for s in input().split()])

vector = deque([1, 1] + [0]*(N-2))
A = []
for _ in range(N):
    A.append(deepcopy(vector))
    vector.rotate(1)
A = np.array(A)

x = np.linalg.solve(A, 2*inputs)
print(' '.join(str(int(i)) for i in x))

Submission status: Time Limit Exceeded

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

c = S
for j in range(N // 2):
  c -= 2 * A[(N-1+(j+1)*2) % N - 1]
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
sign=[1 if i%2==0 else -1 for i in range(n)]
a=np.array(a)
sign=np.array(sign)
plusA=a*sign
minusA=a*sign*-1
# print(plusA,minusA)
for i in range(n):
    if i%2==0:
        # print(minusA[:i],plusA[i:])
        print(np.sum(minusA[:i])+np.sum(plusA[i:]),end=' ')
    else:
        # print(plusA[:i],minusA[i:])
        print(np.sum(plusA[:i])+np.sum(minusA[i:]),end=' ')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([a for a in A[1:N:2]])
ans = "%d"%(x1*2)
x = x1
for a in A[:-1]:
  x = a-x
  ans += " %d"%(x*2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
# E = 0.5 * (np.eye(n) + np.eye(n, n, 1) + np.eye(n, n, -n + 1))
vec = (-1) ** np.arange(n)
print(' '.join([str(int(np.dot(np.roll(vec, i), a))) for i in range(n)]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
A = [int(i) for i in input().split()]
G = [[int(i in (j,(j+1)%N)) for i in range(N)] for j in range(N)]
kakudai = np.array(G)
X=np.linalg.solve(G,A)
print(*[int(x*2) for x in X])

Submission status: Time Limit Exceeded

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = InputToInt()

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

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):
        if i <= j:
            B[i] += A[j]*(-1)**(j-i)
        else:
            B[i] += A[j]*(-1)**(i-j+1)
    print(B[i])

Submission status: Time Limit Exceeded

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

for i in range(n):
    a2 = a[i:] + a[:i]
    b = a2[1:n:2]
    c = a2[2:n-1:2]
    ans += str(a2[0]+a2[n-1]+sum(c)-sum(b))
    if i != n-1:
        ans += ' '

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

matrix=[]
for i in range(N-1):
  array=[0]*i + [1/2,1/2] + [0]*(N-i-2)
  matrix.append(array)
matrix.append([1/2]+[0]*(N-2)+[1/2])

#print(matrix)
mat = np.matrix(matrix)
#print(mat)
mat_rev=mat**-1
#print(mat_rev)

prod=np.dot(mat_rev,arr)
prod_list=prod.tolist()

prod_list_int=[]
for p in prod_list[0]:
  prod_list_int.append(str(int(p)))
  
#print(prod_list_int)
print(" ".join(prod_list_int))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())

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

matA = [[0] * N for _ in range(N)]
y = [0] * N
for i in range(N):
    matA[i][i] = 1
    matA[i][(i+1)%N] = 1

matA = np.matrix(matA)

y = []
for i in A:
    y += [[2 * i]]

inverseA = np.linalg.inv(matA) * y

# print (matA)
# print (inverseA)

lst = inverseA.tolist()
for i in lst:
    print (int(i[0]), end =' ')
print ()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from scipy import linalg

N = int(input())
A = [int(i) for i in input().split()]
b = np.array([2*i for i in A])
B = []
for i in range(N):
    l = [0] * N
    l[i % N] = 1
    l[(i+1)%N] = 1
    B.append(l)
A = np.array(B)
LU = linalg.lu_factor(A)
a = map(int, np.linalg.solve(A, b))
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
dam=[int(x)*2 for x in input().split()]
a=[[0]*n for x in range(n)]
for i in range(n):
    a[i][i],a[i][(i+1)%n]=1,1
a=np.array(a)
dam=np.array(dam)
ans=np.linalg.solve(a,dam)
print(" ".join([str(int(ans[i])) for i in range(n)]))