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 = list(map(int, input().split()))
first = a_list[0]

mem = {}
for i in range(1, n + 1):
    mem[i] = {}

counter = 0

for i in range(first + 1):
    curr = i
    arr = [0] * (n + 1)
    arr[0] = curr * 2

    valid = True
    for j in range(0, n):
        curr = arr[j]
        nxt = 0
        if curr not in mem[j + 1]:
            nxt = int(( a_list[j] - curr / 2) * 2)
            mem[j + 1][curr] = nxt
            counter += 1
        else:
            nxt = mem[j + 1][curr]

        if nxt < 0:
            valid = False
            break
        arr[j + 1] = nxt

    if not valid:
        continue

    if arr[0] == arr[n]:
        print(*arr[:n])
        break

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
aList=list(map(int,input().split()))
rList=[]
for i in range(n):
	r = 0
	for j in range(n):
		k = (i+j)%n
		if j%2 == 0:
			#print('plus')
			r += aList[k]
			#print(aList[k])
		else:
			#print('minus')
			r -= aList[k]
			#print(aList[k])
	rList.append(r)

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

Submission status: Time Limit Exceeded

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

for i in range(n):
	r = 0
	for j in range(n):
		k = (i+j)%n
		if j%2 == 0:
			#print('plus')
			r += aList[k]
			#print(aList[k])
		else:
			#print('minus')
			r -= aList[k]
			#print(aList[k])
	print(str(r) ,end=' ')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
	N = int(input())
	dam = np.array(list(map(int, input().split())))
	
	index_ = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
	ans = []
	for i in range(N):
		ans.append(str(np.dot(dam, index_)))
		index_ = np.roll(index_, 1)
	
	print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
	N = int(input())
	dam = np.array(list(map(int, input().split())))

	index_ = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
	ans = np.array([])
	for i in range(N):
		ans = np.append(ans, np.dot(dam, index_))
		index_ = np.roll(index_, 1)
	ans = [str(int(i)) for i in ans]

	print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
from_pos, from_neg = [], []
for i, a in enumerate(list(map(int, input().split()))):
  if i%2 == 0:
    from_pos.append(a)
    from_neg.append(-1*a)
  else:
    from_pos.append(-1*a)
    from_neg.append(a)    

ans = []
for i in range(N):
  if i%2== 0:
    ans.append(sum(from_neg[:i])+sum(from_pos[i:]))
  else:
    ans.append(sum(from_pos[:i])+sum(from_neg[i:]))
print(*ans)

Submission status: Time Limit Exceeded

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

from_pos, from_neg = [], []
for i in range(N):
  if i%2 == 0:
    from_pos.append(alist[i])
    from_neg.append(-1*alist[i])
  else:
    from_pos.append(-1*alist[i])
    from_neg.append(alist[i])    

ans = []
for i in range(N):
  if i%2== 0:
    ans.append(sum(from_neg[:i])+sum(from_pos[i:]))
  else:
    ans.append(sum(from_pos[:i])+sum(from_neg[i:]))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
    
ans = []
for i in range(N):
  sign = 1
  mi = 0
  for j in range(i,i+N):
    if j <= N-1:
      mi += sign*alist[j]
    else:
      mi += sign*alist[j-(N)]
    sign *= -1
  ans.append(mi)
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dumorig = list(map(int,input().split()))
temp = 0
yama =[]
oddeven=1

for i in range(len(dumorig)):
  j=i
  while j<len(dumorig)-1:
    temp+=dumorig[j]*oddeven
    j+=1
    oddeven*=-1
  temp+=dumorig[j]*oddeven
  j=0
  oddeven*=-1
  while j<i:
    temp+=dumorig[j]*oddeven
    j+=1
    oddeven*=-1
  yama.append(temp)
  temp=0
  oddeven=1
  


print(*yama)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

    b[i]=A[i]*2

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
*A, = map(int, input().split())
X = []
for _ in range(n):
    X += [sum(A[::2])-sum(A[1::2])]
    A += [A.pop(0)]
print(*X)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
*A, = map(int, input().split())
A = np.array(A)
X = []
for _ in range(n):
    X += [sum(A[::2])-sum(A[1::2])]
    A = np.roll(A, -1, 0)
print(*X)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
	N = int(input())
	dam = np.array(list(map(int, input().split())))

	index_ = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
	ans = np.array([])
	for i in range(N):
		ans = np.append(ans, np.dot(dam, index_))
		index_ = np.roll(index_, 1)
	ans = [str(int(i)) for i in ans]

	print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

if __name__ == '__main__':
	N = int(input())
	dam = np.array(list(map(int, input().split())))

	index_ = np.array([1 if i % 2 == 0 else -1 for i in range(N)])
	ans = np.array([])
	for i in range(N):
		index_ = np.roll(index_, 1)
		ans = np.append(ans, np.dot(dam, index_))
	ans = np.roll(ans, 1)
	ans = [str(int(i)) for i in ans]

	print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
import numpy as np

def rain_volume(A, N):
    A_citer = it.cycle(A)
    X = np.array([0]*N)
    for i in range(N):
        if i%2 == 0:
            A_p = [next(A_citer) for i in range(N)]
            X += A_p
            next(A_citer)
        elif i%2 != 0:
            A_m = [-next(A_citer) for i in range(N)]
            X += A_m
            next(A_citer)
    return X

if __name__ == '__main__':
    N = int(input())
    A = np.array(list(map(int, input().split(' '))))

    #N = 10**4 - 1
    #A = [10**9]*N
    print(' '.join(map(str, rain_volume(A, N))))

Submission status: Time Limit Exceeded

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

from numpy.linalg import solve
left=[]
for i in range(N):
    tmp=[0]*N
    tmp[i]=1
    if i==N-1:
        tmp[0]=1
    else:
        tmp[i+1]=1
    left.append(tmp)
right=[2*x for x in a_list]
ans=[str(int(x)) for x in solve(left, right)]
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = list(map(int, input().split()))
y = [0] * N

def shift(l, n):
    return l[n:] + l[:n]
shifted_x = shift(x, -1)
for i in range(N):
  shifted_x = shift(shifted_x, 1)
  odd = sum([n for i, n in enumerate(shifted_x) if i % 2 == 1])
  even = sum([n for i, n in enumerate(shifted_x) if i % 2 == 0])
  y[i] = even - odd


str_y = map(str, y)
output = " ".join(str_y)
print(output)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = list(map(int, input().split()))
y = [sum(x)] * N
  
for i in range(N):
  for j in range(N):
    if j % 2 == 1:
      index = (i + j) % N
      y[i] -= 2 * x[index]
    
str_y = map(str, y)
output = " ".join(str_y)
print(output)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = [0] * N
y = [0] * N

for i, A in enumerate(input().split()):
  x[i] = int(A)
  
for i in range(N):
  for j in range(N):
    index = (i + j) % N
    y[i] += ((-1) ** j) *  x[index]
    
str_y = map(str, y)
output = " ".join(str_y)
print(output)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
for i in range(0,2*min( a[0],a[N-1] )+1,2):
    s=[i/2]
    answer=[]        
    for n in range(N):
        s.append(a[n]-s[n])
        answer.append(int(2*s[n]))
    if s[N-1]+i/2==a[N-1]:
        print(*answer)
        exit(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum1=0
sum2=0
for i in range(a):
  sum1=sum1+N[i]
  if i%2==1:
      sum2=sum2+N[i]

sum1=int(sum1/2)

M=[0]*a
M[0]=sum1-sum2

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

b=''
for i in range(a-1):
 b=b+str(M[i]*2)+' '

b=b+str(M[a-1]*2)

print(b)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in  input().split()]
sigma=0
for i in a:
    sigma+=i
sigma/=2
sigma=int(sigma)

x=[sigma for i in range(n)]


for i in range(n):
    g=i+1
    g=g%n
    for j in range(int((n-1)/2)):
        x[i]-=a[g]
        g+=2
        g=g%n
        
        
x2=[str(i*2) for i in x]
print(" ".join(x2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
rain = [0]*n
sign = [-1, 1]
for i in range(n):
    ex = a[:i] + a[i+1:]
    even = [ex[i] for i in range(n-1) if i%2 == 0]
    odd = [ex[i] for i in range(n-1) if i%2 == 1]
    rain[i] += a[i] + sign[i%2]*sum(even) + sign[(i+1)%2]*sum(odd)
print(*rain)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

det = [[0.5 if (i + j) % 2 == 0 else -0.5 for i in range(N-1)] for j in range(N)]
for idx,arr in enumerate(det):
    arr.insert(idx+1,0.5)
det = np.array(det).T
x = map(str,map(int,np.dot(det,A) * 2))

print(' '.join(x))

Submission status: Time Limit Exceeded

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

l = [[1 if j == i or j - 1 == i else 0 for j in range(N)] for i in range(N)]
l[-1][0] = 1
det = np.linalg.inv(l)

x = map(str,map(int,np.dot(det,A) * 2))

print(' '.join(x))

Submission status: Time Limit Exceeded

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

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

for i in range(int(Y)):
  for j in range(int(Y)):
    if i == int(Y) - 1:
      if j == 0 or j == int(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())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

x1=sum([pow(-1, i)*A[i] for i in range(N)])/2
print(int(2*x1), end=' ')

for i in range(1, N):
  print(int(2*(sum([pow(-1, k-i)*A[k] for k in range(i, N)])-pow(-1, i)*x1)), end=' ')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
total=0
b=[0]*n
a_cycle=a*2

for i in range(n):
  total+=a[i]
for i in range(n):
  a_tot=0
  for j in range(n//2):
  	a_tot+=a_cycle[i+2*j+1]
  b[i]=total-2*a_tot
print(*b)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

def rain_volume(A, N):
    A_citer = it.cycle(A)
    X = [0]*N
    for i in range(N):
        if i%2 == 0:
            A_p = [next(A_citer) for i in range(N)]
            X = [sum(t) for t in zip(X, A_p)] 
            next(A_citer)
        if i%2 != 0:
            A_m = [-next(A_citer) for i in range(N)]
            X = [sum(t) for t in zip(X, A_m)]
            next(A_citer)
    return X

if __name__ == '__main__':
    N = int(input())
    A = [t for t in map(int, input().split(' '))]
    print(' '.join(map(str, rain_volume(A, N))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))

@lru_cache(maxsize=2)
def f(i):
    if i >= 2:
        return f(i - 2) + 2 * A[i - 1] - 2 * A[i - 2]
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = (f(i) for i in range(N))

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] = (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

#   A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# - A[0] + A[1] + A[2] - A[3] + A[4] = B[2]

#   A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# - A[1] + A[2] + A[3] - A[4] + A[0] = B[3]

# B[3] = B[1] + 2 * A[2] - 2 * A[1]

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

def f(i):
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = (f(i) for i in range(N))

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] = (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

def f(i):
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = (f(i) for i in range(N))

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] - (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

A = { i: a for i, a in enumerate(A)}

def f(i):
    total = 0
    for j in range(N):
        if j % 2 == 0:
            total += A[(i + j) % N]
        else:
            total -= A[(i + j) % N]
    return total

B = [f(i) for i in range(N)]

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] - (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

AA = { i: a for i, a in enumerate(A)}

def f(i):
    total = 0
    for j in range(N):
        total += AA[(i + j) % N] * (1 if j % 2 == 0 else -1)
    return total

B = [f(i) for i in range(N)]

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = (B[0] - B[2]) // 2
# A[1] - A[2] = (B[1] - B[3]) // 2
# A[2] - A[3] = (B[2] - B[4]) // 2
# A[3] - A[4] = (B[3] - B[0]) // 2
# A[4] - A[0] - (B[4] - B[1]) // 2

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

def f(i):
    total = 0
    for j in range(N):
        total += A[(i + j) % N] * (1 if j % 2 == 0 else -1)
    return str(total)

B = [f(i) for i in range(N)]

print(*B)

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[0] // 2

# 2 * A[0] = B[0] + B[1]
# 2 * A[1] = B[1] + B[2]
# 2 * A[2] = B[2] + B[0]

# 2 * A[2] - 2 * A[1] = B[0] - B[1]
# 2 * A[0] - 2 * A[2] = B[1] - B[2]
# 2 * A[1] - 2 * A[0] = B[0] - B[2]

# A[0] - A[2] + A[1] = B[1]

# B[i] = A[i] + A[i - 1] - A[i + 1]

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = B[0] - B[2]
# A[1] - A[2] = B[1] - B[3]
# A[2] - A[3] = B[2] - B[4]
# A[3] - A[4] = B[3] - B[0]
# A[4] - A[0] - B[4] - B[1]

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

def f(i):
    total = 0
    for j in range(N):
        total += A[(i + j) % N] * (1 if j % 2 == 0 else -1)
    return total

B = [f(i) for i in range(N)]

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

Submission status: Time Limit Exceeded

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

def f(i):
    total = 0
    for j in range(N):
        total += A[(i + j) % N] * (1 if j % 2 == 0 else -1)
    return total

B = [f(i) for i in range(N)]

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

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[0] // 2

# 2 * A[0] = B[0] + B[1]
# 2 * A[1] = B[1] + B[2]
# 2 * A[2] = B[2] + B[0]

# 2 * A[2] - 2 * A[1] = B[0] - B[1]
# 2 * A[0] - 2 * A[2] = B[1] - B[2]
# 2 * A[1] - 2 * A[0] = B[0] - B[2]

# A[0] - A[2] + A[1] = B[1]

# B[i] = A[i] + A[i - 1] - A[i + 1]

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = B[0] - B[2]
# A[1] - A[2] = B[1] - B[3]
# A[2] - A[3] = B[2] - B[4]
# A[3] - A[4] = B[3] - B[0]
# A[4] - A[0] - B[4] - B[1]

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

def f(i):
    return sum(A[(i + j) % N] * (1 if j % 2 == 0 else -1) for j in range(N))

B = [f(i) for i in range(N)]

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

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[0] // 2

# 2 * A[0] = B[0] + B[1]
# 2 * A[1] = B[1] + B[2]
# 2 * A[2] = B[2] + B[0]

# 2 * A[2] - 2 * A[1] = B[0] - B[1]
# 2 * A[0] - 2 * A[2] = B[1] - B[2]
# 2 * A[1] - 2 * A[0] = B[0] - B[2]

# A[0] - A[2] + A[1] = B[1]

# B[i] = A[i] + A[i - 1] - A[i + 1]

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = B[0] - B[2]
# A[1] - A[2] = B[1] - B[3]
# A[2] - A[3] = B[2] - B[4]
# A[3] - A[4] = B[3] - B[0]
# A[4] - A[0] - B[4] - B[1]

# A[0] - A[1] + A[2] - A[3] + A[4] = B[0]
# A[1] - A[2] + A[3] - A[4] + A[0] = B[1]
# A[2] - A[3] + A[4] - A[0] + A[1] = B[2]
# A[3] - A[4] + A[0] - A[1] + A[2] = B[3]

Submission status: Time Limit Exceeded

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

def f(i):
    return sum(A[(i + j) % len(A)] * (1 if j % 2 == 0 else -1) for j in range(len(A)))

B = [f(i) for i in range(len(A))]

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

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[0] // 2

# 2 * A[0] = B[0] + B[1]
# 2 * A[1] = B[1] + B[2]
# 2 * A[2] = B[2] + B[0]

# 2 * A[2] - 2 * A[1] = B[0] - B[1]
# 2 * A[0] - 2 * A[2] = B[1] - B[2]
# 2 * A[1] - 2 * A[0] = B[0] - B[2]

# A[0] - A[2] + A[1] = B[1]

# B[i] = A[i] + A[i - 1] - A[i + 1]

# A[0] = B[0] // 2 + B[1] // 2
# A[1] = B[1] // 2 + B[2] // 2
# A[2] = B[2] // 2 + B[3] // 2
# A[3] = B[3] // 2 + B[4] // 2
# A[4] = B[4] // 2 + B[0] // 2

# A[0] - A[1] = B[0] - B[2]
# A[1] - A[2] = B[1] - B[3]
# A[2] - A[3] = B[2] - B[4]
# A[3] - A[4] = B[3] - B[0]
# A[4] - A[0] - B[4] - B[1]

# A[0] - A[1] + A[2] - A[3] + A[4] = 2 * B[0]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_large = A * 2
rain = []
S = sum(A)
check = 1
while len(rain) != N:
    sub = sum(A_large[check:check + N - 1:2])
    rain.append(S - sub * 2)
    check += 1
for _ in rain:
    print(_)

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:
N = int(input())
A = list(map(int, input().split()))

# X1の拘束条件
# A1 * 2 && last
X1_up = min(A[0], A[-1]) * 2
Xlast_up = min(A[-1], A[-2]) * 2

def chk(x1, xlast):
    prev = x1
    for index in range(len(A)-1):
        d = 2 * (A[index] - int(prev //2))
        prev = d
    return prev == xlast


ansx1 = -1
ansxlast = -1
is_found = False
for x1 in range(0,X1_up + 1, 2):
    for xlast in range(0, Xlast_up + 1, 2):
        if x1 == 2 * A[-1] - xlast and chk(x1, xlast): 
            ansx1 = x1
            ansxlast = xlast
            is_found = True
            break
    if is_found:
        break


ans = []
ans.append(ansx1)
prev = ansx1
for index in range(len(A)-1):
    d = 2 * (A[index] - int(prev //2))
    ans.append(d)
    prev = d

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
LA = []
for i in range(N):
  LA.append([1 if j==i or j==i+1 else 0 for j in range(N)])

LA[N-1][0] = 1
LA = np.array(LA)
A = np.array(A)
X = np.dot(np.linalg.inv(LA),A)
X = list(map(lambda i:int(i*2),X))
for ans in X:
  print(ans,end=' ')

Submission status: Time Limit Exceeded

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

water_sum = sum(a)
kotae = [water_sum for _ in range(n)]

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

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

Submission status: Time Limit Exceeded

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

double_inputs = list(map(lambda x: x * 2, inputs))
ans = [0 for _ in range(N)]
for i in range(N):
    total = sum(inputs)
    if i == 0:
        for j in range((N - 1) // 2):
            total -= double_inputs[(i+1+2*j)%N]
            ans[i] = total
    elif i == N - 1:
        ans[i] = double_inputs[-1] - ans[0]
    else:
        ans[i] = double_inputs[i-1] - ans[i-1]

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

Submission status: Time Limit Exceeded

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

double_inputs = list(map(lambda x: x * 2, inputs))
for i in range(N):
    total = sum(inputs)
    for j in range((N - 1) // 2):
        total -= double_inputs[(i+1+2*j)%N]
    print(total)

Submission status: Time Limit Exceeded

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

res = ""
for i in range(N):
    res_tmp = 0
    for j, a in enumerate(A[i:i+N]):
        res_tmp += a if j % 2 == 0 else -a
    # res.append(res_tmp)
    res += (str(res_tmp) + " ")
    # print(res_tmp, end=" ")
print(res[:-1])

Submission status: Time Limit Exceeded

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

l = l+l
xl = []
for i in range(n):
    a = 0
    m = False
    for j in range(i, n+i):
        if m is False:
            a += l[j]
            m = True
        else:
            a -= l[j]
            m = False
    xl.append(a)
    
print(" ".join(map(str, xl)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans=[0] * n

while (max(a)!=0):
    idx=np.argmax(a)
    while(idx!=n-1):
        if a[idx+1]==a[idx]:
            idx = idx+1
        else:
            break
    if max(a)-sorted(a)[-2]==0:
        if max(a)-sorted(a)[-3]==0:
            dif = 1
        else:
            dif = max(a)-sorted(a)[-3]
    else:
        dif = max(a)-sorted(a)[-2]

    if dif==0:
        dif = max(a) - sorted(a)[-3]

    if idx==0:
        a[0] -= dif
        a[n-1] -= dif
        ans[0] += dif*2

    else:
        a[idx] -= dif
        a[idx-1] -= dif
        ans[idx] += dif*2

print(*ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
  f = True
  b = a[i:]+a[:i]
  for j in b:
    if f:
      ans[i] += j
      f = False
    else:
      ans[i] -= j
      f = True
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
  f = True
  for j in a[i:]+a[:i]:
    if f:
      ans[i] += j
      f = False
    else:
      ans[i] -= j
      f = True
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
# l = int(((N*N)+1)/2)
b = []
for i in range(int(((N*N)+1)/2)):
    b.append(1)
    b.append(-1)
# b = b[:-1]
c = (np.array(b[:-1])).reshape(N,N)
# print(b)
# c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = ( np.triu(c) - np.tril(c) + np.eye(N) )
# g = np.eye(N)
x = (np.dot(inv,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
l = int(((N*N)+1)/2)
b = []
for i in range(l):
    b.append(1)
    b.append(-1)
b = b[:-1]
c = (np.array(b)).reshape(N,N)
# print(b)
# c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
# d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
g = np.eye(N)
x = 2*(np.dot(inv,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
l = int(((N**2)+1)/2)
b = []
for i in range(l):
    b.append(1)
    b.append(-1)
b = np.array(b)
# print(b)
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# print(c)
d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
g = np.eye(N)
x = 2*(np.dot(inv,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
l = int(((N**2)+1)/2)
b = []
for i in range(l):
    b.append([1,-1])
b = np.array(b).reshape(1,2*l)
c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
d = c.reshape(N,N)
inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
g = np.eye(N)
x = 2*(np.dot(inv,a))
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

start_index = A_LIST.argmin()
for a_part in range(A_LIST[start_index]+1):
    x_list = np.zeros(N)
    x_list[start_index] = a_part
    tmp_index = start_index
    for _ in range(N-1):
        next_index = (tmp_index+1) % N
        x_list[next_index] = A_LIST[tmp_index] - x_list[tmp_index]
        tmp_index = next_index
    if x_list[start_index] + x_list[next_index] == A_LIST[next_index]:
        break
ans = ' '.join((x_list * 2).astype(int).astype(str))
print(ans)