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:
n, a = input(), map(int, raw_input().split())

s = 1
ans = [0] * n
for x in a[-1::-1]:
    ans[0] += x * s
    s = -s

ans[0] >>= 1
for i in xrange(1, n):
    ans[i] = a[i - 1] - ans[i - 1]

for i in xrange(n):
    ans[i] <<= 1
print (' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
s = 0
for i in range(N):
    s = A[i] - s
x = s//2
B = [0]*N
s = x
for i in range(N):
    B[i] = s*2
    s = A[i] - s
print(*B)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

s = sum(As) // 2

Xs = [None] * N
Xs[0] = s - sum(As[1::2])
for i in range(1, N):
    Xs[i] = As[i - 1] - Xs[i - 1]

Xs = [x * 2 for x in Xs]
print(*Xs)

Submission status: Accepted

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

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

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""


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

T = sum(A)

kisu = sum([A[i] for i in range(N) if not i%2])
gusu = sum([A[i] for i in range(N) if i%2])


#print(kisu)
#print(gusu)

zero = T - gusu*2
print(zero,end=" ")
for i in range(1,N):
	n = int((A[i-1]-zero/2)*2)
	print(n,end=" ")
	zero = n
print("")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: "List[int]"):
    f = (sum(A[::2]) - sum(A[1::2])) // 2

    fs = [f]
    for a in A[:-1]:
        fs.append(a - fs[-1])

    ret = ' '.join([str(2 * f) for f in fs])
    return ret


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]"
    result = solve(N, A)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

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

#B
def B():
    n,d = LI()
    x = LIR(n)
    f = defaultdict(lambda : 0)
    for i in range(1000000):
        f[i*i] = 1
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            s = 0
            for k in range(d):
                s += (x[i][k]-x[j][k])**2
            if f[s]:
                ans += 1
    print(ans)
    return

#C
def C():
    l,r = LI()
    if r-l > 2019:
        print(0)
        quit()
    ans = float("inf")
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            if i*j%2019 < ans:
                ans = i*j%2019
    print(ans)
    return

#D
def D():
    n = I()
    a = LI()
    for i in range(n):
        a[i] *= 2
    x = a[0]
    for i in range(1,n):
        if i%2:
            x -= a[i]
        else:
            x += a[i]
    b = [x//2]
    for i in range(n-1):
        b.append(abs(b[-1]-a[i]))
    print(*b)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


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

Submission status: Accepted

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

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
A = map(int, raw_input().split())
x1 = 0
for i in range(N):
    if i % 2 == 0:
        x1 += A[i]
    else:
        x1 -= A[i]
X = [x1]
for i in range(N - 1):
    X += [2 * A[i] - X[i]]
print " ".join(map(str, X))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

cum = [0]
for i in range(2*n):
    cum.append(cum[-1] + a[(i*2+1)%n])
anss = [0] * n
for i in range(n):
    anss[i*2%n] = s - 2*(cum[i+n//2]-cum[i])

for x in anss:
    print(x, end="")
    print(" ", end="")

Submission status: Accepted

Solution code:
import sys

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

ans = [0]
tmp = 0
for a in aaa[:-1]:
    tmp = a - tmp
    ans.append(tmp * 2)
adj = aaa[-1] - tmp
ans2 = []
for a in ans:
    ans2.append(a + adj)
    adj *= -1
print(*ans2)

Submission status: Runtime Error

Solution code:
def nCk(_n,_k):
  if _k==0:
    return 1
  else:
    if _n<0 or _k<0 or _n-_k<0:
      return 0
    else:
      return (fact[_n]//(fact[_k]*fact[_n-_k]))%m

fact=[1]*2005
for i in range(1,2001):
  fact[i]=fact[i-1]*i

n,k=map(int,input().split())
m=10**9+7
ans=cnt=0
for _k in range(1,k+1):
  ans=(nCk(n-k+_k,_k)-cnt)*nCk(k-1,_k-1) if _k>1 else n-k+_k 
  cnt+=ans
  cnt%=m
  ans%=m
  print(ans)

Submission status: Runtime Error

Solution code:
l,r=map(int,input().split())
m,ans=2019,2018
r=min(r,l+2019*2)
for i in range(l,r+1):
  for j in range(i+1,r+1):
    i%=m
    j%=m
    ans=min(ans,(i*j)%m)
print(ans)

Submission status: Runtime Error

Solution code:
from prompt_toolkit.filters.app import is_searching


def resolve():
    '''
    code here
    '''

    N = int(input())
    As = [int(item) for item in input().split()]

    def cal(num):
        res_list = [0 for _ in range(N)]
        ans_list = [0 for _ in range(N)]
        
        for i in range(N):
            if i == 0:
                res_list[0] = num // 2
                res_list[-1] = num // 2
                ans_list[0] = num
                continue
            
            temp_num = 2 * (As[i-1] - res_list[i-1])
            ans_list[i] = temp_num
            if temp_num < 0:
                return 'too small'
            
            if i == N-1:
                if res_list[-1] + temp_num // 2 == As[-1]:
                    return ans_list
                else:
                    return 'too large'

            res_list[i-1] += temp_num // 2
            res_list[i] = temp_num //2

    R = 2 * max(As[0], As[-1])
    L = 0
    mid = (R + L)//2
    is_search = True
    while is_search:
        flag = cal(mid)
        if flag == 'too large':
            R, mid = mid, (L+mid)//2
        elif flag == 'too small':
            L, mid = mid, (R+mid)//2
        else:
            is_search = False

    print(*flag)

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

#+++++
		
def main2():
	n = int(input())
	water_list=list(map(int, input().split()))
	
	mw=water_list[-1]
	for i in range(mw+1):
		cv = mw - i
		init_cv=cv
		for w in water_list[::-1]:
			#print(w,cv, w-cv)
			cv = w - cv
			if cv < 0:
				break
		else:
			#print('hhh', cv, init_cv, mw)
			if init_cv == cv:
				ret = [0 for _ in range(n)]
				cv=init_cv
				for ii, ww in enumerate(water_list):
					ret[ii] = cv*2
					cv = ww - cv
					#print(ret)
				return ret
				
	return 'hoge'
	
def main():
	n = int(input())
	water_list=list(map(int, input().split()))
	a = sum(water_list) - 2*sum(water_list[1::2])
	ret = [a]
	next=a
	for v in water_list[:-1]:
		next = (v*2 - next)
		ret.append(next)
	
	print(*ret)
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(' '.join([str(i) for i in ret]))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  if n < r: return 0
  return comb(n, r) * comb.fac[r]

for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)
  adj[b].append(a)

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    int n;cin>>n;
    int a[MAX];
    rep(i,n)cin>>a[i],a[i]*=2;
    ll offset=0;
    rep(i,n)offset=a[i]-offset;
    ll x=offset/2;

    ll cur=x;
    rep(i,n){
        cout<<cur<<" ";
        cur=a[i]-cur;
    }
    cout<<endl;
}

Submission status: Runtime Error

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


class GaussElimination:
    def __init__(self, a):
        self.a = a
        self.n = len(self.a)

    def exec(self):
        try:
            for k in range(self.n - 1):
                for i in range(k + 1, self.n):
                    d = self.a[i][k] / self.a[k][k]
                    for j in range(k + 1, self.n + 1):
                        self.a[i][j] -= self.a[k][j] * d
            for i in range(self.n - 1, -1, -1):
                d = self.a[i][self.n]
                for j in range(i + 1, self.n):
                    d -= self.a[i][j] * self.a[j][self.n]
                self.a[i][self.n] = d / self.a[i][i]
        except Exception:
            raise


def main():
    N = int(input())
    A = [int(i) for i in input().strip().split()]
    matrix = [[0] * (N + 1) for _ in range(N)]
    for i in range(N):
        if i == N - 1:
            matrix[N - 1][0] = 1
            matrix[N - 1][N - 1] = 1
        else:
            matrix[i][i] = 1
            matrix[i][i + 1] = 1
        matrix[i][N] = A[i]
    gauss = GaussElimination(matrix)
    gauss.exec()
    ans = []
    for i in range(N):
        ans.append(str(int(gauss.a[i][N] * 2)))
    print(" ".join(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))
Arr = np.zeros((n, n))
for i in range(0, n-1):
    Arr[i][i] = 0.5
    Arr[i][i+1] = 0.5
Arr[n-1][n-1] = 0.5
Arr[n-1][0] = 0.5
#print(Arr)

inv_Arr = np.linalg.inv(Arr)
#print(inv_Arr)

ans = np.dot(inv_Arr, A)
ans = list(map(int, ans))
print(*ans, sep=" ")

Submission status: Runtime Error

Solution code:
import numpy as np

N, *A = map(int, open(0).read().split())

l = np.zeros((N,N), dtype='u8')
for i in range(N):
    l[i][i] = 1
    if i+1 >= N:
        l[i][0] = 1
    else:
        l[i][i+1] = 1

r = np.array(A, dtype='u8') * 2

print(*np.linalg.solve(l, r).astype('u8'))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(500*500)

import numpy as np

N, *A = map(int, open(0).read().split())

l = np.zeros((N,N), dtype=int)
for i in range(N):
    l[i][i] = 1
    if i+1 >= N:
        l[i][0] = 1
    else:
        l[i][i+1] = 1

r = np.array(A, dtype=int) * 2

print(*np.linalg.solve(l, r).astype(int))

Submission status: Runtime Error

Solution code:
import numpy as np

N, *A = map(int, open(0).read().split())

l = np.zeros((N,N), dtype=int)
for i in range(N):
    l[i][i] = 1
    if i+1 >= N:
        l[i][0] = 1
    else:
        l[i][i+1] = 1

r = np.array(A, dtype=int) * 2

print(*np.linalg.solve(l, r).astype(int))

Submission status: Runtime Error

Solution code:
import numpy as np
# from numpy.linalg import solve

N, *A = map(int, open(0).read().split())

l = np.zeros((N,N), dtype=int)
for i in range(N):
    l[i][i] = 1
    if i+1 >= N:
        l[i][0] = 1
    else:
        l[i][i+1] = 1

# l = []
# for i in range(N):
#     tmp = [0] * N
#     tmp[i] = 1
#     if i+1 >= N:
#         tmp[0] = 1
#     else:
#         tmp[i+1] = 1
#     l.append(tmp)

# r = list(map(lambda a: a*2, A))
r = np.array(A, dtype=int) * 2

# print(l)
# print(r)
print(*map(int, np.linalg.solve(l, r)))

Submission status: Runtime Error

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


low=0
high=10**10

#binary search the value of rain onto Mountain1
while low<=high:
    mid=(low+high)//2

    cur=mid
    for i,a in enumerate(A):
        cur=a-cur
        if cur<0:#途中で足りなくなったら、midが大きすぎ
            break
       #break
    if cur>=mid:
        low=mid+1
    else:
        if i%2==0:
            low=mid+1
        else:
          	high=mid-1
            low=mid+1


ans=[]
cur=high
for a in A:
    ans.append(cur*2)
    cur=a-cur
print(" ".join(map(str,ans)))

Submission status: Runtime Error

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


low=0
high=10**9*2

#binary search the value of rain onto Mountain1
while low<=high:
    mid=(low+high)//2

    cur=mid
    for a in A:
        cur=a-cur
        if cur<0:#途中で足りなくなったら、midが大きすぎ
            break
       #break
    if cur>=mid:
        low=mid+1
    else:
        high=mid-1


ans=[]
cur=high
for a in A:
    ans.append(cur*2)
    cur=a-cur
assert cur==high
print(" ".join(map(str,ans)))

Submission status: Runtime Error

Solution code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    A = np.array(A)
    C = np.zeros((N, N))
    for i in range(N):
        C[i, i] = C[i, (i + 1) % N] = 1

    X = np.linalg.solve(C, A)
    X = [int(x * 2) for x in X]

    print(*X)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype='i8')
    A = A.reshape((1, N))
    B = np.zeros((N, N), dtype='i8')
    for i in range(N):
        B[i][i - N] = 1
        B[i][i + 1 - N] = 1

    ans = np.dot(np.linalg.inv(B), (A * 2).T)
    ans = ' '.join(map(str, list(map(int, ans.flatten().tolist()))))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype='i8')
    A = A.reshape((1, N))
    B = np.zeros((N, N), dtype='i8')
    for i in range(N):
        B[i][i - N] = 1
        B[i][i + 1 - N] = 1

    ans = np.linalg.inv(B) @ (A * 2).T
    ans = ' '.join(map(str, list(map(int, ans.flatten().tolist()))))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

sum_eve = sum(A[0::2])
sum_odd = sum(A[1::2])

x = [0] * n

x[0] = sum_eve - sum_odd

for num in range(1, n):
    x[num] = 2 * A[num-1] - x[num-1]
    
ans = " ".join(map(str,x))

pritn(ans)

Submission status: Runtime Error

Solution code:
import sympy

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

x = sympy.Symbol("x")

ex = [0] * n
ex[0] = x

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

ans = sympy.solve(ex[0] + ex[-1] - 2 * arr[-1])[0]
ans = [y.subs(x, ans) for y in ex]

print(*ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(lambda x:x*2,a))
All = sum(a)
t = 0
while True :
    t += 1
    if t > n :
        exit()
    print(All-a2[1::2])
    a2.append(a2[0])
    del a2[0]

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a2 = list(map(int,lambda x:x*2,a))
All = sum(a)
t = 0
while True :
    t += 1
    if t > n :
        exit()
    print(All-a2[1::2])
    a2.append(a2[0])
    del a2[0]

Submission status: Runtime Error

Solution code:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = [[int(i)] for i in input().split()]
A_np =np.array(A)

#numpyで連立方程式を解く
mat_1 =np.zeros((N,N),dtype=int)
for i in range(N):
    mat_1[i,i]=1
    mat_1[i,(i+1)%N]=1 #余りをとらないと、i=N-1の時エラーになる
x =np.linalg.solve(mat_1,A_np)*2

#表示
for i in x:
    print(int(i[0]),end=" ")

Submission status: Runtime Error

Solution code:
print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    A = np.array(list(map(int,input().split())))

    X = np.zeros((N,N))
    for i in range(N-1):
        for j in range(2):
            X[i][j+i] = 1

    X[N-1][0] = 1
    X[N-1][N-1] = 1

    ans = map(lambda y: int(y)*2, np.dot(np.linalg.pinv(X),A))
    print(*ans)


if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    A = np.array(list(map(int,input().split())))

    X = np.zeros((N,N))
    for i in range(N-1):
        for j in range(2):
            X[i][j+i] = 1

    X[N-1][0] = 1
    X[N-1][N-1] = 1

    ans = map(lambda y: int(y)*2, np.dot(np.linalg.inv(X),A))
    print(*ans)

if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import accumulate
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    Ae = A[1::2]
    Ao = A[::2]
    x1 = (sum(Ao)-sum(Ae))//2
    table = [0]*(N+1)
    table[0] = x1
    def rec(i):
        if i == N:
            return
        table[i+1] = A[i] - table[i]
        rec(i+1)
    rec(0)
    for i in table[:N]:
        print(i*2, end=' ')
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
l, r = map(int, input().split())
if r //2019 > l //2019:
    print(0)
else:
    res = 2018
    for i in range(l%2019, (r%2019)+1):
        for j in range(i+1, (r%2019)+1):
            res = min(res, (i*j)%2019)
    print(res)

Submission status: Runtime Error

Solution code:
l, r = map(int, input().split())
if r //2019 > l //2019:
    print(0)
else:
    res = 2018
    for i in range(l%2019, (r+1)%2019):
        for j in range(i+1, (r+1)%2019):
            res = min(res, (i*j)%2019)
    print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mat = np.matrix([np.zeros(n) for i in range(n)])
for i in range(n-1):
    mat[i,i] = 1/2
    mat[i,i + 1] = 1/2
mat[n-1,0] = 1/2
mat[n-1,n-1] = 1/2

ans = np.linalg.inv(mat) * np.matrix(a).T
anss = []
for i in range(n):
    anss.append(int(ans[i,0]))
print(*anss)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mat = np.matrix([np.zeros(n) for i in range(n)])
for i in range(n-1):
    mat[i,i] = 1/2
    mat[i,i + 1] = 1/2
mat[n-1,0] = 1/2
mat[n-1,n-1] = 1/2

ans = np.linalg.inv(mat) @ np.matrix(a).T
anss = []
for i in range(n):
    anss.append(int(ans[i,0]))
print(*anss)

Submission status: Runtime Error

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

def main():
    N = int(readline())
    B = np.array(readline().split(), np.int64)
    A = np.eye(N, dtype=np.int64) + np.eye(N, k=1, dtype=np.int64)
    A[N-1][0] = 1
    ans = np.linalg.solve(A, B).astype(np.int64) * 2
    print(' '.join(map(str, ans)))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# Useful data structures
from collections import Counter, defaultdict, deque, namedtuple

# Most useful math functions
from math import gcd

# For sys.std*, sys.argv etc...
import sys

# For cases when input tokens are spread unevenly over many lines.
# This provides methods for reading tokens of various types.
class BufferedTokenizer:
    pass

def read_ints():
    return [int(token) for token in input().split()]

def read_tokens():
    return input().split()

def main():
    N = read_ints()[0]
    D = read_ints()
    M = [0] * N
    for i in range(N):
        if i % 2 == 0:
            M[0] += D[i]
        else:
            M[0] -= D[i]

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
Y = int(input())
L = np.array([0] * (Y ** 2)).reshape(Y, Y)
for i in range(Y-1):
  L[i][i] += 1
  L[i][i+1] += 1
else:
  L[i+1][i+1] += 1
  L[i+1][0] += 1
R = list(map(int, input().split()))
A = list(np.linalg.solve(L, R))
[print(int(i) * 2, end = ' ') for i in A]

Submission status: Runtime Error

Solution code:
import numpy as np
Y = int(input())
l = [0] * (Y ** 2)
L = np.array(l).reshape(Y, Y)
for i in range(Y-1):
  L[i][i] += 1
  L[i][i+1] += 1
else:
  L[i+1][i+1] += 1
  L[i+1][0] += 1
R = np.array(list(map(int, input().split())))
A = list(np.linalg.solve(L, R))
[print(int(i) * 2, end = ' ') for i in A]

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a =list(map(int,input().split()))
box = [[0]*n for _ in range(n)]
for i in range(n-1):
     box[i][i] = 1
     box[i][i+1] = 1

box[n-1][0] = 1
box[n-1][n-1] = 1
boxx = np.array(box)
inv = np.linalg.inv(boxx)
aa = np.array(a)
ans = np.dot(inv,aa)
print(*ans//2)

Submission status: Runtime Error

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/2
print(x1)
for i in range(1,N):
  x1 = 2*a[i] - x1
  print(x1)

Submission status: Runtime Error

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: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    L, R = input_nums()
    MOD = 2019
    a = L%MOD
    b = R%MOD
    if a < b and R - L < 2019:
        print((a*(a+1))%MOD)
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

def solve(b):
    dim = len(b)
    b = np.array(b)
    A = np.eye(dim) + np.eye(dim, k=1)
    A[dim-1][0] = 1
    x = np.linalg.solve(A, b)
    return " ".join([str(int(2*e)) for e in x])

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(A))

main()

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
y=list(map(int,input().split()))
y=list(map(lambda x: x*2,y))
A=np.zeros((n,n),dtype='int')
for i in range(n-1):
  for j in range(i,i+2):
    A[i][j]=1
A[n-1][0],A[n-1][n-1]=1,1
b=np.linalg.solve(A,y)
print(*b)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
y=list(map(int,input().split()))
y=list(map(lambda x: x*2,y))
A=np.zeros((n,n),dtype='int')
for i in range(n-1):
  for j in range(i,i+2):
    A[i][j]=1
A[n-1][0],A[n-1][n-1]=1,1
b=list(map(int,np.linalg.solve(A,y)))
print(*b)

Submission status: Runtime Error

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    diag = np.identity(N,int)

    left = diag + np.roll(diag,1,axis=1)

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

    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())
rain=np.array([int(i)*2 for i in input().split()])

a=np.eye(n,dtype=np.int64)
for i in range(n-1):
  a[i][i+1]=1
a[-1][0]=1

ans=np.linalg.solve(a,rain)
ans=ans.astype(np.int64)
print(*ans)

Submission status: Runtime Error

Solution code:
import sys
from numpy.linalg import solve
import numpy as np
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = np.array(list(map(int, inputs[1].split())))
I = np.eye(n, dtype=np.int)
B = np.empty((n, n), dtype=np.int)
for i in range(n):
    B[i, :] = I[i] + I[(i+1)%n]
print(*(map(lambda x: int(2*x), solve(B, A))))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.matrix([int(x) for x in input().split()], dtype='int64')
Pm = np.matrix([[1, -1], [-1, 1]], dtype='int64')
P = np.tile(Pm, ((N + 1) // 2, (N + 1) // 2))[:-1, :-1]
P = -np.triu(P) + np.tril(P) + np.eye(N)
print(*np.array(A * P).flatten().astype(np.int64).tolist())

Submission status: Runtime Error

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

neye=np.eye(n)
neye_roll=np.roll(np.eye(n),1)
neye_roll[0][0]=0
neye_roll[n-1][0]=1
x=neye+neye_roll
#print(x)

avector=np.array(a)
avector=2*np.reshape(avector, (1,n)).T
#print(avector)
x_ans=np.linalg.solve(x, avector)
#print(x_ans)
ans=[]
for i in range(n):
    ans.append(int(x_ans[i][0]))
print(re.sub("[\[\]\,]","",str(ans)))

Submission status: Runtime Error

Solution code:
n = int(input())

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

total = sum(l)

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

ans = [total]

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