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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    n = int(input())
    mt = list(map(int,input().split()))
    sm = sum(mt) // 2
    ans = [0]*n
    mt1 = [0] + mt

    ans[0] = 2*(sm - sum(mt1[::2]))

    for i in range(1,n):
        ans[i] = 2*(mt[i-1] - (ans[i-1] //2))
    
    print(' '.join(map(str,ans)))
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Accepted

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


BC133_D()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    adj_sum = [2 * a for a in A]
    water_sum = sum(A)

    sum_for_odd = 0
    for i in range(N):
        if i % 2 == 1:
            sum_for_odd += adj_sum[i]

    W = [0] * N
    W[0] = water_sum - sum_for_odd

    for i in range(1, N):
        W[i] = adj_sum[i-1] - W[i-1]

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

main()

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  A = [int(i) for i in input().split()]
  s = sum(A) // 2
  first = s - sum(A[1::2])
  ans = [ first ]
  for i in range(N - 1):
    ans.append(A[i] - ans[-1])
  print(*map(lambda v: v * 2, ans))

solve()

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
As = nl()

n_left = 0
n_right = 0
n_lefts = []
n_rights = []

p_left = 0
p_right = 0
p_lefts = []
p_rights = []

for i in range(1, N+1):
    if i % 2 > 0:
        n_left -= As[i-1]
        p_left += As[i-1]
        n_right -= As[N-1-i+1]
        p_right += As[N-1-i+1]
    else:
        n_left += As[i-1]
        p_left -= As[i-1]
        n_right += As[N-1-i+1]
        p_right -= As[N-1-i+1]

    n_lefts.append(n_left)
    p_lefts.append(p_left)
    n_rights.append(n_right)
    p_rights.append(p_right)
n_rights = n_rights[::-1]
p_rights = p_rights[::-1]

ress = []
for i in range(1, N+1):
    res = As[i-1]
    if i > 1:
        res += As[i-2]

    if i % 2 > 0:
        if i > 2:
            res += n_lefts[i - 3]
        if i <= N - 1:
            res += p_rights[i]
    else:
        if i > 2:
            res += p_lefts[i - 3]
        if i <= N - 1:
            res += n_rights[i]
    ress.append(str(res))

print(' '.join(ress))

Submission status: Accepted

Solution code:
n = int(input())

a =[]
a_li = input().split()

memo = 0
for i in range(n):
    a.append(int(a_li[i]))

    if i%2 == 0:
        memo += int(a_li[i])
    else:
        memo -= int(a_li[i])

ans = [0 for i in range(n)]

ans[0] = int(memo/2)*2

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

for i in range(n):
    print(ans[i], end ="")
    if i != n-1:
        print(" " , end ="")

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split(' ')))
arr = list(map(lambda x: x * 2, arr))
dummy = arr[0]
for i in range(1, n):
    dummy = arr[i] - dummy

ans = []
# starting answer
ans.append(dummy // 2)
for i in range(n-1):
    ans.append(arr[i] - ans[i])
print(*ans)

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def submit():
    n, alist = read_input()

    xlist = [0] * n

    for i, a in enumerate(alist):
        if i % 2 == 0:
            xlist[0] += a
        else:
            xlist[0] -= a

    for i, a in enumerate(alist[:-1]):
        xlist[i + 1] = 2*a - xlist[i]

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


if __name__ == '__main__':
    submit()

Submission status: Accepted

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

y1 = 0
for n in range(N):
  if n%2 == 0:
    y1 += A[n]
  else:
    y1 -= A[n]
y1 //= 2
ans = str(y1)

yn = y1
for i in range(N-1):
  yn = A[i] - yn
  ans += " " + str(yn)
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
A = LI()

A_sum = 0
A_acc_odd = [0]*(N//2+1)
A_acc_even = [0]*(N//2+2)

for i in range(N):
    A_sum += A[i]
    if (i&1):
        A_acc_odd[i//2+1] = A_acc_odd[i//2] + A[i]
    else:
        A_acc_even[i//2+1] = A_acc_even[i//2] + A[i]

x = [None]*N

for i in range(N):
    if (i%2):
        x[i] = A_sum - 2*((A_acc_odd[i//2]-A_acc_odd[0]) + (A_acc_even[-1] - A_acc_even[i//2+1]))
    else:
        x[i] = A_sum - 2*((A_acc_even[i//2]-A_acc_even[0]) + (A_acc_odd[-1] - A_acc_odd[i//2]))
print(*x)

Submission status: Accepted

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

half=sum(a)//2

ans=""
# for i in range(n):
#     tmp=half
#     for j in range(i+1, n, 2):
#         tmp-=a[j]
#     if i%2==0:
#         for j in range(0, i, 2):
#             tmp-=a[j]
#     else:
#         for j in range(1, i, 2):
#             tmp-=a[j]
#     ans+=str(tmp*2)
#     if i!= n-1:
#         ans+=" "
gu=[]
syaku=0
for i in range(1,n,2):
    syaku+=a[i]
for i in range(0,n,2):
    gu.append((half-syaku)*2)
    syaku+=a[i]
    if i+1==n:
        syaku-=a[0]
    else:
        syaku-=a[i+1]
# print(gu)
ki=[]
syaku=0
for i in range(2,n,2):
    syaku+=a[i]
for i in range(1,n,2):
    ki.append((half-syaku)*2)
    syaku+=a[i]
    if i+1==n:
        syaku-=a[0]
    else:
        syaku-=a[i+1]
# print(ki)
ans=[]
for i in range(n//2):
    ans.append(gu[i])
    ans.append(ki[i])
ans.append(gu[n//2])

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
C = [1 if i == 0 or i == N-1 else 0 for i in range(N)]
A = np.fft.fft(A)
C = np.fft.fft(C)
print(" ".join(map(lambda x:str(int(round(x.real))), 2*np.fft.ifft(A/C))))

Submission status: Accepted

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

x1 = (sum(A[0::2])-sum(A[1::2]))
Ans = [x1]
for a in A:
    Ans.append(2*a-Ans[-1])
print(*Ans[:-1],sep = " ")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(n)*2 for n in input().split()]#ans[0]+ans[1]=A[0]
    ans = [0]*N
    #A[0]
    tmp = A[0]
    for i in range(N-1):
        p = -1 if i % 2 == 0 else 1
        tmp += A[i+1] * p
    ans[0] = tmp // 2
    #ほか
    for i in range(N-1):
        ans[i+1] = A[i] - ans[i]
    print(" ".join([str(a) for a in ans]))


main()

Submission status: Accepted

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

b = [0] * (n+1)

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

M = (b[0] + b[n] // 2)

i = 0
while i < n:
  b[i] = (b[i] + M) * 2
  i += 1
  b[i] = (b[i] - M) * 2
  i += 1

print(' '.join(map(str, b[:n])))

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):

    X = [0] * N
    X[0] = 0
    for j in range(1,N):
        X[j] = 2*A[j-1] - X[j-1]
    T = (A[-1]*2 - (X[0]+X[-1])) // 2

    for i,x in enumerate(X):
        print(x + T if i % 2 == 0 else x - T, end="")
        if i != len(X) - 1:
            print(" ", end="")
        else:
            print("")
    return


# Generated by 1.1.4 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 = [int(_) for _ in input().split()] 

X = []
x0 = sum(A) - sum(A[1::2]) * 2
X.append(x0)

for aa in A:
    x0 = (aa - x0 // 2 ) * 2
    X.append(x0)
X.pop()

for xx in X:
    print(xx,  end=" ")

Submission status: Accepted

Solution code:
N = int(input())
dams = [int(x) for x in input().split()]
ans = dams[0]
for i in range(1, N):
  if (i % 2) == 1:
    ans -= dams[i]
  else:
    ans += dams[i]
print(ans, end=' ')
for i in range(N-2):
  ans = (dams[i] - ans // 2) * 2
  print(ans, end=' ')
ans = (dams[N-2] - ans // 2) * 2
print(ans)

Submission status: Accepted

Solution code:
import math

x = input()
n = int(x)

x = input()
x = x.split()

r = 0
hugo = 1
for i in range(0,len(x)):
  r += int(x[i])*hugo
  hugo *= -1

print(r, end=" ")

for i in range(1,n):
  r2 = (int(x[i-1]) - r/2)*2
  print(int(r2) ,end="")
  r = r2
  if i < n-1:
    print(" " ,end="")

Submission status: Accepted

Solution code:
def prob_d():
    n = int(input())
    a_list = [int(a) for a in input().split()]
    even_sum = sum(a_list[2::2])
    odd_sum = sum(a_list[1::2])
    sum_list = even_sum + odd_sum + a_list[0]
    ans = ""
    for i in range(n):
        if i % 2 == 0:
            ans += str(sum_list - odd_sum * 2)
            if i != n-1:
                odd_sum -= a_list[i+1]
                odd_sum += a_list[i]
        else:
            ans += str(sum_list - even_sum * 2)
            if i != n-1:
                even_sum -= a_list[i+1]
                even_sum += a_list[i]
        if i != n-1:
            ans += " "
    print(ans)

prob_d()

Submission status: Accepted

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

rain = [sum([ai for ai in a[::2]]) - sum([ai for ai in a[1::2]])]
for ai in a[:-1]:
  rain.append(ai * 2 - rain[-1])
print(' '.join(str(i) for i in rain))

Submission status: Accepted

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

calc = 0

for i in range(0,len(A),2) :
    calc += A[i]
for i in range(1,len(A),2) :
    calc -= A[i]

p = calc//2

X = [0 for i in range(N)]
X[0] = p

for i in range(1,len(X)) :
    X[i] = A[i-1] - X[i-1]

ans = [x*2 for x in X]
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) # １行に別れてるとき

A1 = []
k = 0
for i in range(N):
    if i % 2 == 0:
        k += A[i]
    else:
        k -= A[i]
    A1.append(k)

ans = []
for i in range(N):
    if i == 0:
        ans.append(A1[-1])
        continue
    pre = A1[-1] - A1[i-1]
    fow = A1[i-1]
    if i % 2 == 0:
        ans.append(pre - fow)
    else:
        ans.append(fow - pre)

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

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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


def bisect_left_callable(fn, x, lo, hi):
    """
    (memo) いっぱい呼ぶなら np.searchsorted のほうがベクトル化されててはやそう
    lo から hi-1 のうち、fn の結果が x 以上となる、最も左の値
    bisect.bisect_left と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


def solve(n, a=False):
    mts = A.copy()
    mts[0] -= n
    mts[-1] -= n
    hist = [n*2]
    for i in range(N):
        mts[(i + 1) % N] -= mts[i]
        hist.append(mts[i] * 2)
    if a:
        return hist
    else:
        return -mts[-1]


n = bisect_left_callable(solve, 0, 0, A[0] + 1)
print(*solve(n, True)[:-1])

Submission status: Accepted

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

Submission status: Accepted

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

goukei = sum(dum_list)

last_yama = int(goukei/2 - sum([a for i,a in enumerate(dum_list[:-1]) if i%2==0] ))
start_yama = dum_list[-1] - last_yama

yama_small = [start_yama,]
for d in dum_list[:-1]:
    yama_small.append(d-yama_small[-1])

print(" ".join(map(str,[int(y*2) for y in yama_small])))

Submission status: Accepted

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




for i in range(n):
    if i %2 == 0:
        x = A - 2*A_odd[i//2]-2*(A_even[(n-1)//2]-A_even[i//2])
    else:
        x = A - 2*A_even[(i-1)//2]-2*(A_odd[(n+1)//2]-A_odd[(i+1)//2])
    print(x,end=" ")

print()

Submission status: Accepted

Solution code:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
D=deque(A)
m=sum(A)//2
for n in range(N//2):m-=A[2*n+1]
ans=str(2*m)
for _ in range(N-1):
    a=deque.popleft(D)-m
    ans+=" "+str(a*2)
    m=a
print(ans)

Submission status: Accepted

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

ans = 0
for j in range(N):
    ans += A[j]*(-1)**j

print(ans)

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

Submission status: Accepted

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

total = sum(a)//2

index = 1
while index <= n-1:
    total -= a[index]
    index += 2

answer = []
for i in range(n):
    answer.append(total*2)
    total = a[i] - total

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = []

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

    for i in range(N - 1):
        ans.append(2 * (A[i] - (ans[i] / 2)))
        
    for value_ in ans:
        print(int(value_), end=" ")
    print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
S = 0
for i in range(N):
    if i%2 == 0:
        S += A[i]
    else:
        S -= A[i]
ans = str(S)
for i in range(N-1):
    S = 2*A[i] - S
    ans += " " + str(S)
print(ans)

Submission status: Accepted

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main
    
    N = int(r())
    A = R()
    total = sum(A)
    ans = [0] * N
    
    tmp = 0
    for i in A[::2]:
        tmp += i*2
    
    ans[0] = tmp - total
    
    tmp = ans[0]
    for i in range(N-1):
        tmp = 2*A[i] - tmp
        ans[i+1] = tmp
    
    print(*ans)
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Accepted

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

x=a[-1]-(l[-2]//2)

print(x,end=" ")
for i in range(1,n):
    if i%2==0:
        print(l[i-1]+x,end=" ")
    else:
        print(l[i-1]-x,end=" ")
print("")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0 for _ in range(N)]
    for i in range(0,2*N-2,2):
        X[(i+2)%N] = X[i%N] + 2*(A[(i+1)%N] - A[i%N]) 
    x0 = (sum(A)-sum(X))//N
    return ' '.join([str(x0+x) for x in X])



if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import sys

n= int(sys.stdin.readline())
a = [ int(x) for x in sys.stdin.readline().split() ]

x = 0
for i in range(n):
    if i%2==0: x+= a[i]
    else: x-=a[i]
#
print( x,end="" )
for i in range(n-1):
    x = 2 * a[i] - x
    print( " {}".format( x ),end="" )
print()

Submission status: Accepted

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

X=[None for i in range(n)]

first=0
sig=1

for i in range(n):
    first+=A[i]*sig
    sig*=-1
    
X[0]=first

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

#print(X)

ans=[str(X[i]) for i in range(n)]

ans=" ".join(ans)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  x1 = 0
  for i in range(n):
    if i%2 == 0:
      x1  += a[i]
    else:
      x1  -= a[i]
  query = deque([x1])
  x = x1
  for i in range(n-1):
    tmp = a[i]-x//2
    tmp *= 2
    query.append(tmp)
    x  = tmp
  print(*query)
solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    s = 0
    for j, a in enumerate(A):
        s += a * (1 if ((j % N) % 2 == 0) else -1)
    ans.append(str(s))
    for i in range(1, N):
        s = -s + 2 * A[i - 1]
        ans.append(str(s))
    return ans


def main():
    print(' '.join(solve()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = sum(a) / 2
p = int((n - 1) / 2)

x = []

t = b
for j in range(p):
    t -= a[2 * j + 1]
x.append(t * 2)

for i in range(n-1):
    t = a[i] - x[i] / 2
    x.append(t * 2)

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

Submission status: Accepted

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

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

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

m = list(map(str, m))
print(" ".join(m))

Submission status: Accepted

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