There was an electronic store heist last night.

All keyboards which were in the store yesterday were numbered in ascending order from some integer number $x$. For example, if $x = 4$ and there were $3$ keyboards in the store, then the devices had indices $4$, $5$ and $6$, and if $x = 10$ and there were $7$ of them then the keyboards had indices $10$, $11$, $12$, $13$, $14$, $15$ and $16$.

After the heist, only $n$ keyboards remain, and they have indices $a_1, a_2, \dots, a_n$. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither $x$ nor the number of keyboards in the store before the heist.


-----Input-----

The first line contains single integer $n$ $(1 \le n \le 1\,000)$ — the number of  keyboards in the store that remained after the heist.

The second line contains $n$ distinct integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{9})$ — the indices of the remaining keyboards. The integers $a_i$ are given in arbitrary order and are pairwise distinct.


-----Output-----

Print the minimum possible number of keyboards that have been stolen if the staff remember neither $x$ nor the number of keyboards in the store before the heist.


-----Examples-----
Input
4
10 13 12 8

Output
2

Input
5
7 5 6 4 8

Output
0



-----Note-----

In the first example, if $x=8$ then minimum number of stolen keyboards is equal to $2$. The keyboards with indices $9$ and $11$ were stolen during the heist.

In the second example, if $x=4$ then nothing was stolen during the heist.

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
a = [0] * n
a[0:n] = map(int, input().split())
maxx = a[0]
minn = a[0]
for i in range(n):
	if a[i] > maxx:
		maxx = a[i]
	if a[i] < minn:
		minn = a[i]
print(maxx - minn - n + 1)


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


n = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
g = x[0] - 1
s = 0
for i in x:
	s += i - g - 1
	g = i
print(s)


x = int(input())
brr = []
l = []
r = []
arr = str(input())
brr = arr.split(' ')
l = [y for y in brr if y != '']
for j in range(x):
	r.append(int(l[j]))
r.sort()
print(r[x - 1] - r[0] - x + 1)


n = input()
a = list(map(int, input().split()))
x1 = min(a)
x2 = max(a)
l = x2 - x1 + 1
print(l - len(a))


import sys
number = sys.stdin.readline()
series = [int(x) for x in sys.stdin.readline().split()]
missing = 0
last = -1
series.sort()
for i in series:
	if last > 0 and last + 1 != i:
		missing += i - last - 1
	last = i
print(missing)


def bubblesort(array):
	lengthOfArray = len(array) - 1
	for i in range(lengthOfArray):
		for j in range(lengthOfArray - i):
			if array[j] < array[j + 1]:
				(array[j], array[j + 1]) = (array[j + 1], array[j])
	return array
n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a = bubblesort(a)
x = 0
for i in range(1, n):
	x += -a[i] + a[i - 1] - 1
print(x)


N = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a) - N + 1)


input()
a = list(map(int, input().split()))
print(max(a) - min(a) - len(a) + 1)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
c = max(a) - min(a)
c -= len(a) - 1
print(c)


n = int(input())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in range(len(a) - 1):
	count += a[i + 1] - a[i] - 1
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort()
tedad = a[-1] - a[0] + 1
ln = len(a)
stolen = tedad - ln
print(stolen)


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


n = int(input())
a = list(map(int, input().split(' ')))
print(max(a) - min(a) - n + 1)


def main():
	keyboards = int(input())
	remain = sorted([int(i) for i in input().split()])
	print(remain[-1] - remain[0] - keyboards + 1)
main()


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


N = int(input())
s = [int(x) for x in input().split()]
s.sort()
m = s[0]
M = s[-1]
c = 0
for i in range(1, len(s)):
	c += s[i] - s[i - 1] - 1
print(c)


n = int(input())
a = [int(s) for s in input().split(' ')]
print(max(a) - min(a) + 1 - n)


n = int(input())
l = list(map(int, input().split(' ')))
print(max(l) - min(l) + 1 - len(l))


n = int(input())
sp = list(map(int, input().split()))
t = max(sp) - min(sp) + 1
print(t - n)


count = int(input())
values = [int(x) for x in input().split(' ')]
values.sort()
counter = 0
for i in range(0, count - 1):
	curr = values[i]
	next = values[i + 1]
	counter += next - curr - 1
print(counter)


n = int(input())
a = list(map(int, input().split()))
min1 = min(a)
max1 = max(a)
ans1 = max1 - min1 + 1
print(ans1 - len(set(a)))


n = int(input())
x = list(map(int, input().split()))
print(max(x) - min(x) - n + 1)


n = int(input())
a = [int(x) for x in input().split(' ')]
(ma, mi) = (max(a), min(a))
print(ma - mi - 1 - (n - 2))


n = int(input())
a = [int(i) for i in input().split()]
low = high = a[0]
for i in range(1, n):
	low = min(low, a[i])
	high = max(high, a[i])
print(high - low + 1 - n)


n = int(input())
l = sorted(map(int, input().split()))
ans = 0
for i in range(1, n):
	ans += l[i] - l[i - 1] - 1
print(ans)


i = int(input())
b = list(map(int, input().split()))
print(max(b) - min(b) - len(b) + 1)


n = int(input())
a = list(map(int, input().split()))
(ma, mi) = (max(a), min(a))
print(ma - mi + 1 - n)


n = int(input())
Arr = list(map(int, input().split()))
print(max(Arr) - min(Arr) - n + 1)


import sys
import math
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(l[-1] - (l[0] + n - 1))


n = int(input())
m = sorted(list(map(int, input().split())))
print(m[-1] - m[0] - n + 1)


def solve(n, a):
	if n == 1:
		return 0
	g = 0
	a.sort()
	return max(a) - min(a) + 1 - n

def main():
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))
main()


n = int(input())
k = 0
a = [int(n) for n in input().split(' ')]
a = sorted(a)
for i in range(len(a) - 1):
	k = k + (a[i + 1] - a[i] - 1)
print(k)


input()
a = list(map(int, input().split()))
a.sort()
result = 0
for i in range(len(a) - 1):
	result += a[i + 1] - a[i] - 1
print(result)


import sys
input = sys.stdin.readline
output = sys.stdout

def solve(n, list1):
	m = max(list1) - min(list1) + 1
	output.write(str(m - n) + '\n')
n = int(input())
list1 = list(map(int, input().split()))
solve(n, list1)


n = int(input())
num = input()
a = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr = get_the_data(0, num, a)
arr.sort()
diff = arr[len(arr) - 1] - arr[0] + 1
length = len(arr)
print(diff - length)


n = int(input())
x = input()
xx = x.split()
for i in range(0, n):
	xx[i] = int(xx[i])
xx.sort()
s = 0
for i in range(1, n):
	s = s + (xx[i] - xx[i - 1] - 1)
print(s)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
x = min(a)
y = max(a)
d = 0
for i in range(0, n):
	if a[i] >= x and a[i] <= y:
		d = d + 1
d = y - x - d + 1
print(d)


n = int(input())
list1 = sorted(list(map(int, input().split())))
print(max(list1) - min(list1) + 1 - n)


n = int(input())
mn = 1000000000000.0
mx = 0
for i in input().split(' '):
	a = int(i)
	if a < mn:
		mn = a
	if a > mx:
		mx = a
print(mx - mn + 1 - n)


n = int(input())
nums = list(map(int, input().split()))
print(max(nums) - min(nums) + 1 - len(nums))


n = int(input())
li = list(map(int, input().split()))
li.sort()
count = 0
for i in range(1, n):
	if li[i] != li[i - 1] + 1:
		count += li[i] - li[i - 1] - 1
print(count)


n = int(input())
arr = sorted([int(x) for x in input().split()][:n])
needed = len(arr)
exist = max(arr) - min(arr) + 1
print(exist - needed)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(mi, ma) = (a[0], a[-1])
print(ma - mi - n + 1)


n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
c = 0
for i in range(0, n - 1):
	if s[i] + 1 == s[i + 1]:
		continue
	else:
		c = c + s[i + 1] - s[i] - 1
print(c)


n = int(input())
array = list(map(int, input().split()))
minValue = min(array)
maxValue = max(array)
print(maxValue - minValue - n + 1)


n = int(input())
s = [int(i) for i in input().split()]
s.sort()
c = 0
for i in range(n - 1):
	if s[i + 1] - s[i] > 1:
		c += s[i + 1] - s[i] - 1
print(c)


def solve(n, t):
	count = 0
	test = sorted(t)
	for i in range(n - 1):
		count += test[i + 1] - test[i] - 1
	return count
n = int(input())
t = list(map(int, input().split()))
print(solve(n, t))


n = int(input())
b = list(map(int, input().strip().split()))[:n]
x = min(b)
y = max(b)
k = 0
for i in range(0, n):
	if b[i] >= x and b[i] <= y:
		k = k + 1
k = y - x - k + 1
print(k)


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

def BubbleSort(n, arr):
	for passnum in range(n - 1, 0, -1):
		for i in range(passnum):
			if arr[i] > arr[i + 1]:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
BubbleSort(n, arr)
print(arr[-1] - arr[0] + 1 - n)


n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(1, n):
	if l[i] - 1 != l[i - 1]:
		count += abs(l[i - 1] - l[i]) - 1
print(count)


a = int(input())
l = sorted(list(map(int, input().split())))
k = 0
if len(l) > 1:
	for i in range(a - 1):
		k += l[i + 1] - l[i] - 1
	print(k)
else:
	print('0')


length = int(input())
array = [int(item) for item in input().split()]
array.sort()
result = 0
for index in range(length - 1):
	result += array[index + 1] - array[index] - 1
print(result)


n = int(input())
b = list(map(int, input().split()))
c = max(b) - min(b) + 1
print(c - len(b))


n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[n - 1] - l[0] + 1
if n == m:
	print(0)
else:
	print(m - n)


def answer():
	n = int(input())
	a = [int(x) for x in input().split()]
	print(abs(n - (max(a) - min(a) + 1)))
answer()


n = int(input())
xs = sorted(list(map(int, input().split()))[:n])
previous = None
missing = 0
for x in xs:
	if previous is not None:
		missing += x - previous - 1
	previous = x
print(missing)


n = int(input())
n1 = list(map(int, input().split()))
s = 0
lst = []
n1.sort()
for i in range(n - 1):
	v = n1[i + 1] - n1[i]
	if v != 1:
		lst.append(v)
print(sum(lst) - len(lst))


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
minimum = min(l)
maximum = max(l)
distance = maximum - minimum + 1
print(distance - n)


t = int(input())
x = list(map(int, input().split()))
x = sorted(x)
sum = 0
for i in range(1, t):
	sum += x[i] - x[i - 1] - 1
print(sum)


import sys
n_s = sys.stdin.readline()
while n_s:
	n = int(n_s)
	kbs = sys.stdin.readline().split()
	kb_num = [int(val) for val in kbs]
	kb_num = sorted(kb_num)
	stolen = 0
	for i in range(1, len(kb_num)):
		stolen += kb_num[i] - kb_num[i - 1] - 1
	print(stolen)
	n_s = sys.stdin.readline()


n = int(input())
a = [int(s) for s in input().split(' ')]
a.sort()
stolen = 0
for i in range(len(a) - 1):
	stolen += a[i + 1] - a[i] - 1
print(stolen)


n = int(input())
a = list(map(int, input().split()))
a.sort()
z = a[-1] - a[0] + 1
print(z - len(a))


n = int(input())
kl = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	kl.sort()
	stolen = 0
	for i in range(n - 1):
		stolen += kl[i + 1] - kl[i] - 1
	print(stolen)


n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
ct = 0
for i in range(n - 1):
	ct = ct + arr[i + 1] - arr[i] - 1
print(ct)


q = lambda : map(int, input().split())
qi = lambda : int(input())
qs = lambda : input().split()
input()
a = sorted(list(q()))
print(a[-1] - a[0] - len(a) + 1)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
small = arr[0]
big = arr[-1]
total = big - small + 1
print(total - n)


k = int(input())
l = [int(i) for i in input().split()]
l.sort()
diff = 0
for i in range(1, k):
	diff += l[i] - l[i - 1] - 1
print(diff)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
print(x[-1] - x[0] - n + 1)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	N = Scanner.int()
	A = Scanner.map_int()
	a = min(A)
	b = max(A)
	print(b - a - N + 1)

def main():
	solve()
main()


n = int(input())
arr = [int(s) for s in input().split()]
print(max(arr) + 1 - min(arr) - n)


from collections import *
import sys
import math
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())

def stli():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = sorted(li())
tot = 0
for i in range(1, n):
	tot += l[i] - l[i - 1] - 1
print(tot)


n = int(input())
li = list(map(int, input().split()))
mn = min(li)
mx = max(li)
print(mx - mn + 1 - len(li))


n = int(input())
ar = list(map(int, input().split()))
s = min(ar)
p = max(ar)
print(p - (s + n - 1))


a = int(input())
b = list(map(int, input().split()))
print(max(b) - min(b) - a + 1)


def heist(n, a):
	return max(a) - min(a) - n + 1
n = int(input())
a = list(map(int, input().split()))
print(heist(n, a))


input()
s = list(map(int, input().split(' ')))
print(max(s) - min(s) + 1 - len(s))


n = int(input())
l = list(map(int, input().split()))
x = min(l)
y = max(l)
total = y - x + 1
print(total - len(l))


import math
n = int(input())
m = input()
li = []
li = m.split(' ')
chck1 = -1
chck2 = 9999999999
for i in li:
	if int(i) >= chck1:
		chck1 = int(i)
	if int(i) <= chck2:
		chck2 = int(i)
t = chck1 - chck2 + 1
print(abs(n - t))


def hst(lst):
	lst.sort()
	h = 0
	for i in range(len(lst) - 1):
		h += lst[i + 1] - lst[i] - 1
	return h
T = int(input())
lst = [int(k) for k in input().split(' ') if k]
print(hst(lst))


def int_lst_input():
	return [int(val) for val in input().split(' ')]

def int_input():
	return int(input())

def solve():
	n = int_input()
	rem_key_idx = int_lst_input()
	_min = min(rem_key_idx)
	_max = max(rem_key_idx)
	print(_max - _min - n + 1)
solve()


import math
n = int(input())
indices = []
indices = input().split(' ')
for i in range(n):
	indices[i] = int(indices[i])
minIndic = min(indices)
maxIndic = max(indices)
diff = maxIndic - minIndic + 1
if diff < n:
	x = 0
else:
	x = diff - n
print(x)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
s = l[-1] - l[0] + 1
length = len(l)
print(s - length)


n = int(input())
a = list(map(int, input().split()))
b = 0
a.sort()
for i in range(1, len(a)):
	if a[i] != a[i - 1] + 1:
		b += a[i] - a[i - 1] - 1
print(b)


x = int(input())
p = map(int, input().split())
p = sorted(list(p))
print(p[len(p) - 1] - p[0] + 1 - x)


n = int(input())
result = 0
lis = [int(x) for x in input().split()]
lis.sort()
mx = max(lis)
mis = min(lis)
n -= 1
result = mx - mis - n
print(result)


n = int(input())
a = [int(i) for i in input().split()]
mi = min(a)
ma = max(a)
print(ma - mi + 1 - n)


n = int(input())
arr = list(map(int, input().split()))
optimumKeyborad = max(arr) - min(arr) + 1
print(optimumKeyborad - n)


n = int(input())
l = sorted([int(n) for n in input().split()])
res = 0
for i in range(n - 1):
	res += l[i + 1] - l[i] - 1
print(res)


import sys
from math import sqrt, floor, factorial
from collections import deque
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def solve():
	n = int(inp())
	arr = read()
	print(max(arr) - min(arr) + 1 - n)
solve()


n = int(input())
li = list(map(int, input().split()))
d = max(li, default=0) - min(li, default=0) + 1
print(d - n)


n = int(input())
a = list(map(int, input().split()))
mini = 10000000000000
maxi = -1
for i in range(n):
	if a[i] < mini:
		mini = a[i]
	if a[i] > maxi:
		maxi = a[i]
print(maxi - mini + 1 - n)


n = int(input())
a = [int(i) for i in input().split(' ')]
a = sorted(a)
print(a[n - 1] - a[0] - n + 1)


n = int(input())
l = list(sorted([int(x) for x in input().split()]))
res = 0
tmp = l[0]
for i in range(1, n):
	res += l[i] - tmp - 1
	tmp = l[i]
print(res)


a = int(input())
b = [int(k) for k in input().split()]
c = max(b)
d = min(b)
if c + 1 - d <= a:
	print(0)
else:
	print(c + 1 - d - a)


print(1 - int(input()) + (lambda a: max(a) - min(a))(list(map(int, input().split()))))


def main():
	count = 0
	sum = 0
	kol = int(input())
	if kol >= 1 and kol <= 1000:
		lst = list(map(int, input().split()))
		if len(lst) == kol and kol != 1:
			ls = sorted(lst)
			for i in range(len(ls) - 1):
				if len(ls) >= 2:
					min1 = ls[i]
					min2 = ls[i + 1]
					res = int(min2 - min1 - 1)
					if res >= 1:
						sum = sum + res
						count += 1
				else:
					pass
			if count > 0:
				print(sum)
			else:
				print('0')
		elif kol == 1:
			print('0')
main()


n = int(input())
a = [int(x) for x in input().split()]
print(max(a) - min(a) + 1 - n)


class Solution:

	def __init__(self):
		self.n = 0
		self.a = []

	def _input_(self):
		self.n = int(input())
		self.a = [int(x) for x in input().split(' ')]

	def run(self):
		self._input_()
		self.a.sort()
		origin = self.a[-1] - self.a[0] + 1
		print(origin - self.n)
Solution().run()


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
result = 0
for i in range(1, n):
	result += a[i] - a[i - 1] - 1
print(result)


n = int(input())
arr = list(map(int, input().split()[:n]))
arr = sorted(arr)
print(arr[-1] - arr[0] - n + 1)


n = int(input())
arr = sorted([int(x) for x in input().split()])
ans = 0
for i in range(1, n):
	if arr[i] - 1 != arr[i - 1]:
		ans += arr[i] - arr[i - 1] - 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
c = 0
x = min(a)
y = max(a)
c = y - x - len(a) + 1
print(c)


n = int(input())
arr = list(map(int, input().split()))
x = min(arr)
y = max(arr)
c = y - x
print(c + 1 - len(arr))


N = int(input())
A = list(map(int, input().split()))
print(max(A) - min(A) - N + 1)


m = int(input())
l = list(map(int, input().split()))
l.sort()
num = l[len(l) - 1] - l[0]
print(num + 1 - m)


n = int(input())
arr = input().split()
c = 0
for i in range(len(arr)):
	arr[i] = int(arr[i])
for i in range(len(arr)):
	for j in range(len(arr) - 1):
		if arr[j] > arr[j + 1]:
			(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
for i in range(n - 1):
	if arr[i + 1] - arr[i] != 1:
		c += arr[i + 1] - arr[i] - 1
print(c)


n = int(input())
a = input().split()
for z in range(n):
	a[z] = int(a[z])
a.sort()
antal = 0
for i in range(1, n):
	if a[i] != a[i - 1] + 1:
		antal += a[i] - a[i - 1] - 1
print(antal)


N = int(input())
L = list(map(int, input().rsplit()))
print(max(L) - min(L) - N + 1)


n = input()
keyboard = list(map(int, input().split()))
keyboard.sort()
k = 0
for i in range(len(keyboard) - 1):
	k += keyboard[i + 1] - keyboard[i] - 1
print(k)


import sys

def heist(n, keys):
	min_key = min(keys)
	max_key = max(keys)
	return max_key - min_key + 1 - n
for line in sys.stdin:
	n = int(line)
	keys = [int(val) for val in sys.stdin.readline().split()]
	answer = heist(n, keys)
	print(answer)


import sys
N = int(sys.stdin.readline())
nums = list(map(int, sys.stdin.readline().split()))
print(max(nums) - min(nums) + 1 - len(nums))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = min(a)
cnt = 0
for i in range(n - 1):
	a.pop()
	if min(a) - x == 1:
		pass
	else:
		cnt = cnt + min(a) - x - 1
	x = min(a)
print(cnt)


a = int(input())
b = input().split()
min = 10000000000
max = 0
for i in range(a):
	if int(b[i]) > max:
		max = int(b[i])
	if int(b[i]) < min:
		min = int(b[i])
print(max - min + 1 - a)


n = int(input())
l = [int(y) for y in input().split()]
mx = max(l)
mn = min(l)
diff = mx - mn + 1
print(diff - n)


import math as mm

def solve(n):
	max1 = max(n)
	min1 = min(n)
	length_old = max1 - min1 + 1
	if length_old == len(n):
		return 0
	else:
		return length_old - len(n)
n = int(input())
user = input().split()
for i in range(n):
	user[i] = int(user[i])
print(solve(user))


n = int(input())
i = list(map(int, input().split()))
i.sort()
k = i[n - 1] - i[0] + 1
print(k - n)


n = input()
lis = list(map(int, input().split(' ')))
(least, highest) = (min(lis), max(lis))
print(highest - least + 1 - len(lis))


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
count = 0
for i in range(1, n):
	d = nums[i] - nums[i - 1]
	if d > 1:
		count += d - 1
print(count)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = inl()
print(max(a) - min(a) - n + 1)


def solve(text):
	text.sort()
	stolen = 0
	for i in range(1, len(text)):
		if text[i] - text[i - 1] > 1:
			stolen += text[i] - text[i - 1] - 1
	return stolen
n = int(input())
text = list(map(int, input().split(' ')))
print(solve(text))


n = int(input())
a = sorted([int(i) for i in input().split()])
c = 0
for j in range(1, n):
	c += a[j] - a[j - 1] - 1
print(c)


def solve():
	n = int(input())
	a = sorted([int(s) for s in input().split()])
	ans = 0
	for i in range(1, n):
		if a[i] > a[i - 1] + 1:
			ans += a[i] - a[i - 1] - 1
	print(ans)
solve()


n = int(input())
ai = list(map(int, input().split()))
print(max(ai) - min(ai) - n + 1)


n = int(input())
num = set(map(int, input().split()))
cnt = max(num) - min(num) + 1
print(cnt - len(num))


n = int(input())
l = sorted([*map(int, input().split())])
print(l[-1] - l[0] + 1 - len(l))


n = int(input())
a = list(map(int, input().split()))
(max_m, min_m) = (max(a), min(a))
print(max_m - min_m + 1 - n)


n = int(input())
l = sorted(list(map(int, input().split())))
print(l[-1] - l[0] - n + 1)


n = int(input())
x = list(map(int, input().split()))
ma = 0
mi = 100000000000000000
for i in range(n):
	if x[i] > ma:
		ma = x[i]
	if x[i] < mi:
		mi = x[i]
print(ma - mi - n + 1)


n = int(input())
A = list(map(int, input().split()))
print(max(A) - (min(A) - 1) - len(A))


n = int(input())
x = list(map(int, input().split()))
i = min(x)
j = max(x)
k = j - i + 1
print(k - len(x))


n = int(input())
a = sorted(map(int, input().split()))
print(a[-1] - a[0] - n + 1)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in range(n - 1):
	count += l[i + 1] - l[i] - 1
print(count)


n = int(input())
l = list(map(int, input().split()))
l.sort()
x = l[-1] - l[0]
print(x - n + 1)


n = int(input())
l = list(map(int, input().split()))
m1 = min(l)
m2 = max(l)
print(m2 - m1 - n + 1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1] - a[0] + 1
print(x - n)


input()
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
for i in range(1, len(a)):
	if a[i - 1] + 1 != a[i]:
		ans += a[i] - a[i - 1] - 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
b = max(l) - min(l) + 1
print(b - n)


n = int(input())
numbers = list(map(int, input().split()))
print(max(numbers) - min(numbers) - n + 1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
small = l[0]
large = l[-1]
print(large + 1 - small - n)


import sys
import math
import os
n = int(sys.stdin.readline())
b = sys.stdin.readline().split()
nums = []
for x in range(len(b)):
	nums.append(int(b[x]))
minimum = min(nums)
maximum = max(nums)
print(maximum + 1 - minimum - n)


n = int(input())
a = list(map(int, input().split()))
i = max(a)
j = min(a)
print(i - j - len(a) + 1)


x = int(input())
ls = [int(i) for i in input().split()]
print(max(ls) - min(ls) - len(ls) + 1)


import sys
lines = sys.stdin.readlines()
ints = sorted([int(l) for l in lines[1].strip().split(' ')])
result = sum((b - a - 1 for (a, b) in zip(ints, ints[1:])))
print(result)


def stolen_boards():
	remaining = int(input())
	keyboards = input().split()
	output = 0
	dic = {}
	minimum = int(keyboards[0])
	maximum = minimum
	dic[int(keyboards[0])] = 1
	for i in range(1, len(keyboards)):
		dic[int(keyboards[i])] = 1
		if int(keyboards[i]) < minimum:
			minimum = int(keyboards[i])
		if int(keyboards[i]) > maximum:
			maximum = int(keyboards[i])
	output = maximum - minimum - (len(keyboards) - 1)
	print(output)
	return
stolen_boards()


n = int(input())
k = list(map(int, input().split()))
print(max(k) - min(k) + 1 - n)


n = int(input())
l = list(map(int, input().split()))
l.sort()
print(l[len(l) - 1] - l[0] + 1 - len(l))


x = int(input())
l = list(map(int, input().split()))
print(max(l) - min(l) - x + 1)


n = int(input())
indices = input().split(' ')
indices = [int(indices[i]) for i in range(n)]
indices.sort()
print(indices[-1] - indices[0] - n + 1)


n = int(input())
b = input().split()
a = []
for i in b:
	a.append(int(i))
print(int(max(a)) - int(min(a)) + 1 - n)


n = int(input())
s = list(map(int, input().split()))
s.sort()
c = 0
for i in range(1, n):
	c += s[i] - s[i - 1] - 1
print(c)


input()
a = list(map(int, input().split()))
a.sort()
i = 1
ans = 0
while i < len(a):
	if a[i] - a[i - 1] == 1:
		i += 1
	else:
		ans += a[i] - a[i - 1] - 1
		i += 1
print(ans)


a = int(input())
b = list(map(int, input().split()))
maxx = max(b)
minn = min(b)
print(maxx - minn + 1 - a)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
from types import CodeType, new_class
n = int(input())
a = [int(x) for x in input().split()]
print(max(a) - min(a) - n + 1)


n = int(input())
nums = list(map(int, input().split()))
(n_max, n_min) = (max(nums), min(nums))
proper = n_max - n_min + 1
dif = proper - len(nums)
print(dif)


n = int(input())
sk = input()
sk2 = []
for x in sk.split(' '):
	sk2.append(int(x))
sk2 = sorted(sk2)
dif = sk2[-1] - sk2[0] + 1
print(dif - n)


n = int(input())
l = list(input().split())
l = [int(i) for i in l]
print(max(l) - min(l) + 1 - len(l))


n = int(input())
keyboards = list(map(int, input().split()))
keyboards = sorted(keyboards)
print(keyboards[-1] - keyboards[0] - len(keyboards) + 1)


n = int(input())
arr = list(map(int, input().split(' ')))
maxx = max(arr)
minn = min(arr)
print(maxx + 1 - minn - n)


n = int(input())
keyboards = map(int, input().split())
keyboards = sorted(keyboards)
last = keyboards[0]
res = 0
for i in keyboards[1:]:
	if last + 1 != i:
		res += i - last - 1
	last = i
print(res)


a = []
n = int(input())
res = input().split()[:n]
for i in range(n):
	a.append(int(res[i]))
print(max(a) - min(a) + 1 - n)


n = int(input())
lox = [int(i) for i in input().split()]
lox.sort()
f = 0
for i in range(len(lox) - 1):
	qw = lox[i + 1] - lox[i]
	if qw != 1:
		f += qw - 1
print(f)


n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for x in range(n):
	if x == 0:
		k = l[x]
		count = 0
	else:
		count += l[x] - k - 1
		k = l[x]
print(count)


n = int(input())
ls = list(map(int, input().split(' ')))
print(abs(max(ls) - min(ls) + 1 - n))


n = int(input())
mots = input().split(' ')
m = []
for i in mots:
	y = int(i)
	m.append(y)
m.sort()
x = m[0]
k = 0
for i in range(1, n):
	k += int(m[i]) - int(x) - 1
	x = m[i]
print(k)


n = int(input())
a = list(map(int, input().split()))
k = max(a)
l = min(a)
x = k - l - len(a) + 1
print(x)


import time
n = int(input())
a = [int(i) for i in input().split()]
start = time.time()
a.sort()
ans = a[-1] - a[0] + 1 - n
print(ans)


x = int(input())
L = list(map(int, input().split()))
L.sort()
print(L[-1] - L[0] - len(L) + 1)


while True:
	try:
		s = input()
		s = sorted(list(map(int, input().split(' '))))
		l = 0
		for i in range(1, len(s)):
			l += s[i] - s[i - 1] - 1
		print(l)
	except:
		break


n = int(input())
mas = list(map(int, input().split()))
delta = max(mas) - min(mas) - 1 - n + 2
print(delta)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = 0
for i in range(n - 1):
	if l[i + 1] - l[i] != 1:
		s = s + (l[i + 1] - l[i])
		s = s - 1
print(s)


n = int(input())
l = list(map(int, input().split()))
s = min(l)
y = max(l)
x = y - s
count = x + 1 - n
print(count)


print((lambda a: max(a) + 1 - min(a) - len(a))((lambda q: [int(x) for x in input().split()])(input())))


n = int(input())
a = [int(el) for el in input().split()]
out = 0
a = sorted(a)
for i in range(n - 1):
	out += a[i + 1] - a[i] - 1
print(out)


n = int(input())
lst = list(map(int, input().split()))
x = min(lst)
y = max(lst)
print(y - x + 1 - len(lst))


n = int(input())
a = list(map(int, input().split()))
(maxx, minx) = (max(a), min(a))
print(maxx - minx + 1 - n)


n = int(input())
k = list(map(int, input().split()))
mi = min(k)
ma = max(k)
ans = ma - mi - n + 1
print(ans)


n = int(input())
indices = list(map(int, input().split()))
stolen = max(indices) - min(indices) + 1 - n
print(str(stolen))


import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
print(max(an) - min(an) + 1 - n)


n = int(input())
arr = list(map(int, input().split()))
min = min(arr)
max = max(arr)
res = max - min - n + 1
print(res)


n = int(input())
boards = []
for i in input().split():
	boards.append(int(i))
boards = sorted(boards)
s = 0
for i in range(n - 1):
	s = s + (boards[i + 1] - boards[i] - 1)
print(s)


n = int(input())
l = list(map(int, input().split()))
l1 = sorted(l)
print(l1[-1] - l1[0] - len(l1) + 1)


import sys
ns = lambda : sys.stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : [int(x) for x in ns().split()]
nall = lambda : [int(x) for x in sys.stdin.readlines()]

def main():
	n = ni()
	ax = na()
	ax.sort()
	print(ax[-1] - ax[0] + 1 - len(ax))
main()


n = int(input())
l = list(map(int, input().split()))
mn = min(l)
print(max(l) - (mn + n - 1))


from sys import stdin, stdout
n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
stdout.write(str(max(vl) - min(vl) + 1 - n))


N = int(input())
lista = [int(i) for i in input().split()]
lista.sort(reverse=False)
ans = lista[-1] - lista[0] + 1 - N
print(ans)


n = int(input())
I = [int(i) for i in input().split()]
I.sort()
count = 0
for i in range(n - 1):
	if I[i + 1] - I[i] != 0:
		count += I[i + 1] - I[i] - 1
print(count)


n = int(input())
cl = list(map(int, input().split()))
mx = max(cl)
mn = min(cl)
print(mx - mn + 1 - n)


n = int(input())
X = [int(x) for x in input().split(' ')]
p = max(X) - min(X) + 1
print(p - n)


n = int(input())
x = sorted(list(map(int, input().split()))[:n])
count = 0
for i in range(n - 1):
	if x[i + 1] - x[i] > 1:
		count += x[i + 1] - x[i] - 1
	else:
		count += 0
print(count)


size = int(input())
nums = input().split(' ')
lst = []
for i in range(size):
	lst.append(int(nums[i]))
minimum = min(lst)
maximum = max(lst)
print(maximum - minimum + 1 - size)


n = int(input())
ind = list(map(int, input().split()))
ind.sort()
d = ind[n - 1] - ind[0]
print(1 + d - n)


n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1] - a[0] + 1
print(l - n)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 0
for i in range(1, n):
	ans += a[i] - a[i - 1] - 1
print(ans)


while True:
	try:
		n = eval(input().strip())
		a = list(map(int, input().strip().split()))
		a = sorted(a)
		res = 0
		for i in range(1, n):
			res += a[i] - a[i - 1] - 1
		print(res)
	except:
		break


t = int(input())
L = [int(x) for x in input().split()]
print(max(L) - min(L) - len(L) + 1)


N = int(input())
s = [int(x) for x in input().split()]
mn = min(s)
mx = max(s)
diff = mx - mn + 1
ans = diff - len(s)
print(ans)


input()
li = list(map(int, input().split()))
print(max(li) + 1 - min(li) - len(li))


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
	return int(input())

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

def readlist():
	return list(map(int, input().split()))
N = read()
A = readlist()
A.sort()
print(A[-1] - A[0] - N + 1)


n = int(input())
x = list(map(int, input().split()))
x.sort()
cnt = 0
if len(x) == 2:
	print(x[-1] - x[0] - 1)
else:
	for i in range(0, n - 1):
		cnt += x[i + 1] - x[i] - 1
	print(cnt)


def heist(ss):
	c = 0
	c = max(ss) - min(ss) + 1 - len(ss)
	return c
n = int(input())
ss = list(map(int, input().split()))
print(heist(ss))


n = int(input())
l = set(list(map(int, input().split())))
min1 = min(l)
max1 = max(l)
print(max(0, max1 - min1 - n + 1))


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(n,) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	a.sort()
	ans = a[-1] - a[0] + 1 - n
	print(ans)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	print(max(a) - min(a) - n + 1)
main()


n = int(input())
L = list(map(int, input().split()))
d = max(L) - min(L)
print(d + 1 - n)


n = int(input())
a = list(map(int, input().split()))
a.sort()
f = True
p = 0
for i in range(1, n):
	p += a[i] - a[i - 1] - 1
print(p)


t = int(input())
a = list(map(int, input().split()))
x = max(a) - min(a) + 1 - t
print(x)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
mn = min(a)
mx = max(a)
tot = mx - mn + 1
stolen = tot - n
print(stolen)


n = int(input())
s = list(map(int, input().split()))
print(max(s) - min(s) + 1 - n)


input()
z = sorted([int(x) for x in input().split()])
ans = 0
for i in range(len(z) - 1):
	if z[i] + 1 == z[i + 1]:
		pass
	else:
		ans = ans + z[i + 1] - z[i] - 1
print(ans)


n = eval(input())
line = input()
strings = line.split()
list = []
for each in strings:
	list.append(eval(each))
list.sort()
print(list[-1] - list[0] + 1 - n)


def main():
	n = int(input())
	indices = [int(x) for x in input().split()]
	print(solve(indices, n))

def solve(indices, n):
	indices.sort()
	t = indices[n - 1] - (indices[0] - 1)
	ans = t - n
	return ans
main()


def krazha(lst):
	return max(lst) - min(lst) + 1 - len(lst)
n = int(input())
b = [int(i) for i in input().split()]
print(krazha(b))


n = int(input())
missing = 0
a = [int(i) for i in input().split()]
a.sort()
for i in range(0, len(a) - 1, 1):
	missing += a[i + 1] - a[i] - 1
print(missing)


n = int(input())
a = list(map(int, input().split()))
k = max(a) - min(a) + 1
if k > n:
	print(k - n)
else:
	print(0)


n = int(input())
a = set(map(int, input().split()))
print(max(a) - min(a) + 1 - n)


n = int(input())
li = [int(c) for c in input().split()]
c = 0
k = max(li)
l = min(li)
z = k - l + 1
print(z - n)


n = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
result = sorted(list)
count = 0
for i in range(len(result) - 1):
	if result[i + 1] != result[i] + 1:
		count += result[i + 1] - result[i] - 1
print(count)


n = int(input())
a = [int(e) for e in input().split()]
print(max(a) - min(a) - n + 1)


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
print(list[n - 1] - list[0] - n + 1)


n = int(input())
a = list(map(int, input().split()))
max_kb = min_kb = a[0]
for kb in a:
	if kb < min_kb:
		min_kb = kb
	if kb > max_kb:
		max_kb = kb
print(max_kb - min_kb - n + 1)


n = int(input())
a = [int(i) for i in input().split()[:n]]
cnt = 0
a.sort(reverse=False)
for i in range(n - 1):
	if a[i] + 1 != a[i + 1]:
		cnt += a[i + 1] - a[i] - 1
print(cnt)


n = int(input())
li = list(map(int, input().split()))
li.sort()
x = 0
i = li[0] + 1
k = 1
if n == 1:
	print(0)
else:
	while i <= li[-1]:
		if i != li[k]:
			x += li[k] - i
			i = li[k] + 1
			k += 1
		else:
			i += 1
			k += 1
	print(x)


n = int(input())
lis = list(map(int, input().split()))
print(max(lis) - min(lis) - (n - 1))


n = int(input())
A = list(map(int, input().split()))
a = min(A)
A.sort()
ans = A[-1] - A[0] + 1 - n
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 0
for i in range(1, n):
	if a[i] - a[i - 1] != 1:
		x += a[i] - a[i - 1] - 1
print(x)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
print(a[len(a) - 1] - a[0] - n + 1)


n = int(input())
a = [int(x) for x in str(input()).split(' ')]
maxA = max(a)
minA = min(a)
total = maxA - minA + 1
print(total - n)


import sys
t = int(sys.stdin.readline())
ip = list(map(int, sys.stdin.readline().strip().split()))
a = min(ip)
b = max(ip)
print(b - a + 1 - t)


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

def heist(l):
	l.sort()
	c = 0
	for i in range(len(l) - 1):
		c += l[i + 1] - l[i] - 1
	return c
print(heist(l))


n = int(input().strip())
x = [int(x) for x in input().split()]
y = sorted(x)
t = y[n - 1] - y[0] + 1
print(t - n)


n = int(input())
keyboardA = [int(s) for s in input().split()]
keyboardB = range(min(keyboardA), max(keyboardA) + 1)
print(len(keyboardB) - len(keyboardA))


n = int(input())
list1 = [int(v) for v in input().split()]
print(max(list1) - min(list1) - n + 1)


n_left = input()
list_left = input().split(' ')
(min, max) = (int(list_left[0]), int(list_left[0]))
for i in list_left:
	integer = int(i)
	if min > integer:
		min = integer
	if max < integer:
		max = integer
del list_left
result = max - min + 1 - int(n_left)
print(result)


a = int(input())
im = [int(i) for i in input().split()]
s = min(im)
t = max(im)
ans = t - s + 1 - a
print(ans)


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a) + 1 - n)


n = int(input())
a = list(map(int, input().split()))
l = min(a)
r = max(a)
tot = r - l + 1
print(tot - len(a))


read = lambda : map(int, input().split())
n = int(input())
A = list(read())
print(max(A) - min(A) + 1 - n)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
count = 0
for i in range(n - 1):
	count += a[i + 1] - a[i] - 1
print(count)


def minimum_keyboards(array, num_after):
	num_before = max(array) - min(array) + 1
	return num_before - num_after
num_after = int(input())
array = [int(x) for x in input().split()]
print(minimum_keyboards(array, num_after))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	print(max(a) - min(a) + 1 - n)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


n = int(input())
n1 = list(map(int, input().split()))
n1.sort()
count = 0
for i in range(len(n1) - 1):
	if n1[i + 1] - n1[i] != 1:
		count = count + (n1[i + 1] - n1[i] - 1)
print(count)


n = int(input())
arr = [int(x) for x in input().split()]
print(max(arr) - min(arr) + 1 - len(arr))


q = int(input())
n = list(map(int, input().split()))
print(max(n) - min(n) - q + 1)


n = int(input())
m = sorted([int(i) for i in input().split(' ')])
print(m[len(m) - 1] - m[0] - n + 1)


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


n = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
new = sorted(list)
difference = 0
result = 0
for i in range(0, n - 1):
	difference += new[i + 1] - new[i]
result = difference - (n - 1)
print(result)


n = int(input())
a = [int(i) for i in input().split()]
x = min(a)
y = max(a)
total = y - x + 1
print(total - n)


n = int(input())
a = list(map(int, input().split()))
a.sort()
res = a[-1] - a[0] + 1 - n
print(res)


n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 0
st = l[0]
mxi = l[n - 1]
print(mxi - st + 1 - n)


from sys import stdin
input = stdin.readline
n = int(input())
L = list(map(int, input().split()))
print(max(L) - min(L) + 1 - n)


n = int(input())
array1 = list(map(int, input().split()))
pres = max(array1) - min(array1) + 1
print(pres - len(array1))


y = int(input())
l = list(map(int, input().split()))
l.sort()
x = l[0]
w = l[-1]
print(w - x - y + 1)


n = int(input())
keyb = list(map(int, input().split()))
print(max(keyb) - min(keyb) + 1 - n)


t = int(input())
a = [int(x) for x in input().strip().split(' ')]
a = sorted(a)
t1 = min(a)
t2 = max(a)
count = 1 + t2 - t1 - t
print(count)


x = eval(input())
l = list(map(int, input().split()))
l = sorted(l)
c = 0
i = 0
while i < len(l) - 1:
	if l[i + 1] - l[i] != 1:
		c = c + (l[i + 1] - l[i] - 1)
	i += 1
print(c)


n = int(input())
a = input().split(' ')
for i in range(len(a)):
	a[i] = int(a[i])
y = min(a)
x = max(a)
z = x - y - len(a) + 1
print(z)


n = int(input())
array = list(map(int, input().split()))
print(max(array) - min(array) + 1 - n)


n = int(input())
xind = [int(x) for x in input().split()]
mini = min(xind)
maxi = max(xind)
print(maxi - (mini + n - 1))


t = 1
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a1 = min(l)
	a2 = max(l)
	print(a2 - a1 - n + 1)
exit(0)


n = int(input())
arr = [*map(int, input().split())]
print(max(arr) - min(arr) + 1 - n)


a = int(input())
s = 0
l = list(map(int, input().split()))
l.sort()
for i in range(len(l) - 1):
	if l[i + 1] - l[i] > 1:
		s += l[i + 1] - l[i] - 1
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
t = 0
for i in range(0, n - 1):
	if l[i] == l[i + 1] + 1:
		continue
	else:
		t = t + l[i + 1] - l[i] - 1
print(t)


n = int(input())
lst = [int(i) for i in input().split()]
max1 = max(lst)
min1 = min(lst)
c = max1 - min1
n = n - 2
c = c - 1
print(abs(n - c))


n = int(input())
a = list(map(int, input().split()))
r = 0
a.sort()
x = a[0]
stole = 0
for item in a[1:]:
	if item - 1 == x:
		x = item
	else:
		stole += item - x - 1
		x = item
print(stole)


input()
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
print(mx - mn - len(a) + 1)


def read():
	return [int(v) for v in input().split()]

def min_stolen(a):
	n = len(a)
	ans = 0
	for i in range(1, n):
		ans += a[i] - a[i - 1] - 1
	return ans

def main():
	read()
	a = sorted(read())
	print(min_stolen(a))
main()


n = int(input())
line = input()
v = [int(h) for h in line.split()]
v = sorted(v)
dif = v[-1] - v[0] + 1
dif = dif - n
print(dif)


x = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) + 1 - x > 0:
	print(max(a) - min(a) + 1 - x)
else:
	print('0')


sum = 0
n = int(input())
li = list(sorted(map(int, input().split())))
for i in range(1, len(li)):
	if 1 < li[i] - li[i - 1]:
		d = abs(li[i] - (li[i - 1] + 1))
		sum += d
print(sum)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
n = int(input())
li = get_list()
print(max(li) - min(li) - n + 1)


n = int(input())
a = list(map(int, input().split()))
x = sorted(a)[-1] - sorted(a)[0] - n + 1
print(x)


n = eval(input())
l = list(map(int, input().split()))
l.sort()
m = l[-1]
m1 = l[0]
print(m + 1 - (m1 + n))


import os
import sys
from io import BytesIO, IOBase
import math
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')
n = int(input())
l = list(map(int, input().split()))
l.sort()
d = l[n - 1] - l[0] + 1
print(d - n)


from sys import stdin, stdout
import cProfile
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def main():
	rem = get_int()
	li = get_list()
	display(max(li) - min(li) + 1 - rem) if max(li) - min(li) + 1 - rem >= 0 else 0
cProfile.run('main()') if test else main()


n = int(input())
minl = 10000000000000000000000
maxl = 0
tt = map(int, input().split())
for t in tt:
	minl = min(minl, t)
	maxl = max(maxl, t)
print(maxl - minl + 1 - n)


n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
	print(0)
else:
	ma = max(*a)
	mi = min(*a)
	k = ma - mi + 1 - n
	print(k)


def main():
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	print(arr[-1] - arr[0] - n + 1)
main()


t = int(input())
s = input().split(' ')
s = [int(i) for i in s]
q = max(s) - min(s) + 1
print(q - len(s))


a = int(input())
m = list(map(int, input().split()))
m = sorted(m)
print(m[a - 1] - m[0] + 1 - a)


n = int(input())
s = input().split()
l = [int(i) for i in s]
l.sort()
lo = l[0]
up = l[-1]
ans = up - lo + 1 - n
print(ans)


try:
	n = int(input())
	l = list(map(int, input().split()))
	x = min(l)
	y = max(l)
	dif = y - x + 1
	print(dif - n)
except EOFError:
	pass


a = []
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = a[n - 1] - a[0]
k = b - n + 1
print(k)


n = int(input())
ans = 0
ls = list(map(int, input().split()))
ls.sort()
for i in range(len(ls) - 1):
	if ls[i + 1] != ls[i] + 1:
		ans = ans + ls[i + 1] - ls[i] - 1
print(ans)


n = int(input())
keyboards = list(map(int, input().split()))
print(1 + max(keyboards) - min(keyboards) - n)


n = int(input())
list1 = sorted(list(map(int, input().split(' '))))
mini = list1[0]
maxi = list1[-1]
print(maxi - mini - n + 1)


n = int(input())
array = input().split()
fin = []
for i in array:
	fin.append(int(i))
fin.sort()
ans = fin[-1] - fin[0] + 1 - n
print(ans)


I = lambda : map(int, input().split())
n = int(input())
a = list(I())
mi = min(a)
mx = max(a)
l = mx - mi + 1
print(l - len(a))


x = int(input())
s = [int(n) for n in input().split()]
z = max(s) - min(s) + 1
print(z - x)


x = int(input())
seqS = input().split(' ')
seq = []
contador = 0
for i in seqS:
	seq.append(int(i))
seq.sort()
print(seq[-1] - seq[0] + 1 - x)


size = int(input())
keyboards = list(map(int, input().split(' ')))
x = max(range(min(keyboards), min(keyboards) + size))
print(max(keyboards) - x)


def prg():
	n = int(input())
	xs = sorted([int(x) for x in input().split()])
	start = xs[0]
	res = 0
	for x in xs:
		if x != start:
			res += x - start
			start += x - start + 1
		else:
			start += 1
	print(res)
prg()


n = int(input(''))
dizi = list(input('').split())
liste = []
for i in range(n):
	liste.append(int(dizi[i]))
liste.sort()
print(liste[liste.__len__() - 1] - liste[0] - n + 1)


n = int(input())
a = input().split()
c = 0
for i in range(len(a) - 1):
	for j in range(i + 1, len(a)):
		if int(a[j]) < int(a[i]):
			temp = a[i]
			a[i] = a[j]
			a[j] = temp
for i in range(len(a) - 1):
	for j in range(i + 1, i + 2):
		minus = int(a[j]) - int(a[i])
		if minus > 1:
			c += minus - 1
print(c)


n = int(input())
lis = [int(x) for x in input().split(' ')]
mini = min(lis)
c = max(lis) - min(lis) + 1 - n
print(c)


n = int(input())
arr = list(map(int, input().split()))
(Max, Min) = (max(arr), min(arr))
print(Max - Min + 1 - n)


n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
x = 0
for i in range(0, len(arr) - 1):
	x = x + abs(arr[i + 1] - arr[i]) - 1
print(x)


n = int(input())
s = list(map(int, input().split()))
d = min(s)
k = max(s)
print(k - d + 1 - len(s))


a = int(input())
cisla = list(map(int, input().split()))
cisla.sort()
ans = 0
for i in range(len(cisla) - 1):
	ans += cisla[i + 1] - cisla[i] - 1
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
count = 0
for i in range(len(arr) - 1):
	if arr[i + 1] - arr[i] != 1:
		count = count + (arr[i + 1] - arr[i]) - 1
print(count)


num = input()
re = input()
rem = sorted(re.split(' '), key=int)
i = 0
stolen = 0
s = 1
while i < len(rem):
	if i == len(rem) - 1:
		s = 0
	if int(rem[i]) - int(rem[i + s]) < -1:
		stolen += abs(int(rem[i]) - int(rem[i + 1]) + 1)
	i += 1
print(stolen)


n = int(input())
keyboards = map(int, input().split())
(a, b) = (float('inf'), float('-inf'))
for i in keyboards:
	if a > i:
		a = i
	if b < i:
		b = i
print(b - a + 1 - n)


s = ''

def func(l1):
	(ma, mi) = (0, 1000000001)
	for i in l1:
		(ma, mi) = (max(ma, i), min(mi, i))
	return ma - mi + 1 - len(l1)
n = int(input())
l1 = list(map(int, input().split()))
print(func(l1))


kol = int(input())
sp = list(map(int, input().split()))
chet = 0

def sort(a):
	for j in range(len(a) - 1):
		for i in range(len(a) - j - 1):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
sort(sp)
for a in range(kol - 1):
	a1 = sp[a]
	a2 = sp[a + 1]
	if a1 + 1 != a2:
		chet = chet + (a2 - a1 - 1)
print(chet)


n = int(input())
tab = list(map(int, input().split()))
tab.sort()
res = 0
for i in range(1, n):
	if tab[i] - tab[i - 1] > 1:
		res += tab[i] - tab[i - 1] - 1
print(res)


n = int(input())
a = [int(k) for k in input().split()]
m = 0
for i in range(n - 1):
	for j in range(n - i - 1):
		if a[j] > a[j + 1]:
			(a[j], a[j + 1]) = (a[j + 1], a[j])
for i in range(n - 1):
	m += a[i + 1] - a[i] - 1
print(m)


def solve(keyboards):
	keyboards.sort()
	stolen = 0
	for i in range(1, len(keyboards)):
		if keyboards[i] - keyboards[i - 1] > 1:
			stolen += keyboards[i] - keyboards[i - 1] - 1
	return stolen
n = int(input())
keyboards = [int(y) for y in input().split()]
print(solve(keyboards))


n = int(input())
arr = sorted([int(i) for i in input().split()])
print(arr[-1] - arr[0] + 1 - n)


n = int(input())
lis = list(map(int, input().strip().split()))
mx = max(lis)
mn = min(lis)
tot = mx - mn + 1
print(tot - n)


n = int(input())
arr = []
arr = list(map(int, input().lstrip().split()))
print(max(arr) - min(arr) + 1 - n)


n = int(input())
l = list(map(int, input().split()))
k = 0
l = sorted(l)
for i in range(1, len(l)):
	k += l[i] - l[i - 1] - 1
print(k)


a = int(input())
c = list(map(int, input().split()))
print(max(c) - min(c) + 1 - a)


N = int(input())
T = sorted(list(map(int, input().split())))
C = 0
for _ in range(N - 1):
	C += T[_ + 1] - T[_] - 1
print(C)


n = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
result = sorted(list)
print(result[-1] - result[0] + 1 - n)


n = int(input())
l = list(map(int, input().split()))
l.sort()
z = max(l) - min(l) + 1
print(z - n)


n = int(input())
comps = list(map(int, input().split()))
comps.sort()
duzdi = 0
for i in range(n - 1):
	if comps[i + 1] - comps[i] != 1:
		duzdi += comps[i + 1] - comps[i] - 1
print(duzdi)


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


n = int(input())
li = [int(i) for i in input().split(' ')]
li.sort()
cnt = 0
for i in range(1, n):
	if li[i] - li[i - 1] > 1:
		cnt += li[i] - li[i - 1] - 1
print(cnt)


a = int(input())
s = 0
b = list(map(int, input().split()))
b.sort()
s = b[a - 1] - b[0]
s = s - a
print(s + 1)


n = int(input())
a = list(input().split(' '))
a = list((int(x) for x in a))
a = sorted(a)
res = 0
for i in range(1, len(a)):
	res += a[i] - a[i - 1] - 1
print(res)


n = int(input())
index = sorted(list(map(int, input().split())))
lost = 0
for i in range(n - 1):
	lost += index[i + 1] - index[i] - 1
print(lost)


n = int(input())
ns = list(map(int, input().split()))
print(max(ns) - min(ns) + 1 - n)


import sys
n = int(sys.stdin.readline())
numbers = sys.stdin.readline().split()
max_val = int(numbers[0])
min_val = int(numbers[0])
for i in numbers[1:]:
	val = int(i)
	if val > max_val:
		max_val = val
	elif val < min_val:
		min_val = val
print(max_val - min_val - n + 1)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
c = 0
for i in range(len(a) - 1):
	if a[i] - a[i + 1] != -1:
		c = c + a[i + 1] - a[i] - 1
print(c)


n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
print(arr[n - 1] - arr[0] - n + 1)


num = int(input())
l = [int(n) for n in input().split()]
count = 0
print(max(l) - min(l) - len(l) + 1)


x = map(int, input().split())
num = []
y = 0
z = 0
num = list(map(int, input().split()))
num.sort()
y = len(num)
z = num[-1] - num[0]
print(1 + (z - y))


n = int(input())
a = list(map(int, input().split()))
c = []
k = []
c.extend(a)
c.sort()
ctr = 0
for i in range(n - 1):
	if c[i + 1] - c[i] > 1:
		k.append(c[i + 1] - c[i])
		ctr += 1
if len(k) > 0:
	print(sum(k) - ctr)
else:
	print('0')


def __starting_point():
	n = int(input())
	a = list(map(int, input().split()))
	(mn, mx) = (min(a), max(a))
	print(mx - mn + 1 - n)
__starting_point()


num = int(input())
l = list(map(int, input().strip().split()))
a = min(l)
b = max(l)
c = 0
for i in range(0, num):
	if l[i] >= a and l[i] <= b:
		c = c + 1
c = b - a - c + 1
print(c)


n = int(input())
x = list(map(int, input().split()))
(a, b) = (min(x), max(x))
print(b - a + 1 - n)


n = int(input())
key = input().split()
for i in range(n):
	key[i] = int(key[i])
maxvalue = max(key)
minvalue = min(key)
ans = maxvalue - minvalue + 1 - n
print(ans)


m = int(input())
nums = list(map(int, input().split()))
k = max(nums) - min(nums) + 1
print(k - m)


n = int(input())
s = sorted(list(map(int, input().split())))
print(s[-1] - s[0] - n + 1)


n = int(input())
a = list(map(int, input().split()))
before = max(a) - min(a) + 1
after = len(a)
print(before - after)


import sys
import collections
input = sys.stdin.readline

def printnl(val):
	sys.stdout.write(str(val) + '\n')
n = int(input())
a = list(map(int, input().split()))
print(max(max(a) - min(a) - n + 1, 0))


n = int(input())
indices = [int(x) for x in input().split()]
indices.sort()
_max = indices[-1]
_min = indices[0]
total = _max - _min + 1
ans = total - n
if ans < 0:
	print(ans * -1)
else:
	print(ans)


n = int(input())
keyboards = list(map(int, input().split()))
minKey = 0
maxKey = 0
for i in range(0, n):
	if i == 0:
		minKey = maxKey = keyboards[i]
	if minKey > keyboards[i]:
		minKey = keyboards[i]
	if maxKey < keyboards[i]:
		maxKey = keyboards[i]
print(maxKey - minKey + 1 - n)


n = int(input())
a = tuple(map(int, input().split()))
print(max(a) - min(a) + 1 - n)


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
count = ar[n - 1] - ar[0] + 1 - n
print(count)


n = int(input())
a = list(map(int, input().split()))
xmin = min(a)
xmax = max(a)
ans = xmax - xmin + 1 - n
print(ans)


a = int(input())
b = input().split(' ')
array = []
for j in range(len(b)):
	array.append(int(b[j]))
maxs = max(array)
mins = min(array)
print(maxs - mins - a + 1)


def solve2(keyboards):
	keyboards.sort()
	return keyboards[-1] - keyboards[0] + 1 - len(keyboards)
n = int(input())
keyboards = list(map(int, input().split(' ')))
print(solve2(keyboards))


n = int(input())
li = [int(i) for i in input().split()]
li.sort()
c = 0
for i in range(n - 1):
	k = li[i + 1] - li[i]
	if k == 1:
		continue
	else:
		c += k - 1
print(c)


n = input()
k = list(map(int, input().split()))
k.sort()
counter = 0
for i in range(len(k) - 1):
	if k[i + 1] - k[i] != 1:
		counter += k[i + 1] - k[i] - 1
print(counter)


n = int(input())
remaining = list(map(int, input().split()))
remaining.sort()
result = 0
for i in range(n - 1):
	result += remaining[i + 1] - remaining[i] - 1
print(result)


n = int(input())
a = input()
a = list(map(int, a.split()))
z = max(a)
q = min(a)
tv = z - q + 1
print(tv - n)


def cin(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(n,) = cin()
m = cin()
print(max(m) - min(m) + 1 - len(m))


n = eval(input())
ly1 = [eval(x) for x in input().split()]
ly2 = sorted(ly1)
print(ly2[len(ly2) - 1] - ly2[0] - n + 1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
k = a[n - 1] - a[0] + 1
print(k - n)


import sys

def main():
	n = int(sys.stdin.readline().rstrip())
	if n == 0:
		return 0
	a = list(map(int, sys.stdin.readline().rstrip().split()))
	a.sort()
	print(str(a[-1] - a[0] - n + 1))
main()


n = int(input())
l = list(map(int, input().split()))
l.sort()
sum = 0
for i in range(n - 1):
	t = l[i + 1] - l[i]
	sum += t - 1
print(sum)


t = int(input())
l = list(map(int, input().split()))
l.sort()
f = 0
for i in range(t - 1):
	if l[i + 1] - l[i] > 1:
		f = f + l[i + 1] - l[i] - 1
print(f)


n = int(input())
a = list(map(int, input().split()))
max_val = max(a)
min_val = min(a)
val = max_val - min_val + 1 - n
print(val)


n = int(input())
data = [int(i) for i in input().split()]
max_d = data[0]
min_d = data[0]
for i in data:
	if i > max_d:
		max_d = i
	if min_d > i:
		min_d = i
print(max_d - min_d + 1 - n)


number_left = int(input())
arr = input().split(' ')
arr = [int(i) for i in arr]
mini = min(arr)
maxi = max(arr)
print(maxi - mini + 1 - number_left)


n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))
a.sort()
total = 0
for i in range(1, len(a)):
	total += a[i] - a[i - 1] - 1
print(total)


n = int(input())
lists = list(map(int, input().split()))
print(max(lists) - min(lists) + 1 - n)


import math
import bisect
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd, Counter as ctr
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))

def mex(arr):
	nList = set(arr)
	mex = 0
	while mex in nList:
		mex += 1
	return mex

def results(arr, n):
	arr.sort()
	(min_, max_) = (arr[0], arr[-1])
	return max_ - min_ - n + 1

def main():
	n = inp()
	a = seq()
	result = results(a, n)
	print(result)
main()


def main():
	n = int(input())
	keyboards = [int(_) for _ in input().split()]
	a = min(keyboards)
	b = max(keyboards)
	n_minimum_keyboards = b - a + 1
	print(n_minimum_keyboards - n)
main()


n = int(input())
a = list(map(int, input().split()))
mayor = max(a)
menor = min(a)
print(max(a) - min(a) + 1 - n)


def stolen(arr):
	big_boi = max(arr)
	smol_boi = min(arr)
	l = big_boi - smol_boi
	return l - len(arr) + 1
n = int(input())
ar = list(map(int, input().rstrip().split()))
print(stolen(ar))


c = int(input())
a = input().split()
for i in range(c):
	a[i] = int(a[i])
b = max(a) - min(a) + 1
print(b - c)


a = int(input())
L = list(sorted(map(int, input().split())))
d = L[-1] - L[0]
print(d + 1 - a)


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

def sort(l, r):
	i = l
	j = r
	mid = a[int((l + r) / 2)]
	while True:
		while a[i] < mid:
			i = i + 1
		while a[j] > mid:
			j = j - 1
		if i <= j:
			tmp = a[i]
			a[i] = a[j]
			a[j] = tmp
			i = i + 1
			j = j - 1
		if i > j:
			break
	if i < r:
		sort(i, r)
	if l < j:
		sort(l, j)
sort(0, n - 1)
ans = 0
for i in range(1, n):
	ans = ans + a[i] - a[i - 1] - 1
print(ans)


n = int(input())
arr = list(map(int, input().rstrip().split()))
a = min(arr)
b = max(arr)
print(b - a + 1 - n)


n = int(input())
a = list(map(int, input().split()))
q = min(a)
p = max(a)
x = len(a)
print(p - q + 1 - x)


n = int(input())
a = sorted(list(map(int, input().split())))
print(sum([a[x] - a[x - 1] - 1 for x in range(1, n)]))


import sys
n = sys.stdin.readline()
temp = sys.stdin.readline().split()
arr = [int(x) for x in temp]
print(max(arr) - min(arr) - int(n) + 1)


d = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
sum1 = 0
i = 0
while i < len(c) - 1:
	sum1 += c[i] - c[i + 1] - 1
	i += 1
print(sum1)


n = int(input())
l = list(map(int, input().split()))
min = min(l)
max = max(l)
num = min + 1
count = 0
nth = max - min + 1
count = nth - len(l)
print(count)


y = int(input())
s = input()
n = [int(s) for s in s.split()]
l = 0
n.sort()
u = n[0]
r = n[y - 1]
print(abs(y - (r - u + 1)))


n = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mina = min(a)
no = maxa - mina + 1
print(no - n)


n = int(input())
x = list(map(int, input().split()))
x.sort()
c = x[n - 1] - x[0] + 1 - n
print(c)


N = int(input())
vals = [int(x) for x in input().strip().split()]
print(max(vals) - min(vals) + 1 - N)


n = int(input())
s = [int(i) for i in input().split()]
print(max(s) - min(s) + 1 - n)


n = int(input())
xs = sorted(list(map(int, input().split())))
print(xs[-1] - xs[0] + 1 - len(xs))


n = int(input())
arr = list(map(int, input().split()))
m1 = min(arr)
m2 = max(arr)
ans = 0
diff = m2 - m1 - 1
l = n - 2
ans = diff - l
print(str(ans))


n = int(input())
ln = list(map(int, input().split()))
a = min(ln)
b = max(ln)
c = b - a + 1 - n
print(c)


from collections import defaultdict
n = int(input().rstrip())
a = list(map(int, input().rstrip().split(' ')))
x = min(a)
y = max(a)
numberOfKeyboards = y - x + 1
stolen = numberOfKeyboards - n
print(stolen)


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
r = ar[-1] - ar[0] + 1
print(r - n)


def stolen(n, lst):
	mn = min(lst)
	mx = max(lst)
	s = 0
	lst.sort()
	for i in range(n - 1):
		diff = lst[i + 1] - lst[i]
		if diff > 1:
			s += diff - 1
	print(s)
n = int(input())
arr = [int(x) for x in input().split()]
stolen(n, arr)


n = int(input())
ins = input().split(' ')
for i in range(len(ins)):
	ins[i] = int(ins[i])
ins.sort()
mmax = ins[len(ins) - 1]
mmin = ins[0]
print(mmax - mmin + 1 - n)


n = int(input())
L = [int(y) for y in input().split()]
print(1 - n + max(L) - min(L))


n = int(input())
li = list(map(int, input().split()))
li.sort()
ans = li[-1] - li[0] + 1 - n
print(ans)


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = max(A) - min(A) + 1 - n
	print(ans)
main()


n = int(input())
a = [int(x) for x in input().split()]
if n == 1:
	print(0)
else:
	if a[0] > a[1]:
		max = a[0]
		min = a[1]
	else:
		max = a[1]
		min = a[0]
	if n % 2 == 0:
		for i in range(2, n, 2):
			if a[i] < a[i + 1]:
				if a[i] < min:
					min = a[i]
				if a[i + 1] > max:
					max = a[i + 1]
			else:
				if a[i] > max:
					max = a[i]
				if a[i + 1] < min:
					min = a[i + 1]
	else:
		for i in range(2, n - 1, 2):
			if a[i] < a[i + 1]:
				if a[i] < min:
					min = a[i]
				if a[i + 1] > max:
					max = a[i + 1]
			else:
				if a[i] > max:
					max = a[i]
				if a[i + 1] < min:
					min = a[i + 1]
		if a[-1] > max:
			max = a[-1]
		elif a[-1] < min:
			min = a[-1]
	print(max - min + 1 - n)


n = int(input())
s = list(map(int, input().split()))
a = max(s)
b = min(s)
print(a - b - len(s) + 1)


from sys import stdin

def read():
	return stdin.readline().strip()
n = int(read())
index = list(map(int, read().split()))
print(max(index) - min(index) + 1 - n)


N = int(input())
li = [int(i) for i in input().split()]
li.sort()
s = 0
for j in range(N - 1):
	s = s + li[j + 1] - li[j] - 1
print(s)


import sys
n = int(input())
mi = 10000000000
ma = 0
l = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	mi = min(mi, l[i])
	ma = max(ma, l[i])
print(ma - mi + 1 - n)


T = int(input())
laptop = list(map(int, input().split()))
laptop.sort()
minimum = laptop[0]
maximum = laptop[T - 1]
print(maximum - minimum + 1 - T)


n = int(input())
l = [int(i) for i in input().split()]
a = min(l)
b = max(l)
k = b - a
print(k - n + 1)


remaining = int(input())
indices = input().split(' ')
max = 1
min = 10 ** 9
for i in range(len(indices)):
	num = int(indices[i])
	if num > max:
		max = num
	if num < min:
		min = num
print(max - min + 1 - remaining)


n = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
sortedList = sorted(list)
size = len(list)
i = sortedList[-1] - sortedList[0] - size + 1
print(i)


i = input
n = int(i())
l = [*map(int, i().split())]
l.sort()
c = 0
for j in range(n - 1):
	c += l[j + 1] - l[j] - 1
print(c)


n = int(input())
A = [*map(int, input().split())]
A.sort()
mis = 0
for i in range(1, len(A)):
	if A[i] > A[i - 1] + 1:
		mis += A[i] - A[i - 1] - 1
print(mis)


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
a = list[0]
(i, cnt) = (0, 0)
while i < n - 1:
	cnt += list[i + 1] - list[i] - 1
	i += 1
print(cnt)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
z = l[0]
m = l[n - 1]
print(m - z + 1 - n)


n = int(input())
x = list(map(int, input().split()))
m = max(x) + 1 - min(x)
if m == len(x):
	print('0')
else:
	print(m - n)


n = int(input())
remaining_keyboards = list(map(int, input().split()))
start = min(remaining_keyboards)
end = max(remaining_keyboards)
k = end - start - 1
for keyboard in remaining_keyboards:
	if keyboard != start and keyboard != end:
		k -= 1
print(max(k, 0))


n = int(input())
l = list(map(int, input().split()))
a = max(l)
b = min(l)
if n == a - b + 1:
	print(0)
else:
	print(abs(a - b + 1 - n))


m = input()
ar = list(map(int, input().split()))
q = min(ar)
w = max(ar)
r = len(ar)
print(w - q - r + 1)


rem = int(input())
nums = sorted(map(int, input().split()))
print(sum((nums[i] - nums[i - 1] - 1 for i in range(1, len(nums)))))


a = int(input())
b = list(map(int, input().split()))
print(max((b[j] for j in range(len(b)))) - min((b[k] for k in range(len(b)))) - a + 1)


def min_stolen(numbers):
	return max(numbers) - min(numbers) + 1 - len(numbers)
n = int(input())
numbers = list(map(int, input().split()))
print(min_stolen(numbers))


n = int(input())
a = [int(_) for _ in input().split()]
print(max(a) - min(a) - n + 1)


n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(1, len(L)):
	ans += L[i] - L[i - 1] - 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
f = min(a)
l = max(a)
res = l - f + 1 - n
print(res)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
p = 0
for i in range(0, n - 1):
	if l[i] + 1 != l[i + 1]:
		p = p + (l[i + 1] - l[i] - 1)
print(p)


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

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

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

def ss():
	return [x for x in input()]
a = ii()
s = si()
s.sort()
ans = 0
for i in range(a - 1):
	ans += s[i + 1] - s[i] - 1
print(ans)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
n = read_int()
indices = read_ints()
print(max(indices) - min(indices) + 1 - n)


import math
from decimal import *
getcontext().prec = 30
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a) + 1 - n)


n = int(input())
s = list(map(int, input().split()))
s.sort()
su = 0
for i in range(1, len(s)):
	su += max(0, s[i] - s[i - 1] - 1)
print(su)


from sys import stdin
n = int(stdin.readline().rstrip())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
nums.sort()
diff = 0
for i in range(1, len(nums)):
	diff += nums[i] - nums[i - 1] - 1
print(diff)


n = int(input())
l = list(map(int, input().split()))
mi = min(l)
mx = max(l)
print(mx - mi - n + 1)


y = input()
mylist = [int(n) for n in input().split(' ')]
min_val = min(mylist)
max_val = max(mylist)
num = max_val - min_val + 1
print(num - len(mylist))


n = int(input())
line = input()
keybs = line.split()
keybs = list(map(int, keybs))
keybs = sorted(keybs)
ans = 0
for i in range(1, len(keybs)):
	ans += keybs[i] - keybs[i - 1] - 1
print(ans)


k = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[-1])
n = 0
for i in range(k - 1):
	n += a[i + 1] - a[i] - 1
print(n)


n = int(input())
indeces = [int(i) for i in input().split(' ')]
_min = min(indeces)
_max = max(indeces)
print(_max + 1 - _min - n)


n = int(input())
z = list(map(int, input().split()))
z.sort()
count = 0
for i in range(n - 1):
	count += z[i + 1] - z[i]
print(count - n + 1)


N = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[-1]
min = a[0]
keyboards = max - min + 1
print(keyboards - N)


n = eval(input())
x = list(map(int, input().split()))
x.sort()
a = x[0]
b = x[len(x) - 1]
count = b - a + 1 - len(x)
print(count)


n = eval(input())
l = list(map(int, input().split()))
print(max(l) + 1 - (min(l) + n))


input()
a = [int(i) for i in input().split()]
ans = max(a) - min(a) - 1 - (len(a) - 2)
print(ans * (ans == abs(ans)))


a = []
x = int(input())
y = input().split()
for i in range(len(y)):
	a.append(int(y[i]))
a.sort()
k = a[0]
l = a[len(y) - 1]
z = l - k
print(z - len(a) + 1)


n = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
total = max(list) - min(list) + 1
print(total - n)


n = int(input())
l = list(map(int, input().strip().split()))
m = max(l)
n1 = min(l)
f = m - n1 + 1
print(f - n)


n = int(input())
ch = input().split()
max1 = int(ch[0])
min1 = int(ch[0])
for i in range(n):
	if int(ch[i]) > max1:
		max1 = int(ch[i])
	if int(ch[i]) < min1:
		min1 = int(ch[i])
kq = max1 - min1 + 1 - n
print(kq)


n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
s = 0
for i in range(0, len(l) - 1):
	s += abs(l[i] - l[i + 1]) - 1
print(s)


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

def mergeSort(a):
	if len(a) <= 1:
		return a
	mid = len(a) // 2
	left = mergeSort(a[:mid])
	right = mergeSort(a[mid:])
	return merge(left, right)

def merge(left, right):
	result = []
	while len(left) > 0 and len(right) > 0:
		if left[0] <= right[0]:
			result.append(left[0])
			left = left[1:]
		else:
			result.append(right[0])
			right = right[1:]
	if len(left) > 0:
		result += left
	if len(right) > 0:
		result += right
	return result
a = mergeSort(a)
ans = a[-1] - a[0] + 1
print(ans - len(a))


x = int(input())
l = [int(x) for x in input().split()]
print(max(l) - min(l) - x + 1)


y = int(input())
z = input().split()
x = list(map(int, z))
x = sorted(x)
global f
f = 0
for i in range(1, y):
	if x[i] - x[i - 1] > 1:
		f = f + (x[i] - x[i - 1] - 1)
print(f)


num_items = int(input())
inp = input()
inp = inp.split()
new_list = []
for current_num in inp:
	new_list.append(int(current_num))
max_num = max(new_list)
min_num = min(new_list)
print(max_num - min_num - num_items + 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	l = LI()
	return max(l) - min(l) + 1 - n
print(main())


n = int(input())
a = input().split()
a = list(map(int, a))
a.sort()
sm = int(a[0])
l = int(a[-1])
s = 0
d = 0
d = l - sm
s = d + 1 - n
print(s)


n = input()
l = [int(x) for x in input().split()]
mi = min(l)
ma = max(l)
print(ma - mi + 1 - len(l))


input()
a = [int(i) for i in input().split()]
m = min(a)
ma = max(a)
print(ma - m + 1 - len(a))


s = int(input())
A = list(map(int, input().split()))
m = max(A) + 1
n = min(A)
print(m - n - s)


from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a) + 1 - n)


n = int(input())
u = list(map(int, input().split()))
u.sort()
ans = 0
for i in range(1, n):
	ans += u[i] - u[i - 1] - 1
print(ans)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = list(rint())
a.sort()
print(a[-1] - a[0] + 1 - len(a))


n = int(input())
li = []
m = input()
li = m.split(' ')
for i in range(1, n):
	temp = int(li[i])
	k = i - 1
	while k >= 0 and int(li[k]) > temp:
		chck = li[k]
		li[k] = li[k + 1]
		li[k + 1] = chck
		temp = int(li[k])
		k = k - 1
c = 0
t = int(li[n - 1])
s = int(li[0])
ans = t - s + 1
print(abs(ans - n))


import sys
n = int(sys.stdin.readline().rstrip())
nums = list(map(int, sys.stdin.readline().split()))
if n == 1:
	print(0)
else:
	maxN = max(nums)
	minN = min(nums)
	output = maxN - minN + 1 - n
	print(output)


daude = input()
daude = [int(i) for i in input().split()]
print(max(daude) - min(daude) + 1 - len(daude))


def mi():
	return map(int, input().split(' '))
n = int(input())
li = list(mi())
li.sort()
ans = 0
print(li[n - 1] - li[0] - n + 1)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in input().split()]
	else:
		return int(input())
n = ri(1)
a = ri()
a.sort()
ans = 0
le = a[-1] - a[0]
print(le - n + 1)


n = int(input())
x = input().split()
for i in range(n):
	x[i] = int(x[i])
print(max(x) - min(x) + 1 - n)


n = int(input())
keyboards = list(map(int, input().split()))
mink = min(keyboards)
maxk = max(keyboards)
total = maxk - mink + 1
print(total - n)


def I():
	return map(int, input().split())
n = int(input())
a = sorted(list(I()))
print(max(a) + 1 - min(a) - n)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
k = min(a)
l = max(a)
c = 0
for i in range(0, n):
	if a[i] >= k and a[i] <= l:
		c = c + 1
c = l - k - c + 1
print(c)


import sys
input = sys.stdin.readline

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

def inlt():
	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()
list = inlt()
list.sort()
i = list[0]
j = list[n - 1]
x = j - i + 1
if x <= n:
	ans = 0
else:
	ans = x - n
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
minxx = min(a)
maxx = max(a)
length = len(a)
print(maxx - minxx + 1 - length)


n = int(input())
aa = list(map(int, input().split()))
print(max(aa) - min(aa) - n + 1)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	a = ain()
	a.sort()
	print(a[-1] - a[0] - len(a) + 1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


nb_keyboard = int(input())
keyboard = [int(x) for x in input().split()]
print(1 + max(keyboard) - min(keyboard) - nb_keyboard)


n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(n - 1):
	if A[i] != A[i + 1] - 1:
		ans += A[i + 1] - A[i] - 1
print(ans)


n = int(input())
cin = input().split()
arr = []
for x in cin:
	arr.append(int(x))
print(max(arr) - min(arr) + 1 - n)


n = int(input())
a = [int(i) for i in input().split()]
print(max(a) - min(a) + 1 - len(a))


keyboard = int(input())
number_Keyboard = []
number_Keyboard = [int(s) for s in input().split()]
number_Keyboard.sort()
current = number_Keyboard[keyboard - 1] - number_Keyboard[0]
print(current - keyboard + 1)


x = int(input())
ls = list(map(int, input().split()))
ls.sort()
c = []
for i in range(1, x):
	if ls[i] - ls[i - 1] > 1:
		c.append(ls[i] - ls[i - 1] - 1)
print(sum(c))


def main():
	n = input()
	r = [int(v) for v in input().split()]
	print(max(r) - min(r) - len(r) + 1)
main()


x = int(input())
y = list(map(int, input().split(' ')))
z = max(y)
g = min(y)
c = z - g + 1
print(c - x)


num_keyboards = int(input())
keyboards = list(map(int, input().split()))
keyboards.sort()
print(keyboards[-1] - keyboards[0] + 1 - num_keyboards)


n = int(input())
items = list(map(int, input().split()))
maxs = max(items)
mins = min(items)
print(maxs - mins + 1 - n)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
x = l[-1] - l[0] + 1
print(x - n)


ch = int(input())
s = input().split(' ')
ls = []
for i in s:
	ls.append(int(i))
ls = sorted(ls)
w = len(ls) - 2
print(ls[-1] - ls[0] - w - 1)


n = int(input())
arr = sorted(list(map(int, input().split())))
count = 0
for i in range(n - 1):
	if arr[i + 1] - arr[i] - 1 > 0:
		count += arr[i + 1] - arr[i] - 1
print(count)


n = int(input())
f = sorted(list(map(int, input().split())))
print(f[-1] - f[0] + 1 - len(f))


(n, l1) = (int(input()), list(map(int, input().split())))
s = max(l1) - min(l1) + 1 - len(l1)
print(s)


x = int(input())
a = list(map(int, input().split(' ')))
m = min(a)
ma = max(a)
diff = ma - m + 1
if diff > len(a):
	print(diff - len(a))
else:
	print(0)


n = int(input())
list1 = list(sorted(list(map(int, input().split()))))
print(list1[-1] - list1[0] - n + 1)


x = int(input())
y = list(map(int, input().split()))
d = max(y) - min(y) + 1
print(d - x)
1


n = int(input())
lst = [int(x) for x in input().split()]
ans = 0
lst.sort()
for i in range(len(lst) - 1):
	if lst[i] + 1 != lst[i + 1]:
		ans += lst[i + 1] - lst[i] - 1
print(ans)


n = int(input())
li = list(map(int, input().rstrip().split()))
li.sort()
z = 0
for i in range(0, n - 1):
	sub = li[i + 1] - li[i]
	if sub != 1:
		z = z + sub - 1
print(z)


n = int(input())
a = sorted(list(map(int, input().split())))
min_ = sum((a[x + 1] - a[x] - 1 for x in range(0, len(a) - 1)))
print(min_)


input()
s = sorted(list(map(int, input().split())))
print(sum((s[i + 1] - s[i] - 1 for i in range(len(s) - 1))), end='')


from sys import stdin, stdout, exit

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
n = int(sin())
li = listInput()
print(max(li) - min(li) + 1 - n)


n = int(input())
lt = list(map(int, input().split()))
print(max(lt) - min(lt) + 1 - n)


n = int(input())
a = list(map(int, input().split()))
ans = max(a) - min(a)
ret = ans - len(a)
print(ret + 1)


import sys
total = int(sys.stdin.readline())
available = sys.stdin.readline().split()
available = [int(a) for a in available]
mini = 1000000000000
maxi = -1
for a in available:
	if a > maxi:
		maxi = a
	if a < mini:
		mini = a
print(maxi - mini + 1 - total)


n = int(input())
z = list(map(int, input().split()))
print(max(z) - (min(z) + n - 1))


a = int(input())
b = [int(b) for b in input().split()]
b.sort()
print(b[a - 1] - b[0] + 1 - a)


n = int(input())
lst = list(map(int, input().split()))
max_no_keyboard = max(lst) - min(lst) + 1
print(max_no_keyboard - n)


n = int(input())
l = [int(x) for x in input().split()]
mn = l[0]
mx = l[0]
for i in l:
	mx = max(mx, i)
	mn = min(mn, i)
print(mx - mn - 1 + 2 - n)


n = int(input())
numbers = [int(n) for n in input().split(' ')]
print(max(numbers) - min(numbers) + 1 - n)


n = int(input())
a = [int(num) for num in input().split()]
print(max(a) - min(a) + 1 - n)


n = int(input())
A = [int(item) for item in input().split()]
A.sort()
print(A[n - 1] - A[0] - n + 1)


import sys
import os
t = sys.stdin.readline()
n_keyborads_remained = int(t)
t = sys.stdin.readline()
vals = t.split()
max_val = 0
min_val = 10000000000.0
for val in vals:
	if int(val) < min_val:
		min_val = int(val)
	if int(val) > max_val:
		max_val = int(val)
rango = max_val - min_val
print(rango - n_keyborads_remained + 1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
count = 0
beg = a[0]
end = a[len(a) - 1] + 1
print(end - beg - n)


a = int(input())
b = [int(i) for i in input().split()]
b.sort()
summ = 0
for i in range(1, len(b)):
	summ += b[i] - b[i - 1] - 1
print(summ)


number = int(input())
ar = list(map(int, input().split()))
c = 0
ar.sort()
for i in range(1, len(ar)):
	if ar[i] != ar[i - 1] + 1:
		c += ar[i] - ar[i - 1] - 1
print(c)


n = int(input())
l = list(map(int, input().split(None, n)[:n]))
s = min(l)
l.sort()
cont = 0
for i in range(len(l) - 1, 0, -1):
	cont += l[i] - l[i - 1] - 1
print(cont)


import sys
sys.setrecursionlimit(10 ** 9)
from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(1, n):
	ans += l[i] - l[i - 1] - 1
print(ans)


kbs = int(input())
remainKbs = [int(x) for x in input().split()]
stolen = 0
minx = min(remainKbs)
maxx = max(remainKbs)
print(maxx - minx + 1 - kbs)


n = int(input())
l = list(map(int, input().strip().split()))
mn = 100000000000000
mx = -1
for i in l:
	if i > mx:
		mx = i
	if i < mn:
		mn = i
print(mx - mn - n + 1)


def main():
	n = int(input())
	a = sorted(list(map(int, input().split(' '))))
	ans = 0
	for i in range(1, len(a)):
		ans += a[i] - a[i - 1] - 1
	print(ans)
exit(main())


k = int(input())
l = list(map(int, input().split()))
l.sort()
t = l[k - 1] - l[0] + 1
an = len(set(l))
aans = t - an
print(aans)


from sys import stdin, stdout

def func(llist):
	count = 0
	for i in range(1, len(llist)):
		diff = llist[i] - llist[i - 1] - 1
		if diff > 0:
			count += diff
	return count
n = stdin.readline()
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
print(func(arr))


a = int(input())
b = list(map(int, input().split()))
c = min(b)
d = max(b)
print(d - c + 1 - a)


n = int(input())
s = input().split(' ')
for i in range(n):
	s[i] = int(s[i])
s.sort()
cnt = 0
for i in range(1, n):
	cnt += s[i] - s[i - 1] - 1
print(cnt)


n = int(input().strip())
l = list(map(int, input().strip().split()))
l.sort()
c = l[-1] - l[0] + 1
print(c - n)


n = int(input())
l = list(map(int, input().rstrip().split()))
x = sorted(l)
c = 0
for i in range(len(l) - 1):
	if x[i + 1] - x[i] > 1:
		c += x[i + 1] - x[i] - 1
print(c)


remaining = int(input())
a = [int(x) for x in input().split()]
a.sort()
c = 0
for x in range(len(a) - 1):
	if a[x + 1] - a[x] > 1:
		c = c + abs(a[x + 1] - a[x] - 1)
print(c)


N = int(input())
l = list(map(int, input().split()))
c = 0
l.sort()
for i in range(1, N):
	if l[i] - l[i - 1] > 1:
		c += l[i] - l[i - 1] - 1
print(c)


n = int(input())
a = sorted([int(a) for a in input().split()])
print(max(a) - min(a) + 1 - n)


_ = int(input())
x = list(map(int, input().split()))
print(max(x) + 1 - min(x) - len(x))


n = int(input())
lists = sorted(list(map(int, input().split())))
(mi, ma) = (lists[0], lists[n - 1])
j = ma - mi + 1
print(j - n)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	for i in range(n - 1):
		ans += a[i + 1] - a[i] - 1
	print(ans)
main()


x = int(input())
a = sorted(list(map(int, input().split())))
i = 0
counter = 0
while i < x - 1:
	if a[i] + 1 != a[i + 1]:
		counter += a[i + 1] - a[i] - 1
	i += 1
print(counter)


input()
ar = list(map(int, input().split()))
l = min(ar)
r = max(ar)
print(r - l + 1 - len(ar))


n = int(input())
a = input().split()
a = [int(item) for item in a]
a.sort()
k = 0
for i in range(n - 1):
	k += a[i + 1] - a[i] - 1
print(k)


stolen = int(input())
keyboards = [int(x) for x in input().split()]
print(1 + (max(keyboards) - min(keyboards)) - len(keyboards))


k = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
for i in range(k - 1):
	c += a[i + 1] - a[i] - 1
print(c)


input()
b = [int(p) for p in input().split()]
b.sort()
print(b[-1] - b[0] + 1 - len(b))


from functools import reduce
n = int(input())
numbers = list(map(int, input().split()))
mn = reduce(lambda accum, value: min(accum, value), numbers)
mx = reduce(lambda accum, value: max(accum, value), numbers)
print(mx - mn + 1 - n)


n = int(input())
T = [int(s) for s in input().split(' ')]
print(max(T) - min(T) - n + 1)


def sol(n, a):
	if n == 1:
		return 0
	return max(a) - min(a) - 1 - (n - 2)
n = int(input())
a = list(map(int, input().split()))
ans = sol(n, a)
print(ans)


n = int(input())
arr = [int(elem) for elem in input().split()]
arr = sorted(arr)
count = 0
for i in range(1, n):
	count += arr[i] - arr[i - 1] - 1
print(count)


import sys
n = int(next(sys.stdin))
lines = [int(e) for i in sys.stdin.readlines() for e in i.split(' ')]
print(max(lines) - min(lines) + 1 - n)


n = input()
numbers = input()
num_list = [int(x) for x in numbers.split(' ')]
sorted_list = sorted(num_list)
i = 0
result = 0
while i < len(sorted_list) - 1:
	result = sorted_list[i + 1] - sorted_list[i] - 1 + result
	i += 1
print(result)


s = int(input())
l = list(map(int, input().split()))
a = max(l) - min(l) + 1
a = a - s
print(a, end='')


n = int(input())
_list = list(map(int, input().split()))
_list.sort()
res = 0
for i in range(n - 1):
	res += int(_list[i + 1]) - int(_list[i]) - 1
print(res)


import math
n = int(input())
a = [int(i) for i in input().split()]
x = min(a)
y = max(a)
l = y - x + 1
print(l - n)


x = input()
y = input()
a = y.split()
b = []
for num in a:
	b.append(int(num))
b.sort()
i = 0
q = 0
k = len(a)
for i in range(0, len(a) - 1):
	d = int(b[i + 1]) - int(b[i])
	if d != 1:
		q = q + d - 1
	else:
		pass
print(q)


n = int(input())
r = [int(i) for i in input().split()]
u = min(r)
m = max(r)
z = m - (u - 1)
print(z - n)


n = int(input())
l = sorted([int(q) for q in input().split()])
answ = 0
for i in range(n - 1):
	answ += l[i + 1] - (l[i] + 1)
print(answ)


input()
a = sorted([int(i) for i in input().split(' ')])
lost = 0
for i in range(1, len(a)):
	lost += a[i] - a[i - 1] - 1
print(lost)


n = int(input())
l = sorted(list(map(int, input().rstrip().split())))
print(sum((l[i] - l[i - 1] - 1 for i in range(1, n) if l[i] - l[i - 1] > 1)))


rem = int(input())
nums = sorted(map(int, input().split()))
m = 0
for i in range(1, len(nums)):
	m += nums[i] - nums[i - 1] - 1
print(m)


n = int(input())
p = list(map(int, input().split()))
l = min(p)
q = max(p)
po = q - l + 1
print(po - n)


n = int(input())
A = list(map(int, input().split()))
c = 0
mi = min(A)
ma = max(A)
a = ma - mi + 1
print(a - n)


n = int(input())
a = list(map(int, input().split()))
a.sort()
k1 = a[0]
k2 = a[n - 1]
diff = k2 - k1 + 1
print(diff - n)


n = int(input())
data = input().split()
for i in range(n):
	data[i] = int(data[i])
minimum = min(data)
maximum = max(data)
print(maximum - minimum - n + 1)


_ = int(input())
k = list(map(int, input().split()))
print(max(k) - min(k) - len(k) + 1)


n = int(input())
l = list(map(int, input().split()))
l.sort()
np = l[n - 1] - l[0] + 1
print(np - n)


remain_num = int(input())
remain = input()
remain = remain.split()
remain = list(map(int, remain))
remain_max = int(max(remain))
remain_min = int(min(remain))
cha = remain_max - remain_min
print(cha - remain_num + 1)


n = int(input())
s = sorted([int(i) for i in input().split()])
print(s[-1] - s[0] + 1 - n)


import sys

def main():
	i = list(map(int, sys.stdin.read().strip().split('\n')[1].split()))
	return max(i) - min(i) - len(i) + 1
print(main())


a = int(input())
b = sorted(map(int, input().split()))
print(b[-1] - b[0] + 1 - a)


a = int(input())
array = list(map(int, input().split()))
c = min(array)
d = max(array)
s = d - c - a + 1
print(s)


N = int(input())
a = input().split(' ')
b = []
for i in a:
	i = int(i)
	b.append(i)
if N == len(b):
	mn = min(b)
	mx = max(b)
	lp = mx - mn + 1
	print(lp - N)


t = int(input())
a = list(map(int, input().split()))
a.sort()
m1 = min(a)
m2 = max(a)
if m2 - m1 + 1 == t:
	print(0)
else:
	print(m2 - m1 + 1 - t)


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	mini = min(l[:])
	maxi = max(l[:])
	print(maxi - mini + 1 - n)


remain = int(input(''))
indexes = list(map(int, input('').split()))
indexes.sort()
length = len(indexes) - 1
count = indexes[length] - indexes[0] - length
print(count)


n = int(input())
ls = sorted(list(map(int, input().split())))
if n == 1:
	print(0)
else:
	c = 0
	for i in range(n - 1):
		c += ls[i + 1] - ls[i] - 1
	print(c)


n = input()
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(len(l)):
	if i != len(l) - 1 and l[i + 1] != l[i] + 1:
		d = l[i + 1] - l[i] - 1
		count += d
print(count)


n = int(input())
l = list(map(int, input().split()))
m = max(l) - min(l) + 1
print(m - n)


n = int(input())
l = list(map(int, input().split()))
tot = max(l) - min(l) + 1
print(tot - n)


input()
a = [i for i in input().split()]
a = list(map(int, a))
a.sort()
dem = a[len(a) - 1] - a[0] + 1
print(dem - len(a))


n = int(input())
a = list(map(int, input().split()))
a1 = min(a)
a2 = max(a)
t = a2 - a1 + 1
print(t - n)


from collections import Counter

def solve():
	n = int(input())
	array = list(map(int, input().split()))
	array.sort()
	count = 0
	for i in range(n - 1):
		if array[i + 1] != array[i] + 1:
			count += array[i + 1] - array[i] - 1
	return count
print(solve())


import sys
n = input()
line2 = str(sys.stdin.readline().rstrip()).split()
arr = []
for i in line2:
	arr.append(int(i))
print(max(arr) - min(arr) + 1 - len(arr))


n = int(input())
data = list(map(int, input().split()))
data.sort()
print(data[-1] - data[0] + 1 - n)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = a[n - 1] - a[0] + 1
print(m - n)


n = int(input())
array = input().split(' ')
minv = int(array[0])
maxv = int(array[0])
for i in range(n):
	if minv > int(array[i]):
		minv = int(array[i])
	if maxv < int(array[i]):
		maxv = int(array[i])
res = maxv - minv + 1
res = res - n
print(res)


n = int(input())
a = [int(i) for i in input().split()]
b = a.sort()
total = 0
for i in range(len(a) - 1):
	if abs(a[i] - a[i + 1]) > 1:
		total += abs(a[i] - a[i + 1]) - 1
print(total)


input()
a = sorted(map(int, input().split()))
print(a[-1] - a[0] - (len(a) - 1))


n = input()
k = int(n)
a = list(map(int, input().split()))
p = sorted(a)
d = p[k - 1] - p[0] + 1
print(d - k)


n = int(input())
a = list(map(int, input().split()))
(u, v) = (min(a), max(a))
print(v - u + 1 - n)


n = int(input())
a = [int(i) for i in input().split()]
m = max(a)
n1 = min(a)
print(m - n + 1 - n1)


__author__ = 'Dilshod'
n = int(input())
m = set(map(int, input().split()))
a = max(m) - (min(m) - 1)
print(a - n)


n = int(input())
l = list(map(int, input().strip().split()))
c = 0
k = 0
i = 0
j = n - 1
l.sort()
for i in range(n - 1):
	if l[i + 1] != l[i] + 1:
		c += l[i + 1] - l[i] - 1
print(c)


n = int(input())
li = [int(i) for i in input().split()]
li.sort()
d = 0
for i in range(n - 1):
	k = li[i + 1] - li[i]
	if k != 1:
		d += k - 1
print(d)


n = int(input())
ar = list(map(int, input().split(' ')))
ar.sort()
was = ar[-1] - ar[0] + 1
now = len(ar)
print(was - now)


n = int(input())
x = [int(e) for e in input().split()]
print(max(x) - min(x) + 1 - n)


def read():
	return list(map(int, input().split()))
n = read()
arr = read()
arr = sorted(arr)
pre = arr[0]
acc = 0
for e in arr[1:]:
	acc += e - pre - 1
	pre = e
print(str(acc))


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
li = ai()
li.sort()
c = 0
for i in range(n - 1):
	c += abs(li[i] - li[i + 1]) - 1
op(c)


n = int(input().strip())
arr = [int(__) for __ in input().strip().split()]
if n == 1:
	print(0)
else:
	arr.sort()
	ans = arr[-1] - arr[0] + 1 - len(arr)
	print(ans)


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


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	print(max(a) - min(a) + 1 - n)


n = int(input())
keyboard_indices = [int(x) for x in input().split(' ')]
number_of_keyboard = max(keyboard_indices) - min(keyboard_indices) + 1
print(number_of_keyboard - len(keyboard_indices))


n = int(input())
l = [int(a) for a in input().split()]
count = 0
l.sort()
for i in range(len(l) - 1):
	count = count + l[i + 1] - l[i] - 1
print(count)


found = eval(input())
line = input()
strings = line.split()
list = []
for string in strings:
	list.append(eval(string))
keyboards = sorted(list)
total = keyboards[len(keyboards) - 1] - keyboards[0] + 1
print(total - found)


f = lambda : map(int, input().split())
n = int(input())
l = list(f())
print(max(l) - min(l) + 1 - n)


n = int(input())
s = [int(x) for x in input().split()]
max = max(s)
min = min(s)
if max - min + 1 == n:
	print(0)
else:
	print(max - min + 1 - n)


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()
	return max(a) - min(a) + 1 - n
print(main())


n = eval(input())
s = list(map(int, input().split()))
s = sorted(s)
i = 0
heist = 0
while i < len(s) - 1:
	if s[i + 1] - s[i] > 1:
		heist = heist + (s[i + 1] - s[i]) - 1
	i += 1
print(heist)


n = int(input())
a = list(map(int, input().split()))
a.sort()
min = a[0]
max = a[-1]
print(max - min - n + 1)


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import deque as que, defaultdict as vector
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
from types import GeneratorType
Testcase = 1
for _ in range(Testcase):
	n = inin()
	a = inar()
	a.sort()
	cnt = 0
	for i in range(1, n):
		cnt += a[i] - a[i - 1] - 1
	print(cnt)


n = int(input())
data = sorted(map(int, input().split()))
print(data[-1] - data[0] + 1 - n)


def main():
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	res = 0
	for i in range(1, n):
		if arr[i - 1] + 1 != arr[i]:
			res += arr[i] - arr[i - 1] - 1 if arr[i - 1] != 0 else arr[i] - 1
	return res
print(main())


n = int(input())
a = [int(i) for i in input().split()]
maxi = max(a)
mini = min(a)
print(maxi - mini + 1 - n)


def main():
	n = int(input())
	ip = [int(item) for item in input().split(' ')]
	ip.sort()
	prev = ip[0]
	cnt = 0
	for i in range(1, len(ip)):
		if ip[i] != prev + 1:
			cnt += ip[i] - prev - 1
		prev = ip[i]
	print(cnt)
main()


n = int(input())
Min = float('inf')
Max = 0
for i in input().split():
	Max = max(Max, int(i))
	Min = min(Min, int(i))
print(Max - Min + 1 - n)


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
n = int(input())
(b, c) = (list(map(int, input().split())), 0)
b.sort()
for i in range(1, n):
	c += b[i] - b[i - 1] - 1
print(c)


from sys import stdin
input = lambda : stdin.readline()

def main():
	N = int(input())
	A = list(map(int, input().split()))
	mina = min(A)
	maxa = max(A)
	keyboards = maxa - mina + 1
	print(keyboards - len(A))
main()


keybs = int(input())
keyb_ind = [int(a) for a in input().split()]
keyb_ind = sorted(keyb_ind)
missing = 0
initial_offset = keyb_ind[0]
for (ind, val) in enumerate(keyb_ind[:-1]):
	missing += keyb_ind[ind + 1] - keyb_ind[ind] - 1
print(missing)