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: Time Limit Exceeded

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

gu_idx = [i for i in range(N) if i % 2 == 0]
ki_idx = [i for i in range(N) if i % 2 == 1]

ans = []
for idx, dam in enumerate(A):
#     print(A[gu_idx])
    ans.append(str(sum(A[gu_idx]) + sum(negative_A[ki_idx])))
    
    A = np.roll(A, -1)
    negative_A = np.roll(negative_A, -1)       
    
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))[::-1]
calc = 0
op = 1

for a in A :
    if op == 1 :
        calc += a
        op = -1
    else :
        calc -= a
        op = 1

for i in range(calc+1) :
    if i == calc-i :
        p = i
        break

X = [p]
op = -1
for a in A[::-1] :
    calc = a - X[-1]
    X.append(calc)

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

Submission status: Time Limit Exceeded

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


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


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
r = []
tmp = [2 * k + 1 for k in range(n//2)]
c = 0
for j in range(n):
  if j in tmp:
    c -= a[j]
  else:
    c += a[j]
r.append(c)
for i in range(n-1):
  r.append((a[i] - r[i] // 2) * 2)
print(*r)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    x = [0] * N
    xsum = sum(A)
    for i in range(N):
        tmp = 0
        for j in range(N // 2):
            tmp += A[(i+2*j+1)%N] * 2
        x[i] = int(xsum - tmp)
    print(*x)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
A = []
for i in range(n):
    c = [0] * n
    if i != n-1:
        c[i], c[i+1] = 1/2, 1/2
    else:
        c[0], c[n-1] = 1/2, 1/2
    A.append(c)

A = np.array(A)
b = np.array(a)
ans = list(np.linalg.solve(A, b))
ans = map(int, ans)
ans = map(str, ans)
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aSum = sum(aList)//2
ansList = []
for i in range(n):
    s = aSum
    counter = (i + 1) % n
    for j in range((n-1)//2):
        s -= aList[counter % n]
        counter += 2
    ansList.append(s*2)
print(' '.join(map(str, ansList)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([A[i] for i in range(1, N, 2)])
ans = "%d"%(x1*2)
x = x1
for i in range(N-1):
  x = A[i]-x
  ans += " %d"%(x*2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = np.array(InputToInt())

    V = np.ones(N)
    
    for i in range(1,N,2):
        V[i] = -1

    for i in range(N):
        print(int(np.dot(A, V)),end=" ")
        v = V[N-1]
        V[1:N] = V[0:N-1]
        V[0] = v

Submission status: Time Limit Exceeded

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

out = [0] * N

for i in range(N) :
    ans = A[i]
    sig = i % 2

    # 前半
    for j in range(0,i) :
        ans += (-1)**(j+sig) * A[j]

    # 後半
    for j in range(i+1,N) :
        ans += (-1)**(j+sig+1) * A[j]
    out[i] = ans

print('{} '.format(out[-1]), end='')
out.pop()

for o in out :
    print('{} '.format(o), end='')

print('')

Submission status: Time Limit Exceeded

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

all_mount = sum(A)
mounts = []
for i in range(N):
  mount = all_mount
  for j in range(0, N, 2):
    mount -= 2 * A[(i+j)%N]
  mounts.append(abs(mount))
    
print(" ".join(map(str,mounts)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
L = []
for i in range(N):
  l = 0
  for j in range(N):
    l += (-1)**j*A[(i+j)%N]
  L.append(l)
print(" ".join(map(str,L)))

Submission status: Time Limit Exceeded

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

mountSum = sum(dams)
result = []
for i in range(n):
    otSum = 0
    if i % 2 == 0:
        for j in range(i // 2):
            otSum += dams[j * 2] * 2
        for j in range(i // 2, n // 2):
            otSum += dams[j * 2 + 1] * 2
    else:
        for j in range(i // 2):
            otSum += dams[j*2 + 1] *2
        for j in range((i // 2) +1, (n //2) +1 ):
            otSum += dams[j * 2] * 2
    result.append(mountSum - otSum)

print(*result)

Submission status: Time Limit Exceeded

Solution code:
from numpy.linalg import solve

n = int(input())
a = [int(x) for x in input().split()]

#left = [[1] * 3 for i in range(3)]
left = []
for i in range(n-1):
    temp = [0] * n
    temp[i] = 1
    temp[i+1] = 1
    left.append(temp)
else:
    temp = [0] * n
    temp[0] = 1
    temp[-1] = 1
    left.append(temp)

#print(left)

right = [x * 2 for x in a]
#print(right)

sol = [int(x) for x in solve(left, right)]
print(' '.join(map(str, sol)))

Submission status: Time Limit Exceeded

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

d_sum = np.sum(a)

result = []
for i in range(n):
    sum = 0
    for j in range(0, n-1, 2):
        d1 = (i+j+1)%n
        sum += a[d1]
    result.append(d_sum - sum*2)
print(" ".join(map(str, result)))

Submission status: Time Limit Exceeded

Solution code:
def prob_d():
    n = int(input())
    a_list = [int(a) for a in input().split()]
    sum_list = sum(a_list)
    ans_list = [sum_list - sum(a_list[1::2]) * 2] + [sum_list - sum(a_list[2::2]) * 2] + \
               [sum_list - sum(a_list[(i+1)::2]) * 2 -
                sum(a_list[i % 2:i-1:2]) * 2 for i in range(2, n-1)] + \
               [sum_list - sum(a_list[0:(n-2):2]) * 2]
    print(" ".join([str(a) for a in ans_list]))

prob_d()

Submission status: Time Limit Exceeded

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

x = []

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
x=[]
for i in range(n):
  s0=s//2
  for j in range((n-1)//2):
    s0-=a[(i+1+2*j)%n]
  x.append(s0*2)
a=' '.join(map(str,x))
print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

i  = lambda: int(input())
li = lambda: list(map(int, input().split()))

N = i()
A = li()

D = [0] * N

full_mount = sum(A)
for i in range(0, N):
    t = full_mount
    for j in range(i + 1, N , 2):
        t -= A[j] * 2
    for j in range(i - 2, -1, -2):
        t -= A[j] * 2
    D[i] = str(t)

print(' '.join(D))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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+=" "
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import copy
sys.setrecursionlimit(4100000)

n = int(input())
a = [int(i) for i in input().split()]
m = {}
m[0] = -1
m[1] = a[0] - m[0]/2
while True:
    m[0] += 1
    for i in range(1,n):
        m[i] = 2*(a[i-1] - m[i-1]/2)
    if (m[0] + m[n-1])//2 == a[n-1]:
        break
b = [int(m[i]) for i in m]
print(* b)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
import numpy as np
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
sys.setrecursionlimit(200000)
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(x): print("debug: ", x, file=sys.stderr)
# template


# fin = open('in_1.txt', 'r')
# sys.stdin = fin
# # local only


def solve(N: int, A: "List[int]"):
    ans = [0] * N
    s = sum(A)
    for i in range(1, N-1):
        ans[i] = A[i - 1] + A[i + 1] - A[i]
    # print(ans)
    A = list(map(lambda x: 2*x, A))
    mat = [[0 for i in range(N)] for i in range(N)]
    for i in range(N-1):
        mat[i][i + 1] = 1.
        mat[i][i] = 1.
    mat[N - 1][N - 1] = 1.
    mat[N - 1][0] = 1.
    mat = np.array(mat)
    # print(mat)  # original matrix
    for i in range(len(mat)-1):
        for j in range(i+1, len(mat)):
            coef = mat[j][i] / mat[i][i]
            mat[j] -= mat[i] * coef
            A[j] -= A[i] * coef
    for i in range(len(mat)-1, 0, -1):
        A[i] /= mat[i][i]
        mat[i] /= mat[i][i]
        for j in range(i):
            A[j] -= A[i] * mat[j][i]
            mat[j][i] = 0
    print(*list(map(int, A)))


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


def main():
    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: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
sign=[(-1)**i for i in range(n)]
ans=[0 for i in range(n)]
for i in range(n):
    tmp=0
    for j in range(n):
        tmp+=a[(i+j)%n]*sign[j]
    ans[i]=tmp
for ai in ans:
    print(ai, end=' ')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
  x+=a[i]
#print(x)
m=[]
for i in range(n):
  m+=[(a[(i+1)%n]-a[i])*2]
#print(m)
for i in range(n):
  x-=m[2*i%n]*(n-i-1)
#print(x)
ans=[0 for _ in range(n)]
ans[0]=x//n
for i in range(1,n):
  ans[2*i%n]=ans[2*(i-1)%n]+m[2*(i-1)%n]
#print(ans)
s=""
for i in range(n-1):
  s+=str(ans[i])+" "
s+=str(ans[n-1])
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
b = np.array([2*i for i in A])
B = []
for i in range(N):
    l = [0] * N
    l[i % N] = 1
    l[(i+1)%N] = 1
    B.append(l)
A = np.array(B)
a = map(int, np.linalg.solve(A, b))
print(*a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_r = sum(A)
ans = ''
for i in range(N):
    amount = sum_r
    for j in range(N//2):
        #print((i+1+j*2)%N)
        amount -= A[(i+1+j*2)%N]*2
    ans += str(amount) + ' '
print(ans.rstrip())

Submission status: Time Limit Exceeded

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

m = (n-1) // 2
s = sum(a) // 2
ans = []
for i in range(n):
    ans.append(s - sum([a[(i+1 + j*2)%n] for j in range(m)]))

print(" ".join([str(a*2) for a in ans]))

Submission status: Time Limit Exceeded

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 = sum(A)

x = [None]*N

for i in range(N):
    x[i] = 2*(A_sum//2 - sum(A[i%2:i:2]+A[i+1::2]))
print(*x)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
count=0
for i in range(n):
    if i%2==0:
        count+=a_list[i]
    else:
        count-=a_list[i]
ans=''
ans=ans+str(count)
now=count//2
for i in range(n-1):
    now=a_list[i]-now
    ans=ans+' '+str(now*2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.asarray(list(map(int, input().split())))
inv = np.asarray([[-1 if j in [(i + 2 * k + 1) % n for k in range(n//2)] else 1 for j in range(n)] for i in range(n)])
print(*np.dot(inv, a))

Submission status: Time Limit Exceeded

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

t = sum(a)//2

for i in range(n):
    b = t
    if i==0 or i==1:
        b-= sum(a[i+1::2])
    else:
        b -= sum(a[i+1::2]+a[i-2::-2])
    print(b*2,end=' ')

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

ans = [
    sum(a[(i + j) % n] * (-1) ** (j % 2)
        for j in range(n))
    for i in range(n)
]

print(" ".join(str(x) for x in ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
A = list(map(int,input().split()))
G = [[int(i in (j,(j+1)%N)) for i in range(N)] for j in range(N)]
kakudai = np.array(G)
X=np.linalg.solve(G,A)
print(*[int(x*2) for x in X])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=LIST()
    ans=[0]*n
    rain=sum(A)
    temp=rain
    for i in range(n):
        if i%2==1:
            temp-=A[i]*2
    ans[0]=temp
    for i in range(1,n):
        ans[i]=A[i-1]*2-ans[i-1]
    
    print(*ans)

if __name__=='__main__':
    do()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
x=-1
y=2*10**9
z=(x+y)//2
for i in range(1000):
    b[0]=z
    for j in range(1,n):
        b[j]=a[j-1]*2-b[j-1]
    if b[0]+b[-1]>2*a[-1]:
        y=z
        z=(x+y)//2
    elif b[0]+b[-1]<2*a[-1]:
        x=z
        z=(x+y)//2
    else:
        break
    if z%2==1:
        y+=1
        z+=1
print(*b)

Submission status: Accepted

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

s = sum([A[i] * (-1) ** i for i in range(N)])

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

Submission status: Accepted

Solution code:
import sys

def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_str_split(): return list(sys.stdin.readline().strip())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))

def Main():
    n = read_int()
    a = read_int_list()
    ans = [0] * 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(*ans)

if __name__ == '__main__':
    Main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(*ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x1 = 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            x1 += a
        else:
            x1 -= a
    x_list = [x1]
    for a in A[:-1]:
        x_list.append(2 * a - x_list[-1])
    print(' '.join([str(x) for x in x_list]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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 = [0] + list(map(int, input().split()))

# 各山に降った雨の量
X = [0] * (N + 1)

# まずx[1]を求める
# X[1] + ... + X[N] = A[1] + ... + A[N]
# X[2]+X[3] = 2*A[2], X[4]+X[5] = 2*A[4], ...より、
# X[1] = A[1] - A[2] + A[3] - ... + A[N]

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

# x[2],x[3],...,x[N]を漸化式から求める
for i in range(2, N + 1):
    X[i] = 2 * A[i - 1] - X[i - 1]
print(*X[1:])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
tmp = 0
for i, a in enumerate(A[:-1]):
    tmp -= pow(-1, i) * a
ans[0] = (A[-1] - tmp) // 2
for i in range(1, N):
    ans[i] = A[i - 1] - ans[i - 1]
print(' '.join(map(lambda x: str(x*2), ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    ans[0] = sum([a[i] * (-1) ** i for i in range(n)])
    for i in range(1, n):
        ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum_a = sum(a)
ans = [0]*n
ans[0] = sum_a - 2*(sum(a[1:n-1:2]))
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()))
s=sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lsA = list(map(int,input().split()))
x1_2 = 0
for i in range(N):
    if i % 2 == 0:
        x1_2 += lsA[i]
    else:
        x1_2 -= lsA[i]
x1 = x1_2//2
lsx = [x1]
for i in range(N):
    lsx.append(lsA[i]-lsx[i])
lsx2 = [str(2*lsx[i]) for i in range(N)]
print(' '.join(lsx2))

Submission status: Accepted

Solution code:

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

    ans = [0] * N
    ans[0] = sum(A)

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

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

    print(*ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
tmp = 0
now = 1
for i in range(N):
    A[i] *= 2
    tmp += now  * A[i]
    now *= -1

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

Submission status: Accepted

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

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

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

x.pop(0)

print(*x)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
whole=sum(A)
x1=whole
for n in range(1,N,2):
    x1-=A[n]*2
answers=[x1]
for n in range(N-1):
    x=2*A[n]-answers[-1]
    answers.append(x)
print(*answers)

Submission status: Accepted

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

X0=0

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

ans=[X0]

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

Submission status: Accepted

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

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

print(*B)

Submission status: Accepted

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

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

for n in range(N):
  if n==0:
    pass
  elif 1<=n<=N-1:
    B[n] = 2*A[n-1]-B[n-1]
  else:
    B[n] = 2*A[n]-B[0]

print(*B)

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr
tot = sum(A)
wo_X0 = 0
for i in range(1, N, 2):
    wo_X0 += A[i]
X = []
X.append(tot - 2 * wo_X0)

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

for x in X:
    print(x, end = ' ')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = []

    x1 = 0
    for i, ai in enumerate(A):
        x1 += ai if i % 2 == 0 else -ai
    x1 //= 2
    ans.append(x1)

    for a in A[:-1]:
        ans.append(a - ans[-1])

    print(" ".join(str(a * 2) for a in ans))


if __name__ == '__main__':
    main()