Permutation p is an ordered set of integers p_1,  p_2,  ...,  p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1,  p_2,  ...,  p_{n}.

You have a sequence of integers a_1, a_2, ..., a_{n}. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 3·10^5) — the size of the sought permutation. The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9).


-----Output-----

Print a single number — the minimum number of moves.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Examples-----
Input
2
3 0

Output
2

Input
3
-1 -1 2

Output
6



-----Note-----

In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).

In the second sample you need 6 moves to build permutation (1, 3, 2).

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
l = sorted(list(map(int, input().strip().split())))
d = [x for x in range(1, n + 1)]
ret = 0
for i in range(n):
	ret += abs(l[i] - d[i])
print(ret)


n = int(input())
p = input().split()
a = []
for i in range(n):
	a.append(int(p[i]))
	i = i + 1
a.sort()
c = 0
for i in range(n):
	c = c + abs(i + 1 - a[i])
print(c)


def main2():
	n = int(input())
	p_list = list(map(int, input().split(' ')))
	running_total = 0
	p_list.sort()
	for i in range(0, n):
		running_total += abs(i + 1 - p_list[i])
	print(running_total)
main2()


n = int(input())
a = list(map(int, input().split()))
L = []
for i in range(1, n + 1):
	L.append(i)
b = sorted(a)
diff = []
zip_object = zip(L, b)
for (L_i, b_i) in zip_object:
	diff.append(abs(L_i - b_i))
print(sum(diff))


n = int(input())
l_i = list(map(int, input().split()))
l_i.sort()
c = 1
t = 0
for i in l_i:
	t += abs(c - i)
	c += 1
print(t)


(s1, s2) = (int(input()), map(int, input().split()))
s2 = sorted(s2)
state = 1
step = 0
for i in range(s1):
	step += abs(s2[i] - state)
	state += 1
print(step)


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


from math import fabs
n = int(input())
a = list(map(int, input().split()))
a.sort()
ctr = 0
for i in range(1, n + 1):
	ctr += abs(a[i - 1] - i)
print(ctr)


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


n = int(input())
p = [int(_) for _ in input().split()]
p.sort()
moves = 0
for i in range(n):
	moves += abs(i + 1 - p[i])
print(moves)


n = int(input())
nums = sorted(map(int, input().split(' ')))
changes = 0
for i in range(n):
	changes += abs(nums[i] - i - 1)
print(changes)


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


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


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 = sorted(LI())
	r = 0
	for i in range(n):
		r += abs(a[i] - (i + 1))
	return r
print(main())


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


gi = lambda : list(map(int, input().split()))
(n,) = gi()
l = sorted(gi())
print(sum([abs(k + 1 - l[k]) for k in range(n)]))


kalanbaba = 1
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
l.sort()
count = 0
for i in range(1, n + 1):
	if l[i - 1] != i:
		count += abs(i - l[i - 1])
print(count)


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


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


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


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


def main():
	n = int(input())
	ip = [int(item) for item in input().split(' ')]
	moves = 0
	ip.sort()
	for i in range(len(ip)):
		moves += abs(ip[i] - i - 1)
	print(moves)
main()


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


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


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


def main():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	res = 0
	for (i, val) in enumerate(a):
		res += abs(val - (i + 1))
	print(res)
main()


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


n = int(input())
array = input().split()
for i in range(n):
	array[i] = int(array[i])
array.sort()
moves = 0
for i in range(n):
	moves += abs(array[i] - (i + 1))
print(moves)


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


import sys
from math import *
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
k = 1
ans = 0
for x in arr:
	ans += int(fabs(x - k))
	k += 1
print(ans)


n = int(input())
ary = [int(i) for i in input().split()]
ary.sort()
out = 0
c = 0
for i in ary:
	c += 1
	out += abs(i - c)
print(out)


from sys import stdin, stdout
n = int(stdin.readline())
array = list(map(int, stdin.readline().split()))
array.sort()
operations = 0
for i in range(len(array)):
	operations += abs(i + 1 - array[i])
stdout.write(str(operations) + '\n')


from sys import stdin
from functools import reduce

def comp(acc, tpl):
	(item, i) = tpl
	return acc + abs(item - i)

def main():
	line = stdin.readline
	n = int(line())
	a = list(map(int, line().split()))
	a.sort()
	total = reduce(comp, enumerate(a, 1), 0)
	print(total)
main()


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


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


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
num = [x for x in range(1, n + 1)]
ans = 0
for i in range(n):
	if arr[i] < 0:
		ans += abs(arr[i]) + num[i]
	else:
		ans += abs(num[i] - arr[i])
print(ans)


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


def scan(type):
	return list(map(type, input().split()))
(n,) = scan(int)
arr = scan(int)
ans = 0
arr.sort()
for i in range(n, 0, -1):
	ans += abs(arr[i - 1] - i)
print(ans)


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


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


n = int(input())
(c, j) = (0, 1)
for i in sorted(list(map(int, input().split()))):
	c += abs(i - j)
	j += 1
print(c)


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


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


N = int(input())
X = sorted(list(map(int, input().split(' '))))
A = 0
S = 0
while A != N:
	S += abs(X[A] - A - 1)
	A += 1
print(S)


a = int(input())
b = list(map(int, input().split()))
b.sort()
k = 1
co = 0
for elem in b:
	co += abs(elem - k)
	k += 1
print(co)


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


import math
import string

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


import sys, os, io, time, copy, math
from functools import lru_cache
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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


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


from sys import stdin
input = stdin.readline
n = int(input())
seq = [int(item) for item in input().split(' ')]
moves = 0
existing = set()
ne = []
for item in seq:
	if 0 < item <= n and item not in existing:
		existing.add(item)
	else:
		ne.append(item)
if len(existing) == n:
	print(0)
	exit()
ne.sort()
j = 0
for i in range(1, n + 1):
	if i in existing:
		continue
	moves += abs(i - ne[j])
	j += 1
print(moves)


def minSteps(arr):
	n = len(arr)
	arr.sort()
	i = n
	ans = 0
	while i >= 1:
		diff = abs(arr[i - 1] - i)
		ans += diff
		i -= 1
	return ans
n = int(input(''))
arr = list()
inputArray = input('').strip().split()
for i in inputArray:
	arr.append(int(i))
print(minSteps(arr))


length = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
tot = 0
for i in range(len(arr)):
	tot += abs(arr[i] - i - 1)
print(tot)


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


n = int(input())
L = sorted(list(map(int, input().split())))
(moves, start) = (0, 1)
for i in L:
	moves += abs(i - start)
	start += 1
print(moves)


n = int(input())
d = [int(x) for x in input().split()]
a = 0
state = [0 for i in range(n + 1)]
for num in d:
	if num < 1:
		a += 1 - num
		state[1] += 1
	elif num > n:
		a += num - n
		state[n] += 1
	else:
		state[num] += 1
odd = []
holes = []
for i in range(1, n + 1):
	cnti = state[i]
	if cnti == 0:
		holes.append(i)
	if cnti > 1:
		for _ in range(cnti - 1):
			odd.append(i)
	while odd and holes:
		fr = odd.pop()
		to = holes.pop()
		a += abs(fr - to)
print(a)


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


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


num_coin = int(input())
value = [int(num_coin) for num_coin in input().split()]
sort_array = sorted(value)
ctr = 1
ans = 0
dif = 0
for x in sort_array:
	dif = ctr - x
	ctr = ctr + 1
	if dif <= 0:
		dif = -dif
	ans = ans + dif
if ans <= 0:
	ans = -ans
	print(ans)
else:
	print(ans)


import sys
import os
import collections
a = int(input())
b = input()
b = b.split()
b = list(map(int, b))
b.sort()
s = 0
index = 1
for i in b:
	s += abs(index - i)
	index += 1
print(s)


import math
import sys
import collections

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

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

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

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))
n = ii()
d = sorted(li())
r = 0
for i in range(1, n + 1):
	r += abs(i - d[i - 1])
print(r)


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


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
check = [-1] * (n + 1)
temp = []
for i in range(n):
	if arr[i] < 1 or arr[i] > n:
		temp.append(arr[i])
	elif check[arr[i]] == -1:
		check[arr[i]] = 1
	else:
		temp.append(arr[i])
res = 0
pos = 0
for i in range(1, n + 1):
	if check[i] == -1:
		res += abs(temp[pos] - i)
		pos += 1
print(res)


n = int(input())
arr = [int(num) for num in input().split(' ')]
arr.sort()
ans = 0
for i in range(n):
	ans = ans + abs(i + 1 - arr[i])
print(ans)


from sys import stdin, stdout

def solve():
	n = int(stdin.readline().strip())
	li = list(map(int, stdin.readline().split()))
	li.sort()
	lo = [i for i in range(1, n + 1)]
	res = 0
	for i in range(n):
		res += abs(lo[i] - li[i])
	print(res)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
t = 1
while t <= tcs:
	solve()
	t += 1


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


import string
alphabet = list(string.ascii_lowercase)
inf = 2 ** 20

def print_sequence(s):
	print(*s, sep=' ')

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

def print_bool_result(res):
	if res:
		print('Yes')
	else:
		print('No')
n = int(input())
seq = sorted(read_sequence())
result = 0
for i in range(n):
	result += abs(seq[i] - i - 1)
print(result)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
check = [-1] * (n + 1)
lower = []
upper = []
for i in range(n):
	if arr[i] < 1:
		lower.append(arr[i])
	elif arr[i] > n:
		upper.append(arr[i])
	elif check[arr[i]] == -1:
		check[arr[i]] = 1
	else:
		upper.append(arr[i])
res = 0
posLower = 0
posUpper = 0
for i in range(1, n + 1):
	if check[i] == -1:
		if posLower < len(lower):
			res += abs(lower[posLower] - i)
			posLower += 1
		elif posUpper < len(upper):
			res += abs(upper[posUpper] - i)
			posUpper += 1
print(res)


def main():
	n = int(input())
	ar = [int(i) for i in input().split()]
	ar.sort()
	count = 0
	for i in range(n):
		count += abs(ar[i] - i - 1)
	print(count)
	return 0
main()


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt, ceil
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())

def main():
	n = inp()
	v = inlt()
	v.sort()
	s = 0
	for (i, vv) in enumerate(v):
		s += abs(vv - (i + 1))
	print(s)
main()


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


from sys import stdin, stdout

def solve(n, lst):
	lst.sort()
	steps = 0
	for i in range(1, n + 1):
		steps += abs(i - lst[i - 1])
	return steps
n = int(stdin.readline().rstrip('\r\n'))
lst = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
stdout.write(str(solve(n, lst)))


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a > 0:
		return gcd(b % a, a)
	return b

def primefs(n):
	if n == 1:
		return 1
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	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
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = sorted(int_array())
ans = 0
for i in range(n):
	ans += abs(i + 1 - a[i])
print(ans)


n = int(input())
s = list(map(int, input().split()))
s.sort()
ans = sum([abs(i + 1 - s[i]) for i in range(n)])
print(ans)


input()
xs = [int(x) for x in input().split()]
xs.sort()
sol = 0
for i in range(0, len(xs)):
	sol += abs(xs[i] - (i + 1))
print(sol)


while True:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	sum = 0
	for i in range(1, n + 1):
		sum += abs(i - a[i - 1])
	print(sum, end='')
	break


n = int(input())
a = list(map(int, input().strip().split(' ')))
a.sort()
i = 1
m = 0
for x in a:
	m += abs(x - i)
	i += 1
print(m)


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


n = int(input())
a = list(map(int, input().rstrip().split()))
j = 1
t = 0
a.sort()
for x in a:
	t += abs(x - j)
	j += 1
print(t)


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


n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
moves = 0
for (i, j) in enumerate(nums):
	moves += abs(j - (i + 1))
print(moves)


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


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


n = int(input())
A = list(map(int, input().split()))
Ans = 0
A.sort(reverse=True)
C = n
for val in A:
	Ans += abs(C - val)
	C -= 1
print(Ans)


n = int(input())
l = sorted([int(x) for x in input().split()])
print(sum((abs(a - (b + 1)) for (a, b) in zip(l, range(n)))))


def permutations(n, arr):
	s = sorted(arr)
	su = 0
	for i in range(1, n + 1):
		su += abs(i - s[i - 1])
	print(su)
n = int(input())
l = list(map(int, input().split()))
permutations(n, l)


import sys
my_file = sys.stdin
n = int(my_file.readline())
a = [int(i) for i in my_file.readline().strip().split()]
a.sort()

def solve():
	turns = 0
	for i in range(1, n + 1):
		if a[i - 1] < i:
			turns += i - a[i - 1]
		elif a[i - 1] > i:
			turns += a[i - 1] - i
	return turns
print(solve())


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
l.sort()
ans = 0
for i in range(n):
	ans += abs(i + 1 - l[i])
sys.stdout.write(str(ans))


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

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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def array():
	return [int(i) for i in input().split()]
n = int(input())
a = sorted(array())
ans = 0
for i in range(n):
	ans += abs(i + 1 - a[i])
print(ans)


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


input()
k = 0
j = 1
for i in sorted(map(int, input().split())):
	k += abs(i - j)
	j += 1
print(k)


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


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


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


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


n = int(input())
arr = list(map(int, input().split()))
validNumbers = set()
toFix = []
for number in arr:
	if 1 <= number <= n and number not in validNumbers:
		validNumbers.add(number)
	else:
		toFix.append(number)
toFix.sort()
total = 0
i = 0
for p in range(1, n + 1, 1):
	if p not in validNumbers:
		total += abs(p - toFix[i])
		i += 1
		validNumbers.add(p)
print(total)


n = int(input())
cost = 0
l = sorted([int(i) for i in input().split()])
for i in range(1, n + 1):
	if not l[i - 1] is i:
		cost += abs(l[i - 1] - i)
	else:
		continue
print(cost)


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


def main():
	n = int(input())
	lista = list(map(int, input().split()))
	lista.sort()
	total = 0.0
	for (i, e) in enumerate(lista):
		total += abs(e - (i + 1))
	print(int(total))
main()


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
b = list(range(1, n + 1))
a.sort()
b.sort()
c = 0
for i in range(n):
	c += abs(a[i] - b[i])
print(c)


def modulus(a):
	if a < 0:
		return -a
	else:
		return a
n = int(input())
a = list(map(int, input().split()))
a.sort()
sum = 0
for i in range(0, n):
	sum = sum + modulus(a[i] - (i + 1))
print(sum)


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


from sys import stdin, stdout
from sys import maxsize as INT_MAX
io = None

def main():
	global io
	io = Stdio()
	n = io.read_int()
	a = [io.read_int() for i in range(n)]
	a.sort()
	ans = 0
	for i in range(n):
		ans += abs(a[i] - i - 1)
	io.println(ans)

class Stdio:
	index = 0
	tokens = []

	def read_line(self):
		return stdin.readline()[:-1]

	def read(self):
		while self.index >= len(self.tokens):
			self.tokens = self.read_line().strip().split()
			num_empty_lines = 0
			if self.tokens == []:
				return None
			self.index = 0
		token = self.tokens[self.index]
		self.index += 1
		return token

	def read_int(self):
		return int(self.read())

	def read_float(self):
		return float(self.read())

	def read_char(self):
		return chr(self.read())

	def print(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))

	def println(self, *objectsToPrint):
		for _obj_ in objectsToPrint:
			stdout.write(str(_obj_))
		stdout.write('\n')
main()


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


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
c = 0
y = 1
for x in range(0, n):
	if a[x] > y:
		c = c + (a[x] - y)
	elif a[x] < y:
		c = c + (y - a[x])
	else:
		pass
	y += 1
print(c)


import math
import sys
import cmath
import string
import bisect
from itertools import combinations, permutations
from queue import Queue, LifoQueue, PriorityQueue
from collections import deque, Counter
n = int(input())
sum = 0
a = list1 = list(map(int, input().split()))
a.sort()
for i in range(n):
	sum += abs(i + 1 - a[i])
print(sum)


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


input()
print(sum((abs(i - a) for (i, a) in enumerate(sorted(map(int, input().split())), 1))))


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


import sys
import math

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


n = int(input())
li = [int(x) for x in input().split()]
li.sort()
check = [i for i in range(1, n + 1)]
add = [0]
sub = [0]
for i in range(n):
	vl = check[i] - li[i]
	if vl > 0:
		add.append(vl)
	elif vl < 0:
		sub.append(abs(vl))
print(sum(add) + sum(sub))


n = int(input())
c = list(map(int, input().split()))
a = []
p = set()
c.sort()
for i in range(n):
	if not c[i] in p or c[i] < 0 or c[i] > n:
		a.append(c[i])
	else:
		p.add(c[i])
l = 0
j = 0
for i in range(1, n + 1):
	if not i in p:
		l += abs(a[j] - i)
		j += 1
print(l)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

def main():
	try:
		n = int(input())
		l = list(map(int, input().split()))
		l.sort()
		su = 0
		for i in range(n):
			su += abs(i + 1 - l[i])
		print(su)
	except:
		pass
P = 1000000007

def search(l, x):
	(a, b) = (0, len(l) - 1)
	while a <= b:
		k = (a + b) // 2
		if l[k] == x:
			return k
		elif l[k] < x:
			a = k + 1
		else:
			b = k - 1
main()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	res = 0
	for i in range(1, n + 1):
		curr = arr[i - 1]
		need = abs(curr - i)
		res += need
	print(res)
	return
solve()


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


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
n = I()
a = L()
a.sort()
ans = sum([abs(a[i] - i - 1) for i in range(n)])
print(ans)


(n, moves) = (int(input()), 0)
for (i, a) in enumerate(sorted(map(int, input().split())), 1):
	moves += abs(i - a)
print(moves)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = szzz()
ans = 0
for (i, j) in enumerate(l):
	ans += abs(j - i - 1)
print(ans)


def main():
	n = int(input())
	a = sorted([int(c) for c in input().split()])
	ans = 0
	for (i, e) in enumerate(a, 1):
		ans += abs(e - i)
	print(ans)
main()


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


n = int(input())
a = list(map(int, input().split()))
tomodify = []
l = [None] + [0] * n
for i in range(1, n + 1):
	if 1 <= a[i - 1] <= n and l[a[i - 1]] == 0:
		l[a[i - 1]] = 1
	else:
		tomodify.append(a[i - 1])
tomodify.sort()
ans = 0
j = 0
for i in range(1, n + 1):
	if l[i] == 0:
		ans += abs(tomodify[j] - i)
		j += 1
print(ans)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
cnt = 0
for i in range(len(lst)):
	if lst[i] < i + 1:
		cnt += abs(i + 1 - lst[i])
	elif lst[i] > i + 1:
		cnt += abs(lst[i] - (i + 1))
print(cnt)


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


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


n = int(input())
p = list(map(int, input().split()))
total = 0
j = 1
for i in sorted(p):
	total += abs(i - j)
	j += 1
print(total)


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


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


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
n = int(input())
ans = 0
for (i, j) in zip(sorted(map(int, input().split())), range(1, n + 1)):
	ans += abs(j - i)
print(ans)


n = int(input())
l = [int(y) for y in input().split()]
l.sort()
ans = 0
c = 1
for i in range(n):
	ans += abs(c - l[i])
	c += 1
print(ans)


n = int(input())
mas = list(map(int, input().split(' ')))
mas.sort()
res = 0
for (i, x) in enumerate(mas):
	res += abs(i - x + 1)
print(res)


n = int(input())
p = sorted([int(x) for x in input().split()])
num = 0
for i in range(n):
	num = num + abs(p[i] - i - 1)
print(num)


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


from collections import deque
from math import ceil, floor, sqrt, gcd

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

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

def li():
	return list(mi())

def si():
	return input()
s = 0
n = ii()
a = li()
a.sort()
for i in range(1, n + 1):
	s += abs(i - a[i - 1])
print(s)


n = int(input())
values = [int(x) for x in input().split(' ')]
values.sort()
result = 0
for (i, x) in enumerate(values):
	result += abs(x - (i + 1))
print(result)


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


from sys import *
from collections import Counter
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = sorted(int_arr())
ct = 0
for i in range(n):
	ct += abs(arr[i] - (i + 1))
print(ct)


n = int(input())
L = sorted([int(k) for k in input().split()])
k = 0
for j in range(n):
	k += abs(L[j] - j - 1)
print(k)


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


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


import sys
limit = int(sys.stdin.readline())
arr = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
cnt = 0
for (index, x) in enumerate(range(limit)):
	if arr[x] < limit - index:
		cnt += limit - index - arr[x]
	elif arr[x] > limit - index:
		cnt += arr[x] - (limit - index)
sys.stdout.write(str(cnt))


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


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


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


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	a.sort()
	x = 0
	for i in range(n):
		x += abs(i + 1 - a[i])
	return x
print(go())


n = int(input())
nums = [(int(x), int(x) + n) for x in input().split()]
nums.sort(key=lambda x: x[1])
moves = 0
for i in range(1, n + 1):
	val = nums[i - 1][0]
	moves = moves + abs(i - val)
print(moves)


from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
index = 1
ans = 0
while A:
	a = A.pop()
	ans += abs(a - index)
	index += 1
print(ans)


(n, values, total) = (int(input()), list(sorted([int(i) for i in input().split()])), 0)
for i in range(n):
	total += abs(i + 1 - values[i])
print(total)


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


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


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
k = 1
count = 0
for i in range(n):
	if arr[i] < 0:
		count += abs(arr[i]) + k
	elif arr[i] >= n:
		count += arr[i] - k
	elif k <= arr[i]:
		count += arr[i] - k
	else:
		count += k - arr[i]
	k += 1
print(count)


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


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


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


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


n = map(int, input().split())
lista = list(map(int, input().split()))
lista = sorted(lista)
res = 0
for (k, num) in enumerate(lista):
	res += abs(k + 1 - num)
print(res)


n = int(input())
mass = sorted(list(map(int, input().split())))
k = 0
for i in range(n):
	if 1 <= mass[i] <= n:
		(mass[mass[i] - 1], mass[i]) = (mass[i], mass[mass[i] - 1])
for i in range(n):
	if mass[i] != i + 1:
		k += abs(i + 1 - mass[i])
		mass[i] = abs(i + 1 - mass[i])
print(k)


import sys
n = int(sys.stdin.readline())
a = sys.stdin.readline().strip()

def findMinSteps(n, a):
	a = a.split()
	a = [int(x) for x in a]
	a.sort()
	needElement = 1
	steps = 0
	for checkElement in a:
		if checkElement != needElement:
			steps += abs(checkElement - needElement)
		needElement += 1
	return steps
print(findMinSteps(n, a))


import sys
sys.setrecursionlimit(10000)
n = int(input())
arr = [int(x) for x in sys.stdin.readline().strip().split()]
arr = sorted(arr)
d = {}
count = 0
for i in range(0, n):
	count += abs(arr[i] - i - 1)
print(count)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
l.sort()
l = [0] + l
ans = 0
for i in range(1, n + 1):
	ans += abs(i - l[i])
print(ans)


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


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


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


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


n_elem = int(input())
numbers = [int(n) for n in input().split()]
numbers.sort()
moves = 0
for x in range(0, n_elem):
	moves += abs(x + 1 - numbers[x])
print(moves)


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


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


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


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


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


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


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


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


def preprocessing(x):
	global maxSize
	global myCount
	if x == 0:
		myCount += 1
		return 1
	elif x < 0:
		myCount += abs(x) + 1
		return 1
	elif x > maxSize:
		myCount += x - maxSize
		return maxSize
	return x
maxSize = int(input())
myCount = 0
user = list(map(lambda x: preprocessing(int(x)), input().split()))
user.sort()
for x in range(maxSize):
	myCount += abs(user[x] - (x + 1))
print(myCount)


n = int(input())
print(sum((abs(x - y) for (x, y) in enumerate(sorted(map(int, input().split())), 1))))


n = int(input())
nums = [int(x) for x in input().split()]
nums.sort()
desired = list(range(n + 1))[1:]
ans = 0
for i in range(n):
	ans += abs(nums[i] - desired[i])
print(ans)


n = int(input())
li = [int(x) for x in input().split(' ')]
li.sort()
ans = [int(x) for x in range(1, n + 1)]
j = 0
count = 0
for i in li:
	count += abs(ans[j] - i)
	j += 1
print(count)


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


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


n = int(input())
p = [int(x) for x in input().split(' ')]
p.sort()
c = 0
for (n, i) in enumerate(p):
	c += abs(n - i + 1)
print(c)


(n, val) = (int(input()), 0)
for (x, y) in zip(sorted((int(x) for x in input().split())), range(1, n + 1)):
	val += abs(x - y)
print(val)


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


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = intl()
	arr.sort()
	ans = 0
	b = [i for i in range(1, n + 1)]
	for i in range(n):
		ans += abs(arr[i] - b[i])
	print(ans)
start_time = time.time()
s = sieve(10 ** 6)
solve()


el = int(input())
ar = []
for i in input().split(' '):
	ar.append(int(i))
ar.sort()
count = 0
for i in range(len(ar)):
	count = count + abs(ar[i] - (i + 1))
print(count)


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
mod = 10 ** 9 + 7

def comp(x):
	return x[1]

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return -1
testCases = 1
for _ in range(testCases):
	n = vary(1)
	num = array_int()
	num.sort()
	ans = 0
	for i in range(n):
		if num[i] < i + 1:
			ans += i + 1 - num[i]
		elif num[i] > i + 1:
			ans += num[i] - (i + 1)
	print(ans)


a = int(input())
c = [int(i) for i in input().split()]
c = list(sorted(c))
m = 0
for i in range(a):
	if c[i] != i + 1:
		m = m + abs(i + 1 - c[i])
print(m)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = int(input())
a = sorted(list(map(int, input().split())))
ref = list((i + 1 for i in range(n)))
ans = 0
for i in range(n):
	ans += abs(ref[i] - a[i])
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
perelem = {}
work = []
for num in a:
	if num >= 1 and num <= n and (num not in perelem):
		perelem[num] = 1
	else:
		work.append(num)
currperm = 1
moves = 0
for i in range(len(work)):
	while currperm in perelem:
		currperm += 1
	moves += abs(currperm - work[i])
	perelem[currperm] = 1
print(moves)


total_number = int(input())
list_nums = sorted(map(int, input().split()))
least_actions = 0
for (index, num) in enumerate(list_nums, 1):
	if num == index:
		()
	if num > index:
		least_actions = least_actions + (num - index)
	if index > num:
		least_actions = least_actions + (index - num)
print(least_actions)


lens = int(input())
given = sorted([int(x) for x in input().split()])
needs = list(range(1, lens + 1))
moves = 0
while given:
	moves += abs(given.pop() - needs.pop())
print(moves)


import math
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
e = 1
sum = 0
for i in range(0, len(a)):
	sum = sum + abs(e - a[i])
	e = e + 1
print(sum)


(n, a) = (int(input()), sorted(map(int, input().split())))
print(sum((abs(n + 1 - ai) for (n, ai) in enumerate(a))))


m = int(input())
n = m
r = map(int, input().split())
f = list(r)
f.sort()
q = f[::-1]
l = len(q)
i = 0
count = 0
while i < l:
	y = q[i]
	if y > n:
		w = y - n
		count = count + w
	elif y < n:
		w = n - y
		count = count + w
	n = n - 1
	i += 1
print(count)


a = int(input())
b = [int(i) for i in input().split()]
b.sort()
s = 0
for (i, j) in zip(b, range(1, a + 1)):
	s += abs(j - i)
print(s)


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


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def main():
	n = int(input())
	arr = array()
	arr.sort()
	nxt = 1
	cnt = 0
	for i in range(n):
		cnt += abs(nxt - arr[i])
		nxt += 1
	print(cnt)
t = 1
for _ in range(t):
	main()


def main():
	n = int(input())
	print(sum((abs(a - b) for (a, b) in zip(sorted(map(int, input().split())), range(1, n + 1)))))
main()


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

def fun(x):
	global c
	c += 1
	return abs(x - c)
from math import *
(n, a, c) = (int(input()), sorted(arr_inp()), 0)
print(sum(map(fun, a)))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	a.sort()
	ans = 0
	for i in range(1, n + 1):
		ans += abs(i - a[i - 1])
	print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.sort()
count = 0
for i in range(n):
	count += max(arr[i], i + 1) - min(arr[i], i + 1)
print(count)


size = int(input().strip())
reqset = [0 for i in range(size + 1)]
numset = sorted(list(map(int, input().strip().split())))
i = 1
ans = 0
while i <= len(numset):
	ans += abs(numset[i - 1] - i)
	i += 1
print(ans)


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


def solution(a, n):
	a.sort()
	moves = 0
	k = 1
	for i in a:
		moves = moves + abs(k - i)
		k = k + 1
	print(moves)
n = int(input())
str_a = input().split(' ')
a = [int(num) for num in str_a]
solution(a, n)


def buildingPermutations(n, li):
	li.sort()
	moves = 0
	for i in range(n):
		moves += abs(i + 1 - li[i])
	return moves
n = int(input())
li = [int(x) for x in input().split()]
print(buildingPermutations(n, li))


x = int(input())
j = sorted([int(i) for i in list(input().split())])
javab = 0
for i in range(x):
	javab += abs(i + 1 - j[i])
print(javab)


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
n = I()
a = LI()
d = Counter(a)
b = []
e = defaultdict(int)
for i in d.keys():
	if i > 0 and i <= n:
		b += [i] * (d[i] - 1)
		e[i] = 1
	else:
		b += [i] * d[i]
b.sort()
c = []
for i in range(1, n + 1):
	if e[i] != 1:
		c += [i]
ans = 0
for i in range(len(c)):
	ans += abs(b[i] - c[i])
print(ans)


size = int(input())
data = list(map(int, input().split()))
data.sort()
minMoves = 0
i = 1
for element in data:
	minMoves += abs(element - i)
	i += 1
print(minMoves)


import sys
my_file = sys.stdin
n = int(my_file.readline())
a = [int(i) for i in my_file.readline().strip().split()]
a.sort()
b = list(range(1, n + 1))
turns = 0
for i in range(n):
	if a[i] < b[i]:
		turns += b[i] - a[i]
	elif a[i] > b[i]:
		turns += a[i] - b[i]
print(turns)


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


import os
import sys
from io import BytesIO, IOBase

def solution(arr, n):
	arr.sort()
	res = sum((abs(a - b) for (a, b) in zip(arr, range(1, n + 1))))
	write(res)

def main():
	n = r_int()
	arr = r_array()
	solution(arr, n)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())
main()


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


N = int(input())
A = [int(x) for x in input().split()]
A.sort()
B = [int(x) for x in range(1, N + 1)]
s = 0
for i in range(N):
	s += abs(A[i] - B[i])
print(int(s))


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


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


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


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


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


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


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
target = 1
ops = 0
for i in arr:
	ops += abs(target - i)
	target += 1
print(ops)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = iinput()
s = list(map(int, input().split()))
s.sort()
a = []
for i in range(1, n + 1):
	a.append(i)
count = 0
for i in range(n):
	if a[i] < s[i]:
		count += s[i] - a[i]
	elif a[i] > s[i]:
		count += a[i] - s[i]
print(count)


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
n = INT()
arr = LIST()
cnt = 0
arr.sort()
c = 1
for i in arr:
	cnt += abs(i - c)
	c += 1
print(cnt)


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


n = int(input())
per = [i for i in range(1, n + 1)]
li = sorted(list(map(int, input().split())))
ind = 0
c = 0
for i in li:
	c += abs(per[ind] - i)
	ind += 1
print(c)


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


count = map(int, input())
num_list = map(int, input().split())
num_list = sorted(num_list)
start = 1
total = 0
for i in num_list:
	total += abs(start - i)
	start += 1
print(total)


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


def main():
	n = read_int()
	A = read_ints()
	A.sort()
	total = 0
	for (i, x) in enumerate(A):
		total += abs(i + 1 - x)
	print(total)
from collections import *
MOD = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b, a % b)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))
main()


def main():
	n = int(input()) + 1
	l = [True] * n
	l[0] = False
	tail = []
	for a in map(int, input().split()):
		if 0 < a < n and l[a]:
			l[a] = False
		else:
			tail.append(a)
	tail.sort()
	print(sum((abs(a - b) for (a, b) in zip((i for (i, _) in enumerate(l) if _), tail))))

def __starting_point():
	main()
__starting_point()


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
sm = 0
for (i, j) in zip(sorted(il()), range(1, n + 1)):
	sm += abs(i - j)
print(sm)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = [i for i in range(1, n + 1)]
print(sum((abs(ans[i] - l[i]) for i in range(n))))


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


import sys
from collections import Counter
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
N = inp()
A = inlt()
A.sort()
out = 0
for i in range(1, N + 1):
	out += abs(A[i - 1] - i)
print(out)


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


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


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf
n = iinp()
a = lmp()
a.sort()
ans = 0
for i in range(n):
	ans += abs(a[i] - i - 1)
print(ans)


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


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


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


def build_permutation(l):
	s = sorted(l)
	p = []
	for i in range(1, len(l) + 1):
		p.append(i)
	sum = 0
	for j in range(len(l)):
		if s[j] >= p[j]:
			sum += s[j] - p[j]
		else:
			sum += p[j] - s[j]
	print(sum)
n = int(input())
l = [int(x) for x in input().split()]
build_permutation(l)


n = int(input())
arr = sorted([int(i) for i in input().split()])
res = [abs(i - arr[i - 1]) for i in range(1, 1 + n)]
print(sum(res))


import sys
t = sys.stdin.buffer.readline()
t = int(t)
ls = list(map(int, input().split()))
arr = sorted(ls)
count = 0
for i in range(t):
	count += abs(i + 1 - arr[i])
print(count)


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


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
print(sum((abs(x - i - 1) for (i, x) in enumerate(arr))))


a = int(input())
b = [int(b) for b in input().split()]
b.sort()
c = 1
d = 0
for i in range(a):
	d += abs(b[i] - c)
	c += 1
print(d)


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


input()
row = input().rstrip('\n')
arr = row.split(' ')
arr = list(map(lambda x: int(x), arr))
arr.sort()
ans = 0
for (i, v) in enumerate(arr):
	if i + 1 > v:
		ans += i + 1 - v
	elif i + 1 < v:
		ans += v - (i + 1)
print(ans)


n = int(input())
a = list(map(int, input().strip().split()))
a.sort()
l = 1
p = 0
for i in range(0, n):
	d = l - a[i]
	if d < 0:
		d = d * -1
	p = p + d
	l += 1
print(p)


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


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


import sys
import math
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
a.sort()
res = 0
for i in range(n):
	res += int(math.fabs(i + 1 - a[i]))
print(res)


n = int(input())
i = sorted(list(map(int, input().split())))
print(sum((abs(j + 1 - x) for (j, x) in enumerate(i))))


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


def steps():
	n = int(input())
	array = [int(x) for x in input().split(' ')]
	array.sort()
	sum = 0
	for x in range(n):
		diff = abs(array[x] - (x + 1))
		sum = sum + diff
	print(sum)
steps()


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


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


def main():
	n = int(input())
	ans = 0
	for (i, j) in zip(sorted(map(int, input().split())), range(1, n + 1)):
		ans += abs(j - i)
	print(ans)
main()


n = int(input())
array = [0]
b = list(map(int, input().split()))
b.sort()
array.extend(b)
solution = 0
for pos in range(1, n + 1):
	solution += abs(pos - array[pos])
print(solution)


n = int(input())
array = [int(x) for x in input().split(' ')]
array.sort()
t = 0
for i in range(n):
	t += abs(array[i] - (i + 1))
print(t)


n = int(input())
A = [int(a) for a in input().split()]
A.sort()
ans = 0
curr = 1
for i in range(n):
	if A[i] < curr:
		ans += abs(curr - A[i])
		A[i] = curr
	elif A[i] > curr:
		ans += abs(A[i] - curr)
		A[i] = curr
	curr += 1
print(ans)


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


input()
a = [int(x) for x in input().strip().split(' ')]
a.sort()
ans = 0
for i in range(len(a)):
	ans += abs(a[i] - i - 1)
print(ans)


d = int(input())
e = [int(i) for i in input().split()]
e.sort()
s = [int(i) for i in range(1, d + 1, 1)]
answer = 0
for i in range(d):
	if e[i] != s[i]:
		answer += abs(e[i] - s[i])
print(answer)


a = int(input())
s = 0
for i in sorted(map(int, input().split()), reverse=True):
	s += abs(a - i)
	a -= 1
print(s)


N = 3 * pow(10, 5) + 1
n = int(input())
inp = input().split()
inp = [int(i) for i in inp]
flag = []
for i in range(N):
	flag.append(False)
a = []
b = []
ans = 0
for i in range(n):
	if inp[i] >= 1 and inp[i] < N and (inp[i] <= n):
		if flag[inp[i]] == False:
			flag[inp[i]] = True
		else:
			a += [inp[i]]
	else:
		a += [inp[i]]
a.sort()
for i in range(1, n + 1):
	if flag[i] == False:
		b += [i]
for i in range(len(a)):
	ans += abs(a[i] - b[i])
print(ans)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x
for t in range(1):
	n = int(input())
	nums = list(map(int, input().split()))
	nums.sort()
	sumi = 0
	for i in range(1, n + 1):
		sumi += abs(i - nums[i - 1])
	print(sumi)


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


def getPermu(arr, n):
	tempArr = [i for i in range(1, n + 1)]
	arr.sort()
	tempArr.sort()
	total = 0
	for j in range(0, n):
		total += abs(arr[j] - tempArr[j])
	return total
n = int(input())
arr = list(map(int, input().split()))
print(getPermu(arr, n))


from sys import stdin, stdout
n = int(stdin.readline())
a = sorted(map(int, stdin.readline().split()))
s = 0
for i in range(n):
	s += abs(a[i] - (i + 1))
print(s)


from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def time_t():
	print('Current date and time: ', datetime.datetime.now())
	print('Current year: ', datetime.date.today().strftime('%Y'))
	print('Month of year: ', datetime.date.today().strftime('%B'))
	print('Week number of the year: ', datetime.date.today().strftime('%W'))
	print('Weekday of the week: ', datetime.date.today().strftime('%w'))
	print('Day of year: ', datetime.date.today().strftime('%j'))
	print('Day of the month : ', datetime.date.today().strftime('%d'))
	print('Day of week: ', datetime.date.today().strftime('%A'))

def ip():
	return int(input())

def sip():
	return input()

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

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def prime(n):
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
arr = lip()
arr.sort()
count = 0
p = 1
for i in range(n):
	count += abs(p - arr[i])
	p += 1
print(count)


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


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


n = int(input())
ar = [int(i) for i in input().split()]
ar = sorted(ar)
c = 0
for (i, j) in enumerate(ar):
	if i + 1 >= j:
		c += i + 1 - j
	else:
		c += j - (i + 1)
print(c)


from sys import stdin, stdout

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

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
n = INI()
A = sorted(INL())
ans = 0
for _ in range(n):
	ans += abs(_ + 1 - A[_])
OPS(ans)


n = int(input())
inp = sorted(list(map(int, input().split())))
print(sum([abs(i + 1 - inp[i]) for i in range(n)]))