The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).


-----Input-----

The first line of the input contains a single number n (1 ≤ n ≤ 10^5) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers h_{i} (1 ≤ h_{i} ≤ 10^9), where h_{i} equals the number of floors in the i-th house. 


-----Output-----

Print n integers a_1, a_2, ..., a_{n}, where number a_{i} is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then a_{i} should be equal to zero.

All houses are numbered from left to right, starting from one.


-----Examples-----
Input
5
1 2 3 1 2

Output
3 2 0 2 0 
Input
4
3 2 1 4

Output
2 3 4 0

Difficulty: EASY
Tags: Mathematics

Implementation

Starter code:

Solutions:
def f(l):
	n = len(l)
	rl = [0] * n
	rm = l[-1]
	for i in range(n - 2, -1, -1):
		rl[i] = max(rm + 1 - l[i], 0)
		if l[i] > rm:
			rm = l[i]
	return rl
_ = input()
l = list(map(int, input().split()))
print(*f(l))


n = int(input())
arr = list(map(int, input().split()))
maxi = 0
e = []
for i in range(len(arr)):
	if arr[len(arr) - 1 - i] > maxi:
		maxi = arr[len(arr) - 1 - i]
		flag = len(arr) - 1 - i
	if len(arr) - 1 - i == flag:
		e.append(arr[flag] - arr[len(arr) - 1 - i])
	else:
		e.append(arr[flag] - arr[len(arr) - 1 - i] + 1)
for i in range(len(e)):
	print(e[len(e) - i - 1], end=' ')


n = int(input())
a = list(map(int, input().split()))
worst = 0
for i in reversed(range(n)):
	b = a[i]
	if a[i] <= worst:
		a[i] = worst - a[i] + 1
	else:
		a[i] = 0
	if b > worst:
		worst = b
print(' '.join(map(str, a)))


n = int(input())
floors = list(map(int, input().split()))
ma = floors[:]
max_so_far = float('-inf')
for i in range(n - 1, -1, -1):
	ma[i] = max(0, 1 + max_so_far - floors[i])
	max_so_far = max(max_so_far, floors[i])
print(' '.join(map(str, ma)))


n = int(input())
arr = list(map(int, input().split()))
res = [0] * n
mx = -1
for i in range(n - 1, -1, -1):
	if arr[i] > mx:
		mx = arr[i]
		res[i] = 0
	else:
		add = max(0, mx + 1 - arr[i])
		res[i] = add
print(*res)


l = int(input())
c = list(map(int, input().split()))
m = [0]
for i in range(l - 1, -1, -1):
	m.append(max(c[i], m[l - 1 - i]))
for i in range(l):
	if m[l - 1 - i] < c[i] or i == l - 1:
		print(0, end=' ')
	else:
		print(m[l - 1 - i] + 1 - c[i], end=' ')


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
m = -1
res = [0] * n
for i in range(n - 1, -1, -1):
	if a[i] > m:
		res[i] = 0
	else:
		res[i] = m + 1 - a[i]
	m = max(m, a[i])
for b in res:
	print(b, end=' ')


n = int(input())
h = list(map(int, input().split()))
m = h[-1]
res = []
for x in h[::-1]:
	res.append(str(max(0, m - x)))
	m = max(m, x + 1)
print(' '.join(res[::-1]))


x = int(input())
inp = input().split()
out = []
maxh = 0
for i in reversed(range(0, x)):
	j = int(inp[i])
	if j <= maxh:
		out.append(maxh - j + 1)
	else:
		out.append(0)
		maxh = j
s = ''
for i in reversed(out):
	s += str(i) + ' '
print(s)


n = int(input())
height = list(map(int, input().split()))
maxHeight = [0] * n
m = 0
for i in range(n - 1, 0, -1):
	m = max(height[i], m)
	maxHeight[i - 1] = m
ans = [max(m - h + 1, 0) for (h, m) in zip(height, maxHeight)]
print(' '.join([str(x) for x in ans]))


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
mx = a[n - 1]
for i in range(n - 2, -1, -1):
	b[i] = max(0, mx - a[i] + 1)
	if a[i] > mx:
		mx = a[i]
print(*b)


n = int(input())
array = list(map(int, input().split()))
maxH = -1
luxury = list()
for i in range(n - 1, -1, -1):
	luxury.append(max(maxH + 1 - array[i], 0))
	maxH = max(maxH, array[i])
print(*luxury[::-1])


n = int(input())
arr = [int(x) for x in input().split()]
ans = [0 for i in range(n)]
maxi = arr[-1]
for i in range(n - 2, -1, -1):
	if arr[i] > maxi:
		maxi = arr[i]
		ans[i] = 0
	else:
		ans[i] = maxi - arr[i] + 1
for i in ans:
	print(i, end=' ')


n = int(input())
home = list(map(int, input().split()))
suff = [0] * n
for i in range(n - 2, -1, -1):
	suff[i] = max(suff[i + 1], home[i + 1])
for i in range(n):
	if home[i] > suff[i]:
		print(0, end=' ')
	else:
		print(suff[i] - home[i] + 1, end=' ')


n = int(input())
h = map(int, input().split()[::-1])
m_h = 0
res = []
for h in h:
	if m_h < h:
		res.append(0)
		m_h = h
	else:
		res.append(m_h - h + 1)
print(' '.join(map(str, res[::-1])))


n = int(input())
a = list(map(int, input().split()))
maxr = [0 for i in range(n)]
result = [0 for i in range(n)]
for i in range(n - 2, -1, -1):
	maxr[i] = max(maxr[i + 1], a[i + 1])
for i in range(n):
	result[i] = maxr[i] - a[i] + 1
	if result[i] < 0:
		result[i] = 0
print(' '.join((str(r) for r in result)))


n = int(input())
h = list(map(int, input().split()))
l = []
m = h.pop()
l.append(0)
while h:
	if h[-1] <= m:
		l.append(m - h[-1] + 1)
		m = max(m, h.pop())
	else:
		l.append(0)
		m = max(m, h.pop())
for i in range(len(l) - 1, -1, -1):
	print(l[i], end=' ')


n = int(input())
L = list(map(int, input().split()))
R = ['' for _ in range(n)]
R[n - 1] = '0'
m = L[n - 1]
for k in range(n - 2, -1, -1):
	if m >= L[k]:
		R[k] = str(m - L[k] + 1)
	else:
		R[k] = '0'
	m = max(L[k], m)
print(' '.join(R))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
m = a[n - 1] - 1
for i in range(n - 1, -1, -1):
	if a[i] <= m:
		b[i] = m - a[i] + 1
	else:
		m = a[i]
		b[i] = 0
print(' '.join(map(str, b)), end=' ')


n = int(input())
hs = list(map(int, input().split()))
maxx = 0
ans = []
for h in reversed(hs):
	if h > maxx:
		ans.append(0)
	else:
		ans.append(maxx - h + 1)
	maxx = max(maxx, h)
print(' '.join(map(str, reversed(ans))))


n = int(input())
a = list(map(int, input().split()))
x = 1
r = []
for i in range(n - 1, -1, -1):
	r += [max(x - a[i], 0)]
	x = max(x, a[i] + 1)
print(' '.join(map(str, r[::-1])))


n = int(input())
a = [int(x) for x in input().split()]
b = [0] * n
for i in range(n - 2, -1, -1):
	b[i] = max(b[i + 1], a[i + 1])
print(' '.join((str(max(0, x - y + 1)) for (x, y) in zip(b, a))))


num = int(input())
a = list(map(int, input().split()))
b = [0] * num
maxx = a[-1]
for i in range(num - 2, -1, -1):
	if a[i] <= maxx:
		b[i] = maxx - a[i] + 1
	else:
		maxx = a[i]
print(*b)


n = int(input())
arr = list(map(int, input().split()))
cur = arr[n - 1]
dp = [0] * n
for i in range(n - 2, -1, -1):
	if arr[i] > cur:
		dp[i] = 0
		cur = arr[i]
	else:
		dp[i] = cur - arr[i] + 1
print(*dp)


import array

def main():
	n = int(input())
	hs = input().split()
	maxi = 0
	p = array.array('Q', n * [0])
	for i in range(n - 1, -1, -1):
		hi = int(hs[i])
		p[i] = max(0, maxi - hi + 1)
		maxi = max(maxi, hi)
	for i in range(n - 1):
		print(p[i], '', end='')
	print(p[n - 1])
main()


n = int(input())
heights = list(map(int, input().split()))
highest = 0
result = n * [0]
for i in range(len(heights) - 1, -1, -1):
	if heights[i] <= highest:
		result[i] = highest - heights[i] + 1
	else:
		highest = heights[i]
print(' '.join(map(str, result)))


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


n = int(input())
houses = list(map(int, input().split()))
height = [0]
result = []
for i in range(n):
	if houses[n - i - 1] > height[i]:
		height.append(houses[n - i - 1])
		result.append(0)
	else:
		height.append(height[i])
		result.append(height[i] - houses[n - i - 1] + 1)
for i in range(n):
	print(result[n - i - 1], end=' ')


n = int(input())
a = list(map(int, input().split()))
a.reverse()
mx = 0
out = [0] * n
for i in range(n):
	out[i] = max(mx + 1, a[i]) - a[i]
	mx = max(a[i], mx)
out.reverse()
print(' '.join(map(str, out)))


n = int(input(''))
arr = list(map(int, input().split()))
max = -1
b = []
for i in range(0, n):
	p = arr[n - 1 - i]
	if p > max:
		b.append(0)
		max = p
	else:
		b.append(max - p + 1)
for i in range(0, n):
	print(b[n - i - 1], end=' ')


import sys
import math
n = int(input())
a = list(map(int, input().split()))
mx = 0
ans = [0 for i in range(n)]
for i in range(n - 1, -1, -1):
	ans[i] = max(0, mx + 1 - a[i])
	if a[i] > mx:
		mx = a[i]
for i in range(0, n):
	print(ans[i], end=' ')


n = int(input())
arr = list(map(int, input().split()))
maxArr = arr.copy()
maxArr.reverse()
maxArr[0] = maxArr[0] * -1
for i in range(1, len(arr)):
	if maxArr[i] > abs(maxArr[i - 1]):
		maxArr[i] = maxArr[i] * -1
	else:
		maxArr[i] = abs(maxArr[i - 1])
maxArr.reverse()
resultArr = []
for i in range(len(arr)):
	if maxArr[i] < 0:
		print('0', end=' ')
	else:
		print(maxArr[i] - arr[i] + 1, end=' ')


from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
mx = -1
ans = [0] * n
for i in reversed(range(n)):
	ans[i] = max(0, mx + 1 - a[i])
	mx = max(mx, a[i])
print(*ans)


n = int(input())
l = list(map(int, input().split()))
s = [0] * n
a = [0] * n
s[-1] = l[-1]
for i in range(1, n):
	if l[n - i - 1] <= s[n - i]:
		a[n - i - 1] = s[n - i] - l[n - i - 1] + 1
	s[n - i - 1] = max(l[n - i - 1], s[n - i])
print(' '.join(map(str, a)))


n = int(input())
L = list(map(int, input().split()))
mayor = L[-1]
L[-1] = '0'
for k in range(2, n + 1):
	if L[-k] > mayor:
		mayor = L[-k]
		L[-k] = '0'
	else:
		L[-k] = str(mayor - L[-k] + 1)
print(' '.join(L))


n = int(input())
h = [int(i) for i in input().split()]
l = []
l_2 = []
for i in range(n):
	l_2 += [0]
l_2[n - 1] = h[n - 1]
for i in range(n - 2, 0, -1):
	l_2[i] = max(l_2[i + 1], h[i])
l_2 = l_2 + [0]
for i in range(n):
	m = l_2[i + 1]
	g = max(m - h[i] + 1, 0)
	l += [g]
for i in l:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = []
mx = -10 ** 10
for i in range(n - 1, -1, -1):
	b.append(max(0, mx + 1 - a[i]))
	mx = max(mx, a[i])
b = b[::-1]
for i in b:
	print(i, end=' ')


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
result = [0] * n
top = Arr[-1]
for i in range(n - 2, -1, -1):
	if Arr[i] > top:
		result[i] = 0
		top = Arr[i]
	elif Arr[i] == top:
		result[i] = 1
	else:
		result[i] = top - Arr[i] + 1
print(*result, sep=' ')


n = int(input())
l = list(map(int, input().split()))
m = l[-1]
z = [0] * n
for i in range(n - 2, -1, -1):
	if l[i] > m:
		m = l[i]
	else:
		z[i] = m - l[i] + 1
print(*z)


n = int(input())
ans = []
ma = 0
for h in list(reversed(list(map(int, input().split())))):
	ans += [max(0, ma - h + 1)]
	ma = max(ma, h)
print(' '.join(map(str, reversed(ans))))


n = int(input())
l = [int(i) for i in input().split()]
ans = [0]
mx = l[n - 1]
for i in range(n - 2, -1, -1):
	if l[i] > mx:
		ans.append(0)
	else:
		ans.append(mx - l[i] + 1)
	mx = max(mx, l[i])
ans = ans[::-1]
print(*ans)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
currMax = 0
ans = [0] * n
for i in range(n - 1, -1, -1):
	ans[i] = max(0, currMax - arr[i] + 1)
	currMax = max(currMax, arr[i])
print(*ans)


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs):
	max_height = 0
	result = []
	for x in reversed(xs):
		if x > max_height:
			result.append(0)
			max_height = x
		else:
			additional = max_height - x + 1
			result.append(additional)
	return reversed(result)

def main():
	n = int(input())
	xs = [int(i) for i in input().strip().split()]
	assert len(xs) == n
	result = solve(xs)
	print(' '.join(map(str, result)))
main()


n = int(input())
a = [int(x) for x in input().split()]
m = [0] * (n + 1)
m[n] = -10 ** 9 - 7
for i in range(n - 1, 0, -1):
	m[i] = max(m[i + 1], a[i])
for i in range(n):
	print(max(a[i], m[i + 1] + 1) - a[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
m = -1
ans = []
for i in range(n):
	if a[n - i - 1] > m:
		ans.append('0')
	else:
		ans.append(str(m + 1 - a[n - i - 1]))
	m = max(a[n - i - 1], m)
print(' '.join(ans[::-1]))


n = int(input())
a = list(map(int, input().split()))
(z, s) = (0, [])
for i in range(n - 1, -1, -1):
	if a[i] > z:
		s.append(0)
		z = a[i]
	else:
		s.append(max(0, z + 1 - a[i]))
s.reverse()
print(*s)


n = int(input())
h = list(map(int, input().split()))
h.reverse()
s = []
m = 0
for i in h:
	if i > m:
		m = i
		a = 0
	elif m >= i:
		a = m - i + 1
	s += [str(a)]
s.reverse()
print(' '.join(s))


n = int(input())
l = list(map(int, input().split()))
mx = 0
ans = []
for i in range(n - 1, -1, -1):
	if l[i] > mx:
		mx = l[i]
		ans.append(0)
	elif l[i] == mx:
		ans.append(1)
	else:
		ans.append(mx - l[i] + 1)
ans.reverse()
print(*ans)


_ = input()
a = [int(x) for x in input().split()]
mx = 0
ans = []
for x in reversed(a):
	if x > mx:
		ans.append(0)
		mx = x
	else:
		ans.append(mx - x + 1)
ans = reversed(ans)
print(' '.join((str(x) for x in ans)))


n = int(input())
l = [int(i) for i in input().split()]
l.reverse()
n1 = 1
ans = [0]
mx = l[0]
if n > 1:
	if l[0] < l[1]:
		ans.append(0)
	else:
		ans.append(l[0] - l[1] + 1)
	while n1 < n - 1:
		num1 = l[n1]
		num2 = l[n1 + 1]
		mx = max(num1, l[0], mx)
		if num2 <= mx:
			ans.append(mx - num2 + 1)
		else:
			ans.append(0)
		n1 += 1
	ans.reverse()
	print(*ans)
else:
	print(0)


from sys import *
inp = lambda : stdin.readline()

def main():
	n = int(inp())
	l = [int(i) for i in inp().split()]
	(maxl, maxe) = ([0 for i in range(n)], 0)
	for i in range(n - 1, -1, -1):
		maxe = max(maxe, l[i])
		maxl[i] = maxe
	for i in range(n - 1):
		print(max(0, maxl[i + 1] - l[i] + 1), end=' ')
	print(0)
main()


a = int(input())
x = list(map(int, input().split()))
y = [0]
mx = x[-1]
for i in range(a - 2, -1, -1):
	y.append(max(0, mx - x[i] + 1))
	mx = max(mx, x[i])
print(' '.join(map(str, y[::-1])))


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


n = int(input())
h = list(map(int, input().split())) + [0]
h_max = [0] * n
res = ['0'] * n
for i in range(n - 1, 0, -1):
	h_max[i - 1] = max(h_max[i], h[i] + 1)
	res[i] = str(max(h_max[i] - h[i], 0))
res[0] = str(max(h_max[0] - h[0], 0))
print(' '.join(res))


n = int(input())
arr = [int(x) for x in input().split()]
m = [0] * (n + 1)
ans = [0] * (n + 1)
for i in range(n - 2, -1, -1):
	m[i] = max(m[i + 1], arr[i + 1])
	ans[i] = max(m[i] - arr[i] + 1, 0)
print(*ans[:-1])


n = int(input())
lst = list(map(int, input().split()))
res = [0]
k = 0
for i in range(-2, -len(lst) - 1, -1):
	if k < lst[i + 1]:
		k = lst[i + 1]
	if k >= lst[i]:
		res.append(k - lst[i] + 1)
	else:
		res.append(0)
print(*res[::-1])


n = int(input())
l = list(map(int, input().split()))
max1 = 0
arr1 = []
for i in range(n - 1, -1, -1):
	if l[i] > max1:
		max1 = l[i]
		arr1.append(0)
	elif l[i] == max1:
		arr1.append(1)
	else:
		arr1.append(max1 - l[i] + 1)
arr1 = arr1[::-1]
print(*arr1)


n = int(input())
h = list(map(int, input().split()))
maxh = 0
a = [0] * n
for i in range(n - 1, -1, -1):
	if h[i] > maxh:
		maxh = h[i]
		a[i] = 0
	elif h[i] <= maxh:
		a[i] = max(0, maxh + 1 - h[i])
print(' '.join(map(str, a)))


n = int(input())
a = [int(x) for x in input().split()]
m = [0 for x in range(n)]
m[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
	m[i] = max(m[i + 1], a[i])
for i in range(n - 1):
	print(max(0, m[i + 1] + 1 - a[i]), end=' ')
print(0)


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
n = int(input())
nums = list(map(int, input().split()))
m = 0
ans = []
for i in range(n - 1, -1, -1):
	if nums[i] <= m:
		ans.append(str(m - nums[i] + 1))
	else:
		ans.append('0')
	m = max(m, nums[i])
ans = ans[::-1]
print(' '.join(ans))


n = int(input())
ai = list(map(int, input().split()))
maxm = ai[n - 1]
bi = [0] * n
for i in range(len(ai) - 2, -1, -1):
	bi[i] = max(0, maxm + 1 - ai[i])
	if ai[i] > maxm:
		maxm = ai[i]
print(*bi)


N = int(input())
A = list(map(int, input().split()))
B = A[:]
for i in range(N - 2, -1, -1):
	if B[i] < B[i + 1]:
		B[i] = B[i + 1]
for i in range(0, N - 1):
	if A[i] > B[i + 1]:
		print('0', end=' ')
	else:
		print(B[i + 1] + 1 - A[i], end=' ')
print('0')


n = int(input())
A = list(map(int, input().split()))
etaj = [0] * n
l = len(A)
ma = A[-1]
for i in range(-2, -l - 1, -1):
	if A[i] > ma:
		ma = A[i]
		etaj[i] = 0
	elif A[i] == ma:
		etaj[i] = 1
	else:
		etaj[i] = ma - A[i] + 1
for elem in etaj:
	print(elem, end=' ')


n = int(input())
q = [int(x) for x in input().split()]
vmax = -1
for i in range(n - 1, -1, -1):
	t = q[i]
	if q[i] > vmax:
		q[i] = 0
	else:
		q[i] = vmax - q[i] + 1
	vmax = max(vmax, t)
print(' '.join(map(str, q)))


n = int(input())
a = list([int(x) for x in input().split()])
maxs = a[-1]
needed = [0] * n
for i in range(n - 2, -1, -1):
	need = max(0, maxs - a[i] + 1)
	needed[i] = need
	maxs = max(maxs, a[i])
print(*needed)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
ans = [0] * n
mx = 0
for i in range(n - 1, -1, -1):
	ans[i] = max(0, mx - a[i] + 1)
	mx = max(a[i], mx)
print(*ans)


n = int(input())
l = list(map(int, input().split()))[::-1]
m = 0
l2 = []
for i in range(n):
	if l[i] > m:
		l2.append(0)
		m = l[i]
	elif l[i] == m:
		l2.append(1)
	else:
		l2.append(m - l[i] + 1)
print(*l2[::-1])


k = int(input())
houses = list(map(int, input().split()))
maxim = 0
answer = []
for i in range(len(houses) - 1, -1, -1):
	currentVal = houses[i]
	if maxim < currentVal:
		answer.append(0)
		maxim = currentVal
	else:
		answer.append(maxim - currentVal + 1)
print(' '.join(reversed([str(i) for i in answer])))


n = int(input())
string = input()
numbers = string.split(' ')
for x in range(n):
	numbers[x] = int(numbers[x])
floors = []
maximum = numbers[n - 1]
for x in range(n - 2, -1, -1):
	a = numbers[x]
	if a > maximum:
		maximum = a
		floors.append('0')
	else:
		floors.append(str(maximum - a + 1))
floors = floors[::-1]
floors.append('0')
print(' '.join(floors))


n = int(input())
a = [int(i) for i in input().split()]
pref = [0] * n
from collections import defaultdict
d = defaultdict(int)
pref[-1] = a[-1]
d[pref[-1]] = n - 1
for i in range(n - 2, -1, -1):
	pref[i] = max(pref[i + 1], a[i])
	if d[pref[i]] == 0:
		d[pref[i]] = i
out = [0] * n
for i in range(n):
	if a[i] == pref[i] and i == d[a[i]]:
		continue
	elif a[i] == pref[i]:
		out[i] = 1
	else:
		out[i] = pref[i] - a[i] + 1
print(*out)


n = input()
buildings = list(map(int, input().split(' ')))
m = 0
result = []
for i in range(len(buildings) - 1, -1, -1):
	b = buildings[i]
	x = m - b
	if x < 0:
		result.append(0)
		m = b
	else:
		result.append(x + 1)
print(' '.join(map(str, result[::-1])))


n = int(input())
a = list(map(int, input().split()))
a.reverse()
c = []
c.append(0)
maxi = a[0]
for i in range(len(a) - 1):
	if a[i + 1] > maxi:
		c.append(0)
		maxi = a[i + 1]
	elif a[i + 1] <= maxi:
		c.append(abs(1 + maxi - a[i + 1]))
c.reverse()
print(*c)


n = int(input())
h = list(map(int, input().split()))
MaxH = 0
H = []
for i in range(n - 1, -1, -1):
	if h[i] > MaxH:
		H.append(0)
		MaxH = h[i]
	elif h[i] == MaxH:
		H.append(1)
	else:
		H.append(MaxH - h[i] + 1)
for i in range(n - 1, -1, -1):
	print(H[i], end=' ')


n = int(input())
h = list(map(int, input().split()))
a = [0] * n
m = -1
for i in range(n - 1, -1, -1):
	a[i] = max(m + 1 - h[i], 0)
	m = max(m, h[i])
print(*a)


z = int(input())
x = list(map(int, input().split()))
x.reverse()
f = x[0]
d = []
for i in range(z):
	if f >= x[i] and i != 0:
		d.append(str(f - x[i] + 1))
	elif f == x[i]:
		d.append('0')
	elif f < x[i]:
		d.append('0')
		f = x[i]
d.reverse()
print(' '.join(d).strip())


n = int(input())
l = input().split()
s = []
for i in range(n):
	l[i] = int(l[i])
	s.append(0)
i = 0
m = l[n - 1]
while i < n:
	k = n - i - 1
	if m >= l[k] and i != 0:
		s[k] = m - l[k] + 1
	else:
		m = l[k]
	i += 1
for i in range(n):
	print(s[i])


def get(data):
	return data[1]

def get_answer(houses):
	maxv = []
	local_max = 0
	for i in reversed(range(0, len(houses))):
		if houses[i] > local_max:
			local_max = houses[i]
			maxv.append(-1)
		else:
			maxv.append(local_max)
	maxv = list(reversed(maxv))
	for i in range(len(houses)):
		if maxv[i] == -1:
			print(0)
		else:
			print(maxv[i] - houses[i] + 1)
input()
data = input()
data = data.split(' ')
data = list(map(int, data))
get_answer(data)


n = int(input())
h = [int(s) for s in input().split()]
m = [0] * n
m[n - 1] = h[n - 1]
for i in reversed(range(n - 1)):
	m[i] = max(h[i], m[i + 1])
a = [max(0, m[i + 1] + 1 - h) for (i, h) in enumerate(h[:-1])] + [0]
print(' '.join((str(x) for x in a)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def abs(x):
	return x if x >= 0 else -x

def sumelem(x, start, end):
	sum = 0
	for i in range(start, end + 1):
		sum += x[i]
	return sum
for t in range(1):
	n = int(input())
	buildings = list(map(int, input().split()))
	li = [0]
	maxi = buildings[-1]
	for i in range(n - 2, -1, -1):
		li.append(max(maxi + 1 - buildings[i], 0))
		maxi = max(maxi, buildings[i])
	for i in range(n - 1, -1, -1):
		print(li[i], end=' ')


import sys
try:
	while True:
		n = int(input())
		val = list(map(int, input().split()))
		maxval = 0
		for i in range(n - 1, -1, -1):
			if maxval >= val[i]:
				val[i] = maxval - val[i] + 1
			else:
				maxval = val[i]
				val[i] = 0
		print(*val)
except EOFError:
	pass


(n, m, v) = (int(input()), 0, [])
for x in map(int, reversed(input().split())):
	v.append(max(0, m - x + 1))
	m = max(m, x)
print(' '.join(map(str, reversed(v))))


n = int(input())
h = list(map(int, input().split()))
out = [0]
best = h[-1]
for i in range(n - 2, -1, -1):
	if h[i] < best:
		out.append(best - h[i] + 1)
	elif h[i] > best:
		best = h[i]
		out.append(0)
	else:
		out.append(1)
print(' '.join(map(str, reversed(out))))


a = int(input())
l = list(map(int, input().split()))
(d, c) = ([0] * a, l[-1])
for x in range(2, a + 1):
	d[-x] = max(0, c - l[-x] + 1)
	c = max(c, l[-x])
print(*d)


n = int(input())
l_n = list(map(int, input().split()))
m = 0
l_a = [0 for i in range(n)]
for i in range(n):
	l_a[n - i - 1] = max(0, m + 1 - l_n[n - i - 1])
	m = max(m, l_n[n - i - 1])
print(' '.join((str(x) for x in l_a)))


n = int(input())
l = list(map(int, input().split()))
maxh = 0
a = []
for i in range(n - 1, -1, -1):
	a.append(max(0, maxh + 1 - l[i]))
	if l[i] > maxh:
		maxh = l[i]
for i in range(n - 1, -1, -1):
	print(a[i], end=' ')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
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 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 S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	m = -1
	r = []
	for c in a[::-1]:
		r.append(max(0, m + 1 - c))
		if m < c:
			m = c
	return ' '.join(map(str, r[::-1]))
print(main())


n = int(input())
l = [int(q) for q in input().split()]
c = 0
d = l[::-1]
m = d[0]
ans = [0]
for i in range(1, len(l)):
	ans.append(max(0, m - d[i] + 1))
	if d[i] > m:
		m = d[i]
print(*ans[::-1])


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = rr()
arr += [arr[-1] - 1]
x = 0
ans = []
for i in range(n, -1, -1):
	x = max(x, arr[i])
	if i:
		ans.append(max(0, x - arr[i - 1] + 1))
print(*ans[::-1])


n = int(input())
h = list(map(int, input().split()))
m = max(h)
l = h.index(m)
i = n - 2
a = [0]
maxh = h[n - 1]
while i >= 0:
	if maxh == h[i]:
		a.append(1)
	else:
		maxh = max(h[i], maxh)
		if maxh == h[i]:
			a.append(0)
		else:
			a.append(maxh - h[i] + 1)
	i -= 1
a.reverse()
for i in a:
	print(i, end=' ')


n = int(input())
arr = [int(i) for i in input().split()]
stack = []
res = [0 for _ in range(n)]
for i in range(n - 1, -1, -1):
	if stack and stack[-1] >= arr[i]:
		res[i] = stack[-1] - arr[i] + 1
	if not stack:
		stack.append(arr[i])
	elif stack[-1] < arr[i]:
		stack.append(arr[i])
print(*res)


t = int(input())
a = list(map(int, input().split()))
b = []
max = a[t - 1]
i = t - 2
while i >= 0:
	if a[i] <= max:
		b.append(max - a[i] + 1)
	else:
		max = a[i]
		b.append(0)
	i = i - 1
b.insert(0, '0')
i = t - 1
while i >= 0:
	print(b[i], end=' ')
	i = i - 1


n = int(input())
s = list(map(int, input().split()))
s.reverse()
d = s[0]
a = []
for i in range(1, n):
	f = int(s[i])
	if f <= d:
		k = str(d - f + 1)
		a.append(k)
	else:
		a.append(0)
		d = f
a.insert(0, '0')
a.reverse()
for j in a:
	print(j, end=' ')


from bisect import bisect_left as bs
from math import log as lg
from math import factorial as f
log = lambda *x: print(*x)

def cin(*fn, def_fn=str):
	(i, r) = (0, [])
	if fn:
		def_fn = fn[0]
	for c in input().split(' '):
		r += [(fn[i] if len(fn) > i else def_fn)(c)]
		i += 1
	return r
(n,) = cin(int)
h = cin(int)
r = [0] * n
mxr = h[-1]
for i in range(n - 2, -1, -1):
	if h[i] > mxr:
		(r[i], mxr) = (0, h[i])
	else:
		r[i] = mxr - h[i] + 1
log(' '.join((str(c) for c in r)))


n = int(input())
t = list(map(int, input().split()))[::-1]
f = [0]
u = t[0]
for k in range(1, n):
	if t[k] > u:
		f.append(0)
		if t[k] > u:
			u = t[k]
	else:
		s = u - t[k] + 1
		f.append(s)
		if t[k] > u:
			u = t[k]
print(*f[::-1])


import sys

def solve():
	(n,) = rv()
	(h,) = rl(1)
	maxsofar = 0
	res = [0] * n
	for i in range(n - 1, -1, -1):
		if h[i] <= maxsofar:
			res[i] = maxsofar - h[i] + 1
		else:
			maxsofar = h[i]
	prt(res)

def prt(l):
	return print(' '.join(map(str, l)))

def rs():
	return map(str, input().split())

def rv():
	return map(int, input().split())

def rl(n):
	return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


n = int(input())
lst = list(map(int, input().split()))
(res, mx) = ([0], lst[-1])
for i in range(n - 2, -1, -1):
	x = lst[i]
	if x <= mx:
		res.append(mx - x + 1)
	else:
		res.append(0)
		mx = x
res.reverse()
print(*res)


n = int(input())
l = list(map(int, input().split()))
ans = n * [0]
ma = 0
i = n - 1
while i >= 0:
	if l[i] <= ma:
		ans[i] = ma - l[i] + 1
	else:
		ans[i] = 0
		ma = l[i]
	i -= 1
for i in range(n):
	print(str(ans[i]) + ' ', end='')


n = int(input())
a = list(map(int, input().split()))
(m, l) = (0, [])
for _ in range(n):
	x = a.pop()
	if x > m:
		m = x
		l.append(0)
	else:
		l.append(m - x + 1)
print(' '.join(map(str, l[::-1])))


n = int(input())
l = list(map(int, input().split()))
a = []
max1 = 0
for i in range(n - 1, -1, -1):
	if l[i] > max1:
		max1 = l[i]
		a.append(0)
	else:
		a.append(max1 - l[i] + 1)
a.reverse()
print(*a)


n = int(input())
a = list(map(int, input().split()))
max_num = 0
res = [0] * n
for i in range(n - 1, -1, -1):
	res[i] = max(0, max_num - a[i] + 1)
	max_num = max(max_num, a[i])
print(' '.join(map(str, res)))


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
lst = [0] * n
mx_sofar = arr[n - 1]
for i in range(n - 2, -1, -1):
	if arr[i] > mx_sofar:
		mx_sofar = arr[i]
		lst[i] = 0
	else:
		lst[i] = mx_sofar - arr[i] + 1
print(*lst)


__author__ = 'yarsanich'
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
m = 0
for i in range(n - 1, -1, -1):
	b[i] = max(0, m - a[i] + 1)
	m = max(m, a[i])
print(*b)


n = int(input())
v = list(map(int, input().split()))
v1 = [0] * n
m = 0
for i in range(n):
	if v[-i - 1] > m:
		m = v[-i - 1]
	else:
		v1[-i - 1] = m - v[-i - 1] + 1
print(' '.join(map(str, v1)))


n = int(input())
l = [int(x) for x in input().split()]
a = [0] * n
m = l[n - 1]
for i in range(n - 2, -1, -1):
	if l[i] > m:
		a[i] = 0
		m = l[i]
	else:
		a[i] = m - l[i] + 1
for x in a:
	print(x, end=' ')


n = int(input())
a = [int(s) for s in input().split()]
b = [0] * n
i = n - 1
sum = 0
while i > 0:
	sum = max(sum, a[i])
	b[i - 1] = max(0, sum + 1 - a[i - 1])
	i = i - 1
for elem in b:
	print(elem, end=' ')


n = int(input())
bF = list(map(int, input().split()))
max_ahead = [0]
for i in range(n - 2, -1, -1):
	max_ahead.append(max(bF[i + 1], max_ahead[-1]))
max_ahead = max_ahead[::-1]
for i in range(0, n):
	if bF[i] > max_ahead[i]:
		print(0, end=' ')
	else:
		print(max_ahead[i] - bF[i] + 1, end=' ')


n = int(input())
h = list(map(int, input().split()))
max_height = 0
diff = n * [0]
for i in range(n).__reversed__():
	if h[i] > max_height:
		max_height = h[i]
		diff[i] = 0
	else:
		diff[i] = max_height - h[i] + 1
print(*diff)


import itertools
n = int(input())
h = [int(x) for x in input().split()] + [0]
max_tail = list(itertools.accumulate(reversed(h), max))
max_tail.pop()
max_tail.reverse()
for i in range(n):
	print(max(max_tail[i] - h[i] + 1, 0), end=' ')


n = int(input())
arr = list(map(int, input().split()))
temp = [None] * n
m = 0
last = 0
for i in range(n):
	if last > m:
		m = last
	last = arr[n - 1 - i]
	temp[n - 1 - i] = m
for i in range(len(arr)):
	if arr[i] < temp[i] + 1:
		print(temp[i] + 1 - arr[i], end=' ')
	else:
		print(0, end=' ')


n = int(input())
h = [int(i) for i in input().split()]
p = n * [0]
p[-1] = 0
gg = n * [0]
gg[-1] = 0
for i in range(n - 2, -1, -1):
	gg[i] = max(gg[i + 1], h[i + 1])
for i in range(n):
	d = gg[i] - h[i]
	if d < 0:
		d = 0
		p[i] = d
	else:
		p[i] = d + 1
for i in range(n):
	print(p[i], end=' ')


(N, X, Answer) = (int(input()), list(map(int, input().split())), [0])
Max = X[-1]
for i in X[:N - 1][::-1]:
	Answer.append(max(0, Max - i + 1))
	Max = max(Max, i)
print(*Answer[::-1])


n = int(input())
h = list(map(int, input().split()))
stat = [0] * n
for i in range(n - 2, -1, -1):
	stat[i] = max(stat[i + 1], h[i + 1])
for j in range(n):
	if h[j] > stat[j]:
		print('0', end=' ')
	else:
		print(stat[j] - h[j] + 1, end=' ')


n = int(input())
input = list(map(int, input().split()))
output = [0 for x in range(len(input))]
m = 0
for i in range(n - 1, -1, -1):
	output[i] = max(0, m - input[i] + 1)
	m = max(m, input[i])
print(' '.join((str(output[i]) for i in range(len(output)))))


__author__ = 'Admin'
n = int(input())
mas1 = list(map(int, input().split()))
masans = [0]
max = mas1[n - 1]
for i in range(n - 2, -1, -1):
	if mas1[i] > max:
		max = mas1[i]
		masans.append(0)
	else:
		masans.append(max - mas1[i] + 1)
masans.reverse()
print(*masans)


n = int(input())
c = list(map(int, input().split()))
a = [0] * n
l = c[-1]
for i in range(n - 2, -1, -1):
	if c[i] > l:
		l = c[i]
	else:
		a[i] = l - c[i] + 1
print(*a)


n = int(input())
a = map(int, input().split(' '))
rmax = 0
res = []
for x in reversed(list(a)):
	t = rmax - x
	res.append(0 if t < 0 else t + 1)
	rmax = max(x, rmax)
for x in reversed(res):
	print(x, end=' ')
print()


def make_luxurious(n, arr):
	arr.reverse()
	tallest = arr[0]
	ans = []
	ans.append(str(0))
	for x in arr[1:]:
		if x > tallest:
			tallest = x
			ans.append(str(0))
		else:
			ans.append(str(tallest - x + 1))
	ans.reverse()
	return ' '.join(ans)
n = int(input())
arr = list(map(int, input().split()))
print(make_luxurious(n, arr))


n = int(input())
h = list(map(int, input().split()))
ans = [0] * n
ans[n - 1] = 0
maxh = h[n - 1]
for i in range(n - 2, -1, -1):
	if h[i] > maxh:
		ans[i] = 0
	else:
		ans[i] = maxh - h[i] + 1
	maxh = max(maxh, h[i])
print(' '.join(map(str, ans)))


n = int(input())
arr = list(map(int, input().split()))
maxarr = [0] * n
maxarr[n - 1] = arr[-1]
curmax = maxarr[-1]
index = n - 1
for val in arr[::-1]:
	maxarr[index] = max(val, curmax)
	curmax = maxarr[index]
	index -= 1
for (index, val) in enumerate(arr):
	out = 0
	if maxarr[index] == val:
		if index + 1 < n and maxarr[index + 1] == maxarr[index]:
			out = 1
	else:
		out = maxarr[index] - val + 1
	print(out, end=' ')
print()


import itertools
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
m = a[-1]
for i in range(n - 2, -1, -1):
	b[i] = max(0, m - a[i] + 1)
	m = max(m, a[i])
print(' '.join(map(str, b)))


n = int(input())
l = list(map(int, input().split()))
v = 0
S = []
for i in range(n - 1, -1, -1):
	if l[i] <= v:
		S.append(abs(l[i] - v) + 1)
	else:
		S.append(0)
	if l[i] > v:
		v = l[i]
S1 = []
for i in range(n - 1, -1, -1):
	S1.append(str(S[i]))
print(' '.join(S1))


import copy
n = int(input())
l = list(map(int, input().split()))
m = copy.copy(l)
ma = 0
for i in range(n - 2, -1, -1):
	if l[i + 1] > ma:
		ma = l[i + 1]
	m[i] = ma
for i in range(n - 1):
	print(max(0, m[i] - l[i] + 1), end=' ')
print(0)


n = int(input())
a = list(map(int, input().split()))
_max = max(a)
b = [0] * n
b[n - 1] = 0
c = a[n - 1]
for i in range(n - 2, -1, -1):
	if a[i] > c:
		b[i] = 0
		c = a[i]
	else:
		c = max(c, a[i])
		b[i] = c - a[i] + 1
for i in range(n):
	print(b[i])


n = int(input())
h = [int(i) for i in input().split()] + [0]
v = [0 for i in h]
for p in range(n, -1, -1):
	if p == n:
		v[p] = h[p]
	else:
		v[p] = max(v[p + 1], h[p])
print(' '.join(['%s' % max(0, v[i + 1] + 1 - h[i]) for i in range(n)]))


n = int(input())
mat = list(map(int, input().split()))[::-1]
rmnd = 0
sat = []
for i in mat:
	if rmnd >= i:
		sat.append(rmnd - i + 1)
	else:
		sat.append(0)
		rmnd = i
print(*sat[::-1])


a = int(input())
b = list(map(int, input().split()))
mark = 0
answer = list()
for x in range(a):
	if b[a - x - 1] > mark:
		answer.append(0)
		mark = b[a - x - 1]
	else:
		answer.append(mark - b[a - x - 1] + 1)
for x in range(a):
	print(answer[a - x - 1], '', end='', flush=True)


z = int(input())
l = list(map(int, input().rstrip().split(' ')))
a = [0] * z
m = l[-1]
if z == 1:
	print(0)
else:
	for i in range(z - 2, 0, -1):
		if l[i] <= m:
			a[i] = m - l[i] + 1
		if l[i] > m:
			m = l[i]
	if l[0] <= m:
		a[0] = m - l[0] + 1
	for j in a:
		print(j, end=' ')


n = int(input())
houses = list(map(int, input().split(' ')))
answers = []
mh = 0
for h in houses[::-1]:
	if mh >= h:
		answers.append(mh - h + 1)
	else:
		answers.append(0)
	mh = max(mh, h)
print(' '.join(map(str, answers[::-1])))


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
right_max = arr[n - 1]
ans = [0]
for i in range(n - 2, -1, -1):
	if arr[i] > right_max:
		ans.append(0)
		right_max = arr[i]
	else:
		ans.append(right_max - arr[i] + 1)
ans = ans[::-1]
for x in ans:
	print(x, end=' ')


a = int(input())
b = list(map(int, input().split()))
b = b[::-1]
h = 0
g = []
for i in b:
	if h < i:
		h = i
		g.append(0)
	elif h == i:
		g.append(1)
	else:
		g.append(h - i + 1)
g = g[::-1]
for i in g:
	print(i, end=' ')


n = int(input())
l = [int(x) for x in input().split()]
assert len(l) == n
l.reverse()
pre = [0]
for i in range(1, n):
	pre.append(max(pre[-1], l[i - 1]))
out = [max(0, 1 + pre[i] - l[i]) for i in range(n)]
out.reverse()
print(' '.join((str(x) for x in out)))


n = int(input())
a = list(map(int, input().split()))
flag = 0
b = [0]
k = a[-1]
for i in range(1, n):
	if k > a[n - i - 1]:
		b.append(-a[n - i - 1] + k + 1)
	else:
		if k - a[n - i - 1] + 1 > 0:
			b.append(k - a[n - i - 1] + 1)
		else:
			b.append(0)
		k = a[n - i - 1]
for i in b[::-1]:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
f = [0] * (n + 1)
r = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	f[i] = f[i + 1]
	if f[i] >= a[i]:
		r[i] = f[i] - a[i] + 1
	f[i] = max(f[i], a[i])
for i in range(n):
	print(r[i], end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
arr1 = [0] * n
m = arr[n - 1]
for i in range(n - 2, -1, -1):
	if arr[i] < m:
		arr1[i] = m - arr[i] + 1
	elif arr[i] == m:
		arr1[i] = 1
	else:
		m = arr[i]
print(*arr1)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
b = [0] * n
for i in range(n - 2, -1, -1):
	b[i] = max(a[i + 1], b[i + 1])
c = [max(b[i] + 1 - a[i], 0) for i in range(n)]
c[-1] = 0
print(' '.join([str(i) for i in c]))


import sys
n = int(input())
h = [int(i) for i in input().split()]
h = h[::-1]
ans = []
curmax = h[0] - 1
for i in range(n):
	if h[i] <= curmax:
		ans.append(curmax + 1 - h[i])
	else:
		ans.append(0)
	curmax = max(curmax, h[i])
ans = ans[::-1]
for x in ans:
	print(x, end=' ')


n = int(input())
l = list(map(int, input().split()))
ans = [0]
tmp = l[-1]
for i in range(n - 2, -1, -1):
	ans.append(max(0, tmp - l[i] + 1))
	if l[i] > tmp:
		tmp = l[i]
print(*ans[::-1])


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * len(a)
	m = a[-1]
	for i in range(len(a) - 2, -1, -1):
		if a[i] > m:
			m = a[i]
		else:
			b[i] = m - a[i] + 1
	print(' '.join(map(str, b)))
main()


a = int(input())
b = list(map(int, input().split()))
m = [0] * a
an = b[a - 1]
for i in range(a - 2, -1, -1):
	m[i] = max(0, an - b[i] + 1)
	if b[i] > an:
		an = b[i]
print(*m)


n = int(input())
lst = list(map(int, input().split()))
mx = 0
arr = [0] * n
for i in reversed(range(n)):
	if lst[i] <= mx:
		arr[i] = mx - lst[i] + 1
	mx = max(mx, lst[i])
for i in arr:
	print(i, end=' ')


n = int(input())
h = list(map(int, input().split()))
maxi = 0
c = []
for i in reversed(h):
	if i > maxi:
		maxi = i
		c.append(0)
	else:
		c.append(maxi + 1 - i)
for i in reversed(c):
	print(i, end=' ')


n = int(input())
li = list(map(int, input().split(' ')))
lu = []
k = 0
for i in range(n - 1, -1, -1):
	lu.append(max(0, k + 1 - li[i]))
	k = max(k, li[i])
lu.reverse()
print(' '.join(map(str, lu)))


n = str(input())
line = [int(it) for it in str(input()).split()]
line.reverse()
res = list()
mark = 0
for it in line:
	res.append(str(max(1 + mark - it, 0)))
	mark = max(mark, it)
res.reverse()
print(' '.join(res))


n = int(input())
h = list(map(int, input().split()))
r = [0]
m = h[-1]
for i in range(n - 2, -1, -1):
	if h[i] <= m:
		r.append(m + 1 - h[i])
	else:
		r.append(0)
		m = h[i]
for i in range(n - 1, -1, -1):
	print(r[i], end=' ')


n = int(input())
houses = [int(c) for c in input().split()]
ans = [0] * n
max_ = -1
for i in range(n - 1, -1, -1):
	ans[i] = max_ - houses[i] + 1 if houses[i] <= max_ else 0
	max_ = max(max_, houses[i])
print(*ans)


N = int(input())
H = [int(_) for _ in input().split()]
suffix_max = [0] * (N + 1)
for i in range(N - 1, -1, -1):
	suffix_max[i] = max(H[i], suffix_max[i + 1])
ans = [0] * N
for i in range(N):
	ans[i] = max(suffix_max[i + 1] - H[i] + 1, 0)
print(' '.join((str(_) for _ in ans)))


from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
ra = a[::-1]
mx = [ra[0]]
c = Counter(a)
for i in range(1, n):
	mx.append(max(mx[i - 1], ra[i]))
for i in range(n):
	if mx[n - 1 - i] == a[i]:
		if c[a[i]] > 1:
			print(1, end=' ')
		else:
			print(0, end=' ')
	else:
		print(mx[n - 1 - i] + 1 - a[i], end=' ')
	if c[a[i]] > 1:
		c[a[i]] -= 1


n = int(input())
l = list(map(int, input().split()))
a = list(range(n + 1))
y = 0
for i in range(n - 1, -1, -1):
	y = max(y, l[i])
	a[i] = y
a[n] = 0
for i in range(n):
	if (l[i] == a[i]) & (l[i] != a[i + 1]):
		print('0 ', end='')
	else:
		print(a[i] - l[i] + 1, end='')
		print(' ', end='')


n = int(input())
h = list(map(int, input().split()))
l1 = [0] * n
mx = 0
ans = ''
for i in range(n - 1, -1, -1):
	mx = max(mx, h[i])
	l1[i] = mx
for i in range(n - 1):
	if h[i] > l1[i + 1]:
		ans += '0 '
	else:
		ans += f'{l1[i] - h[i] + 1} '
ans += '0'
print(ans)


n = int(input())
h = [i for i in map(int, input().split())]
h = h[::-1]
ans = []
maxH = h[0]
for i in range(1, len(h)):
	if maxH - h[i] + 1 < 0:
		ans.append(0)
	else:
		ans.append(maxH - h[i] + 1)
	maxH = max(maxH, h[i])
ans = ans[::-1]
ans.append(0)
print(*ans)


n = int(input())
arr = list(map(int, input().split()))
dp = [0] * (n + 1)
dp[-1] = -1
for i in range(n - 1, -1, -1):
	maxx = max(dp[i + 1], arr[i])
	dp[i] = maxx
ans = []
for i in range(n):
	if arr[i] > dp[i + 1]:
		ans.append(0)
	else:
		ans.append(dp[i + 1] - arr[i] + 1)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
v = []
ma = 0
for i in range(n - 1, -1, -1):
	if l[i] > ma:
		v.append(0)
		ma = l[i]
	else:
		v.append(max(0, ma - l[i] + 1))
v.reverse()
print(*v)


n = int(input())
l = list(map(int, input().split()))
m = 0
d = []
for i in range(n - 1, -1, -1):
	s = max(0, m + 1 - l[i])
	d.append(s)
	if l[i] > m:
		m = l[i]
print(*d[::-1])


from collections import deque
input()
(A, max_h) = (deque(), 0)
for h in reversed(list(map(int, input().split()))):
	if h > max_h:
		max_h = h
		A.appendleft(0)
	else:
		A.appendleft(max_h - h + 1)
print(*A)


n = int(input())
mas = list(map(int, input().split(' ')))
submas = [0] * n
ma = 0
for i in range(n - 1, -1, -1):
	submas[i] = str(max(ma - mas[i] + 1, 0))
	if ma < mas[i]:
		ma = mas[i]
print(' '.join(submas))


n = int(input())
h = list(map(int, input().split()))
maxi = h[n - 1]
maxes = [0] * n
maxes[n - 1] = 0
res = ''
for i in range(n - 1, 0, -1):
	if h[i - 1] > maxi:
		maxi = h[i - 1]
		maxes[i - 1] = 0
	else:
		maxes[i - 1] = maxi - h[i - 1] + 1
for i in range(n):
	res += str(maxes[i]) + ' '
print(res[:-1])


n = int(input())
arr = list(map(int, input().split()))
h = 0
for i in range(n - 1, -1, -1):
	x = max(0, h - arr[i] + 1)
	h = max(h, arr[i])
	arr[i] = x
print(*arr)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = il()
l1 = [0] * n
mx = 0
for i in range(n - 1, -1, -1):
	if l[i] <= mx:
		l1[i] = mx - l[i] + 1
	mx = max(l[i], mx)
print(*l1)


n = int(input())
hs = list(map(int, input().split()))
r = []
maxi = 0
for h in hs[::-1]:
	r.append(max(0, maxi - h + 1))
	maxi = max(maxi, h)
print(' '.join(map(str, r[::-1])))


n = int(input())
h = tuple(map(int, str.split(input())))
hm = [0] * n
ch = 0
for (i, x) in enumerate(reversed(h)):
	hm[i] = max(0, ch - x + 1)
	ch = max(ch, x)
print(str.join(' ', map(str, reversed(hm))))


from sys import stdin
n = int(stdin.readline())
hi = list(map(int, stdin.readline().split()))
res = [''] * n
vmax = 0
for i in range(n - 1, -1, -1):
	if vmax < hi[i]:
		vmax = hi[i]
		res[i] = '0'
	else:
		res[i] = str(vmax - hi[i] + 1)
print(' '.join(res))


n = int(input())
x = list(map(int, input().split()))
abc = x[-1]
a = [0]
for i in range(2, n + 1):
	if x[-i] <= abc:
		a.append(abc - x[-i] + 1)
	elif x[-i] > abc:
		abc = x[-i]
		a.append(0)
print(*a[::-1])


def solve(n, h_arr):
	h_arr = list(h_arr)
	h_increment = [0] * n
	largest = h_arr[n - 1]
	for i in range(n - 2, -1, -1):
		if h_arr[i] <= largest:
			h_increment[i] = largest - h_arr[i] + 1
		else:
			largest = h_arr[i]
	return ' '.join((str(h_inc) for h_inc in h_increment))
n = int(input())
h_arr = map(int, input().split(' '))
print(solve(n, h_arr))


n = int(input())
a = list(map(int, input().split()))
add = [0] * n
m = a[n - 1]
for i in range(n - 2, -1, -1):
	if a[i] > m:
		add[i] = 0
		m = a[i]
	else:
		add[i] = m - a[i] + 1
print(*add)


n = int(input())
arr = list(map(int, input().split()))
arr.reverse()
count = 0
arr2 = []
for k in arr:
	arr2.append(max(count + 1 - k, 0))
	count = max(count, k)
arr2.reverse()
for kk in arr2:
	print(kk, end=' ')


n = int(input())
a = [int(x) for x in input().split()] + [0]
s = [0 for x in range(n)]
m = a[-1]
for i in range(n):
	m = max(m, a[n - i])
	s[n - i - 1] = m
res = ''
for i in range(n):
	res += str(max(s[i] - a[i] + 1, 0)) + ' '
print(res[:-1])


n = int(input())
mass1 = list(map(int, input().split()))
maxx = 0
mass2 = []
for i in range(n - 1, -1, -1):
	if mass1[i] > maxx:
		mass2.append(0)
		maxx = mass1[i]
	else:
		mass2.append(maxx - mass1[i] + 1)
for i in range(n - 1, -1, -1):
	print(mass2[i], end=' ')


NumberOfHouses = int(input())
Floors = list(map(int, input().split()))
AddMeArr = [0] * NumberOfHouses
MaxNum = Floors[-1]
for i in range(NumberOfHouses - 2, -1, -1):
	if Floors[i] > MaxNum:
		MaxNum = Floors[i]
	else:
		AddMeArr[i] = MaxNum - Floors[i] + 1
print(*AddMeArr, sep=' ')


n = int(input())
s = [int(i) for i in input().split()]
cnt = 0
m = 0
for i in range(n - 1, -1, -1):
	if s[i] > m:
		m = s[i]
		s[i] = 0
	else:
		s[i] = m - s[i] + 1
print(*s)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
ans = [0] * n
curr = 0
for i in range(n - 1, -1, -1):
	if ara[i] <= curr:
		ans[i] = curr - ara[i] + 1
	curr = max(curr, ara[i])
print(*ans)


input()
H = [int(x) for x in input().split(' ')]
T = []
mx = H[-1]
for (i, e) in enumerate(H):
	j = len(H) - i - 1
	if j == len(H) - 1:
		T.append(0)
	else:
		h = mx - H[j]
		if h >= 0:
			T.append(h + 1)
		else:
			T.append(0)
		mx = max(mx, H[j])
for (i, x) in enumerate(T):
	print(T[len(T) - i - 1], end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
curr_max = -1
for i in range(n - 1, -1, -1):
	if a[i] > curr_max:
		ans[i] = 0
		curr_max = a[i]
	else:
		ans[i] = curr_max - a[i] + 1
for i in range(n):
	print(ans[i], end=' ')


def main():
	input()
	hh = list(map(int, input().split()))[::-1]
	h0 = 0
	for (i, h) in enumerate(hh):
		if h0 < h:
			h0 = h
			hh[i] = 0
		elif h0 > h:
			hh[i] = h0 + 1 - h
		else:
			hh[i] = 1
	print(*hh[::-1])
main()


from __future__ import print_function
t = int(input())
a = list(map(int, input().split()))
b = []
max = a[t - 1]
i = t - 2
while i >= 0:
	if a[i] <= max:
		b.append(max - a[i] + 1)
	else:
		max = a[i]
		b.append(0)
	i = i - 1
b.insert(0, '0')
i = t - 1
while i >= 0:
	print(b[i], end=' ')
	i = i - 1


n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.reverse()
mx = a[0]
ans = list()
ans.append(0)
for i in a[1:]:
	ans.append(max(0, mx - i + 1))
	mx = max(mx, i)
ans.reverse()
p = ''
for i in ans:
	p += i.__str__() + ' '
print(p)


n = int(input())
l = list(map(int, input().split()))
k = l[n - 1]
y = [0]
for i in range(1, n):
	if k < l[n - i - 1]:
		k = l[n - i - 1]
		y.append(0)
	else:
		y.append(k + 1 - l[n - i - 1])
for i in range(n):
	print(y[n - i - 1], end=' ')


n = int(input())
houses = [int(x) for x in input().split(' ')]
max_sizes = [0] * n
current_max = 0
for i in reversed(range(n)):
	max_sizes[i] = current_max
	if houses[i] > current_max:
		current_max = houses[i]
for i in range(n):
	floors_added = max_sizes[i] - houses[i] + 1
	if floors_added < 0:
		floors_added = 0
	if i < n - 1:
		print(floors_added, end=' ')
	else:
		print(floors_added)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
i = n - 1
l2 = []
m = 0
while i >= 0:
	if lst[i] > m:
		l2.append(0)
		m = lst[i]
	elif m == lst[i]:
		l2.append(1)
	else:
		l2.append(m + 1 - lst[i])
	i -= 1
for j in range(n):
	print(l2[n - j - 1], end=' ')


n = int(input())
l = [int(x) for x in input().split()]
g = []
h = 0
for i in range(n - 1, -1, -1):
	x = max(0, h + 1 - l[i])
	h = max(h, l[i])
	g.append(x)
g = g[::-1]
print(*g)


n = int(input())
nums = [int(i) for i in input().split()]
floorstoadd = []
largesttoright = nums[-1]
for i in range(len(nums) - 2, -1, -1):
	if nums[i] <= largesttoright:
		newone = str(largesttoright - nums[i] + 1)
		floorstoadd.append(newone[::-1])
	else:
		largesttoright = nums[i]
		floorstoadd.append('0')
answerstring = ' '.join(floorstoadd)
print(answerstring[::-1] + ' 0')


n = int(input())
h = [int(i) for i in input().split()]
maxHeight = h[-1]
heightRequired = [0]
for i in range(len(h) - 2, -1, -1):
	heightRequired.append(max(0, maxHeight - h[i] + 1))
	maxHeight = max(maxHeight, h[i])
heightRequired.reverse()
for i in range(len(heightRequired)):
	print(heightRequired[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
ma = a[n - 1]
ans = [0]
i = n - 2
while i >= 0:
	if a[i] > ma:
		ans.append(0)
		ma = a[i]
	else:
		d = ma - a[i] + 1
		ans.append(d)
	i = i - 1
ans.reverse()
print(*ans)


i = int(input())
l = list(reversed(list(map(int, input().split()))))
m = 0
t = []
for x in l:
	if x > m:
		t.append(0)
	else:
		t.append(m + 1 - x)
	if x > m:
		m = x
print(' '.join([str(elem) for elem in list(reversed(t))]))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, arr):
	out = [0]
	mx = arr[-1]
	for i in range(n - 2, -1, -1):
		if arr[i] > mx:
			out.append(0)
			mx = arr[i]
		else:
			out.append(mx - arr[i] + 1)
	print(*out[::-1])
n = int(input())
arr = int_arr()
solve(n, arr)


n = int(input())
ls = list(map(int, input().split()))
ans = [0] * n
curr_max = ls[-1]
for i in range(n - 2, -1, -1):
	if ls[i] > curr_max:
		curr_max = ls[i]
	else:
		ans[i] = curr_max - ls[i] + 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))
L = [0] * n
mx = 0
for i in range(n - 1, -1, -1):
	if a[i] > mx:
		L[i] = 0
	else:
		L[i] = mx + 1 - a[i]
	mx = max(mx, a[i])
print(*L)


n = int(input())
a = list(map(int, input().split()))
ans = []
m = 0
for i in range(n - 1, -1, -1):
	ans.append(max(0, m + 1 - a[i]))
	m = max(m, a[i])
ans.reverse()
for i in ans:
	print(i, end=' ')


input()
(n, result) = ([int(x) for x in input().split()], [])
max = -1
for i in range(len(n) - 1, -1, -1):
	if n[i] <= max:
		result.append(max - n[i] + 1)
	else:
		max = n[i]
		result.append(0)
for i in range(len(result) - 1, -1, -1):
	print(result[i], end=' ')
print()


n = int(input())
house = list(map(int, input().split()))
house.reverse()
final = []
largestVal = 0
for i in house:
	if i > largestVal:
		final.append('0')
	else:
		final.append(f'{largestVal - i + 1}')
	largestVal = max([largestVal, i])
final.reverse()
print(' '.join(final))


n = int(input())
houses = list(reversed(list(map(int, input().split()))))
ans = [0] * n
highestToTheRight = houses[0]
for i in range(1, n):
	if houses[i] > highestToTheRight:
		highestToTheRight = houses[i]
		ans[i] = 0
	else:
		ans[i] = highestToTheRight - houses[i] + 1
print(*reversed(ans))


n = int(input())
h = list(map(int, input().split()))
mx = h[-1]
mh = []
for i in range(n - 1, -1, -1):
	if mx < h[i]:
		mx = h[i]
	mh.append(mx)
mh = list(reversed(mh))
for i in range(n):
	res = 0
	if i + 1 < n and mh[i] == mh[i + 1]:
		res = mh[i] - h[i] + 1
	print(res, end=' ')


N = int(input())
tini = list(map(int, input().split()))
max_height = 0
diff = N * [0]
for i in range(N).__reversed__():
	if tini[i] > max_height:
		max_height = tini[i]
		diff[i] = 0
	else:
		diff[i] = max_height - tini[i] + 1
print(*diff)


n = int(input())
x = list(map(int, input().split()))
x = [0] + x
y = [0] * (n + 1)
mx = 0
for i in range(n, 0, -1):
	y[i] = max(0, mx - x[i] + 1)
	mx = max(mx, x[i])
for i in range(1, n + 1):
	print(y[i])


n = int(input())
lst = list(map(int, input().split()))
dp = [-1000] * n
dp[n - 1] = 0
for i in range(len(lst) - 2, -1, -1):
	dp[i] = max(dp[i + 1], lst[i + 1])
for i in range(n):
	if dp[i] >= lst[i]:
		print(dp[i] - lst[i] + 1, end=' ')
	else:
		print(0, end=' ')


n = int(input())
l = [int(i) for i in input().split()]
b = n * [0]
maxh = l[n - 1]
for i in range(n - 2, -1, -1):
	b[i] = max(0, maxh + 1 - l[i])
	maxh = max(maxh, l[i])
print(*b)


n = int(input())
L = list(map(int, input().split()))
maxlist = [L[-1] for i in range(n)]
for i in range(n - 2, -1, -1):
	maxlist[i] = max(L[i], maxlist[i + 1])
M = [None for i in range(n)]
for i in range(n):
	if L[i] == maxlist[i]:
		if i + 1 < n and maxlist[i] == maxlist[i + 1]:
			M[i] = str(1)
		else:
			M[i] = str(0)
	else:
		M[i] = str(maxlist[i] + 1 - L[i])
print(' '.join(M))


n = int(input())
houses = list(map(int, input().split()))
lis = [0] * n
mx = 0
for i in range(n - 1, -1, -1):
	if houses[i] > mx:
		mx = houses[i]
	else:
		lis[i] = mx - houses[i] + 1
print(*lis)


input()
nums = [int(t) for t in input().split()]
max_ = nums[-1] - 1
for i in range(len(nums) - 1, -1, -1):
	newVal = nums[i] if nums[i] > max_ else max_ + 1
	max_ = max(max_, nums[i])
	nums[i] = newVal - nums[i]
for (i, k) in enumerate(nums):
	print(k, end=' ' if i != len(nums) - 1 else '\n')


n = int(input())
a = list(map(int, input().split()))
maxi = -1
for i in range(n - 1, -1, -1):
	t = a[i]
	if a[i] > maxi:
		a[i] = 0
	else:
		a[i] = maxi - a[i] + 1
	maxi = max(maxi, t)
print(*a)


input()
a = list(map(int, input().split()))[::-1]
x = -1
b = []
for v in a:
	b += [max(0, x - v + 1)]
	x = max(x, v)
print(*b[::-1])


n = int(input())
h = list(map(int, input().split()))
h.reverse()
ans = [0]
m = h[0]
for i in range(1, n):
	if h[i] > m:
		ans.append(0)
		m = h[i]
	else:
		ans.append(m - h[i] + 1)
ans.reverse()
print(*ans, sep=' ')


n = input()
buildings = input().split(' ')
m = 0
result = []
for building in buildings[::-1]:
	b = int(building)
	x = m - b
	if x < 0:
		result.append('0')
		m = b
	else:
		result.append(str(x + 1))
print(' '.join(result[::-1]))


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

def solve(n, hs):
	dp = [0] * n
	zeros = [0] * n
	maxh = 0
	for i in range(n - 1, -1, -1):
		if hs[i] > maxh:
			zeros[i] = 1
			maxh = hs[i]
		dp[i] = maxh
	result = []
	for i in range(n):
		if zeros[i]:
			result.append(0)
		else:
			result.append(dp[i] - hs[i] + 1)
	return result
print(*solve(n, hs))


N = int(input())
H = list(map(int, input().split()))
maxh = H[-1]
maxlst = []
for i in range(N):
	maxh = max(maxh, H[N - i - 1])
	maxlst.append(maxh)
maxlst.reverse()
ans = []
for i in range(N):
	if i == N - 1:
		a = 0
	else:
		maxv = maxlst[i + 1]
		if H[i] == maxv:
			a = 1
		elif H[i] > maxv:
			a = 0
		else:
			a = maxv - H[i] + 1
	ans.append(a)
print(' '.join(map(str, ans)))


import time
n = int(input())
A = [int(i) for i in input().split()]
start = time.time()
A = [A[n - i - 1] for i in range(n)]
ans = [0 for i in range(n)]
m = 0
for i in range(n):
	if A[i] > m:
		m = A[i]
	else:
		ans[i] = 1 + m - A[i]
for i in range(n):
	print(ans[n - 1 - i], end=' ')
print()
finish = time.time()


n = int(input())
h = list(map(int, input().split()))
cur = 0
l = [0] * n
for i in range(n - 1, -1, -1):
	l[i] = max(0, cur + 1 - h[i])
	cur = max(cur, h[i])
print(' '.join(map(str, l)))


n = int(input())
h = [int(x) for x in input().split()]
tmp = []
for i in range(n):
	tmp.append(0)
tmp[n - 1] = h[n - 1]
for i in range(n - 2, -1, -1):
	if h[i] > tmp[i + 1]:
		tmp[i] = h[i]
	else:
		tmp[i] = tmp[i + 1]
for i in range(n - 1):
	if h[i] == tmp[i + 1]:
		print(1, end=' ')
	elif h[i] == tmp[i]:
		print(0, end=' ')
	else:
		print(tmp[i] + 1 - h[i], end=' ')
print(0)


n = int(input())
l = list(map(int, input().split()))
max1 = l[-1]
stack = [0]
for i in range(2, n + 1):
	if l[-i] == max1:
		stack.append(1)
	elif l[-i] > max1:
		max1 = l[-i]
		stack.append(0)
	else:
		stack.append(abs(l[-i] - max1) + 1)
for i in range(len(stack)):
	print(stack.pop(), end=' ')


n = int(input())
a = [int(i) for i in input().split()]
res = [0] * n
maxh = a[n - 1]
for i in range(n - 2, -1, -1):
	res[i] = max(0, maxh - a[i] + 1)
	if maxh < a[i]:
		maxh = a[i]
print(*res)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
n = ii()
a = li()
ans = [0]
inf = a[-1]
for i in range(n - 1):
	if a[-i - 2] <= inf:
		ans.append(inf - a[-i - 2] + 1)
	else:
		ans.append(0)
		inf = a[-i - 2]
ans.reverse()
print(wr(ans))


n = int(input())
a = [int(x) for x in input().split()][::-1]
ans = []
m = 0
for i in range(len(a)):
	if i == 0:
		ans.append(0)
		m = a[i]
	elif a[i] <= m:
		ans.append(m - a[i] + 1)
	else:
		ans.append(0)
		m = a[i]
ans = ans[::-1]
for i in ans:
	print(i, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
ans = []
m = 0
for i in range(n - 1, -1, -1):
	if a[i] <= m:
		ans.append(m - a[i] + 1)
	elif a[i] > m:
		ans.append(0)
		m = a[i]
print(*ans[::-1])


n = int(input())
w = list(map(int, input().split()))
out = []
out.append(0)
ma = w[n - 1]
for i in range(n - 2, -1, -1):
	if w[i] < ma:
		out.append(ma + 1 - w[i])
	elif w[i] > ma:
		out.append(0)
		ma = w[i]
	elif w[i] == ma:
		out.append(1)
for k in range(n - 1, -1, -1):
	print(out[k], end=' ')


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(0)
	exit()
m = [-1] * n
maxx = l[-1]
m[-2] = maxx
for i in range(n - 3, -1, -1):
	maxx = max(maxx, m[i + 1], l[i + 1])
	m[i] = maxx
ans = []
for i in range(n):
	if l[i] > m[i]:
		ans.append(0)
	else:
		ans.append(m[i] - l[i] + 1)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
m = l[-1]
l[-1] = 0
for i in range(n - 2, -1, -1):
	if l[i] == m:
		l[i] = 1
	elif l[i] > m:
		m = l[i]
		l[i] = 0
	else:
		l[i] = m - l[i] + 1
print(' '.join(map(str, l)))


n = int(input())
h = list(map(int, input().split()))
a = []
if n == 1:
	print(0)
	quit()
y = h[-1]
h[-1] = 0
for i in reversed(range(n - 1)):
	if h[i] > y:
		y = max(h[i], y)
		h[i] = 0
		h[-1] = 0
	else:
		h[i] = y - h[i] + 1
print(' '.join(map(str, h)))


__author__ = 'User'
n = int(input())
arr = list(map(int, input().split()))
mx = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	mx[i] = max(mx[i + 1], arr[i])
for j in range(n):
	if mx[j + 1] >= arr[j]:
		print(mx[j] - arr[j] + 1, end=' ')
	else:
		print(0, end=' ')


from collections import *

def arr_inp():
	return [int(x) for x in input().split()]

def max_arr(a):
	(d, ans, new) = (deque([a[-1]]), deque([0]), 0)
	for i in range(n - 2, -1, -1):
		if a[i] == d[0]:
			new = 1
		elif a[i] > d[0]:
			new = 0
		else:
			new = d[0] - a[i] + 1
		ans.appendleft(new)
		d.appendleft(max(a[i], d[0]))
	return ans
(n, a) = (int(input()), arr_inp())
arr = max_arr(a)
print(*arr)


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


n = int(input())
house = list(map(int, input().split(' ')))
dos = [0] * n
maximum = house[n - 1]
for i in range(n - 2, -1, -1):
	dos[i] = max(0, maximum - house[i] + 1)
	if house[i] > maximum:
		maximum = house[i]
print(*dos)