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: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N = iip(False)
    A = iip(True)

    s = sum(A) // 2
    sa = 0
    for i, a in enumerate(A, 1):
        if i % 2 == 0:
            sa += a
    a1 = s-sa

    result = []
    cur = a1*2
    for i in A:
        result.append(cur)
        cur = (i - cur // 2)*2

    split_print_space(result)


#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = [0] * N
for i in range(N): res[0] += a[i] * (pow(-1, i % 2))
for i in range(N - 1):
  a[i] -= res[i] // 2
  res[(i + 1) % N] = a[i % N] * 2
print(*res)

Submission status: Accepted

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

Submission status: Accepted

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

S = 0
for i, a in enumerate(A):
    S += (-1)**i * a

ans = [0] * N
ans[0] = S
for i, a in enumerate(A[:-1], start=1):
    S *= -1
    S += 2 * a
    ans[i] = S

print(*ans)

Submission status: Accepted

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

print(*x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = [0] * n

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

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

for i in range(n):
    print(x[i], end=' ')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
b1 = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        b1 += a
    else:
        b1 -= a

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

print(*B)

Submission status: Accepted

Solution code:
N=int(input())
A=[0]+[(-1)**i*x for i,x in enumerate(map(int,input().split()))]
import itertools
cumsum=list(itertools.accumulate(A))
print(*[(-1)**(i-1)*(cumsum[-1]-cumsum[i-1]-cumsum[i-1]) for i in range(1,N+1)])

Submission status: Accepted

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

Ws= [0 for i in range(N)]

sum_w1_wn = 0
for i in range((N-1)//2):
    sum_w1_wn += As[2*i+1]

#print('sum_v1_wn:', sum_w1_wn)

Ws[0] = sum(As) - 2*sum_w1_wn
#print('Ws[0]:', Ws[0])


print(Ws[0], end='')
for i in range(1,N):
    Ws[i] = 2*As[i-1] - Ws[i-1]
    print('', Ws[i], end='')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
c = 0
for idx, i in enumerate(a):
  if idx %2 ==0:
    c += i
  else: 
    c -= i
x1 = c
print(x1)
for i in range(1,N):
  x1 = 2*a[i-1] - x1
  print(x1)

Submission status: Accepted

Solution code:
#ABC133-D
N=int(input())
A=[int(i) for i in input().split()]
ANS=[sum(A)-2*sum(A[1::2])]
for i in range(N-1):
    ANS.append(2*A[i]-ANS[-1])
print(*ANS)

Submission status: Accepted

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

Submission status: Accepted

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

b=[0]*(N+1)
b[0] = sum(a)-2*sum(a[1::2])
for i in range(1,N+1):
    b[i] = 2*a[i-1] - b[i-1]
print(*b[:N])

Submission status: Accepted

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

ans = [S - sum([2 * Alist[i] for i in range(1, N - 1, 2)])]
for i in range(1, N):
    ans.append(-ans[i - 1] + 2 * Alist[i - 1])


print(*ans)

Submission status: Accepted

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

s = sum(a)
sodd = 0
for i in range(n):
    if i % 2 == 1:
        sodd += a[i]

x = [0] * n

x[0] = s - 2 * sodd

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

print(*x)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)
init = SUM - 2*sum(A[1::2])
dp = [0]*n
dp[0] = init
for i in range(1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
print(*dp)

Submission status: Accepted

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

dp = [0]*n
dp[0] = cnt = 0
for i in range(1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]

init = SUM-cnt
dp = [0]*n
dp[0] = cnt = init
for i in range(1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]

print(*dp)

Submission status: Accepted

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

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

su1 = sum(lis)
su2 = sum(lis[1::2])

ans = [0] * n
ans[0] = su1 - 2 * su2

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

print(*ans)

Submission status: Accepted

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

n = int(input())
lis = list(map(int, input().split()))
res = sum(lis)
su = [0] * n

for i in range(n):
    if i < 2:
        su[i] = lis[i]
    else:
        su[i] = su[i-2] + lis[i]

ans = []
ans_a = ans.append

for i in range(n):
    if i == 0:
        b = su[-2]
        ans_a(res-2*b)
    elif i == 1:
        b = su[-1] - su[i-1]
        ans_a(res-2*b)
    elif i == n:
        b = su[-1] - lis[-1]
        ans_a(res-2*b)
    elif i % 2 == 0:
        b = su[-2] - su[i-1] + su[i-2]
        ans_a(res-2*b)
    else:
        b = su[-1] - su[i-1] + su[i-2]
        ans_a(res-2*b)
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
b = []
for i in range(N):
    cnt += A[i]*(-1)**i
    b.append(cnt)
ans = [0]*N
for i in range(N):
    if i%2 == 0:
        ans[i] = b[N-1]
        if i-1 >= 0:
            ans[i] -= 2*b[i-1]
    else:
        ans[i] = -b[N-1]
        if i-1 >= 0:
            ans[i] += 2*b[i-1]
print (*ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
am = [a[i]*(-2) for i in range(0,n,2)]

ans = [0 for i in range(n)]
ans[n-1] = sum(a) + sum(am) - am[(n-1)//2]

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
am = [a[i]*(-2) for i in range(0,n,2)]

sa = sum(a)
sam = sum(am)

ans = [0 for i in range(n)]
ans[n-1] = sum(a) + sum(am) - am[(n-1)//2]

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)
MIN = min(A)
start = A.index(MIN)

dp = [0]*n
dp[start] = cnt = 0
for i in range(start+1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]
else:
    for i in range(start):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]

odd = SUM-cnt
dp = [0]*n
dp[start] = cnt = odd
for i in range(start+1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]
else:
    for i in range(start):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]

print(*dp)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0 for _ in range(n)]

x0 = 0
for i in range(n):
  if i%2 ==0 :
    x0 += a[i]
  else:
    x0-= a[i]
    
x[0] = x0
print(x[0],end = ' ')
for j in range(1,n):
  x[j] = 2*a[j-1] -x[j-1]
  print(x[j],end = ' ')

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

'''
from numpy.linalg import solve

N =ii()
left = dp2(0, N, N)
for i in range(N-1):
    left[i][i] = left[i][i+1] = 0.5
left[N-1][N-1] = left[N-1][0] = 0.5

right = li()

for i in solve(left, right):
    print(int(i), end='')
    print(' ', end='')
'''

N = ii()
A = li()

ans = [0]*N

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

for i in range(N):
    print(ans[i], end='')
    print(' ', end='')

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    #山1の降水量
    def check(x):
        s = x
        for i in a:
            x = i * 2 - x
        if s>=x:
            return 1
        else:
            return 0

    left = -1
    right = 10**10
    while right - left > 1:
        mid = (right+left) // 2
        if check(mid*2):
            right = mid
        else:
            left = mid
    res = [right*2]
    for i in a:
        res.append(i*2 - res[-1])
    res = map(str, res[:-1])
    print(' '.join(res))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = sum(A)//2

x0 = total
for i in range(N//2):
  x0 -= A[2*i+1]

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

print(*ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

li = [0]*n
li[0] = sum(a[::2])-sum(a[1::2])

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

print(*li)

Submission status: Accepted

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]
    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: Accepted

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

Submission status: Accepted

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

M=[0]*N
M[0]=2
for i in range(N):
    if i+1==N:
        pass
    else:
        M[i+1]=(A[i]-M[i]//2)*2
dif=A[N-1]-M[0]//2-M[N-1]//2
#print(M)
#print(dif)
for i in range(N):
    if i%2==0:
        M[i]+=dif
    else:
        M[i]-=dif
print(' '.join(list(map(str, M))))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    n = int(input())
    a = list(map(int, input().split()))
    res = []
    x = sum(a[::2]) - sum(a[1::2])
    res.append(x)
    for i in range(1, n):
        x = 2 * a[i - 1] - x
        res.append(x)
    print(" ".join(str(x) for x in res))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sign = 1
ret = 0

for i in range(len(a_list)):
    ret += sign * a_list[i]
    sign *= -1

r_list = []
r_list.append(str(ret))

tmp = ret

for i in range(len(a_list)-1):
    tmp = (a_list[i] - (int(tmp) // 2)) * 2
    r_list.append(str(tmp))

print(' '.join(r_list))

Submission status: Accepted

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

Submission status: Accepted

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

now = sum(l)-2*sum(l[1::2])
ans = [now]

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

Submission status: Accepted

Solution code:

"""
各山に振った雨をm1,m2,...とすると
a1 + a2 + ... + aN = m1 + m2 + ... + mN
また、あるダムについて、左右の山の雨が半分ずつたまるから
(mi + mi+1)/2 = ai -> mi + mi+1 = 2*ai
これらより
m1 = (a1 + ... + aN) - (m2 + m3 + ... + mN)
m2+m3 = 2*a2, m4+m5 = 2*a4, ...
からm1が決まる
m1 + m2 =2*a1 からm2がきまって～がmNまで続く
"""

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

total = sum(A)
tmp = 0
for i in range(1,N,2):
    tmp += 2 * A[i]

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

print(*ans)

Submission status: Accepted

Solution code:
N=int(input())
#ダムに溜まった水
A=list(map(int, input().split()))

"""
+ A[0]=B[0]//2+B[1]//2
- A[1]=B[1]//2+B[2]//2
+ A[2]=B[2]//2+B[3]//2
  ...
+ A[N-1]=B[N-1]//2+B[0]//2 #奇数番目

A[0]-A[1]+A[2]+....+A[N-1]=B[0]
"""
b_0=0
for i in range(N):
  if i%2==0:
    b_0+=A[i]
  else:
    b_0-=A[i]
    
for i in range(N):
  if i==0:
    print(b_0, end=" ")
    b=b_0
  else:
    b_n=(A[i-1]-b//2)*2
    print(b_n, end=" ")
    b=b_n

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A2s = [2*A[i] for i in range(N)]
    M1 = 0
    sign = 1
    for i in range(len(A2s)):
        M1 += sign * A2s[i]
        sign *= -1
    prev = M1//2
    resultS = str(prev)
    for i in range(N-1):
        current = A2s[i] - prev
        prev = current
        resultS += " " + str(current)
    print(resultS)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

ans = [0] * n
ans[0] = sum(a) - sum(a[1::2])*2

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(input())
a=list(map(int,input().split()))
rain=[[] for _ in range(N)]
tot=sum(a)
i=0
tmp=tot
while i!=N-1:
  tmp-=2*a[i]
  i+=2
rain[-1]=str(tmp)
for i in range(-2,-N-1,-1):
  rain[i]=str(2*a[i]-int(rain[i+1]))
print(' '.join(rain))

Submission status: Accepted

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

# A[0]は0と1の間に振ったものなので、
a = 0
for i in range(N//2):
  a +=  A[2*i] - A[2*i+1]

a0 = (a + A[-1]) //2

for i in A:
  print(a0*2,end=" ")
  a0 = i - a0

Submission status: Accepted

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

Submission status: Accepted

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

al = sum(A)

x = al - sum(A[1::2]) * 2

ans = []
ans.append(x)

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

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

Submission status: Accepted

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

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

print(" ".join(str(n) for n in res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
dam = sum(A)
for i in range(1,N-1,2):
    dam -= 2*A[i]
X = [dam]
for i in range(N-1):
    Xtemp = 2*A[i]-X[i]
    X.append(Xtemp)
print(" ".join(map(str,X)))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
	a -= A[i] * 2
	i += 2
print(a, end=' ')
i = 1
while i < N:
	a = A[i - 1] * 2 - a
	print(a, end=' ')
	i += 1

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
	a -= A[i] * 2
	i += 2
print(str(a) + ' ', end='')
i = 1
while i < N:
	a = A[i - 1] * 2 - a
	print(str(a) + ' ', end='')
	i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

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

print(*x)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())

total = A.sum()
answer = [0] * N
answer[0] = total - A[1::2].sum() * 2
A = A.tolist()
for i in range(1, N):
    answer[i] = A[i-1]*2 - answer[i-1]
print(*answer)

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    s=0
    ans=[0]*n
    flg=1
    for i in range(n):
        s+=flg*a[i]
        flg*=-1
    flg=1
    for i in range(n):
        ans[i]=abs(s)
        s=s-2*a[i]*flg
        flg*=-1
    print(' '.join(map(str,ans)))
  
if __name__ == '__main__':
    main()

Submission status: Accepted

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 == 1:
        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: Accepted

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: Accepted

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

x = sum(A) - 2 * sum([A[2*i+1] for i in range(N//2)])
ans = [x]
for i in range(N-1) :
    ans.append(2 * A[i] - x)
    x = ans[i+1]

print(*ans)

Submission status: Accepted

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(' '.join(map(str,ret)))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
tmp = 0
for i in range(1, len(a), 2):
    tmp += a[i]
x1 = summ - 2 * tmp
print(x1, end=" ")
for i in range(1, n):
    x1 = 2 * a[i - 1] - x1
    if i != n - 1:
        print(x1, end=" ")
    else:
        print(x1)

Submission status: Accepted

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

l = [0]
for i in range(1,len(a)):
    l.append(a[i - 1] * 2 - l[i - 1])
dam = [sum(a) - sum(l)]

for i in a[:-1]:
    dam.append((i - dam[-1] // 2) * 2)
print(*dam)

Submission status: Accepted

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

SUM_A = A[0]
rev = -1
for i in range(N - 2):
    SUM_A += rev*A[i+1]
    rev *= -1

X = [0]*N

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

Submission status: Accepted

Solution code:
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A):
    x = [0 for i in range(N)]
    x[0] = sum([A[i]*(-1)**i for i in range(0, N)]) // 2
    for i in range(0, N-1):
        x[i+1] = A[i] - x[i]
    x = [2 * x[i] for i in range(N)]
    return ' '.join(map(str, x))

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

dam = [0]*N
s = A[0]
for i in range(1,N):
    if i%2 == 1:
        s -= A[i]
    else:
        s += A[i]
dam[0] = s//2
    
for i in range(1,N):
    dam[i] = A[i-1]-dam[i-1]

[print(i,end=" ") for i in dam]