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:
n = int(input())
a = list(map(int, input().split()))
ans = []
ans.append(0)
for i in range(1, n):
    if i ==1:
        ans.append(a[0]*2)
    else:
        ans.append(2*a[i]-ans[i-1]) 
x = (a[-1]-ans[-1])/2
for i in range(n):
    ans[i]=int(ans[i]+pow(-1, i)*x)
print(*ans, sep=" ")

Submission status: Wrong Answer

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

x1 = sum(A)
for i in range(n):
    if i % 2 == 0:
        x1 -= A[i]
ans = [x1]
for i in range(n-1):
    tmp = 2 * A[i] - ans[i]
    ans.append(tmp)
print(" ".join([str(int(n)) for n in ans]))

Submission status: Wrong Answer

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

suma = sum(a)
suma2 = sum([a[x] for x in range(1,n,2)])
b = [suma-suma2*2]
for i in range(1,n):
    b.append(a[i-1]*2-b[i-1])
print(b)

Submission status: Wrong Answer

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

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

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

print(x_list)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    ans = [0] * n
    if 0 in A:
        t = A.index(0)
        for i in range(1, n):
            ans[(t + i + 1) % n] = A[(t + i) % n] * 2
            A[(t + i + 1) % n] -= A[(t + i) % n]
    else:
        for i in range(3):
            ans[i % 3] = A[i % 3] // 2 - (A[i % 3] // 2 & 1)
            ans[(i + 1) % 3] = (A[i % 3] - ans[i % 3] // 2) * 2
            ans[(i + 2) % 3] = (A[(i + 1) % 3] - ans[(i + 1) % 3] // 2) * 2
            if sum(ans[:3]) == sum(A[:3]):
                break
        for j in range(2, n - 1):
            ans[j + 1] = (A[j] - ans[j] // 2) * 2
    print(*ans)
solve()

Submission status: Wrong Answer

Solution code:

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

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans_1 = [0]*N
ans_2 = [0]*N
flg = 0
for i in range(N):
    if A[i] % 2:
        flg = 1
        break
if flg:
    ans_1[i] = 2
    if i + 1 == N - 1:
        ans_2[0] = 2
    else:
        ans_2[i + 1] = 2
    for j in range(i+1, N+i):
        idx = j - N if j >= N else j
        idx_2 = idx - 1 if idx - 1 >= 0 else N - 1
        ans_1[idx] = (A[idx_2] - ans_1[idx_2]//2) * 2
        idx_3 = idx + 1 if idx + 1 < N else 0
        ans_2[idx_3] = (A[idx] - ans_1[idx]//2) * 2
    if sum(A) == sum(ans_1):
        print(' '.join(str(ans_1)[1:-1].split(', ')))
    else:
        print(' '.join(str(ans_2)[1:-1].split(', ')))

else:
    for i in range(N-1):
        if A[i] == A[i+1]:
            break
    idx = i+1
    ans_1[idx] = 0
    ans_1[idx] = A[idx]*2
    for i in range(idx + 1, N + idx):
        ct = i - N if i >= N else i
        ct_2 = N - 1 if ct - 1 < 0 else ct - 1
        ans_1[ct] = (A[ct_2] - ans_1[ct_2]//2) * 2
        ans_2[ct] = (A[ct_2] - ans_2[ct_2]//2) * 2
    if sum(A) == sum(ans_1):
        print(' '.join(str(ans_1)[1:-1].split(', ')))
    else:
        print(' '.join(str(ans_2)[1:-1].split(', ')))

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)
B = np.zeros(N)

for j in np.arange(int((N-1)/2)):
    B += np.roll(A, -j*2-1)
    
ans = (sum - B) * 2
    
print(*ans.astype(np.int16))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
ans=0
x=[]
y=[]
for i in range(n):
    ans+=a[i]*pow(-1, i)
x.append(ans)

for i in range(n-1):
    c=x[i]
    x.append(int(a[i+1]-c/2))
    
for i in range(n):
    y.append(str(x[i]))
print(" ".join(y))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in list(input().split())]
A = np.array(A)

res = np.zeros(len(A))

max_idx = np.argmax(A)

if max_idx - 1 >= 0:
    max_idx -= 1
else:
    max_idx = max_idx + N - 1

a = A[max_idx] // 2 * 4

if max_idx + 1 > N - 1:
    res[0] = a
else:
    res[max_idx + 1] = a
A[max_idx] -= a // 2
    
    
for i in range(N - 1):
    b = A[max_idx]
    res[max_idx] += b * 2
    if max_idx - 1 >= 0:
        max_idx -= 1
    else:
        max_idx = max_idx + N - 1
    A[max_idx] -= b
    
for i in res.astype(np.int64):
    print(i, end=' ')

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in list(input().split())]
A = np.array(A)

res = np.zeros(len(A))

max_idx = np.argmax(A)

if max_idx - 1 >= 0:
    max_idx -= 1
else:
    max_idx = max_idx + N - 1

a = A[max_idx] // 2 * 4

if max_idx + 1 > N - 1:
    res[0] = a
else:
    res[max_idx + 1] = a
A[max_idx] -= a // 2
    
    
for i in range(N - 1):
    b = A[max_idx]
    res[max_idx] += b * 2
    if max_idx - 1 >= 0:
        max_idx -= 1
    else:
        max_idx = max_idx + N - 1
    A[max_idx] -= b
    
print(res.astype(np.int64))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

s = 0
for i in range(1,n-1):
    s += pow(-1,n) * a[i]
x = []
x1 = (a[0] - s) /2
x2 = (a[0] + s) /2
x.append(x1)
x.append(x2)
for i in range(2,n):
    x.append(a[i-1] - x[i-1])
s = ""
for i in range(n):
    s += str(int(x[i]*2)) + " "
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().strip().split()))
X = []
X.append(sum(A[0::2])-sum(A[1::2]))
for k in range (N-1):
  X.append(2*A[k] - X[k])
print(X)

Submission status: Wrong Answer

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

min_=li[-1]+li[0]
length=len(li)

index=[-1,0]

for i in range(0,length-1):
  a=li[i]+li[i+1]
  if min_>a:
    min_=a
    index=[i,i+1]
    
min_num=min(li[index[0]],li[index[1]])
min_index=index[0]
result=[]
if li[index[0]]>li[index[1]]:
  min_index=index[1]
  
for i in range(min_num,-1,-1):
  num=i
  result=[i]
  for j in range(length):
    num=li[(j+min_index)%(length)]-num
    result.append(num)
    if num<0:
      break
  if num>=0 and num==i:
    break

result=result[0:-1]
L=[str(a*2) for a in result]
L=" ".join(L)
print(L)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
A=list(map(int,input().split()))
anp=np.array(A)
anp*=2
anp[1::2]*=-1

for i in range(len(A)):
    cp=anp.copy()
    cp[i+1::2]*=-1
    x=np.sum(cp)
    x/=2
    print(int(x),end=" ")
print()

Submission status: Wrong Answer

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

for i in range(N):
    rain=rain+A[i]
n=N//2
for i in range(n):
    c=2*(i-1)
    r=r+2*A[c]
B[N-1]=rain-r
B[0]=int(2*(A[N-1]-B[N-1]/2))
for i in range(1,N-1):
    B[i]=int(2*(A[i-1]-B[i-1]/2))
print(*B)

Submission status: Wrong Answer

Solution code:
N = int(input())
pool = [int(i) for i in input().split()]
sum = 0
sub = 0
for i in range(len(pool)):
    sum += pool[i]
    sum = sum/2
sub = sum
for i in range(0,len(pool),2):
    sub -= pool[i]
a = pool[N-1]-sub
print(pool[N-1]-sub)
for i in range(len(pool)-1):
    print(pool[i]-a)
    a = pool[i]-a

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
all_chk = sum(A_list)
A_list.append(A_list[0])
A_list.append(A_list[1])
A_list.append(A_list[2])
ans_list = []
if N != 3:
    for i in range(N):
        ans=all_chk-A_list[i+1]*2-A_list[i+3]*2
        ans_list.append(ans)
else:
    for i in range(3):
        ans_list.append(all_chk-A_list[i+1])    
print(*ans_list)

Submission status: Wrong Answer

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

for i in range(0, min(2 * A[0], 2 * A[1]) + 1, 2):
    ans = [0] * N
    ans[0] = i
    odd = False
    for j in range(1, N):
        ans[j] = 2 * A[j - 1] - ans[j - 1] // 2
        if ans[j] % 2 == 1:
            odd = True
            break
    if not odd:
        print(' '.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
t=[0,a[0]*2,a[-1]*2,a[0]//2,(a[0]+1)//2,a[-1]//2,(a[-1]+1)//2,(a[0]+a[-1])//2,(a[0]+a[-1]+1)//2,(a[0]+a[-1]+2)//2]
#for i in range(0,max(a[0],a[-1])*2+1,2):
for i in t:
    ans=[0]*n
    ans[0]=i
    t=[x for x in a]
    for j in range(n):
        t[j]-=ans[j]//2
        t[j-1]-=ans[j]//2
        if j+1<n: ans[j+1]=t[j]*2
    if max(t)==min(t)==0:
        print(*ans)
        exit()

Submission status: Wrong Answer

Solution code:
# n = int(input())
# a = [int(i) for i in input().split()] 
n=3
a=[2, 2, 4]
d=[0]*n
# a.sort(reverse=True)
for i in range(n):
    for j in range(n):
        if a[j]==min(a):
            d[j] += a[j]/2
            if(j+1<n):
                d[j+1] += a[j]/2
            else:
                d[0] += a[j]/2
            a[j]=0;
            
    print(d)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
all_chk = sum(A_list)
A_list.append(A_list[0])
A_list.append(A_list[1])
A_list.append(A_list[2])
print(all_chk)
ans_list = []
if N != 3:
    for i in range(N):
        ans=all_chk-A_list[i+1]*2-A_list[i+3]*2
        ans_list.append(ans)
else:
    for i in range(3):
        ans_list.append(all_chk-A_list[i+1])    
print(*ans_list)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
S=sum(A)
ans=[]
base0=sum(A[0:N:2])
base1=sum(A[1:N:2])

ans.append(base0)
ans.append(base1)
for i in range(2,N):
    if i % 2 ==0 :    
        base0=base0-A[i-1]+A[i-2]
        ans.append(base0)
    if i % 2 !=0:
        base1=base1-A[i-1]+A[i-2]
        ans.append(base0)
        
print(' '.join(map(str, ans)))

Submission status: Wrong Answer

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

s = 0
for i in range(1,n-1):
    s += pow(-1,n) * a[i]
x = []
x1 = (a[0] - s) /2
x2 = (a[0] + s) /2
x.append(x1)
x.append(x2)
for i in range(2,n):
    x.append(a[i-1] - x[i-1])
for i in range(n):
    print(x[i]*2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
l = 0
r = A[0]
y1 = A[0] // 2
yn = 0
sm = 0
y = [y1]
for a in A:
    if a % 2 == 0:
        sm += a
    else:
        sm -= a
while l <= r:
    yn = sm-y1
    if A[-1] == -y1 + yn and yn > 0 and y1 > 0:
        break
    elif A[-1] > y1 + yn:
        r = y1 - 1
    elif A[-1] < y1 + yn:
        l = y1 + 1
    y1 = (l + r) // 2

for i in range(N):
    if i== 0:
        print(2 * y1, end=" ")
    else:
        print(2*(A[i - 1] - 2*y[i - 1]), end=" ")
        y.append(2*(A[i-1]-2*y[i-1]))

Submission status: Wrong Answer

Solution code:
from numpy.linalg import solve

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

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

print(left)

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

print(answer)

Submission status: 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)
B = np.zeros(N)

for j in np.arange(int((N-1)/2)):
    B += A + np.roll(A, -j*2-1)
    
ans = (sum - B) * 2
    
print(*ans.astype(np.int16))

Submission status: Wrong Answer

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

s = 0
for i in range(1,n-1):
    s += pow(-1,n) * a[i]
x = []
x1 = (a[0] - s) /2
x2 = (a[0] + s) /2
x.append(x1)
x.append(x2)
for i in range(2,n):
    x.append(a[i-1] - x[i-1])
for i in range(n):
    print(x[i])

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]
    f=True
    for i in range(0,n):
        if tmp-fl//2<0:
            r=mid
            f=False
            break
        else:
            if i==0:
                xx-=fl//2
            if i==n-1:
                tmp-=fl//2
                break
            fl=(tmp-fl//2)*2
            if i!=n-1:
                tmp=a[i+1] if i!=n-2 else xx
    if f:
        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:
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()))
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)

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

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

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

#m = m - 1
for i in range(m-1, m+2):
    if ans(0, i):
        break

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
ls=input().split()
for i in range(n):
    ls[i]=int(ls[i])

lsls=ls
a=ls[0]
b=0
for i in range(n-1):
    if ls[i+1]<a:
        b=i+1

lsans=np.zeros(n)
for i in range(ls[b]):
    ls=lsls
    ls[(b+1)%n]-=i
    for j in range(n-1):
        ls[(b+2+j)%n]-=ls[(b+1+j)%n]
    if ls[b]==i:
        ls=lsls
        ls[(b+1)%n]-=i
        lsans[(b)%n]+=i
        lsans[(b+1)%n]+=i
        for k in range(n-1):
            ls[(b+2+j)%n]-=ls[(b+1+j)%n]
            lsans[(b+1+j)%n]+=ls[(b+1+j)%n]
            lsans[(b+2+j)%n]+=ls[(b+1+j)%n]
        break

for i in range(n):
    lsans[i]=int(lsans[i])

for j in range(n):
    print(int(lsans[j]), end=' ')

print()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(e) for e in input().split(" ")]
ll =[]
for i,e in enumerate(l):
    ll.append([i+1,e])

ret = []
for i in range(1,n+1):
    tmp = 0
    pm = 0
    for j in range(1,n+1):
        if i == j:
            pm = 1
        elif i > j:
            if abs(i-j)%2 == 0:
                pm = -1
            else:
                pm = 1
        elif j < i:
            if abs(i-j)%2 == 1:
                pm = -1
            else:
                pm = 1
        tmp += (pm * ll[j-1][1])//2
    ret.append(str(tmp))
print(" ".join(ret))

Submission status: Wrong Answer

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

x = A[0]
for j, a in enumerate(A[1:]):
    if j%2==0:
      x -= a
    else:
      x += a
print(x)
for i in A[:-1]:
  x = 2*(i-x/2)
  print(x)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""

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

    
def main():
    m = [0]*N
    sgn = (-1)
    Atot=0
    for n in range(N):
        Atot += sgn**(n)*A[n]
    m[0] = Atot//2
    for n in range(1,N):
        m[n] = A[n-1]-m[n-1]
    for n in range(N):
        m[n] = m[n]*2
    
        
    print(m)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math


def get_iv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [int(arg) for arg in argv]
    return iargv


def water_on_mountains(N, A):
    w = [0 for _ in range(N)]
    Nm1 = N - 1
    for off, a in enumerate(A):
        sm = 0
        for j in range(N):
            i = (off + j) % N
            sm += (-1) ** j * A[i]
        w[off] = sm
    return w


def main():
    specs = get_iv()
    N = specs[0]
    A = get_iv()
    rv = water_on_mountains(N, A)
    print(rv)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = int(input())

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

minIndex = [i for i, x in enumerate(a) if x == min(a)]


for argmin in minIndex:

    amin = a[argmin]

    i = argmin
    ai = amin
    ans = [0 for i in range(N)]
    for _ in range(N):
        ans[i] = ai
        if(i == 0):
            i = N-1
        else:
            i-= 1
        anext = a[i]
        tmp = anext - ai/2
        ai = int(2*tmp)

    if(ai == amin):
        print(ans)
        sys.exit()
    else:
        ans = [0 for i in range(N)]
        i = argmin
        ai = 0
        ans = [0 for i in range(N)]
        for _ in range(N):
            ans[i] = ai
            if(i == 0):
                i = N-1
            else:
                i-= 1
            anext = a[i]
            tmp = anext - ai/2
            ai = int(2*tmp)
        if(ai == amin):
            print(ans)
            sys.exit()

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]
    f=True
    for i in range(0,n):
        if tmp-fl//2<0:
            r=mid
            f=False
            break
        else:
            if i==0:
                xx-=fl//2
            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
    if f:
        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:
n = int(input())
lis = list(map(int,input().split()))
s=sum(lis)
for i in range(n//2):
  s-=2*lis[2*i]
print(s,end="")
ans=s
for i in range(n-1):
  ans=2*lis[i]-ans
  print(" ",end="")
  print(ans,end="")

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

def doit(start):
    mnt = [start*2]
    if start > dam[0]:
        return []
    temp = dam[0] - start
    for i in range(1,N):
        if dam[i%N] >= temp:
            mnt.append(2*temp)
            temp = dam[i%N] - temp
        else:
            return []
    if start == temp:
        return mnt
    else:
        return []

init = 0
while(init <= dam[0]//2):
    ret = doit(init)
    if len(ret) == N:
        print(ret)
    init += 1

Submission status: Wrong Answer

Solution code:
N = int(input())
water = list(map(int, input().split()))
sum_water = sum(water)
water.append(water[0])
ans = [0] * N

for i in range(1, water[0] + 1):
    tmp = [0] * N
    tmp[0] = i * 2
    for j in range(1, N):
        tmp[j] = (water[j - 1] - tmp[j - 1] // 2) ** 2
        if tmp[j] < 0:
            break

    if sum(tmp) == sum(water) - water[0]:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
t=[0,a[0]*2,a[-1]*2,a[0]//2,(a[0]+1)//2,a[-1]//2,(a[-1]+1)//2,(a[0]+a[-1])//2,(a[0]+a[-1]+1)//2]
#for i in range(0,max(a[0],a[-1])*2+1,2):
for i in t:
    ans=[0]*n
    ans[0]=i
    t=[x for x in a]
    for j in range(n):
        t[j]-=ans[j]//2
        t[j-1]-=ans[j]//2
        if j+1<n: ans[j+1]=t[j]*2
    if max(t)==min(t)==0:
        print(*ans)
        exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sumA = 0
for i in range(N):
    sumA += A[i]
k = 0
ans = []
res = []
for i in range(N):
    if i % 2 == 0:
        res.append(A[i])
    else:
        res.append(-A[i])
P = sum(res)
ans.append(P)
tem = A[0]
tempans = P - tem
for i in range(N-1):
    tempans = -tempans+A[i]
    ans.append(tempans)
    tempans -= A[i+1]
print(ans)

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]+3,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()))
odd=[]
even=[]
for i in range(int((n+1)/2)):
    odd.append(a[i*2])
for i in range(int((n)/2)):
    even.append(a[i*2+1])
ans=[]
ans.append(sum(odd)-sum(even))
for i in range(n-1):
    tmp=0
    if(i%2==0):
        ans.append(sum(even[int(i/2):])-sum(odd[int(i/2):]))
    else:
        ans.append(sum(odd[int(i/2):])-sum(even[int(i/2):]))

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

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

ans_tmp = []


for i in range(0, A[0]+1):
    B[0] = A[0] - i
    ans_tmp.append(str(i*2))

    for n in range(1, N):
        B[n] = A[n] - B[n-1]
        if B[n] < 0:
            break
        
        else:
            ans_tmp.append(str(B[n-1]*2))

    if i == B[N-1]:
        break
    
    ans_tmp = []


print(" ".join(ans_tmp))