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:
from math import ceil
N = int(input())
A = list(map(int, input().split()))
if A[0] % 2 == 0 and A[-1] % 2 == 0:
    ans = [min(A[0], A[-1]) * 2]
else:
    ans = [min(A[0], A[-1]) // 2 * 2]

for i in range(N - 1):
    A[i] -= ceil(ans[i] / 2)
    ans.append(A[i] * 2)
print(*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))

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

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
A = list(map(int, input().split()))
if A[0] % 2 == 0 and A[-1] % 2 == 0:
    ans = [min(A[0], A[-1]) * 2]
else:
    ans = [min(A[0], A[-1]) // 2 * 2]

for i in range(N - 1):
    A[i] -= ceil(ans[i] / 2)
    ans.append(min(A[i], A[i + 1]) * 2)
print(*ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
A = list(map(int, input().split()))
if A[0] % 2 == 0 and A[-1] % 2 == 0:
    ans = [min(A[0], A[-1]) * 2]
else:
    ans = [min(A[0], A[-1]) // 2 * 2]

for i in range(N - 1):
    A[i] -= ceil(ans[i] / 2)
    ans.append(min(A[i], A[i + 1]) * 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n,*b=map(int,open(0).read().split())
b*=2
l=[]
for i in range(n):
    l.append(b[i]+b[i+1]-b[i+2])

print(*([l[-1]]+l[:-1]))

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
a=a+a
l=[]
for i in range(n):
    l.append((a[i+1]+a[i+2]-a[i+3]))
l.append(l[0])
print(*l[1:])

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())

l=[]
for i in range(n):
    l.append(a[i-3]+a[i-1]-a[i-2])
print(*l)

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[1:n-1])
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())
a=list(map(int,input().split()))
s=[]
for i in range(1,n+1):
    if i%2==0:
        s.append(a[i])
A=sum(a)
ans=[0]*n
ans[0]=A-sum(s)
for i in range(1,n):
    ans[i]=2*a[i-1]-ans[i-1]
print(*ans)

Submission status: Wrong Answer

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

def isOK(a):
    prev = a
    for i in range(N-1):
        prev = (As[i] - (prev // 2)) * 2
    return (a + prev) // 2 >= As[-1]

r = 10 ** 9 // 2
l = -1
while r - l > 1:
    m = l + (r - l) // 2
    if isOK(m*2):
        r = m
    else:
        l = m

ans = []
prev = r*2
ans.append(prev)
for i in range(N-1):
    prev = (As[i] - (prev // 2)) * 2
    ans.append(prev)
print(' '.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
c = sum(a[::2]) - sum(a[1::2])
for i in range(1,N):
  c = 2*a[i-1] - c
  print(c)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    S = sum(A)
    x0 = S
    for i in range(1, N, 2):
        x0 -= 2 * A[i]
    print(x0)
    ans = []
    ans.append(x0)
    for i in range(N - 1):
        x = 2 * A[i] - ans[-1]
        ans.append(x)
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
a=list(map(int,input().split()))
rain=[[] for _ in range(N)]
for i in range(0,2*a[-1]+2,2):
  j=2*a[-1]-i
  rain=[0  for _ in range(N)]
  rain[0]=str(i)
  rain[-1]=str(j)
  flag=0
  for v in range(1,(N-1)//2):
    rain_l=2*a[v-1]-int(rain[v-1])
    if rain_l<0:
      flag=1
      break
    rain_r=2*a[-v]-int(rain[-v])
    if rain_r<0:
      flag=1
      break
    rain[v]=str(rain_l)
    rain[-v-1]=str(rain_r)
  if flag:
    pass
  else:
    index=(N-1)//2
    v1=2*a[index]-int(rain[index+1])
    v2=2*a[index-1]-int(rain[index-1])
    if v1==v2>=0:
      rain[index]=str(v1)
      print(' '.join(rain))
      sys.exit()

Submission status: Wrong Answer

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

b0 = 0
b = []
bodd0 = 0
bodd  = []
beven0 = 0
beven = []
for h,i in enumerate(a):
    b0 += i
    b.append(b0)
    if h%2 == 0:
        beven0 += i
        beven.append(beven0)
    else:
        bodd0 += i
        bodd.append(bodd0)

s1 = b[-1] - beven[-1]*2
ans = [s1]
for i in a:
    s1 = int((i - s1/2)*2)
    ans += [s1]

print(*ans[:-1])

Submission status: Wrong Answer

Solution code:
# D
n = int(input())
y = list(map(int, input().split()))
for i,num in enumerate(y):
    if i % 2 == 1:
        y[i] = -y[i]

a2=[0]
for i in y:a2.append(a2[-1]+i)
def SumArea(r, l):
    return a2[l]-a2[r]
    
ans = [0 for i in range(n)]
for i in range(n):
    count=0
    if i % 2 == 1:
        count += SumArea(i, n)
        count -= SumArea(0, i)
    else:
        count += SumArea(i, n)
        count += SumArea(0, i)
    ans[i] = count
print(*ans, sep=' ')

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

N = int(input())
A = list(map(int, input().split(' ')))
ret = [0 for _ in range(len(A))]
tmp = [0 for _ in range(len(A))]

init = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
ret[0] = init
for i in range(N):
    if i == 0:
        tmp[i] += ret[i] // 2
        tmp[i-1] += ret[i] // 2
    else:
        d = A[i-1] - tmp[i-1]
        if d < 0:
            break
        else:
            tmp[i] += d
            ret[i] += d * 2

print(ret)

Submission status: Wrong Answer

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

MaxX1=min(A[-1],A[1])*2

for i in range(0,MaxX1+2,2):
    X=[i]*N
    for j in range(N-1):
        X[j+1]=2*A[j]-X[j]
        AJ=[0]*N
        for k in range(N):
            AJ[k-1]=X[k-1]/2+X[k]/2
        if AJ==A:
            print(X)
            exit

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
water_sum = sum(A)
# x = [0] * N
flag = True
for i in range(2, water_sum+1):
    flag = True
    x = []
    x.append(i)
    for j in range(N-1):
        if len(x)-1 == j:
            # if j != N-1:
            water = 2 * A[j] - x[j]
            if water % 2 == 0 and water > 0:
                x.append(water)

        if len(x) == N:
            print(*x)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

memo = 0

for i in range(1, n):
    if i%2==0:
        continue
    else:
        memo += t[i]
x1 = sum(t)-2*memo

print(x1)

res = []

res.append(x1)

for i in range(1, n):
    res.append(2*t[i-1]-res[i-1])
print(' '.join(map(str,res)))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

memo = 0

for i in range(1, n):
    if i%2==0:
        continue
    else:
        memo += t[i]
x1 = sum(t)-2*memo

print(x1)

res = []

res.append(x1)

for i in range(1, n):
    res.append(2*t[i-1]-res[i-1])
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = A + [A[0]]
    s = sum(A[:-1])/2
    x = [0] * N
    for i in range(N):
        x[i] = int(2*(s-A[i+1]))
    print(*x)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from numpy.linalg import solve

def main():
    N = int(input())
    A = list(map(int,input().split()))
    left = [[0]*(N-2) for _ in range(N)]

    for i in range(N-1):
        left[i].insert(i,1)
        left[i].insert(i,1)

    left[N-1].insert(0,1)
    left[N-1].insert(N-1,1)

    ans = list(map(int,2 * solve(left, A)))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from numpy.linalg import solve

def main():
    N = int(input())
    A = list(map(int,input().split()))
    left = [[0]*(N-2) for _ in range(N)]

    for i in range(N):
        left[i].insert(i,1)
        if(i == N-1):
            left[i].insert(0,1)
        else:
            left[i].insert(i,1)


    print(A)
    print(left)

    print(2 * solve(left, A))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

s = sum(A)
c = 0
for i in range(2, N, 2):
    c += A[i]

ans = [s - 2 * c]

for i in range(1, N):
    ans.append((A[i] - ans[-1] // 2) * 2)

print(*ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
T = [[(-1)**(((i-j)%(N))) for i in range(N)] for j in range(N)]


arr = np.matrix(T).T
a = np.matrix(A).reshape(N, 1)
print(arr, a)
rain = arr.T * a
print(*[int(i) for i in rain])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

b.append(sum(a) - 2*sum(a[1:n-1]))
i = 0
while i < n-1:
    b.append(2*a[i]-b[i])
    i += 1

print(*b)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

total = sum(l)

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

ans = [total]

for i in range(1,n):
    ans.append(2* l[i-1] - ans[i-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jan  4 16:07:46 2020

@author: USER
"""

N=int(input())
A=list(map(int,input().split()))
for i in range(len(A)-1):
    A[i+1]=A[i+1]-A[i]
A[-1]=int(A[-1]/2)
for i in range(int((N-1)/2)):
    A[2*i]=A[2*i]-A[-1]
    A[2*i+1]=A[2*i+1]+A[-1]
for i in range(len(A)):
    A[i]=2*A[i]
B=[]
for i in range(len(A)):
    B.append(A[i-1])

     
print(B)

Submission status: Wrong Answer

Solution code:
from numpy.linalg import solve
import numpy

n = int(input())
dam = list(map(int,input().split()))
rain = [[0 for x in range(n)] for y in range(n)]
print(rain)
for i in range(n):
  rain[i][i] = 1/2
  try:
    rain[i][i+1] = 1/2
  except:
    rain[i][0] = 1/2
print(solve(rain,dam))
temp_ans = solve(rain,dam).tolist()
temp2_ans = list(map(int,temp_ans))
temp3_ans = list(map(str,temp2_ans))
ans = " ".join(temp3_ans)
print(ans)

Submission status: Wrong Answer

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

ok=0
over=(10**9)*2
rains=[0]*(N+1)
while over-ok>1:
    m=(ok+over)//2
    rains[0]=m
    for i in range(N):
        rains[i+1]=A[i]*2-rains[i]
    if rains[N]<rains[0]:
        over=m
    else:
        ok=m

rain=ok
for i in range(N):
    print(rain)
    rain=A[i]*2-rain

Submission status: Wrong Answer

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

ok=0
over=(10**9)*2
rains=[0]*(N+1)
while over-ok>1:
    m=(ok+over)//2
    rains[0]=m
    for i in range(N):
        rains[i+1]=(A[i]-rains[i]//2)*2
    if rains[N]<rains[0]:
        over=m
    else:
        ok=m

rain=ok
for i in range(N):
    print(rain)
    rain=(A[i]-rain//2)*2

Submission status: Wrong Answer

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while l < r:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Wrong Answer

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 100) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 <= dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 30:
        break
    count += 1

"""
7
110 50 53 50 11 36 88
"""

Submission status: Wrong Answer

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 100) // 2
while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    flag = True
    for i in range(n - 1):
        next_amount = (dum[i] - rain[i] // 2) * 2
        if next_amount < 0:
            flag = False
        rain[i + 1] += next_amount
    # print(rain)
    if flag and rain[0] // 2 + rain[-1] // 2 == dum[-1]:
        # print("ok")
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if rain[0] + rain[-1] <= dum[-1]:
        # 最初に決めたやつが小さすぎた
        l = mid
    else:
        # 最初に決めたやつが大きすぎた
        r = mid

    # セーフティネット 必要ないけど
    if count > 30:
        break
    count += 1

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(_) for _ in input().split()])
lis = [([0] * N) for n in range(N)]
for n in range(N - 1):
    lis[n][n] = lis[n][n + 1] = 1
lis[N - 1][0] = lis[N - 1][N - 1] = 1



print(*np.dot(np.linalg.inv(np.array(lis)), A) * 2)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().rstrip().split()])
A_sum = A.sum()
A_sum //= 2
A_bi = 2 * A
ans = []
if N > 3:
    for i in range(N):
        if i < N - 3:
            ans.append(A_sum - (A[i+1] + A[i+3]))
        elif i == N - 3:
            ans.append(A_sum - (A[i+1] + A[0]))
        elif i == N - 2:
            ans.append(A_sum - (A[i+1] + A[1]))
        else:
            ans.append(A_sum - (A[0] + A[2]))
else:
    ans.append(A_sum - A[1])
    ans.append(A_sum - A[2])
    ans.append(A_sum - A[0])
print(* (2 * np.array(ans)))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().rstrip().split()])
A_sum = A.sum()
A_sum //= 2
A_bi = 2 * A
ans = []
if N > 3:
    for i in range(N):
        if i < N - 3:
            ans.append(A_sum - (A[i+1] + A[i+3]))
        elif i == N - 3:
            ans.append(A_sum - (A[i+1] + A[0]))
        elif i == N - 2:
            ans.append(A_sum - (A[i+1] + A[1]))
        else:
            ans.append(A_sum - (A[0] + A[2]))
else:
    ans.append(A_sum - A[1])
    ans.append(A_sum - A[2])
    ans.append(A_sum - A[0])

Submission status: Wrong Answer

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

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

ans = [0] * N
ans[0] = a

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

print(*ans)

Submission status: Wrong Answer

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

A_tmp = 0

for i in range(len(A)):
  if i%2 == 0:
    A_tmp += 2*A[i]
  else:
    A_tmp -= 2*A[i]

A1 = A_tmp * 2//3
ans = [A1]
for i in range(len(A)-1):
  ans.append(2*A[i]-ans[i])

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
A = list(map(int, input().split()))

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

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

for b in B:
    print(b)

Submission status: Wrong Answer

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

import numpy as np

n = ii()
a = li()

total = sum(a)
ans = [0]*n

if n==3:
    ans[0] += total - a[1]*2
    ans[1] += total - a[2]*2
    ans[2] += total - a[0]*2
else:
    a_1 = a[1:]
    a_1.extend([a[0]])
    a_1 = np.array(a_1)*2
    a_2 = a[-2:]
    a_2.extend(a[:-2])
    a_2 = np.array(a_2)*2

    for i in range(n):
        ans[i] += int(total - a_1[i] - a_2[i])

print(*ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy as np
left = []
a = []
for i in range(N):
  if (i == 0 or i == 1):
      a.append(0.5)
  else:
    a.append(0)
a = np.array(a)
for i in range(N):
  left.append(np.roll(a, i))
left = np.array(left)
print(left)
from numpy.linalg import solve
answer = solve(left, A)
answer = list(map(int, answer))
print(*answer)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N = I()
A = LI()
ans = [0]*N
dis = [0]*N
dis[0] = (A[1]-A[0])*2
for i in range(N-1):
    dis[i+1] = dis[i]+2*(A[-N+2*i+3]-A[-N+2*i+2])
#print(dis)

basic = (sum(A) - sum(dis))//N
ans[0] = basic
for i in range(1,N):
    ans[2*i-N] = basic + dis[i-1]

print(ans)

Submission status: Wrong Answer

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

minv = 0
maxv = 1000000000

nxt = [0] * (n + 1)
while minv != maxv:
  nxt[0] = (minv + maxv) // 2
  for i in range(n):
    nxt[i+1] = a[i] * 2 - nxt[i]
  if nxt[0] == nxt[n]:
    break
  elif nxt[0] > nxt[n]:
    maxv = nxt[0] - 1
  else:
    minv = nxt[0] + 1
    
for i in range(n):
  print(nxt[i], end=' ')

Submission status: Wrong Answer

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

a_sum = sum(a)
a_sum //= 2

a_sum_0 = sum(a[1::2])

ans = []
a0 = a_sum -a_sum_0
print(a_sum,a_sum_0,a0)
ans.append(2*a0)
a[0] -= a0
for i in range(n-1):
    ans.append(2*a[i])
    a[i+1] -= a[i]
    
print(*ans)

Submission status: Wrong Answer

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


def ishigh(mid):
	cur = mid
	for idx in range(len(A)):
		need = A[idx] - cur//2
		cur = need * 2
		if(cur<0):
			return True
	if(mid <= cur):
		return False
	return True

start = 0
end = A[0]//2 + 2

while start + 1 < end:
	mid = (start + end)//2
	bfirst = mid * 2
	if(ishigh(bfirst)):
		end = mid
	else:
		start = mid

b = []
b.append(2*start)
for a in A:
	b.append((a - b[len(b)-1]//2)*2)

print(" ".join(list(map(str, b[:-1]))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i, t in enumerate(a):
    double_x += (1 + -2 * (i % 2)) * t

ans[0] = double_x

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
p = np.array(list(map(int,input().split())))
a0 = 0
for i in range(0,N,2):
    a0 += p[i]
    
for i in range(1,N-1,2):
    a0 -= p[i]
    
ans2 = [a0]*N
# iは-1している(slice)ので、+1しないといけないことに注意
for i,one in enumerate(p[1:]):
    ans2[i+1] = 2*p[i] - ans2[i]

Submission status: Wrong Answer

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

W = [0] * N
tmp0 = int(np.ceil(A[N-1] / 2) % 2)
tmp1 = int(np.ceil(A[0] / 2) % 2)
if tmp0 == 0 and tmp1 == 0:
    W[0] = int(min(np.ceil(A[N-1] / 2),np.ceil(A[0] / 2)))
elif tmp0 == 0 and tmp1 == 1:
    W[0] = int(np.ceil(A[N-1] / 2))
elif tmp0 == 1 and tmp1 == 0:
    W[0] = int(np.ceil(A[0] / 2))
else:
    W[0] = 0
for i in range(1,N):
    W[i] = 2 * A[i - 1] - W[i - 1]
print(*W)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = []
rain = sum(a for a in A)
for i in range(n):
  cost = 0
  
  C = A[:i]
  cost += sum(C[2*k] for k in range(i//2))
  D = A[i:]
  cost += sum(D[2*k+1] for k in range((n-i)//2))
  B.append(rain - 2*cost)
  
L=[str(a) for a in B]
L=" ".join(L)
print(L)

Submission status: Wrong Answer

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

for i in range(A[0]+1):
    ans = []
    x1 = i*2
    ans.append(x1)
    for j in range(len(A)-1):
        x2 = 2*A[j] - x1
        ans.append(x2)
        x1  = x2
    
    ans1 = np.array(ans)
    ans2 = np.array(ans[1:] + [ans[0]])
    ans3 = (ans1 + ans2) // 2
    if sum(A==ans3)==n:
        print(*ans3)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    m = min(A)
    xi = A.index(m)
    for a in range(0, m*2+1, 2):
        B = A.copy()
        ans = [0]*N
        B[(xi-1)%N] -= a//2
        B[xi] -= a//2
        ans[xi] = a
        for i in range(xi+1, xi+N):
            x = B[(i-1)%N]*2
            if B[i%N]-x//2 < 0:
                break
            B[(i-1)%N] -= x//2
            B[i%N] -= x//2
            ans[i%N] += x
            if sum(B) == 0:
                print(ans)
                return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(a[0])

diff = [0] * n

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

sum1 = [0] * (n//2+1)
for i in range(n//2):
    sum1[i+1] = diff[i*2] + sum1[i]

sum2 = [0] * (n//2)
sum2[0] = sum1[-1] + diff[-1]
for i in range(1, n//2-1):
    sum2[i+1] = diff[i*2-1] + sum2[i]

s = [0] * n
s[::2] = sum1
s[1::2] = sum2

del a[-1]
num_diff = (sum(a) - sum(s)) // n

for i in range(n):
    s[i] += num_diff

print(*s)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

X = [0]*N
X[0] = sum(A) - 2 * (sum(A[1:N-1]))
for i in range(1, N):
  X[i] = 2 * A[i-1] - X[i-1]
print (' '.join(map(lambda x: str(x), X)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def sol():
    n=int(input())
    a=tuple(int(i) for i in input().split())
    chk=a.index(min(a))
    #for i in range(min(a[0],a[-1])*2,-1,-2):
    print(chk)
    for i in range(a[chk]*2,-1,-2):
        ans=[0]*n
        ans[chk]=i
        f=1
        for k in range(1,n):
            j=(chk+k)%n
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        #if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
        if f and ans[chk-1]//2+ans[chk-2]//2==a[chk-2] and ans[chk-1]//2+ans[chk]//2==a[chk-1]:
            print(*ans)
            exit()

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
def sol():
    n=int(input())
    a=tuple(int(i) for i in input().split())
    chk=a.index(min(a))
    #for i in range(min(a[0],a[-1])*2,-1,-2):
    for i in range(a[chk]*2,-1,-2):
        ans=[0]*n
        ans[chk]=i
        f=1
        for k in range(1,n):
            j=(chk+k)%n
            t=(a[j-1]-ans[j-1]//2)*2
            if t>=0 and (t+ans[j-1])//2==a[j-1]:
                ans[j]=t
            else:
                f=0
                break
        if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
            print(*ans)
            exit()

if __name__=="__main__":
    sol()

Submission status: Wrong Answer

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

# main
x = sum(A) - 2*sum([A[i] for i in range(1, N, 2)])
water = [x]

for i in range(N):
  x = 2*A[i] - x
  water.append(x)
  # print("new water: ", water)

# output
print(*water)

Submission status: Wrong Answer

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

# main
water = []
for i in range(N - 1, -1, -1):
  if A[i] == 0 or A[i - 1] == 0:
    x = 0
  elif A[i] == 1 or A[i - 1] == 1:
    x = 1
  else:
    if A[i - 1] < A[i]:
      x = 2*(A[i - 1]//2)
    else:
      x = 2*(A[i]//2) 
  A[i] -= x
  A[i - 1] -= x
  water.append(2*x)
  
# output
for i in water[::-1]:
  print(i, end = " ")

Submission status: Wrong Answer

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

"""
1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
S = sum(A)
X1 = S − 2(A2 + A4 + ... + AN−1)

2.以降の山も順次求めていく
Xi + Xi+1 = 2Ai 
Xi+1 = 2Ai − Xi
"""

## 1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
X1 = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
ans = [X1]

## 2.以降の山も順次求めていく
for n in range(1,N,1):
  _ = 2 * A[n-1] - ans[n-1]
  ans.append(_)


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
rest = 0
x = input().split()
rest = 0

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

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

Submission status: Wrong Answer

Solution code:
#coding utf-8
N=int(input())
A=list(map(int,input().split())) 
x = [0 for i in range(N)]
S =sum(A)
x[0]=S
for i in range(1,N,2):
  x[0]-=2*A[i]

for i in range(1,N):
  x[i]=2*A[i-1]-x[i-1]
print(S)
ans= map(str,x)
print(' '.join(ans))