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()))
b=[0]*n
x=-1
y=2*10**9
z=(x+y)//2
for i in range(1000):
    b[0]=z
    for j in range(1,n):
        b[j]=a[j-1]*2-b[j-1]
    if b[0]+b[-1]>2*a[-1]:
        y=z
        z=(x+y)//2
    elif b[0]+b[-1]<2*a[-1]:
        x=z
        z=(x+y)//2
    else:
        break
print(*b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from array import array
N = int(input())
S = input()
a = ['A', 'B', 'X', 'Y']
L = []
for i in range(16):
    L.append(a[i//4]+a[i%4])
ans = N+1
for m in range(16):
    for n in range(16):
        i=L[m]
        j=L[n]
        dp = array('i', [k for k in range(N+1)])
        for k in range(2, N+1):
            if S[k-2]+S[k-1] in {i, j}:
                dp[k] = min(dp[k-2], dp[k-1])+1
            else:
                dp[k] = dp[k-1]+1
        ans = min(ans, dp[N])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
t = sum(A)
B = [0] * N
for i in range(0, N, 2):
  B[0] += A[i]
B[0] = 2 * B[0] - t
print(B[0])

for i in range(1,N):
  B[i] = 2 * A[i-1] - B[i-1]

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

Submission status: Wrong Answer

Solution code:

def resolve():
    '''
    code here
    '''

    N = int(input())
    As = [int(item) for item in input().split()]

    def cal(num):
        res_list = [0 for _ in range(N)]
        ans_list = [0 for _ in range(N)]
        
        for i in range(N):
            if i == 0:
                res_list[0] = num // 2
                res_list[-1] = num // 2
                ans_list[0] = num
                continue
            
            temp_num = 2 * (As[i-1] - res_list[i-1])
            ans_list[i] = temp_num
            if temp_num < 0:
                return 'too small'
            
            if i == N-1:
                if res_list[-1] + temp_num // 2 == As[-1]:
                    return ans_list
                else:
                    return 'too large'

            res_list[i-1] += temp_num // 2
            res_list[i] = temp_num //2

    R = 2 * max(As[0], As[-1])
    L = 0
    mid = (R + L)//2
    is_search = True
    while is_search:
        flag = cal(mid)
        if flag == 'too large':
            R, mid = mid, (L+mid)//2
        elif flag == 'too small':
            L, mid = mid, (R+mid)//2
        else:
            is_search = False

    print(*flag)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def rain(i):
  rainfall = (total/2 - sum(a[:i-2:-2]) - sum(a[i+1::2])) * 2
  print(int(rainfall))

i = 0
a.insert(0, a[n-1])
del a[n]
i += 1
rain(i)
a.append(a[0])
del a[0]

for i in range(1, n-1):
  rain(i)

i = n-1
a.append(a[0])
del a[0]
n -= 1
rain(i)

Submission status: Wrong Answer

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

All = sum(A)

lim = len(A)//2
Exc1 = sum([A[i+1] for i in range(lim)])

one = All - Exc1*2
ans = [one]
for i in range(1,N):
    print('{}'.format(ans[-1]),end=' ')
    ans.append(A[i-1]*2 - ans[-1])
print('{}'.format(ans[-1]))

Submission status: Wrong Answer

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

R1 = S
for i in range(N//2):
    R1-=2*A[2*i+1]
R = [R1]

for j in range(1, N):
    R.append(A[j-1]*2-R[-1])
print(R)

Submission status: Wrong Answer

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

tmp = 0
for i in range(N//2-1):
  tmp += A[2*i]
  
ans = []
if sum(A) > 2*tmp:
  ans.append(sum(A)-2*tmp)
else:
  ans.append(0)
  
for i in range(N):
  ans.append(2*A[i]-ans[-1])
print(*ans)

Submission status: Wrong Answer

Solution code:
# ABC 133 D
N = int(input())
A_list = list(map(int, input().split()))
x_list = [0] * N
x_list[0] = sum(A_list) - sum([2*a for a in A_list[1::2]])
for i, a in enumerate(A_list[:-1]):
    x_list[i+1] = 2*a - x_list[i]

print(x_list)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
n = int(input())
a=[int(i) for i in input().split()]
tmp = 0
res = [0]*n
f=1
for i in a:
    tmp += f*i
    f=f*-1
res[0]=tmp

for i in range(1,n):
    res[i] = 2*a[i-1]-res[-1]
    if(i==n-1):
        res[i] = 2*a[i]-res[0]
print(*res)

Submission status: Wrong Answer

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


low=0
high=10**9*2

#binary search the value of rain onto Mountain1
while low<=high:
    mid=(low+high)//2
    cur=mid
    for a in A:
        cur=a-cur
        if cur<0:#途中で足りなくなったら、midが大きすぎ
            break
       #break
    if cur>=mid:
        low=mid+1
    else:
        high=mid-1


ans=[]
cur=high
for a in A:
    ans.append(cur*2)
    cur=a-cur
print(" ".join(map(str,ans)))

Submission status: Wrong Answer

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


low=0
high=10**9

#binary search the value of rain onto Mountain1

while low<=high:
    mid=(low+high)//2

    cur=mid
    for a in A:
        cur=a-cur
        if cur<0:#途中で足りなくなったら、midが大きすぎ
            break

    #if cur>=mid:
        #break
    if cur>=mid:
        low=mid+1
    else:
        high=mid-1


ans=[]
cur=high
for a in A:
    ans.append(cur*2)
    cur=a-cur

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

Submission status: Wrong Answer

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


low=0
high=10**9

#binary search the value of rain onto Mountain1

while True:
    mid=(low+high)//2

    cur=mid
    ok=True
    for a in A:
        cur=a-cur
        if cur<0:
            break

    if cur==mid:
        break
    if cur>mid:
        low=mid+1
    else:
        high=mid-1


ans=[]
cur=mid
for a in A:
    ans.append(cur*2)
    cur=a-cur

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=0
    r=A[0]+1

    def f(mid):
        cur=mid
        for i in range(0,N-1):
            if A[i]<cur:
                return 0
            cur=A[i]-cur
        if mid+cur>A[-1]:
            return 0
        return 1

    while r-l>1:
        mid=(r+l)//2
        if f(mid):
            l=mid
        else:
            r=mid
    ans=[0]*N
    ans[0]=2*l
    cur=l
    for i in range(1,N):
        cur=A[i-1]-cur
        ans[i]=cur*2
        


    print(*ans)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp_A = [0]*N
for i, x in enumerate(A):
	if i%2 == 0:
		tmp_A[i] = x
	else:
		tmp_A[i] = -x

tmp = sum(tmp_A)/2

ans = []

for i in range(N):
	print(int(tmp*2), end = " ")
	tmp = A[0] - tmp

print()

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
al = list(map(int, input().split()))
asum = sum(al)

first_q = al[1:n:2]
last_ind = n-2
curr_sum = sum(first_q)
q = deque(first_q)

print(first_q)

ans = [0]*n
ans[0] = asum - curr_sum*2
for i in range(2,n,2):
    next_ind = (last_ind+2)%n
    next_a = al[next_ind]
    poped_a = q.popleft()
    curr_sum -= poped_a
    curr_sum += next_a
    ans[i] = asum - curr_sum*2
    last_ind = next_ind


first_q = al[2:n:2]
last_ind = n-1
curr_sum = sum(first_q)
q = deque(first_q)
ans[1] = asum - curr_sum*2
for i in range(3,n,2):
    next_ind = (last_ind+2)%n
    next_a = al[next_ind]
    poped_a = q.popleft()
    curr_sum -= poped_a
    curr_sum += next_a
    ans[i] = asum - curr_sum*2
    last_ind = next_ind

print(*ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
for i in range(ls[0]+1):
    di[0] = i
    for j in range(n):
        di[j+1] = ls[j] - di[j]
        if di[j+1] < 0:
            break
    if di[0] == di[-1]:
        di = list(map(lambda x :2*x,di))
        print(*di[:-1])
        break

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

res = x // 2
for i in range(n):
    print(2*res, end=' ')
    res = a[i] - res

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

INF = 2 * 10 ** 9 + 5

right = INF
left = -1
while right - left > 1:
    x = (right + left) // 2
    if x % 2 == 1:
        x -= 1
    dam = [0] * N
    rains = [0] * N
    dam[-1] = x // 2
    dam[0] = x // 2
    rains[0] = x

    actual_total = sum(A)
    for i in range(1, N):
        r = A[i - 1] - dam[i - 1]
        if r < 0:
            right = x
            break
        dam[i - 1] += r
        dam[i] += r 
        rains[i] = 2 * r
    total = sum(dam)
    if total > actual_total:
        right = x
    elif actual_total < total:
        left = x
    else:
        for r in rains:
            print(r)
        break

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

INF = 2 * 10 ** 9 + 5

right = INF
left = -1
while right - left > 1:
    x = (right + left) // 2
    if x % 2 == 1:
        x -= 1
    dam = [0] * N
    rains = [0] * N
    dam[-1] = x // 2
    dam[0] = x // 2
    rains[0] = x

    for i in range(1, N):
        r = A[i - 1] - dam[i - 1]
        if r < 0:
            right = x
            break
        dam[i - 1] += r
        dam[i] += r 
        rains[i] = 2 * r
    if dam[-1] > A[-1]:
        right = x
    elif dam[-1] < A[-1]:
        left = x
    else:
        for r in rains:
            print(r)
        break

Submission status: Wrong Answer

Solution code:
def solve(a):
    li = [0] * n
    li[0] = a * 2
    for i in range(1, n):
        li[i] = (L[i-1] - li[i-1] // 2) * 2
    return (L[-1] - li[-1] // 2) * 2

n = int(input())
L = list(map(int, input().split()))
l = 0
r = 10 ** 9 + 1
while abs(r - l) > 1:
    m = (r + l) // 2
    if solve(m) > m:
        l = m
    else:
        r = m
ans = [0] * n
ans[0] = l * 2
for i in range(1, n):
    ans[i] = (L[i-1] - ans[i-1] // 2) * 2
print(*ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
# 山1の雨の量を2分探索
l, r = 0, 2*min(A[0], A[-1])
while l <= r:
    m1 = (l+r)//2
    m = m1
    for i in range(N):
        m = 2*A[i]-m
    if m == m1:
        l = m
        break
    elif m1 < m:
        l = m1+2
    else:
        r = m1-2

m = [0]*N
m[0] = l
for i in range(1, N):
    m[i] = 2*A[i-1]-m[i-1]
print(*m)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
# 山1の雨の量を2分探索
l, r = 0, 2*min(A[0], A[-1])
while l <= r:
    m1 = (l+r)//2
    m = m1
    for i in range(N):
        m = 2*A[i]-m
    if m == m1:
        break
    elif m1 < m:
        l = m1+2
    else:
        r = m1-2

m = [0]*N
m[0] = l
for i in range(1, N):
    m[i] = 2*A[i-1]-m[i-1]
print(*m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum_eve = sum(A[0::2])
sum_odd = sum(A[1::2])

x = [0] * n

x[0] = sum_eve - sum_odd

for num in range(1, n):
    x[num] = 2 * A[num-1] - x[num-1]
    
print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

rain = sum(a)/2

dam=[0]*n

for i in range(n):
    if i!=n-1:
        dam[i] = int((rain - a[i+1])*2)
    else:
        dam[i] = int((rain - a[0])*2)

print(*dam)

Submission status: Wrong Answer

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

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

    print(*ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

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

    print(*ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
p = All-sum(a2[1::2])
a3 = [p]
for i in range(n-1) :
    q = a[i]*2 - p
    a3.append(q)
mountain = ""
for j in range(n) :
    mountain += str(a3[j])
    if j == n-1 :
        print(mountain)
        exit()
    mountain += " "

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
p = All-sum(a2[1::2])
a3 = [p]
for i in range(n-1) :
    q = a[i]*2 - p
    a3.append(q)
mountain = ""
for j in range(n) :
    mountain += str(a3[j])
    if j == n-1 :
        exit()
    mountain += " "
print(mountain)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
p = All-sum(a2[1::2])
a3 = [p]
for i in range(n-1) :
    q = a[i]*2 - p
    a3.append(q)
mountain = ""
for j in range(n) :
    mountain += str(a3[j])
    mountain += " "
print(mountain)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
p = All-sum(a2[1::2])
a3 = [p]
for i in range(n-1):
    q = a[i]*2 - p
    a3.append(q)
print(a3)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = [ 2*int(i) for i in sys.stdin.readline().split()]
ans = [0 for i in range(n)]
ans[0] = a[n-1] - a[0]
for i in range(1, n):
    ans[i%n] = a[i%n] - a[(i-1)%n]
print(" ".join(map(str, ans)))

Submission status: Wrong Answer

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

M[0]= sum(A[2::2])
for i in range(1,N):
  M[i]= 2*(A[i-1]-M[i-1]//2)
print(*M)

Submission status: Wrong Answer

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

M[0]=maxi//4
tmp=10**9

while M[0]/2 != tmp:
  for i in range(1,N):
    M[i]= 2*(A[i-1]-M[i-1]//2)
  tmp = A[-1] - M[N-1]//2
  #print(M,tmp)
  if M[0] != tmp*2:
    M[0] = (M[0]+tmp*2)//2
    if M[0]%2!=0:
      M[0] +=1
else:
  print(M)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
a2 = 0
for i in range(1, n):
    a2 += a[i]

ans = [0] * n
ans[0] = sum_a - 2*a2
for i in range(1, n, 2):
    ans[i] = 2*a[i-1] - ans[i-1]
print(*ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
M=[0]*N
maxi=sum(A)
mini=0
last=-1

while last!=M[0]:
  for i in range(1,N):
    M[i]= 2*( A[i-1]-(M[i-1]//2) )
  last = 2*A[-1]-M[-1]
  if M[0]>last:
    M[0],maxi= (M[0]+mini)//2,M[0]
  elif M[0]<last:
    M[0],mini= (M[0]+maxi)//2,max(M[0],0)
    
print(*M)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
total_odd = sum(aa[1::2])
total_eve = sum(aa[2::2])
tmp = aa[0] + total_odd - total_eve
last = tmp
for i in range(1,n):
    tmp = 2*aa[i] - tmp
    print(tmp)
print(last)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(x,end=" ")

for i in range(n-1):
    x = 2*A[i]-x
    print(x,end=" ")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
# print(A)
# left = 0
# right = total + 1

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

# while left + 1 < right:
#     c = (left + right) // 2
#     if solver(c):
#         right = c
#     else:
#         left = c

for i in range(total):
    if solver(i):
        print(" ".join(map(str, ans)))
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = [0]*n
ok = -1
ng = min(a[-1], a[0]) + 1
if ng - ok == 1:
    b[0] = 0
    for i in range(1, n):
        b[i] = (a[i - 1] - b[i - 1] // 2) * 2
else:
    while ng - ok > 1:
        mid = (ok + ng)//2
        b[0] = mid*2
        for i in range(1, n):
            b[i] = (a[i-1] - b[i-1]//2)*2
        if sum(b) <= sum_a:
            ok = mid
        elif sum(b) > sum_a:
            ng = mid

print(*b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = [0]*n
ok = 0
ng = min(a[-1], a[0]) + 1
if ng - ok == 1:
    b[0] = 0
    for i in range(1, n):
        b[i] = (a[i - 1] - b[i - 1] // 2) * 2
else:
    while ng - ok > 1:
        mid = (ok + ng)//2
        b[0] = mid*2
        for i in range(1, n):
            b[i] = (a[i-1] - b[i-1]//2)*2
        if sum(b) <= sum_a:
            ok = mid
        elif sum(b) > sum_a:
            ng = mid

print(*b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(lambda x:2*int(x),input().split()))

ans=[0]*n
s=int(sum(a)/2)
for i in range(1,n,2):
    s-=a[i]
ans[0]=s
for i in range(1,n):
    ans[i]=a[i-1]-ans[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
odd=sum(A[::2])
even=sum(A[1::2])
rtemp=10**9+1
ltemp=-1
while rtemp-ltemp>1:
    mid=(rtemp+ltemp)//2
    if odd-even-mid<=mid:
        rtemp=mid 

    else:
        ltemp=mid

ans=rtemp
D=[]
for i in range(n-1):
    D.append(ans*2)
    ans=A[i]-ans
    
D.append(ans)
print(*D)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
odd=sum(A[::2])
even=sum(A[1::2])
rtemp=10**9+1
ltemp=-1
while rtemp-ltemp>1:
    mid=(rtemp+ltemp)//2
    if odd-even-mid<=mid:
        rtemp=mid 

    else:
        ltemp=mid

ans=rtemp
for i in range(n-1):
    print(ans*2)
    ans=A[i]-ans

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
even_s, even_t = 2, N-1
even = 0
for i in range(N):
  if (i+1) % 2 == 0:
    even += A[i]
odd_s, odd_t = 3, N
odd = 0
for i in range(2, N):
  if (i+1) % 2 == 1:
    odd += A[i]
odd_s, odd_t = 3, N
X = [0]*N
X[0] = S - even * 2
X[1] = S - odd * 2
for i in range(3, N+1):
  if i % 2:
    even -= A[even_s-1] 
    even += A[(even_t+2)%N-1]
    even_s += 2
    even_t = (even_t+2)%N
    X[i-1] = S - even * 2
  else:
    odd -= A[odd_s-1]
    odd += A[(odd_t+2)%N-1]
    odd_s += 2
    odd_t = (odd_t+2)%N
    X[i-1] = S - odd * 2

print(X)

Submission status: Wrong Answer

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

def solve():
    B = [None] * N
    B[0] = sum(A[i] * (-1 ** (i&1)) for i in range(N))
    for i in range(N-1, 0, -1):
        B[i] = 2 * A[i] - B[(i+1) % N]
    return B

print(*solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dam = 0
sign = 1
for mountain in a:
  dam = sign * mountain
  sign = -sign
print(dam, end=' ')
for i in range(n - 1):
  dam = 2 * a[i] - dam
  print(dam, end=' ')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

X = [0]*N
X[0] = S-2*(S-A[0]-A[-1])

for i in range(1, N):
  X[i] = 2*A[i-1]-X[i-1]
print(*X)

Submission status: Wrong Answer

Solution code:
from itertools import*


n,*b=map(int,open(0).read().split())

a1=sum(b[i]*(-1)**(i%2) for i in range(n))


l=[a1]
for i in range(n-1):
    l.append((b[i]-l[-1]//2)*2)
print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = [(l[0]-l[1]+l[-1])]
for i in range(1,n):
    if i == n-1:
        ans.append((l[n-1]-l[0]+l[i-1]))
    else:
        ans.append((l[i]-l[i+1]+l[i-1]))
print(' '.join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
from itertools import*


n,*b=map(int,open(0).read().split())

a1=sum(b[i]*(-1)**(i%2) for i in range(n))

print(a1)

l=[a1]
for i in range(n-1):
    l.append((b[i]-l[-1]//2)*2)
print(*l)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = [(l[0]-l[1]+l[-1])]
for i in range(1,n):
    if i == n-1:
        ans.append((l[n-1]-l[0]+l[i-1]))
    else:
        ans.append((l[i]-l[i+1]+l[i-1]))
print(ans)