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:
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, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
A=LI()
sm=0
ans=[0 for i in range(n)]
for i in range((n-1)//2):
    sm+=2*A[2*i+1]
ans[0]=sum(A)-sm
for i in range(n-1):
    ans[i+1]=-ans[i]+2*A[i]
print(*ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))

s = sum(a[::2]) - sum(a[1::2])
ans = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

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

    ans = [0 for _ in range(N)]
    ans[0] = res // 2
    for i in range(0, N - 1):
        ans[i + 1] = A[i] - ans[i]
    ans[N - 1] = A[N - 1] - ans[0]
    ans = [2 * a for a in ans]
    print(*ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

rslt = []
ttl = sum(ns)
x = ttl - 2 * sum(ns[i] for i in range(1, n, 2))
rslt.append(x)
for i in range(0, n-1):
    x = 2 * ns[i] - x
    rslt.append(x)
print(*rslt)

Submission status: Accepted

Solution code:
# solution

data = int(input())
array = list(map(int, input().split()))

t = [0] * data
t[0] = sum(array[::2]) - sum(array[1::2])
for i in range(1, data):
    t[i] = 2 * array[i - 1] - t[i - 1]
print(*list(map(str, t)))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

even_A = sum([A[i] for i in range(len(A)) if i % 2 == 0])
odd_A = sum([A[i] for i in range(len(A)) if i % 2 == 1])

# print(even_A)
# print(odd_A)

ans[0] = even_A - odd_A

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

print(*ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n * a, b))
    return

#B
def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return

#C
def C():
    l, r = LI()
    ans = 2018
    if l // 2019 == r // 2019:
        for i in range(l, r + 1):
            for k in range(i+1, r + 1):
                ans = min(ans, (i * k) % 2019)
        print(ans)
    else:
        print(0)
    return

#D
def D():
    n = II()
    a = LI()
    a = a + [a[0]]
    ans = [0] * n
    x = 0
    for i in range(1, n, 2):
        x = x + a[i + 1] - a[i]
    ans[1] = a[0] - x
    ans[0] = ans[1] + 2 * x
    for i in range(2, n):
        ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
    print(" ".join(map(str, ans)))

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
sa = [0] * n
nn = n // 2
q = sum(a) // 2

a = a * 3
su1 = 0
su2 = 0
for i in range(nn):
    su1 += a[1+2*i]
    su2 += a[2+2*i]

for i in range(n):
    if i%2 == 0:
        sa[i] = su1
        su1 = su1 - a[1+i] + a[1+i+2*nn]
    if i%2 == 1:
        sa[i] = su2
        su2 = su2 - a[1+i] + a[1+i+2*nn]
        
ans = [0] * n
for i in range(n):
    ans[i] = (q - sa[i]) * 2
    
print(*ans)

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  # Xi+Xi+1=2Ai
  # Xi=S-(Xi+1+Xi+2...)
  # X1=S-2A2-2A4...

  n=I()
  l=LI()
  sm=sum(l)
  _a=0
  for i,x in enumerate(l):
    if i%2==1:
      _a+=x
  x1=sm-_a*2
  ans=[x1]
  for i in range(n-1):
    b=2*l[i]-x1
    x1=b
    ans.append(x1)
  return ' '.join([str(x) for x in ans])

# main()
print(main())

Submission status: Accepted

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

    s = 0
    for i in range(n-1):
        s += (-1)**(i+1)*a[i]
    x = (a[n-1]-s)//2
    ans = [x]
    for i in range(n-1):
        ans.append(a[i]-ans[i])
    print(' '.join(list(map(str,list(map(lambda x:2*x,ans))))))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

sb=0
for i in range(N-1):
    if i%2==0:
        sb += A[i+1]-A[i]
sm =A[N-1]
ans=[sm-sb]

for j in range(N-1):
    ans.append(int((A[j]-ans[j]/2)*2))
print(' '.join(str(k) for k in ans))

Submission status: Accepted

Solution code:
N = int(input())
Dams = list(map(int,input().split()))
sum = 0

for i in range(N):
    sum += Dams[i]

non1 = 0
for j in range(1,N // 2 + 1):
    non1 += 2 * Dams[2*j-1]

ans = [0 for i in range(N)]
ans[0] = sum - non1

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

for k in range(N):
    print(ans[k],end=" ")

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
oddr = [0]*(n+1)
oddl = [0]*(n+1)
ever = [0]*(n+1)
evel = [0]*(n+1)
#r:右への和 l左への和
for i in range(1,n+1):
    oddr[i] = oddr[i-1]
    ever[i] = ever[i-1]
    if i%2==1:
        oddr[i]+=A[i-1]
    else:
        ever[i]+=A[i-1]

for i in range(1,n+1):
    oddl[i] = oddl[i-1]
    evel[i] = evel[i-1]
    if i%2==1:
        oddl[i]+=A[-i]
    else:
        evel[i]+=A[-i]

ans = [0]*n
sa = sum(A)
for i in range(1,n+1):
    idxl = (n+1-i)
    if i%2==0:
        ans[i-1] = sa - 2*((oddr[-1] - oddr[i]) + (evel[-1] - evel[idxl]))
    else:
        ans[i-1] = sa -2*( (ever[-1] - ever[i]) + (oddl[-1] - oddl[idxl]))

print(*ans)

Submission status: Accepted

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

Asum = sum(As)
sum_eve = 0 #偶数
sum_odd = 0 #奇数

for i,a in enumerate(As+[As[0]]):
    if i % 2 == 0:
        sum_eve += a
    if i % 2 == 1:
        sum_odd += a 
# print(sum_eve)   
# print(sum_odd)
ans = [0] * N
ans[0] = sum_eve-Asum//2
ans[1] = sum_odd-Asum//2

n = N//2
for i in range(2,N):
    i_d = i-2  #消す
    i_a = (i+2*n)%N ##加える 
    # print(i)
    ans[i] = ans[i-2] - As[i_d] + As[i_a]

ans = [2*a for a in ans]

print(*ans)

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    x1 = sum([a if i % 2 == 0 else -a for i, a in enumerate((A))])
    X = [x1]
    for i in range(1, N):
        xi = 2 * A[i-1] - X[i-1]
        X.append(xi)
    
    print(*X)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = [0] * n
a_o = [a[i] for i in range(len(a)) if i % 2 == 1]
x[0] = sum(a) - 2*sum(a_o)

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

S = sum(A)
A_even_sum = 0
for i in range(1, N - 1, 2):
    A_even_sum += A[i]
X = []
x_1 = (S - 2 * A_even_sum)
X.append(x_1)
for i in range(N - 1):
    x_next = int(2 * A[i] - X[i])
    X.append(x_next)
    X[i] = str(X[i])
X[N - 1] = str(X[N - 1])

ans = " ".join(X)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x = a[0]-((ans[0]+ans[1])//2)
for i in range(len(ans)):
    ans[i] += x
print(*ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(lambda x: int(x)*2, readline().split()))
ans = [0] * n
for i in range(n):
    if i % 2 == 0:
        ans[0] += a[i]
    else:
        ans[0] -= a[i]
ans[0] //= 2
for i in range(1, n):
    ans[i] = a[i - 1] - ans[i - 1]
print(*ans)

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

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

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

print(*x)

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

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

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())
List = list(map(int,input().split()))
Ans = [0]*N
for i in range(N):
  if i % 2 == 0:
    Ans[0] += List[i]
  else:
    Ans[0] -= List[i]
for i in range(1,N):
  Ans[i] = 2*List[i-1] - Ans[i-1]
print(*Ans)

Submission status: Accepted

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

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

print(*solve())

Submission status: Accepted

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

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

print(*solve())

Submission status: Accepted

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

res = [0] * N
allrain = sum(As)
elselast = sum(As[:-1:2]) * 2
res[-1] = allrain - elselast

for idx in range(0, N-1)[::-1]:
    res[idx] = As[idx] * 2 - res[idx + 1]

print(*res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    mount = [0] * n
    tmp = 0
    for i in range(n - 1):
        if i % 2 == 1:
            tmp += a[i] * 2
    mount[0] = sum(a) - tmp

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

    mount = list(map(str, mount))
    print(' '.join(mount))

Submission status: Accepted

Solution code:
_,l=open(0);*l,=map(int,l.split())
a=[];t=sum(l)-sum(l[1::2])*2
for i in l:a+=t,;t=i*2-t
print(*a)

Submission status: Accepted

Solution code:
_,*l=map(int,open(0).read().split())
a=[];t=sum(l)-sum(l[1::2])*2
for i in l:a+=[t];t=i*2-t
print(*a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

    all_sum = sum(A)
    od_sum =sum([A[i*2] for i in range((N+1)//2)])
    a = []
    a1 = (od_sum - all_sum//2)*2
    pre = a1
    a.append(a1)
    for x in range(0,N-1):
        t = (A[x] - pre//2)*2
        a.append(t)
        pre = t

    print(*a)
    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()))

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

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int,input().split()))
first = 0
for i in range(len(a_list)):
    if i%2 == 0:
        first += a_list[i]
    else:
        first -= a_list[i]
        
ans_list = [first]
for i in range(0,len(a_list)-1):
    ans_list.append(2*(a_list[i]-int(ans_list[i]/2)))
    
print(*ans_list)

Submission status: Accepted

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

ans=[0]*(n+1)
xn=0
for i in range(n):
    if i!=n-1:
        xn=xn-a[i]*(-1)**i
    else:
        xn=xn+a[i]
ans[-1]=xn
ans[0]=xn
for i in range(n):
    temp=2*a[i-1]-ans[i]
    ans[i+1]=temp

print(*ans[1:])

Submission status: Accepted

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

ans = []
rain = 0

#山1を出す
for i in range(N):
  if i % 2 == 0:
    rain += A[i]
  else :
    rain -= A[i]

ans.append(rain)

#山2~Nを出す
for i in range(1,N):
  ans.append((A[i-1]-(ans[i-1]//2))*2)

L=[str(a) for a in ans]
L=" ".join(L)
print(L)

Submission status: Accepted

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

k = N-4
a = A[N-1] - A[N-2] + A[N-3]

for i in range((N-1)//2 - 1):
    a -= A[k]
    k -= 1
    a += A[k]
    k -= 1

print(a,end=" ")
t = a
for i in range(N-1):
    t = (A[i] - t//2)*2
    print(t,end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#N%2==1なので
#a1=S-2((a2+a3)+(a4+a5)+...+(aN-1+aN))
#=S-2(A2+A4+...+AN-1)よりa1を求め
#ai+ai+1=2Ai<=>ai+1=2Ai-aiより再帰的にa2以降を求める
N=int(input())
A=list(map(int,input().split()))
count=0
allcount=0
matrix=[]
ans=[0]*N
allsum=0
a1=0
for i in range(N):
    allsum=allsum+A[i]
a1=allsum
for i in range(N):
    if i%2==1:
        a1=a1-2*A[i]
ans[0]=a1
for i in range(0,N-1,1):
    ans[i+1]=2*A[i]-ans[i]
print(*ans,sep=" ")

Submission status: Accepted

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

Submission status: Accepted

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

start = 0
for i in range(0,n,2):
  if i == n-1:
    start += a[n-1]
    break
  start += a[i]-a[i+1]

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

l = [str(a) for a in ans]
l = " ".join(l)
print(l)

Submission status: Accepted

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

X = [0]*N
X[0] = S-2*(S-sum(A[0::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()))

n = [0]*N
n[0] = sum(A)-sum(A[1::2])*2
print(n[0], end = " ")

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

print("")

Submission status: Accepted

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

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

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

print(*b)

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))
    res = [0] * n
    xs = sum(a)
    res[0] = xs - 2 * (sum(a[1::2]))

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

    print(*res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
dif1=[0 for _ in range(n)]
dif2=dif1[:]
ans=[0 for _ in range(n)]
s=sum(a)
for i in range(n):
  dif2[i]=a[(i+1)%n]-a[i%n]
p=0  
for i in range(1,n):
  j=(2*i)%n
  dif1[j]=p+a[j-1]-a[j-2]
  p=dif1[j]
ans[0]=(s-sum(dif1)*2)//n
p=ans[0]
for i in range(1,n):
  ans[i]=p+dif1[i]*2


#print(dif2,dif1,ans[0])
print(*ans)

Submission status: Accepted

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

Submission status: Accepted

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

e = sum(A[::2])
o = sum(A[1::2])
ans = [e-o]
for a in A:
  ans.append(2*(a-ans[-1]//2))

ans.pop()
print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
l1 = [] #odd *-1
l2 = [] #even *-1
ans = []
for i in range(n):
    if i%2:l1.append(-1*l[i])
    else:l1.append(l[i])
for j in range(n):
    if j%2:l2.append(l[j])
    else:l2.append(-1*l[j])

a = [0]+list(accumulate(l2[::-1]))
b = [0]+list(accumulate(l1))
c = [0]+list(accumulate(l1[::-1]))
d = [0]+list(accumulate(l2))
for k in range(n):
    if k%2:
        ans.append(a[~k]+b[k])
    else:
        ans.append(c[~k]+d[k])

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

Submission status: Accepted

Solution code:
from itertools import*


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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

def check(si,xi):
    X = [-1] * N
    X[si] = xi
    for i in range(N-1):
        ci = (si+i+1)%N-1
        X[ci+1] = 2*A[ci] - X[ci]
    if X[si] == 2*A[si-1] - X[si-1]:
        return X
    return [2*A[si-1] - X[si-1]]

mm = 10**10
mi = -1
for i,a in enumerate(A):
    if a < mm:
        mm = a
        mi = i

xi = 0
while xi <= 2*mm:
    X = check(mi, xi)
    if len(X) == N:
        print(*X)
        exit()
    xi = (xi + X[0]) // 2

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = [0]*n
ans[0] = x
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()))

ans = [0] * n
sum_ = sum(a)
even = 0
odd = 0
for i in range(1, n):
    if i % 2 == 1:
        odd += a[i]
    else:
        even += a[i]

for i in range(n):
    if i % 2 == 1:
        ans[i] = sum_ - 2 * even
        even -= a[(i + 1) % n]
        even += a[(i + 1 + n - 1) % n]
    else:
        ans[i] = sum_ - 2 * odd
        odd -= a[(i + 1) % n]
        odd += a[(i + 1 + n - 1) % n]
print(*ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
x = [0 for _ in range(n)]
x[0] = sum(a) - 2 * sum([a[i] for i in range(1, n, 2)])
for i in range(1, n):
    x[i] = 2 * (a[i - 1] - x[i - 1] // 2)
debug(x)
x = [str(i) for i in x]
print(' '.join(x))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
e = sum(A[::2])
o = sum(A[1::2])
ans = [e-o]
for a in A:
    ans.append(2*(a-ans[-1]//2))
ans.pop()
print(*ans)