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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

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

	ans = [0 for _ in range(N)]
	
	ed = min(A[0]*2, A[-1]*2)
	s = 0
	if ed > 1000000 * 2:
		s = 1000000000
	for i in range(s, ed+1, 2):
		fin = True
		for j in range(N):
			if j == 0:
				ans[j] = i
				continue
			tmp = (A[j-1] - (ans[j-1] / 2))*2

			if tmp < 0 or tmp % 2 == 1:
				fin = False
				break
			else :
				ans[j] = int(tmp)
		
		if fin == False:
			pass
		else:
			if (ans[-1] / 2) + (ans[0] / 2) == A[-1]:
				#print("sss")
				break

	ans = [str(a) for a in ans]
	print(' '.join(ans))


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from sys import exit

N = int(input())

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


a = 0
for i in range(N - 1):
    if i % 2 == 0:
        a -= A[i]
    else:
        a += A[i]

n = A[N - 1] + a

_x = n
ans = []
for i in range(N - 1):
    if i == 0:
        ans.append((A[N - 1] - _x / 2) * 2)
        _x = (A[N - 1] - _x / 2) * 2
    else:
        ans.append((A[i - 1] - _x / 2) * 2)
        _x = (A[i - 1] - _x / 2) * 2

ans.append(n)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=[0]*N
for i in range(N-1):
    a[i]=A[i+1]-A[i]
a[N-1]=A[0]-A[N-1]
S=sum(A)
t=[0]*N
for i in range(0,N,2):
    if i+2==N+1:
        t[1]=t[i]+a[i]*2
    else:
        t[i+2]=t[i]+a[i]*2
for i in range(1,N-2,2):
    t[i+3]=t[i+1]+a[i+1]*2
s=sum(t)
d=(S-s)//N
ans=[d+i for i in t]
print(' '.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(lambda x: int(x),input().split()))
X = [(-1)**i for i in range(N)]
for i in range(N):
    c = 0
    for j in range(N):
        c += A[j]*X[(j+i)%N]
    print(c,end=" ")

Submission status: Wrong Answer

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

def solve(idx, m):
    x[idx] = m
    # (x[i] + x[i+1]) / 2 = a[i]
    for i in range(n-1):
        x[i+1] = 2 * a[i] - x[i]

#    return sum(x) == sum(a)
    return sum(x) > sum(a)


l = 0
r = 100000000
m = (l + r) // 2

while l <= r:
    if solve(0, m):
        r = m - 1
        m = (l + r) // 2
    else:
        l = m + 1
        m = (l + r) // 2

#m = m - 1
solve(0, m)

# for i in range(a[0]+a[1] + 1):
#     if solve(0, i):
#         # print("found!")
#         # print(x)
#         break

print(' '.join([str(i) for i in x]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from numpy import roll, array

n = int(input())
x = input().split(' ')
a = [int(v) for v in x]

b = roll(a, 1)

ans = (array(a) + array(b)) / 2
ans = list(ans)

N = [str(int(p)) for p in ans]

print(' '.join(N))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
input=lambda : sys.stdin.readline().rstrip()

n=int(input())
a=list(map(int,input().split()))
l,r=0,min(a[0],a[-1])+10
ans=-1
while l+1<r:
    mid = (l+r)//2
    tmp=a[0]
    fl=mid*2
    xx=a[-1]
    for i in range(n):
        if tmp-fl//2<0:
            r=mid
            break
        else:
            if i==0:
                xx-=fl//2
                if xx<0:
                    r=mid
                    break
            if i==n-1:
                tmp-=fl//2
            fl=(tmp-fl//2)*2
            if i!=n-1:
                tmp=a[i+1] if i!=n-2 else xx
    else:
        if tmp>=0:
            l=mid
        else:
            r=mid
ans=l*2
ans_a=[]
for i in range(n):
    ans_a.append(ans)
    ans=(a[i]-ans//2)*2
print(*ans_a)

Submission status: Wrong Answer

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

argminD = np.argmin(D)
for i in range(0, D[argminD]*2+1, 2):
  first = int(i)
  final = D[argminD]*2 - int(i)
  for j in range(argminD+1, N+argminD):
    j = j % N
    final = D[j]*2-final
    if final < 0:
      break
  if first == final:
    result = [str(first)]
    final = D[argminD]*2 - first
    for j in range(argminD+1, N+argminD):
      j = j % N
      result.append(str(final))
      final = D[j]*2-final
    if argminD == 0:
      print(" ".join(result))
    else:
      #print(result)
      #print(argminD)
      print(" ".join(result[argminD-1:]) + " " +  " ".join(result[:argminD-1]))
    sys.exit(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = [int(i) * 2 for i in input().split()]

L1 = [[0] * n for _ in range(n)]
for i in range(n):
    if i + 1 <= n-1:
        L1[i][i] = 1
        L1[i][i+1] = 1
    else:
        L1[i][i] = 1
        L1[i][0] = 1
        
L1 = np.linalg.inv(L1)
L2 = np.array(A)

Submission status: Wrong Answer

Solution code:
from numpy import roll, array

n = int(input())
x = input().split(' ')
a = [int(v) for v in x]

b = roll(a, 1)

ans = (array(a) + array(b)) / 2
ans = list(ans)

N = [str(p) for p in ans]

print(' '.join(N))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(int(i) for i in input().split())
st = l.index(min(l))
ll = l[st:]
ll.extend(l[:st])

y = 0
for i in range(0,ll[0]+1,2):
    lx = ll[:]
    x = [0]*n
    x[0] = i
    if i >= y:
        for ii in range(n):
            lx[ii-1] = lx[ii-1] - (x[ii]/2)
            lx[ii]  = lx[ii]  - (x[ii]/2)
            if lx[ii] < 0:
                y = i - lx[ii]
                break

            if ii < n-1:
                x[ii+1] = lx[ii] * 2
            elif lx[ii] != 0:
                break
            else:
                res = x[-st:]
                res.extend(x[:-st])
                res = [int(z) for z in res]
                y = 10**10
                print(res)

Submission status: Wrong Answer

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

for i in range(N):
    m = min(A[i], A[(i+1)%N])
    ans[(i+1)%N] += m * 2
    A[i] -= m
    A[(i+1)%N] -= m
for _ in range(10):
    for i in range(N):
        if A[i] >= 2:
            ans[(i+1)%N] += 2
            ans[(i+2)%N] -= 2
            A[(i+2)%N] += 1
            ans[(i)%N] += 2
            ans[(i-1)%N] -= 2
            A[(i-2)%N] += 1
            A[i] -= 2
    for i in range(N):
        m = min(A[i], A[(i+1)%N])
        ans[(i+1)%N] += m * 2
        A[i] -= m
        A[(i+1)%N] -= m
ans = map(str, ans)
print(" ".join(ans))

Submission status: Wrong Answer

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

def initial():
    rain0 = 0
    for i in range(n):
        rain0 += ((-1)**i) * ds[i]
    return rain0

rain0 = initial()
rains = [rain0]

def solve():
    rain_i = rain0
    for i in range(n-1):
        if i != n-1:
            rain_i_ = 2 * ds[i] - rain_i
        else:
            rain_i_ = 2 * ds[i] - rain0
        
        rains.append(rain_i_)
        rain_i = rain_i_
        
solve()
print(rains)

Submission status: Wrong Answer

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

for i in range(n):
    now = (i+2)%n
    others = 0
    while now%n != (i+1)%n:
        others += l[(now-1)%n]
        now = (now+2)%n
    ans.append(all_rain-others*2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

n = int((A[N-1] - M[0]//2 - M[N-1]//2)//2)

for i in range(N):
    if i%2 == 0:
        print(M[i] + 2*n, end=" ")
    else:
        print(M[i] - 2*n, end=" ")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa
exit()

A = np.zeros((n, n), dtype=np.int)

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

exit()

Submission status: Wrong Answer

Solution code:
N = int(input())

# A_i たまった水
A = list(map(int,input().split()))

A_total = sum(A)

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

# 0,2,3,...
tmp_sum = 0
for j in range((N - 1) // 2):
    tmp_sum += (2 * A[(0+1 + (j * 2)) % N])
ans[0] = A_total - tmp_sum
for i in range(1,N//2):
    tmp_sum = tmp_sum - A[i*2 % N] + A[(i*2 + N) %N]
    ans[i] = A_total - tmp_sum

# 1,3,4...
tmp_sum = 0
for j in range((N - 1) // 2):
    tmp_sum += (2 * A[(1+1 + (j * 2)) % N])
ans[1] = A_total - tmp_sum
for i in range(1,N//2):
    tmp_sum = tmp_sum - A[((i*2)+1) % N] + A[(((i*2)+1) + N) %N]
    ans[i] = A_total - tmp_sum


ans_s = str(ans[0])
for a_i in ans[1:]:
    ans_s = ans_s + " " + str(a_i)
print(ans_s)

Submission status: Wrong Answer

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = i2nn()
    B = [0] * N
    B[0] = min(A[0], A[-1]) * 2
    for i in range(1, N):
        B[i] = (A[i-1] - B[i-1] // 2) * 2
    #print(B)
    d = (A[-1] - B[-1]) // 2
    for i in range(N):
        if (i & 1) == 0:
            B[i] += d
        else:
            B[i] -= d
    #print(d)
    print(' '.join([str(n) for n in B]))

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A_list = [int(i) for i in input().split()]
A_matrix = np.matrix(A_list)
N_matrix_list=[]
for i in range(N):
    tmp = [0]*N
    tmp[i]=1
    if i == N-1:
        tmp[0]=1
    else:
        tmp[i+1]=1
    N_matrix_list.append(tmp)
N_matrix = np.matrix(N_matrix_list)
N_matrix_inv = N_matrix.I
X_matrix = N_matrix_inv * A_matrix.T *2
ans = X_matrix.T.astype(int).tolist()[0]
print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
M = [sum(A)] * N
for j in range(N):
    for i in range(1, N, 2):
        M[j] -= A[(i + j) % N] * 2
print(M)

Submission status: Wrong Answer

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

cmid=0
mid=AL[0]*2
left=0
right=AL[0]*4
while True:
    if cmid==mid:
        print('e')
        break
    cmid=mid
    
    flag=True
    mid=(left+right)//2
    k=mid
    L=[k]
    for i,a in enumerate(AL):
        if a<k//2:
            if i%2==0:#midを減らす
                right=mid-1
                flag=False
                break
            else:#midを増やす
                left=mid+1
                flag=False
                break
        else:
            k=(a-k//2)*2
            L.append(k)

    if flag:
        if mid==k:
            print(" ".join([str(x) for x in L[:-1]]))
            break
        elif (k+mid)/2>a:#減らす
            right=mid-1
        else:#増やす
            left=mid+1

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

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

y = np.zeros((n, 1), dtype=np.int)

for i, wa in enumerate(a):
    y[i][0] = wa
exit()

A = np.zeros((n, n), dtype=np.int)

for i in range(n-1):
    A[i][i] = 1
    A[i][i+1] = 1

A[n-1][n-1] = 1
A[n-1][0] = 1

exit()

Submission status: Wrong Answer

Solution code:
N = int(input())

# A_i たまった水
A = list(map(int,input().split()))

A_total = sum(A)

ans = [0 for _ in range(N)]
for i in range(N):
    tmp_sum = 0
    for j in range((N - 1) // 2):
        tmp_sum += (2 * A[(i+1 + (j * 2)) % N])
    ans[i] = A_total - tmp_sum

# 0,2,3,...
tmp_sum = 0
for j in range((N - 1) // 2):
    tmp_sum += (2 * A[(0+1 + (j * 2)) % N])
ans[0] = A_total - tmp_sum
for i in range(1,N//2):
    tmp_sum = tmp_sum - A[i*2 % N] + A[(i*2 + N) %N]
    ans[i] = A_total - tmp_sum

# 1,3,4...
tmp_sum = 0
for j in range((N - 1) // 2):
    tmp_sum += (2 * A[(1+1 + (j * 2)) % N])
ans[1] = A_total - tmp_sum
for i in range(1,N//2):
    tmp_sum = tmp_sum - A[((i*2)+1) % N] + A[(((i*2)+1) + N) %N]
    ans[i] = A_total - tmp_sum


ans_s = str(ans[0])
for a_i in ans[1:]:
    ans_s = ans_s + " " + str(a_i)
print(ans_s)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

sum = int(np.sum(A) / 2)

ans = np.zeros(N)
for i in range(N):
    m = 0
    for j in np.arange(int((N-1)/2)):
        m += A[(i + j*2+1)%N]    
    ans[i] = int((sum - m) * 2)
    
print(ans.astype(np.int32))

Submission status: Wrong Answer

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

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

n = int(input())
a = list(map(int, input().split()))
ans = np.zeros(n, np.int8)

for i in range(0, a[0]*2+1, 2):
    ans[0] = i
    tempa = np.zeros(n, np.int8)
    for j in range(n):
        tempa[j] = ans[j % n] // 2
        if(j+1 != n):
            ans[(j + 1) % n] = (a[j] - tempa[j]) * 2
        #print(a, tempa,ans)
    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: Wrong Answer

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

start = A.index(min(A))
B = [0]*N
flag = False

for j in range(5*10000):    
    B[start] = 2 * j
    for i in range(start,start+N):
        B[(i+1)%N] = 2*A[i%N] - B[i%N]
        if B[(i+1)%N] < 0:
            break
        if (i+1)%N == start and B[start] == 2*j:
            flag = True
    if flag == True:
        break
        
for k in range(N):
    print(B[k], end=" ")

Submission status: Wrong Answer

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

x = [-1]*n

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

for i in range(1,n):
    x[i] = 2*a[i-1]-x[i-1]

print(x)

Submission status: Wrong Answer

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(2):  # 0,1はちゃんと調べる、それ以降はメモ化的に削る
    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


for j in range(1, 1+(N // 2)):
    sa = rain[0]
    sa -= water[2 * j-1]*2
    sa += water[2 * j - 2]*2
    rain[2 * j] = sum - sa
    if j * 2 == N - 1:
        break
    sa = rain[1]
    sa -= water[2 * j]*2
    sa += water[2 * j - 1]*2
    rain[2*j+1] = sum-sa


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
    m = min(A[i], A[(i+1)%N])
    ans[(i+1)%N] += m * 2
    A[i] -= m
    A[(i+1)%N] -= m
for _ in range(5):
    for i in range(N):
        if A[i] != 0:
            ans[(i+1)%N] += 2
            ans[(i+2)%N] -= 2
            A[(i+2)%N] += 1
            ans[(i)%N] += 2
            ans[(i-1)%N] -= 2
            A[(i-2)%N] += 1
            A[i] -= 2
    for i in range(N):
        m = min(A[i], A[(i+1)%N])
        ans[(i+1)%N] += m * 2
        A[i] -= m
        A[(i+1)%N] -= m
ans = map(str, ans)
print(" ".join(ans))

Submission status: Wrong Answer

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

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

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

    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i-1] - ans[i-1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N-1] - (ans[N-1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = (A[0] + A[N - 1]) / 2
    jump = N // 4

    while True:
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i*2) for i in ans]))

solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [int(i) for i in input().split()]
B = [0]*len(C)
ind = C.index(min(C))
A = C[ind:] + C[:ind]
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 tmp < 0:
            break
        if j == N:
            if tmp == B[0]:
                flag = True
            break
        B[j] = tmp
    if flag:
        break
D = B[ind:] + B[:ind]
ans = " ".join(map(str, D))
print(ans)

Submission status: Wrong Answer

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

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

min_ind = 0
min_val = 3e9
for i in range(1, N):
    tmp = A[i]+A[i-1]
    if tmp < min_val:
        min_val = tmp
        min_ind = i

# ダムmin_indから決めていく
rain = [0 for i in range(N)]
start = min_ind
end = (start+N-1)%N
lim = min(A[end], A[start]) * 2
for r in range(0, lim, 2):
    rain[start] = r
    now = (start+1)%N
    pre = start
    ok = False
    while now != start:
        rain[now] = (A[pre] - rain[pre] // 2) * 2
        if A[now] < rain[now]//2:
            break
        now = (now+1)%N
        pre = (pre+1)%N
    if now == start:
        if rain[now] == (A[pre] - rain[pre]//2) * 2:
            ok = True
    if ok:
        for i in range(N):
            print(rain[i], end="")
            if i != N-1:
                print(" ",end="")
            else:
                print()
        break

Submission status: Wrong Answer

Solution code:
rem = pow(10,9)+7

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
n = ip()
a = iprow()
b = []
summer = sum(a)
left = 0
right = a[0]
startnow = a[0]//2
now = a[0]//2
s=0
while s != summer:
    s = 0
 #   print(now,summer)
    over = 0
    for i in range(n):
        s+=now
        now = a[i]-now
        if now < 0:
            over = 1
    if  over:
   #     print("over")
        right//=2+1
        now = (left+right)//2
        startnow = now
    elif s*2 < summer:
 #       print("under",s,left,right)
        left = startnow+1
        now = (left+right)//2
        startnow = now
    elif s*2==summer:
        now = startnow
        for i in range(n):
            if i != n-1:print(now*2,end = ' ')
            else :print(now*2)
            now = a[i]-now
        exit(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*n
for i in range(n):
  x[i] = sum(a)
  for j in range(0, i):
    if (j-i) % 2 == 0:
      x[i] -= 2*a[j]
  for j in range(i, n):
    if (j-i) % 2 == 1:
      x[i] -= 2*a[j]
print(x)

Submission status: Wrong Answer

Solution code:
import numpy

n = int(input())
a = [int(u) for u in input().split(" ")]
v = [[(1 if (v==u or v==u+1 or (v==0 and u==n-1)) else 0) for v in range(n)] for u in range(n)]
print(v)
w = numpy.linalg.inv(v)
x = list(numpy.dot(w,a))
print(" ".join([str(int(u*2)) for u in x]))

Submission status: Wrong Answer

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

for i in range(a[0]+1):
    ans = [i*2]
    diff = i

    for rep2 in range(1, n-1):
        dam = a[rep2] - diff
        ans += [dam*2]
        diff = dam
        if diff < 0:
            break
            
    if a[-1] - ans[-1]//2 == a[0]-i:
        print([(a[0]-i)*2] + ans)
        exit()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

cumevA = list(accumulate(A[::2]))
cumodA = list(accumulate(A[1::2]))

ans = [None] * N
for i in range(N):
    if i == 0:
        ans[i] = str(sumA - 2 * cumodA[-1])
    elif i == 1:
        ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[0]))
    elif i == N-1:
        ans[i] = str(sumA - 2 * (cumevA[-2]))
    else:
        if i % 2 == 0:
            ans[i] = str(sumA - 2 * (cumodA[-1] - cumodA[i//2 - 1] + cumevA[i // 2 - 1]))
        else:
            ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[(i+1)//2] + cumodA[(i-1) // 2]))

print(" ".join(ans))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())
A = LI()

mountains = [-1 for i in range(N)]
last = sum(A)//2
for i in range(0,N//2+1,2):
    last -= A[i]

mountains[-1] = last

for i in reversed(range(N-1)):
    mountains[i] = A[i] - mountains[i+1]

for i in range(N):
    print(mountains[i]*2,end=" ")

Submission status: Wrong Answer

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

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



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


    def check(A, x):
        ans = [x]
        for i in range(1, N):
            tmp = A[i-1] - ans[i-1]
            if tmp < 0:
                if i % 2 == 1:
                    return 1, ans
                else:
                    return -1, ans
            else:
                ans.append(tmp)

        tmp = A[N-1] - (ans[N-1])
        if x > tmp:
            return 1, ans
        elif x < tmp:
            return -1, ans
        else:
            return 0, ans

    x = min(A[0], A[N - 1])
    jump = N // 2

    i = 0
    while True:
        i += 1
        if i > 10:
            break
        ret, ans = check(A, x)
        if ret == 1:
            x = x - jump
        elif ret == -1:
            x = x + jump
        else:
            dprint(x, ret, ans, jump)
            break
        jump = max(jump // 2, 1)
        dprint(x, ret, ans, jump)

    print(" ".join([str(i*2) for i in ans]))

solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
diff = []
for i in range(N):
    d = A[(i+1)%N]-A[i]
    diff.append(d)
B = [0 for i in range(N)]
for i in range(N):
    if i%2 == 0:
        if i < N-2:
            B[i+2] = B[i]+diff[i]
for i in range(N):
    if i%2 == 1:
        if i == 1:
            B[1] = B[-1]+diff[-1]
        elif i < N-2:
            B[i+2] = B[i]+diff[i]
sa = sum(A)
sb = sum(B)
kari = ((sa//2)-sb)//N
for i in range(N):
    print(2*(kari+B[i]),end=" ")

Submission status: Wrong Answer

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
n = int(input())
a = list(map(int, input().split()))

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

cur = 0
x = 0
while True:
    if x > 4:
        break
    pre = cur
    ans = [0 for _ in range(n)]
    ans[0] = cur
    for i in range(n-1):
        cur = a[i] * 2 - cur
        ans[i+1] = cur
        if cur < 0:
            break
    if a[-1] * 2 == cur + pre:
        print(" ".join(list(map(str, ans))))
        break
    x += 1
    cur = x * 2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
lista = [int(i) for i in input().split()]

ans = [0]*n
sum_ = sum(lista)/2

tmp = 0
for i in range(0,n-1,2):
    tmp+=lista[i]
ans[-1] = int(sum_-tmp)*2
#print(ans)

for i in range(n-1):
    ans[n-2-i] = int(lista[n-2-i]*2 - ans[n-1- i])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cl
N = int(input())
water = cl.deque(map(int,input().split()))
sum = sum(water)
ans = []
for i in range(N):
  sum_odd = 0
  sum_even = 0
  for k in range((N+1)//2):
    sum_odd += water[2*k]
  sum_even = sum - sum_odd
  ans.append((sum_odd - sum_even))
  water.rotate(-1)
  
print(*water)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

sum = np.sum(A) / 2

ans = np.zeros(N)
for i in range(N):
    m = 0
    for j in np.arange(int((N-1)/2)):
        m += A[(i + j*2+1)%N]    
    ans[i] = int((sum - m) * 2)
    

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n = ip()
a = iprow()
b = []
summer = sum(a)
left = 0
right = a[0]
startnow = a[0]//2
now = a[0]//2
s=0
while s != summer:
    s = 0
 #   print(now,summer)
    over = 0
    for i in range(n):
        s+=now
        now = a[i]-now
        if now < 0:
            over = 1
    if  over:
   #     print("over")
        right//=2+1
        now = (left+right)//2
        startnow = now
    elif s*2 < summer:
 #       print("under",s,left,right)
        left = startnow+1
        now = (left+right)//2
        startnow = now
    elif s*2==summer:
        now = startnow
        for i in range(n):
            if i != n-1:print(now*2,end = ' ')
            else :print(now*2)
            now = a[i]-now
        exit(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
B=[]
res=0
for m in range(N):

	for i in range(N):
		n=(i+m)%N
		if n%2!=0:res-=A[n]
		else:res+=A[n]
	B=B+[res]
	res=0
	zero=A[0]
	for s in range(N-1):
		A[s]=A[s+1]		
	A[N-1]=zero

print(B)