You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".

Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to $\frac{n}{2}$.

In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.

Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).


-----Input-----

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard. 

The second line of the input contains $\frac{n}{2}$ integer numbers $p_{1}, p_{2}, \ldots, p_{\frac{n}{2}}$ (1 ≤ p_{i} ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.


-----Output-----

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.


-----Examples-----
Input
6
1 2 6

Output
2

Input
10
1 2 3 4 5

Output
10



-----Note-----

In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.

In the second example the possible strategy is to move $5 \rightarrow 9$ in 4 moves, then $4 \rightarrow 7$ in 3 moves, $3 \rightarrow 5$ in 2 moves and $2 \rightarrow 3$ in 1 move.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import sys
import math

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

def fun():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	sum1 = sum2 = 0
	for i in range(int(n / 2)):
		sum1 += abs(arr[i] - (i * 2 + 1))
		sum2 += abs(arr[i] - (i * 2 + 2))
	print(min(sum1, sum2))
fun()


import os, sys, math

def main():
	T = int(input())
	l = [int(x) - 1 for x in input().split()]
	l.sort()
	diffs_1 = [2 * i - l[i] for i in range(len(l))]
	diffs_abs_1 = [abs(x) for x in diffs_1]
	d1 = sum(diffs_abs_1)
	diffs_2 = [2 * i + 1 - l[i] for i in range(len(l))]
	diffs_abs_2 = [abs(x) for x in diffs_2]
	d2 = sum(diffs_abs_2)
	print(min(d1, d2))

def debug(*args):
	if 'DEBUG' in os.environ:
		print(*args)
main()


n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
a.sort()
for i in range(n // 2):
	ans1 += abs(i * 2 + 1 - a[i])
	ans2 += abs(i * 2 + 2 - a[i])
print(min(ans1, ans2))


n = int(input())
m = map(int, input().split())
ret1 = 0
ret2 = 0
for (i, v) in enumerate(sorted(m)):
	ret1 += abs(v - i * 2 - 1)
	ret2 += abs(v - i * 2 - 2)
print(min(ret1, ret2))


n = int(input())
str = input()
intvec = str.split(' ')
mymap = map(int, intvec)
data = list()
for itr in mymap:
	data.append(itr)
data.sort()
cnt = 1
cost_odd = 0
cost_even = 0
for itr in data:
	cost_odd = abs(itr - cnt) + cost_odd
	cost_even = abs(itr - cnt - 1) + cost_even
	cnt = cnt + 2
print(min(cost_odd, cost_even))


import math
n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
ans1 = 0
ans2 = 0
for i in range(n // 2):
	ans1 += math.fabs(a[i] - (i * 2 + 1))
	ans2 += math.fabs(a[i] - (i * 2 + 2))
print(int(min(ans1, ans2)))


n = int(input())
a = sorted(list(map(int, input().split())))
(ansA, ansB) = (0, 0)
for i in range(n // 2):
	(u, v) = (i * 2 + 1, i * 2 + 2)
	ansA += abs(a[i] - u)
	ansB += abs(a[i] - v)
print(min(ansA, ansB))


import math
n = int(input())
cnt0 = 0
cnt1 = 0
p = input().split()
for i in range(n // 2):
	p[i] = int(p[i]) - 1
p.sort()
for i in range(n // 2):
	cnt0 += math.fabs(p[i] - 2 * i)
	cnt1 += math.fabs(p[i] - 2 * i - 1)
print(int(min(cnt0, cnt1)))


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	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())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = inlt()
	a.sort()
	ans_odd = ans_even = 0
	for i in range(n // 2):
		ans_odd += abs(a[i] - i * 2 - 1)
		ans_even += abs(a[i] - i * 2 - 2)
	print(min(ans_odd, ans_even))


n = int(input())
pi = list(map(int, input().split()))
pi.sort()
pi2 = [0] * (n // 2)
for i in range(n // 2):
	pi2[i] = pi[i]
ans = 0
for i in range(n // 2):
	i = i * 2
	ans += abs(pi[i // 2] - 1 - i)
ans2 = 0
for i in range(n // 2):
	i = i * 2 + 1
	ans2 += abs(i - (pi2[i // 2] - 1))
print(min(ans, ans2))


i1 = int(input())
ar = list(map(int, input().split()))
sm1 = 0
sm2 = 0
ar.sort()
for i in range(1, i1, 2):
	sm2 += abs(i - ar[int(i / 2)])
ar.sort(reverse=True)
for i in range(0, i1, 2):
	sm1 += abs(i1 - i - ar[int(i / 2)])
print(min(sm1, sm2))


n = int(input())
p = list(sorted(map(int, input().split())))
s1 = s2 = 0
for i in range(n // 2):
	k = 1 + i * 2
	s1 += abs(p[i] - k)
	s2 += abs(p[i] - k - 1)
print(min(s1, s2))


n = int(input())
integer_numbers = input()
init_position = [int(x) - 1 for x in integer_numbers.split()]
init_position.sort()
sum_B = 0
for i in range(len(init_position)):
	sum_B += abs(init_position[i] - 2 * i)
sum_W = 0
for i in range(len(init_position)):
	sum_W += abs(init_position[i] - 2 * i - 1)
print(min(sum_B, sum_W))


n = int(input())
p = list(map(int, input().split()))
p.sort()
ao = list(range(1, n, 2))
ae = list(range(2, n + 1, 2))
do = [abs(p[i] - ao[i]) for i in range(len(p))]
de = [abs(p[i] - ae[i]) for i in range(len(p))]
print(min(sum(do), sum(de)))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
fit1 = [2 * i for i in range(1, n // 2 + 1)]
fit2 = [2 * i - 1 for i in range(1, n // 2 + 1)]
print(min(sum([abs(a[i] - fit1[i]) for i in range(n // 2)]), sum([abs(a[i] - fit2[i]) for i in range(n // 2)])))


N = int(input())
r1 = 0
r2 = 0
arr = sorted(list(map(int, input().split())))
for (i, j) in enumerate(range(1, N + 1, 2)):
	r1 += abs(arr[i] - j)
for (i, j) in enumerate(range(2, N + 1, 2)):
	r2 += abs(arr[i] - j)
print(min(r1, r2))


def main():
	N = int(input())
	P = list(map(int, input().split()))
	P.sort()
	(even, odd) = (0, 0)
	for (i, j) in enumerate(range(2, N + 1, 2)):
		even += abs(P[i] - j)
	for (i, j) in enumerate(range(1, N + 1, 2)):
		odd += abs(P[i] - j)
	print(min(even, odd))
main()


N = int(input())
a = list(map(int, input().split()))
a = sorted(a)
num1 = 0
num2 = 0
for i in range(N // 2):
	num1 += abs(a[i] - (2 * i + 2))
	num2 += abs(a[i] - (2 * i + 1))
print(min(num1, num2))


def main():
	n = int(input())
	pos = [int(x) for x in input().split()]
	pos = sorted(pos)
	odd_pos = [x for x in range(1, n + 1, 2)]
	even_pos = [x for x in range(2, n + 1, 2)]
	odd_move = sum([abs(x - y) for (x, y) in zip(odd_pos, pos)])
	even_move = sum([abs(x - y) for (x, y) in zip(even_pos, pos)])
	print(min(odd_move, even_move))
main()


n = int(input())
a = sorted(map(int, input().split()))
(r1, r2) = (0, 0)
for (i, x) in enumerate(a):
	r1 += abs(x - 1 - 2 * i)
	r2 += abs(x - 1 - 2 * i - 1)
print(min(r1, r2))


n = int(input())
n >>= 1
(sum1, sum2) = (0, 0)
a = list(map(int, input().split()))
a.sort()
for i in range(n):
	sum1 += abs(a[i] - (i * 2 + 1))
	sum2 += abs(a[i] - (i + 1) * 2)
print(min(sum1, sum2))


n = int(input())
P = input().split(' ')
for i in range(n // 2):
	P[i] = int(P[i])
P.sort()
B = [0] * (n // 2)
W = [0] * (n // 2)
for i in range(n // 2):
	B[i] = 2 * i + 1
	W[i] = 2 * i + 2
b = 0
w = 0
for i in range(n // 2):
	b += abs(B[i] - P[i])
	w += abs(W[i] - P[i])
print(min(b, w))


n = int(input())
m = n - 1
pos = reversed(sorted(map(int, input().split())))
odd = 0
even = 0
for p in pos:
	even += abs(n - p)
	n -= 2
	odd += abs(m - p)
	m -= 2
print(min(odd, even))


i = int(input())
l = list(sorted(list(map(int, input().split())), reverse=True))
c = i
t = 0
for x in l:
	t += abs(c - x)
	c -= 2
p = i - 1
g = 0
for y in l:
	g += abs(p - y)
	p -= 2
print(min(t, g))


n = int(input().strip())
pis = list(map(int, input().strip().split()))
pis.sort()
w1 = sum((abs(2 * i + 1 - p) for (i, p) in enumerate(pis)))
w2 = sum((abs(2 * i + 2 - p) for (i, p) in enumerate(pis)))
print(min(w1, w2))


n = int(input())
numbers = list(map(int, input().split()))
numbers.sort()
allWhite = 0
allBlack = 0
for i in range(len(numbers)):
	allWhite += abs(numbers[i] - 2 * i - 1)
	allBlack += abs(numbers[i] - 2 * i - 2)
print(min(allWhite, allBlack))


def calc(num):
	ans = 0
	for i in range(len(l)):
		ans += abs(l[i] - 1 - (2 * i + num))
	return ans
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(min(calc(0), calc(1)))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
sum1 = 0
j = 1
k = 2
sum2 = 0
for i in range(len(arr)):
	sum1 += abs(j - arr[i])
	sum2 += abs(k - arr[i])
	j += 2
	k += 2
print(min(sum1, sum2))


n = int(input())
a = sorted(map(int, input().split()))
(o, e) = (0, 0)
for i in range(n // 2):
	o += abs(a[i] - (i * 2 + 2))
	e += abs(a[i] - (i * 2 + 1))
print(min(o, e))


R = lambda : map(int, input().split())
n = int(input())
p = list(R())
p.sort()
s1 = s2 = 0
for i in range(n // 2):
	s1 += abs(p[i] - 2 * i - 1)
	s2 += abs(p[i] - 2 * i - 2)
print(min(s1, s2))


n = int(input())
pos = list(map(int, input().split(' ')))
pos = sorted(pos)
countStepB = 0
for i in range(len(pos)):
	cur = pos[i]
	if cur != 1 + i * 2:
		countStepB += abs(1 + i * 2 - cur)
countStepW = 0
for i in range(len(pos)):
	cur = pos[i]
	if cur != 2 + i * 2:
		countStepW += abs(2 + i * 2 - cur)
print(min(countStepB, countStepW))


(ans1, ans2) = (0, 0)
n = int(input())
vals = input().split(' ')
vals = [int(x) for x in vals]
vals.sort()
i = 1
for k in vals:
	ans1 += abs(i - k)
	ans2 += abs(i + 1 - k)
	i += 2
print(min(ans1, ans2))


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


n = int(input())
arr = [int(i) for i in input().strip().split()]
arr.sort()
brr = [i for i in arr]
ans = 0
for i in range(n, 0, -2):
	ele = arr.pop()
	ans += abs(i - ele)
ans2 = 0
for i in range(n - 1, 0, -2):
	ele = brr.pop()
	ans2 += abs(i - ele)
print(min(ans, ans2))


n = int(input())
a = list(map(int, input().split(' ')))
a = sorted(a)
x = 0
y = 0
for i in range(n // 2):
	x += abs(a[i] - i * 2 - 1)
	y += abs(a[i] - i * 2 - 2)
print(min(x, y))


def main():
	n = int(input())
	arr = [int(t) for t in input().split()]
	arr = sorted(arr)
	val = 1
	step = 2
	cnt1 = 0
	for item in arr:
		if item != val:
			cnt1 += abs(item - val)
		val += step
	val = 2
	cnt2 = 0
	for item in arr:
		if item != val:
			cnt2 += abs(item - val)
		val += step
	print(min(cnt1, cnt2))
main()


n = input()
numbers = sorted(map(int, input().split()))
(black, white) = (0, 0)
for (i, number) in enumerate(numbers, 1):
	black += abs(number - (i * 2 - 1))
	white += abs(number - i * 2)
print(min(black, white))


import sys

def main():
	n = int(sys.stdin.readline())
	p = list(map(int, sys.stdin.readline().split()))
	chess = [1 if i + 1 in p else 0 for i in range(n)]
	res = n * n
	first = chess[0]
	for j in [chess, chess[::-1]]:
		tmp = 0
		(piece, free) = ([], [])
		for i in range(n):
			if i % 2 and first == j[i]:
				continue
			elif i % 2:
				free.append(i)
			elif first == j[i]:
				piece.append(i)
		for i in range(len(free)):
			tmp += abs(free[i] - piece[i])
		res = min(tmp, res)
	print(res)
main()


n = int(input().rstrip())
pos = list(map(int, input().rstrip().split()))
pos = sorted(pos)
ans1 = 0
ans2 = 0
for i in range(len(pos)):
	ans1 += abs(2 * (i + 1) - 1 - pos[i])
for i in range(len(pos)):
	ans2 += abs(2 * (i + 1) - pos[i])
if n == 2:
	print(0)
else:
	print(min(ans1, ans2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
d0 = 0
for i in range(0, n // 2):
	d0 += abs(a[i] - (i * 2 + 2))
d1 = 0
for i in range(0, n // 2):
	d1 += abs(a[i] - (i * 2 + 1))
print(min(d0, d1))


n = int(input())
positions = []
positions += [int(x) for x in input().split(' ')]
positions = list(reversed(sorted(positions)))
odds = list(reversed(list(range(1, n, 2))))
evens = list(reversed(list(range(2, n + 2, 2))))
sum_odds = 0
for p in positions:
	sum_odds += abs(p - odds[0])
	odds.pop(0)
sum_evens = 0
for p in positions:
	sum_evens += abs(p - evens[0])
	evens.pop(0)
print(min(sum_odds, sum_evens))


n = int(input())
s = [int(x) for x in input().split()]
s.sort()
B = [1 for x in range(n // 2)]
for i in range(1, len(B)):
	B[i] = B[i - 1] + 2
W = [2 for x in range(n // 2)]
for i in range(1, len(W)):
	W[i] = W[i - 1] + 2
s1 = 0
s2 = 0
k = 0
for elem in B:
	s1 += abs(elem - s[k])
	k += 1
k = 0
for elem in W:
	s2 += abs(elem - s[k])
	k += 1
print(min(s1, s2))


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	P = list(map(int, input().split()))
	P.sort()
	ans1 = 0
	ans2 = 0
	for (i, p) in enumerate(P):
		ans1 += abs(i * 2 - (p - 1))
		ans2 += abs(i * 2 + 1 - (p - 1))
	print(min(ans1, ans2))
main()


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


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

def getTransIntList(n):
	first = getIntList()
	m = len(first)
	result = [[0] * n for _ in range(m)]
	for i in range(m):
		result[i][0] = first[i]
	for j in range(1, n):
		curr = getIntList()
		for i in range(m):
			result[i][j] = curr[i]
	return result
n = int(input())
p = getIntList()
p.sort()
result1 = 0
for (i, x) in enumerate(p):
	result1 += abs(x - (2 * i + 1))
result2 = 0
for (i, x) in enumerate(p):
	result2 += abs(x - (2 * i + 2))
print(min(result1, result2))


n = int(input())
piece = list(map(int, input().split()))
piece.sort()
a = []
b = []
temp = 0
for i in range(n // 2):
	temp += 2
	a.append(0 + temp)
	b.append(-1 + temp)
min1 = 0
for (j, k) in zip(a, piece):
	min1 += abs(j - k)
min2 = 0
for (j, k) in zip(piece, b):
	min2 += abs(j - k)
if min1 < min2:
	print(min1)
else:
	print(min2)


n = int(input())
(r1, r2) = (0, 0)
p = list(map(int, input().split()))
p.sort()
for i in range(n // 2):
	r1 += abs(2 * i + 1 - p[i])
	r2 += abs(2 * i + 2 - p[i])
print(min(r1, r2))


n = int(input())
a = sorted(list(map(int, input().split())))
(k1, k2, i, a1, a2) = (1, 2, 0, 0, 0)
while i < len(a):
	if a[i] > k1:
		a1 += a[i] - k1
	else:
		a1 += k1 - a[i]
	if a[i] > k2:
		a2 += a[i] - k2
	else:
		a2 += k2 - a[i]
	i += 1
	k1 += 2
	k2 += 2
print(min(a1, a2))


n = int(input())
p = sorted(map(int, input().split()))
print(min((sum((abs(x - i) for (x, i) in zip(p, range(s, n + 1, 2)))) for s in (1, 2))))


n = int(input())
p = sorted([int(i) for i in input().split()])
ans1 = 0
cur = 1
for i in p:
	ans1 += abs(cur - i)
	cur += 2
ans2 = 0
cur = 2
for i in p:
	ans2 += abs(cur - i)
	cur += 2
print(min(ans1, ans2))


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


n = int(input())
p = list(map(int, input().split()))
p = list(sorted(p))
ans = n * n
for i in range(1, 3):
	cnt = 0
	for j in range(n // 2):
		cnt += abs(2 * j + i - p[j])
	ans = min(ans, cnt)
print(ans)


t = int(input())
li = [int(x) for x in input().split()]
li.sort()
odd = 0
even = 0
oddLi = [x for x in range(1, t + 1, 2)]
evenLi = [x for x in range(2, t + 1, 2)]
for i in range(t // 2):
	odd += abs(li[i] - oddLi[i])
	even += abs(li[i] - evenLi[i])
print(min(odd, even))


m = int(input()) // 2
p = list(map(int, input().split()))
p = sorted(p)
e = 0
o = 0
for i in range(m):
	e += abs(2 * i + 1 - p[i])
	o += abs(2 * i + 2 - p[i])
print(min(e, o))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
n = n // 2
s_1 = 0
s_2 = 0
nech = 1
chet = 2
for i in range(n):
	s_1 = s_1 + abs(nech - arr[i])
	nech += 2
	s_2 = s_2 + abs(chet - arr[i])
	chet += 2
print(min(s_1, s_2))


import os
import sys
import math

def solve(n, inpArray):
	inpArray.sort()
	i = 0
	(odds, evens) = (0, 0)
	while 2 * i < n:
		odds += abs(inpArray[i] - (2 * i + 1))
		evens += abs(inpArray[i] - (2 * i + 2))
		i += 1
	return min(odds, evens)
n = int(input())
inpArray = input().split()
inpArray = [int(i) for i in inpArray]
print(solve(n, inpArray))


n = int(input())
table = sorted(list(map(int, input().split())))
sum = 0
for i in table:
	sum += i
avg = sum / (n / 2)
if avg < n / 2 + 0.5:
	pos = 1
else:
	pos = 2
sm = 0
for i in table:
	sm += abs(i - pos)
	pos += 2
print(sm)


n = int(input())
p = sorted(map(int, input().split()))
ans1 = 0
ans2 = 0
for (i, j) in enumerate(p):
	ans1 += abs(1 + i * 2 - j)
	ans2 += abs(2 + i * 2 - j)
print(min(ans1, ans2))


n = int(input())
s = [int(x) for x in input().split()]
s.sort()
sum_even = 0
sum_odd = 0
for (i, k) in enumerate(s):
	sum_even += abs(k - (i * 2 + 2))
for (i, k) in enumerate(s):
	sum_odd += abs(k - (i * 2 + 1))
print(min(sum_even, sum_odd))


n = int(input())
inp = [int(j) for j in input().split()]
inp.sort()
owd = 0
evn = 0
for i in range(int(n / 2)):
	owd += abs(2 * i + 1 - inp[i])
	evn += abs(2 * i + 2 - inp[i])
print(min(owd, evn))


def f(n, p, p2):
	ans = 0
	for (i, j) in zip(p, p2):
		ans += abs(i - j)
	return ans
n = int(input())
p = sorted(list(map(int, input().split(' '))))
odd = [2 * i + 1 for i in range(n // 2)]
even = [i + 1 for i in odd]
print(min(f(n, p, odd), f(n, p, even)))


from heapq import heappush, heappop
n = int(input())
(u0, u1) = (1, 2)
(m0, m1) = (0, 0)
a = []
for i in input().split():
	heappush(a, int(i))
for i in range(n // 2):
	i = heappop(a)
	m0 += abs(i - u0)
	u0 += 2
	m1 += abs(i - u1)
	u1 += 2
print(min(m0, m1))


from collections import defaultdict
_ = int(input())
ps = list(map(int, input().split()))
ps.sort()
even = list(range(2, _ + 1, 2))
odd = list(range(1, _, 2))
even_sum = 0
odd_sum = 0
for i in range(len(ps)):
	even_sum += abs(even[i] - ps[i])
	odd_sum += abs(odd[i] - ps[i])
print(min(even_sum, odd_sum))


n = int(input())
L = list(map(int, input().split()))
L.sort()
z1 = 1
z2 = 2
s0 = 0
s1 = 0
for i in L:
	s0 += abs(i - z1)
	s1 += abs(i - z2)
	z1 += 2
	z2 += 2
print(min(s0, s1))


import sys

def mp():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = sorted(list(mp()))
w = 0
i = 1
b = 0
j = 2
for x in range(n // 2):
	w += abs(a[x] - i)
	b += abs(a[x] - j)
	i += 2
	j += 2
print(min(w, b))


n = int(input())
li = input().split()
for i in range(0, len(li)):
	li[i] = int(li[i])
li.sort()
sum1 = 0
p1 = 1
sum2 = 0
p2 = 2
for i in li:
	sum1 += abs(p1 - i)
	sum2 += abs(p2 - i)
	p1 += 2
	p2 += 2
print(min(sum1, sum2))


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


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
c1 = 0
c2 = 0
for i in range(n // 2):
	p = abs(l[i] - 2 * i - 1)
	c1 += p
for i in range(n // 2):
	c2 += abs(l[i] - (i + 1) * 2)
print(min(c1, c2))


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)
n = int(input())
x = sorted(map(int, input().split()))
(a, b) = (0, 0)
for i in range(n // 2):
	a += abs(x[i] - 2 * i - 1)
	b += abs(x[i] - 2 * i - 2)
print(min(a, b))


n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr.sort(reverse=True)
count = n
total = 0
total1 = 0
for i in range(len(arr)):
	l = abs(count - arr[i])
	count = count - 2
	total = total + l
count1 = n - 1
for i in range(len(arr)):
	l = abs(count1 - arr[i])
	count1 = count1 - 2
	total1 = total1 + l
min1 = min(total, total1)
print(min1)


n = int(input())
p = [int(v) for v in input().split()]
p.sort()
a = sum((abs(pp - ii) for (ii, pp) in zip(list(range(1, n + 1, 2)), p)))
b = sum((abs(pp - ii) for (ii, pp) in zip(list(range(2, n + 1, 2)), p)))
print(min(a, b))


n = int(input())
pos = list(map(int, input().split(' ')))
pos.sort()
(dp, di) = (0, 0)
impar = range(1, n, 2)
par = range(2, n + 1, 2)
for i in range(len(pos)):
	p = par[i]
	po = pos[i]
	im = impar[i]
	dp += p - po if p - po >= 0 else po - p
	di += po - im if po - im >= 0 else im - po
print(min([dp, di]))


n = int(input())
ls = list(map(int, input().split()))
ls.sort()
even = [2 * i + 2 for i in range(n // 2)]
odd = [2 * i + 1 for i in range(n // 2)]
d1 = d2 = 0
for i in range(n // 2):
	d1 += abs(even[i] - ls[i])
	d2 += abs(odd[i] - ls[i])
print(min(d1, d2))


n = int(input())
fig = list(map(int, input().split()))
turn1 = 0
turn2 = 0
fig.sort()
for i in range(n // 2):
	turn1 += abs(fig[i] - (i * 2 + 1))
	turn2 += abs(fig[i] - (i * 2 + 2))
print(min(turn1, turn2))


n = int(input())
givenConfig = [int(x) for x in input().split()]
sortedConfig = givenConfig
sortedConfig.sort()
moves = 0
for i in range(len(givenConfig)):
	moves += abs(givenConfig[i] - sortedConfig[i])
poss1 = [i for i in range(1, n) if i % 2 != 0]
poss2 = [i for i in range(1, n + 1) if i % 2 == 0]
moves1 = 0
for (i, vals) in enumerate(givenConfig):
	moves1 += abs(poss1[i] - vals)
moves2 = 0
for (i, vals) in enumerate(givenConfig):
	moves2 += abs(poss2[i] - vals)
print(min(moves1 + moves, moves2 + moves))


n = int(input())
a = list(map(int, input().split()))
idx = []
for i in range(1, n // 2 + 1):
	idx.append(2 * i + 1)
a.sort()
s1 = 0
s2 = 0
for i in range(0, n // 2):
	s1 += abs(a[i] - 2 * i - 1)
	s2 += abs(a[i] - 2 * i - 2)
print(min(s1, s2))


count = int(input())
array = list(map(int, input().split()))
n = 0
for elem in array:
	if elem % 2 == 0:
		n += 1
count1 = count // 2
array1 = list()
array2 = list()
s1 = 0
s2 = 0
for elem in range(count):
	if elem + 1 in array:
		for elem1 in range(count):
			if not elem1 + 1 in array1 and elem1 % 2 == 0:
				array1.append(elem1 + 1)
				s1 = s1 + abs(elem1 - elem)
				break
		for elem1 in range(count):
			if not elem1 + 1 in array2 and elem1 % 2 == 1:
				array2.append(elem1 + 1)
				s2 = s2 + abs(elem1 - elem)
				break
print(min(s1, s2))


def mod(a):
	if a >= 0:
		return a
	return -a
n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
(cb, cw) = (0, 0)
for i in range(len(a)):
	cb += mod(2 * i + 1 - a[i])
	cw += mod(2 * i + 2 - a[i])
print(min(cb, cw))


n = int(input())
arr = [int(x) for x in input().split()]
moves1 = 0
moves2 = 0
arr.sort()
count = n // 2 - 1
for i in range(n, 0, -1):
	if i % 2 == 0:
		moves1 += abs(i - arr[count])
	else:
		moves2 += abs(i - arr[count])
		count -= 1
print(min(moves1, moves2))


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	odd_sum = 0
	even_sum = 0
	for i in range(n // 2):
		odd_sum += abs(a[i] - (i * 2 + 1))
		even_sum += abs(a[i] - (i * 2 + 2))
	if odd_sum > even_sum:
		print(even_sum)
	else:
		print(odd_sum)
main()


n = int(input())
pieces = list(map(int, input().split(' ')))
pieces.sort()

def even():
	diffEven = 0
	for i in range(len(pieces)):
		diffEven += abs(pieces[i] - (i + 1) * 2)
	return diffEven

def odd():
	diffOdd = 0
	for j in range(len(pieces)):
		diffOdd += abs(pieces[j] - (j * 2 + 1))
	return diffOdd
white = even()
black = odd()
print(min(black, white))


n = input()
pos = sorted([int(x) for x in input().split(' ')])
ans1 = ans2 = 0
i = 1
for item in pos:
	ans1 += abs(item - i)
	ans2 += abs(item - i - 1)
	i += 2
print(min(ans1, ans2))


n = int(input())
a = sorted(map(int, input().split()))
r1 = sum((abs(a[i] - 2 * i - 1) for i in range(n // 2)))
r2 = sum((abs(a[i] - 2 * i - 2) for i in range(n // 2)))
print(min(r1, r2))


(n, p) = (int(input()), sorted(map(int, input().split())))
b = sum((abs(2 * i + 1 - pi) for (i, pi) in enumerate(p)))
w = sum((abs(2 * i + 2 - pi) for (i, pi) in enumerate(p)))
print(min(b, w))


def get_ints():
	return list(map(int, input().split()))
N = int(input())
a = get_ints()
a = sorted(a)
g = sum([abs(a[i] - (2 * i + 1)) for i in range(N // 2)])
h = sum([abs(a[i] - (2 * i + 2)) for i in range(N // 2)])
print(min(g, h))


n = int(input())
list1 = [int(x) for x in input().split()]
list1.sort()
moves_odd = 0
moves_even = 0
start_odd = 1
start_even = 2
for i in list1:
	temp = i
	moves_odd += abs(temp - start_odd)
	start_odd += 2
	moves_even += abs(temp - start_even)
	start_even += 2
print(min(moves_even, moves_odd))


import re
import math
import decimal
import bisect

def read():
	return input().strip()
n = int(read())
ps = [0 for i in range(1, n + 1)]
nadd = 10
for x in sorted([int(_) for _ in read().split()]):
	ps[x - 1] = nadd
	nadd += 10
nadd = 15
for (i, p) in enumerate(ps):
	if p == 0:
		ps[i] = nadd
		nadd += 10
swapped = True
swapsA = 0
workps = ps[:]
while swapped:
	swapped = False
	for i in range(n - 1):
		if workps[i] > workps[i + 1]:
			tmp = workps[i]
			workps[i] = workps[i + 1]
			workps[i + 1] = tmp
			swapsA += 1
			swapped = True
for (i, p) in enumerate(ps):
	if p % 10 == 5:
		ps[i] -= 10
swapped = True
swapsB = 0
workps = ps[:]
while swapped:
	swapped = False
	for i in range(n - 1):
		if workps[i] > workps[i + 1]:
			tmp = workps[i]
			workps[i] = workps[i + 1]
			workps[i + 1] = tmp
			swapsB += 1
			swapped = True
print(min(swapsA, swapsB))


from sys import stdin

def solve(tc):
	n = int(stdin.readline().strip())
	li = list(map(int, stdin.readline().split()))
	li.sort()
	odd = 0
	p = 1
	for i in range(n // 2):
		odd += abs(li[i] - p)
		p += 2
	even = 0
	p = 2
	for i in range(n // 2):
		even += abs(li[i] - p)
		p += 2
	print(min(odd, even))
tc = 1
solve(tc)


n = int(input())
lst = [int(x) for x in input().split()]
lst.sort()
k = 0
p1 = 0
p2 = 0
for x in lst:
	k += 1
	p1 += abs(2 * k - 1 - x)
	p2 += abs(2 * k - x)
print(min(p1, p2))


import logging
fmt = '%(levelname)s - %(name)s (line:%(lineno)s) - %(message)s'
formatter = logging.Formatter(fmt)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
ch.setFormatter(formatter)
logger = logging.getLogger('chess_placing')
logger.setLevel(logging.ERROR)
logger.addHandler(ch)

def solve(pos):
	pos = sorted(pos)
	return min(sum((abs(2 * i + 1 - pos[i]) for i in range(len(pos)))), sum((abs(2 * i + 2 - pos[i]) for i in range(len(pos)))))

def main():
	_ = input()
	positions = [int(x) for x in input().strip().split()]
	result = solve(positions)
	print(result)
main()


n = int(input())
l = sorted(list(map(int, input().split())))
o = [2 * i + 1 for i in range(n // 2)]
e = [2 * i + 2 for i in range(n // 2)]
(s1, s2, k) = (0, 0, 0)
for i in l:
	s1 += abs(i - o[k])
	k += 1
k = n // 2 - 1
for i in reversed(l):
	s2 += abs(e[k] - i)
	k -= 1
print(min(s1, s2))


def chess(lst, m):
	(count1, count2) = (0, 0)
	for i in range(m // 2):
		count1 += abs(lst[i] - 1 - 2 * i)
		count2 += abs(lst[i] - 2 - 2 * i)
	return min(count1, count2)
n = int(input())
a = [int(j) for j in input().split()]
print(chess(sorted(a), n))


def main():
	n = int(input())
	p = [int(c) for c in input().split()]
	p.sort()
	moves_odd = 0
	moves_even = 0
	for i in range(n // 2):
		moves_odd += abs(p[i] - (i * 2 + 1))
		moves_even += abs(p[i] - i * 2 - 2)
	print(min(moves_odd, moves_even))
main()


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
b = 0
w = 0
for i in range(n // 2):
	b += abs(a[i] - 2 * i - 1)
	w += abs(a[i] - 2 * i - 2)
print(min(b, w))


N = int(input())
data = input().split()
pos = [int(i) for i in data]
pos.sort()
odd = 0
even = 0
start = 1
for p in pos:
	odd += abs(p - start)
	even += abs(p - (start + 1))
	start += 2
print(min(odd, even))


n = int(input())
L = list(map(int, input().split()))
L.sort()
s = 0
t = 0
for i in range(0, n // 2):
	s += abs(L[i] - 2 * i - 1)
	t += abs(L[i] - 2 * i - 2)
print(min(s, t))


n = int(input())
v = list(map(int, input().split()))
v.sort()
even = []
odd = []
for x in range(1, n + 1):
	if x % 2:
		odd.append(x)
	else:
		even.append(x)
a = 0
b = 0
for x in range(0, int(n / 2)):
	a = a + abs(odd[x] - v[x])
	b = b + abs(even[x] - v[x])
if a < b:
	print(a)
else:
	print(b)


from sys import stdin, stdout
from math import factorial
from math import log10
from math import sqrt
n = int(stdin.readline())
values = sorted(list(map(int, stdin.readline().split())))
cur = 1
cnt = 0
for v in values:
	cnt += abs(v - cur)
	cur += 2
ans = cnt
cur = 2
cnt = 0
for v in values:
	cnt += abs(v - cur)
	cur += 2
ans = min(ans, cnt)
stdout.write(str(ans))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
(c0, c1) = (0, 0)
for i in range(1, n // 2 + 1):
	c0 += abs(2 * i - 1 - a[i - 1])
	c1 += abs(2 * i - a[i - 1])
print(min(c0, c1))


n = int(input())
x = sorted(map(int, input().split()))
print(min((sum((abs(a - b) for (a, b) in zip(x, range(ty, n + 1, 2)))) for ty in (1, 2))))


N = int(input())
P = list(map(int, input().split()))
P.sort()
moveswhite = 0
movesblack = 0
i = 1
for items in P:
	moveswhite += abs(i - items)
	i += 2
i = 2
for items in P:
	movesblack += abs(i - items)
	i += 2
print(min(moveswhite, movesblack))


import math
a = 0
b = 0
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
a1 = []
a2 = []
for i in range(1, n + 1):
	if i % 2 == 0:
		a2.append(i)
	else:
		a1.append(i)
for i in range(len(arr)):
	a += abs(arr[i] - a1[i])
for i in range(len(arr)):
	b += abs(arr[i] - a2[i])
print(min(a, b))


n = int(input())
p = sorted(map(int, input().split()))
(m1, m2) = (0, 0)
for (i, el) in enumerate(p):
	m1 += abs(el - (2 * i + 1))
	m2 += abs(el - (2 * i + 2))
print(min(m1, m2))


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

def main():
	a.sort()
	b = w = 0
	for (i, x) in enumerate(a):
		x -= 1
		b += abs(2 * i - x)
		w += abs(2 * i + 1 - x)
	print(min(b, w))
main()


def main():
	n = int(input())
	p = [int(c) for c in input().split()]
	p.sort()
	B = [i for i in range(1, n + 1, 2)]
	W = [i for i in range(2, n + 1, 2)]
	white = 0
	black = 0
	for i in range(n // 2):
		white += abs(B[i] - p[i])
		black += abs(W[i] - p[i])
	print(min(white, black))
main()


def feven(pieces, n):
	res = 0
	for i in range(len(pieces)):
		res += abs(pieces[i] - 2 * (1 + i))
	return res

def fodd(pieces, n):
	res = 0
	for i in range(len(pieces)):
		res += abs(pieces[i] - (2 * (1 + i) - 1))
	return res
n = int(input())
pieces = list(map(int, input().split()))
pieces = sorted(pieces)
ans1 = feven(pieces, n)
ans2 = fodd(pieces, n)
print(min(ans1, ans2))


def dist(a, b):
	return sum((abs(x - y) for (x, y) in zip(a, b)))

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	odds = list(range(1, n + 1, 2))
	evens = list(range(2, n + 1, 2))
	ans = min(dist(a, odds), dist(a, evens))
	print(ans)
main()


n = int(input())
l = input().split(' ')
l = [int(e) for e in l]
assert len(l) == n // 2
s1 = 0
s2 = 0
l = sorted(l)
for (i, x) in enumerate(l):
	s1 += abs(2 * i + 1 - x)
	s2 += abs(2 * i + 2 - x)
print(min(s1, s2))


import configparser
import math
import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = sorted([int(x) for x in input().split(' ')])
	i = 1
	ans = 0
	for p in a:
		ans += abs(p - i)
		i += 2
	i = 2
	ans2 = 0
	for p in a:
		ans2 += abs(p - i)
		i += 2
	print(min(ans, ans2))
main()


input()
(xb, xw) = (1, 2)
res_b = res_w = 0
for p in sorted(list(map(int, input().split()))):
	res_b += abs(p - xb)
	res_w += abs(p - xw)
	xb += 2
	xw += 2
print(min(res_b, res_w))


n = int(input())
p = list(map(int, input().split()))
white = [x for x in range(1, n + 1, 2)]
black = [x for x in range(2, n + 1, 2)]
p.sort()
ws = sum([abs(white[i] - p[i]) for i in range(n // 2)])
bs = sum([abs(black[i] - p[i]) for i in range(n // 2)])
print(min(ws, bs))


def main():
	n = int(input())
	p = list(map(int, input().split()))
	p.sort()
	s1 = sum((abs(i * 2 + 2 - p[i]) for i in range(n // 2)))
	s2 = sum((abs(i * 2 + 1 - p[i]) for i in range(n // 2)))
	print(min(s1, s2))
main()


n = int(input())
numarr = [int(i) for i in input().split()]
numarr.sort()
count1 = 0
count2 = 0
for i in range(int(n / 2)):
	count1 += abs((i + 1) * 2 - 1 - numarr[i])
for i in range(int(n / 2)):
	count2 += abs((i + 1) * 2 - numarr[i])
print(count1 if count1 < count2 else count2)


def count(a):
	a = sorted(a)
	s = 0
	d = 0
	i = 2
	j = 1
	for e in a:
		s = s + abs(e - i)
		i = i + 2
	for e in a:
		d = d + abs(e - j)
		j = j + 2
	return min(s, d)
c = input()
a = [int(x) for x in input().split()]
print(count(a))


n = int(input())
p = []
for i in map(int, input().split()):
	p.append(i)
p.sort()
ans1 = 0
ans2 = 0
for i in range(1, n // 2 + 1):
	ans1 += abs(p[i - 1] - ((i - 1) * 2 + 1))
	ans2 += abs(p[i - 1] - i * 2)
print(min(ans1, ans2))


n = int(input())
l = list(map(lambda x: int(x) - 1, input().split()))
l.sort()
a1 = 0
a2 = 0
for i in range(n // 2):
	a1 += abs(i * 2 - l[i])
	a2 += abs(i * 2 + 1 - l[i])
print(min(a1, a2))


n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr.sort()
ind = n
cnt = 0
for i in range(n // 2 - 1, -1, -1):
	cnt = cnt + abs(arr[i] - ind)
	ind -= 2
cnt1 = 0
ind = n - 1
for i in range(n // 2 - 1, -1, -1):
	cnt1 = cnt1 + abs(arr[i] - ind)
	ind -= 2
print(min(cnt, cnt1))


n = int(input())
a = sorted(map(int, input().split()))
print(min([sum((abs(x - y) for (x, y) in zip(a, range(i, n + 1, 2)))) for i in [1, 2]]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
resodd = 0
reseven = 0
n = int(n / 2)
for i in range(n):
	resodd += abs(i * 2 + 1 - a[i])
	reseven += abs(i * 2 + 2 - a[i])
print(min(resodd, reseven))


n = int(input())
figures = sorted(list(map(int, input().split())))
res1 = 0
for i in range(n // 2):
	res1 += abs(figures[i] - i * 2 - 1)
res2 = 0
for i in range(n // 2):
	res2 += abs(figures[i] - i * 2 - 2)
print(min(res1, res2))


n = int(input())
mas = list(map(int, input().split()))
mas.sort()
k = 0
j = 0
delta = 1
for i in range(n // 2):
	k += abs(mas[i] - delta)
	delta += 2
delta = 2
for i in range(n // 2):
	j += abs(mas[i] - delta)
	delta += 2
print(min(j, k))


import math
n = int(input())
line = list(map(int, input().split()))
line.sort()
ans_black = 0
ans_white = 0
counter = 1
for i in line:
	ans_black += int(math.fabs(counter - i))
	counter += 2
counter = 2
for i in line:
	ans_white += int(math.fabs(counter - i))
	counter += 2
print(min(ans_white, ans_black))


n = int(input())
arr = sorted(map(int, input().split()))
m1 = 0
i = 2
m2 = 0
j = n - 1
for e in arr:
	m1 += abs(e - i)
	i += 2
for e in arr[::-1]:
	m2 += abs(e - j)
	j -= 2
print(min(m1, m2))


n = int(input())
p = sorted(list(map(int, input().split())))
(c1, c0) = (0, 0)
for i in range(n // 2):
	c1 += abs(2 * i + 1 - p[i])
	c0 += abs(2 * (i + 1) - p[i])
print(min(c0, c1))


k = int(input())
ns = list(map(int, input().split()))
n = k // 2
ns.sort()
ans1 = ans2 = 0
fs = [x for x in range(1, k + 1, 2)]
js = [x for x in range(2, k + 1, 2)]
for x in range(n):
	ans1 += abs(ns[x] - fs[x])
	ans2 += abs(ns[x] - js[x])
print(min(ans1, ans2))


import sys
readline = sys.stdin.readline
N = int(readline())
P = list(map(lambda x: int(x) - 1, readline().split()))
P.sort()
inf = 10 ** 18
res = inf
for geta in range(2):
	cnt = 0
	for i in range(N // 2):
		cnt += abs(P[i] - (2 * i + geta))
	res = min(res, cnt)
print(res)


def main():
	n = int(input())
	numbers = sorted([x - 1 for x in list(map(int, input().split()))])
	evens = [abs(item[0] - item[1]) for item in zip([x for x in range(0, n + 1, 2)], numbers)]
	odds = [abs(item[0] - item[1]) for item in zip([x for x in range(1, n, 2)], numbers)]
	print(min(sum(evens), sum(odds)))
main()


n = int(input())
tab = list(map(int, input().split()))
tab.sort()
tot = [0, 0]
for i in range(n // 2):
	tot[0] += abs(n - i * 2 - tab[-1 - i])
	tot[1] += abs(n - i * 2 - 1 - tab[-1 - i])
print(min(tot[0], tot[1]))


n = int(input())
p = sorted([int(i) for i in input().split()])
b = 0
w = 0
for (i, v) in enumerate(p):
	b += abs(v - (2 * i + 1))
	w += abs(v - (2 * i + 2))
print(min(b, w))


while True:
	try:

		def solution(n):
			a = list(map(int, input().split()))
			a.sort()
			e = [i for i in range(1, n, 2)]
			o = [i for i in range(2, n + 1, 2)]
			ans = 0
			for i in range(n // 2):
				ans += abs(e[i] - a[i])
			anst = 0
			for i in range(n // 2):
				anst += abs(o[i] - a[i])
			print(min(ans, anst))

		def read():
			n = int(input())
			solution(n)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


k = int(input())
k1 = input().split()
k2 = [int(i) for i in k1]
sum1 = 0
sum2 = 0
k2.sort()
for i in range(int(k / 2)):
	sum1 += abs(k2[i] - (2 * i + 1))
	sum2 += abs(k2[i] - (2 * i + 2))
print(min(sum1, sum2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
j = 1
t1 = 0
t2 = 0
for i in l:
	t1 += abs(i - j)
	j += 2
j = 2
for i in l:
	t2 += abs(i - j)
	j += 2
print(min(t2, t1))


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
sum_odd = 0
sum_even = 0
lst.sort()
for i in range(n // 2):
	sum_odd += abs(lst[i] - (2 * i + 1))
for i in range(n // 2):
	sum_even += abs(lst[i] - 2 * (i + 1))
print(min(sum_odd, sum_even))


n = int(input())
x = [*map(int, input().split())]
x.sort()
(ans1, ans2) = (0, 0)
for i in range(len(x)):
	ans1 += abs(x[i] - (i * 2 + 1))
	ans2 += abs(x[i] - (i + 1) * 2)
print(min(ans1, ans2))


import sys, math
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
odd = []
even = []
for i in range(1, n + 1, 2):
	j = i
	temp = []
	while j <= n:
		temp.append(j)
		j += 2
	if len(temp) == len(arr):
		odd.append(temp)
for i in range(2, n + 1, 2):
	j = i
	temp = []
	while j <= n:
		temp.append(j)
		j += 2
	if len(temp) == len(arr):
		even.append(temp)
ans = 9876543210
for i in odd:
	temp = 0
	for j in range(len(arr)):
		temp += abs(i[j] - arr[j])
	ans = min(temp, ans)
for i in even:
	temp = 0
	for j in range(len(arr)):
		temp += abs(i[j] - arr[j])
	ans = min(temp, ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
da = 0
db = 0
for i in range(1, n // 2 + 1):
	da += abs(a[i - 1] - (2 * i - 1))
	db += abs(a[i - 1] - 2 * i)
print(min(da, db))


def f(filled, empty):
	filled.sort()
	empty.sort()
	c = 0
	for i in range(len(filled)):
		c += abs(empty[i] - filled[i])
	return c
n = int(input())
filled_w = []
empty_b = []
filled_b = []
empty_w = []
numbers = []
for i in range(1, n + 1):
	numbers.append(i)
for item in input().split():
	item = int(item)
	if item % 2 == 0:
		filled_w.append(item)
	else:
		filled_b.append(item)
	numbers.remove(item)
for item in numbers:
	if item % 2 == 0:
		empty_w.append(item)
	else:
		empty_b.append(item)
print(min(f(filled_w, empty_b), f(filled_b, empty_w)))


n = int(input())
L = sorted(map(int, input().split()))
(s1, s2) = (0, 0)
(p, q) = (1, 2)
for i in range(n // 2):
	s1 += abs(p - L[i])
	p += 2
	s2 += abs(q - L[i])
	q += 2
print(min(s1, s2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
(s1, s2) = (0, 0)
for i in range(n // 2):
	s1 += abs(l[i] - (2 * i + 1))
	s2 += abs(l[i] - (2 * i + 2))
print(min(s1, s2))


n = int(input())
m = map(int, input().split())
(s1, s2) = (0, 0)
for (i, v) in enumerate(sorted(m)):
	s1 += abs(v - 2 * i - 1)
	s2 += abs(v - 2 * i - 2)
print(min(s1, s2))


n = int(input())
l = list(map(int, input().split()))
temp = [0] * n
for i in range(len(l)):
	x = l[i] - 1
	temp[x] = 1
(d1, d2, k1, k2) = ({}, {}, 0, n - 1)
for i in range(len(temp)):
	if temp[i] == 1:
		d1.update({i: k1})
		k1 += 2
for i in range(len(temp) - 1, -1, -1):
	if temp[i] == 1:
		d2.update({i: k2})
		k2 -= 2
(a, b) = (0, 0)
for i in range(len(temp)):
	if temp[i] == 1:
		a = a + abs(i - d1[i])
for i in range(len(temp) - 1, -1, -1):
	if temp[i] == 1:
		b = b + abs(i - d2[i])
print(min(a, b))


def min_step():
	n = int(input())
	Place = sorted(list(map(int, input().split())))
	print(min(sum([abs(x - y) for (x, y) in zip([x for x in range(1, n + 1, 2)], Place)]), sum([abs(x - y) for (x, y) in zip([x for x in range(2, n + 1, 2)], Place)])))
min_step()


n = int(input())
a = list(map(int, input().split(' ')))
a = sorted(a)
b = [x for x in range(1, n, 2)]
c = [x for x in range(2, n + 1, 2)]
s1 = 0
s2 = 0
for (i, j) in zip(a, b):
	s1 += abs(i - j)
for (i, j) in zip(a, c):
	s2 += abs(i - j)
print(min(s1, s2))


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


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

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

def li():
	return list(mi())
n = ii()
a = li()
a.sort()
c1 = 0
p = 1
for ai in a:
	c1 += abs(ai - p)
	p += 2
c2 = 0
p = 2
for ai in a:
	c2 += abs(ai - p)
	p += 2
ans = min(c1, c2)
print(ans)


n = int(input())
figs = sorted(list(map(int, input().split())))
sum1 = 0
sum2 = 0
for i in range(n // 2):
	sum1 += abs(figs[i] - (2 * i + 1))
	sum2 += abs(figs[i] - (2 * i + 2))
print(min(sum1, sum2))


n = list(map(int, input().split()))
nums = sorted(list(map(int, input().split())))
act1 = 0
act2 = 0
for (i, x) in enumerate(nums):
	act1 += abs(2 * i + 1 - x)
	act2 += abs(2 * i + 2 - x)
print(min(act1, act2))


n = int(input())
l = list(map(int, input().split()))
l.sort()
(s, c) = (0, 0)
x = 1
for i in l:
	s = s + abs(x - i)
	x = x + 2
y = 2
for i in l:
	c += abs(y - i)
	y += 2
print(min(c, s))


n = int(input().strip())
arr = [int(i) for i in input().strip().split()]
arr.sort()
s1 = [i for i in range(1, n + 1, 2)]
s2 = [i for i in range(2, n + 1, 2)]
(su1, su2) = (0, 0)
for i in range(len(arr)):
	su1 += abs(s1[i] - arr[i])
	su2 += abs(s2[i] - arr[i])
print(min(su1, su2))


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
even = [i for i in range(1, n + 1, 2)]
odd = [i for i in range(2, n + 1, 2)]
(a, b) = (0, 0)
for (n, e, o) in zip(nums, even, odd):
	a += abs(n - e)
	b += abs(n - o)
print(min(a, b))


n = int(input())
pos = list(map(int, input().split()))
pos.sort()
bsum = sum([abs(pos[i] - 2 * i - 1) for i in range(int(n / 2))])
wsum = sum([abs(pos[i] - 2 * i - 2) for i in range(int(n / 2))])
print(min(bsum, wsum))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
s1 = 0
s2 = 0
j1 = 1
j2 = 2
for i in arr:
	s1 += abs(i - j1)
	s2 += abs(i - j2)
	j1 += 2
	j2 += 2
print(min(s1, s2))


n = int(input())
p = list(map(int, input().split()))
p.sort()
(a, b) = (0, 0)
offset = 1
for i in range(n // 2):
	a += abs(p[i] - offset)
	b += abs(p[i] - (offset + 1))
	offset += 2
print(min(a, b))


def read():
	return list(map(int, input().split()))
n = int(input())
a = read()
a.sort()
j = 0
ans1 = 0
for i in range(1, n + 1, 2):
	ans1 += abs(a[j] - i)
	j += 1
j = 0
ans2 = 0
for i in range(2, n + 1, 2):
	ans2 += abs(a[j] - i)
	j += 1
print(min(ans1, ans2))


n = int(input())
p = input().split()
i = 0
while i < n // 2:
	p[i] = int(p[i])
	i = i + 1
i = 0
m1 = 0
p.sort()
m2 = 0
while i < n // 2:
	m1 = m1 + abs(p[i] - (2 * i + 1))
	m2 = m2 + abs(p[i] - (2 * i + 2))
	i = i + 1
print(min(m1, m2))


import itertools
import math
n = input()
n = int(n)
zoma = int(n / 2)
posArray = [int(x) for x in input().split()]
posArray.sort()
evenCount = 0
oddCount = 0
for (i, j) in zip(range(n, 0, -2), range(zoma - 1, -1, -1)):
	if posArray[j] != i:
		evenCount += abs(i - posArray[j])
for (i, j) in zip(range(n - 1, 0, -2), range(zoma - 1, -1, -1)):
	if posArray[j] != i:
		oddCount += abs(i - posArray[j])
print(min(evenCount, oddCount))


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
l1 = [i for i in range(2, n + 1, 2)]
l2 = [i for i in range(1, n, 2)]
s1 = sum((abs(l1[i] - l[i]) for i in range(n // 2)))
s2 = sum((abs(l2[i] - l[i]) for i in range(n // 2)))
print(min(s1, s2))


TN = 1

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	ch = 0
	nch = 0
	l = list(sorted(l))
	for i in range(n // 2):
		ch += abs(l[-i - 1] - (n - 2 * i))
		nch += abs(l[-i - 1] - (n - 1 - 2 * i))
	print(min(ch, nch))
while TN != 0:
	solution()
	TN -= 1


n = int(input())
s = [int(x) - 1 for x in input().split()]
s1 = 0
s2 = 0
s.sort()
for i in range(len(s)):
	s1 += abs(i * 2 - s[i])
	s2 += abs(i * 2 - s[i] + 1)
print(min(s1, s2))


lines = [[input()], input().split(' ')]
n = int(lines[0][0])
coords = sorted([int(lines[1][i]) - 1 for i in range(int(n / 2))])
odd = 0
even = 0
for i in range(int(n / 2)):
	odd += abs(coords[i] - 2 * i)
	even += abs(coords[i] - 2 * i - 1)
print(min(odd, even))


from math import *
import random, sys

def nextInt():
	return int(input())

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

def nextInts():
	return list(map(int, nextStrs()))

def main():
	n = nextInt()
	arr = nextInts()
	arr.sort()
	res = 10 ** 9 + 7
	cnt = 0
	for i in range(len(arr)):
		cnt += abs(arr[i] - 2 * (i + 1))
	res = min(res, cnt)
	cnt = 0
	for i in range(len(arr)):
		cnt += abs(arr[i] - 2 * i - 1)
	res = min(res, cnt)
	print(res)
exit(main())


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = sum([abs(a[i] - x) for (i, x) in enumerate(range(1, n, 2))])
c = sum([abs(a[i] - x) for (i, x) in enumerate(range(2, n + 1, 2))])
print(min(b, c))


n = int(input())
a = list(map(int, input().split()))
a.sort()
t = 0
t2 = 0
for i in range(n // 2):
	t += abs(2 * i + 1 - a[i])
	t2 += abs(2 * i + 2 - a[i])
print(min(t, t2))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
var1 = 2
su = 0
for i in range(n // 2):
	su += abs(var1 - arr[i])
	var1 += 2
s = 0
var = 1
for i in range(n // 2):
	s += abs(var - arr[i])
	var += 2
print(min(s, su))


import sys
n = int(input())
a = sorted(map(int, input().split()))
(ans1, ans2) = (0, 0)
for (i, x) in enumerate(a):
	ans1 += abs(i * 2 + 1 - x)
	ans2 += abs((i + 1) * 2 - x)
print(min(ans1, ans2))


n = int(input())
k = int(n / 2)
s = 0
s1 = 0
s2 = 0
p = input().split()
for i in range(k):
	p[i] = int(p[i])
	s += p[i]
p.sort()
minim = 1
maxim = n
for i in range(k):
	s1 += abs(p[i] - minim)
	minim += 2
	s2 += abs(maxim - p[k - i - 1])
	maxim -= 2
if s1 < s2:
	print(s1)
else:
	print(s2)


n = int(input())
x = int(n / 2)
a = [1] * x
a = [int(a) for a in input().split()]
a.sort()
white = 0
black = 0
position = 1
i = 0
while i < x:
	black = black + abs(a[i] - position)
	i = i + 1
	position += 2
i = 0
position = 2
while i < x:
	white = white + abs(a[i] - position)
	i = i + 1
	position += 2
if white <= black:
	print(white)
else:
	print(black)


input()
p = list(map(int, input().split()))
p.sort()
e = o = 0
c = 1
for x in p:
	s = 2 * c
	e += abs(s - x)
	o += abs(s - 1 - x)
	c += 1
print(e) if e < o else print(o)


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

def f(r):
	i = 0
	d = 0
	for j in r:
		d += abs(j - l[i])
		i += 1
	return d
print(min(f(range(1, n + 1, 2)), f(range(2, n + 1, 2))))


n = int(input())
n = n / 2
a = [int(x) for x in input().split(' ')]
a.sort()
p1 = 1
p2 = 2
r1 = 0
r2 = 0
for element in a:
	r1 = r1 + abs(element - p1)
	r2 = r2 + abs(element - p2)
	p1 = p1 + 2
	p2 = p2 + 2
print(min(r1, r2))


n = int(input())
p = sorted(list(map(int, input().split())))
x = sum((abs(i * 2 - p[i] + 1) for i in range(n // 2)))
y = sum((abs(i * 2 + 1 - p[i] + 1) for i in range(n // 2)))
print(min(x, y))


n = int(input())
a = sorted([int(x) for x in input().split()])
i = 1
sum1 = 0
sum2 = 0
n = n // 2
for j in range(n):
	if a[j] >= i:
		sum1 += a[j] - i
	else:
		sum1 += i - a[j]
	i += 2
i = 2
for j in range(n):
	if a[j] >= i:
		sum2 += a[j] - i
	else:
		sum2 += i - a[j]
	i += 2
print(min(sum1, sum2))


N = int(input())
(R1, R2) = (0, 0)
k = 1
for i in sorted(list(map(int, input().split()))):
	R1 += abs(k - i)
	R2 += abs(k + 1 - i)
	k += 2
print(min(R1, R2))


n = int(input().strip())
f = list(map(int, input().split()))
f.sort()
k = len(f)
ma = sum((abs(f[i] - 2 * (i + 1)) for i in range(k)))
mb = sum((abs(f[i] - (2 * i + 1)) for i in range(k)))
print(min(ma, mb))


n = int(input())
array = []
line = input()
for x in line.split():
	array.append(int(x))
s1 = s2 = 0
a1 = 1
a2 = 2
array.sort()
for i in array:
	s1 += abs(i - a1)
	s2 += abs(i - a2)
	a1 += 2
	a2 += 2
print(min(s1, s2))


n = int(input())
(*p,) = map(int, input().split())
p.sort()
black = sum((abs(i * 2 + 1 - x) for (i, x) in enumerate(p)))
white = sum((abs(i * 2 + 2 - x) for (i, x) in enumerate(p)))
print(min(black, white))


n = input()
P = sorted(map(int, input().split()))
e = sum((abs(p - 1 - 2 * i) for (i, p) in enumerate(P)))
o = sum((abs(p - 1 - (2 * i + 1)) for (i, p) in enumerate(P)))
print(min(e, o))


n = int(input())
a = sorted(list(map(int, input().split())))
cnt1 = 0
cnt2 = 0
d = n
for i in range(1, n // 2 + 1):
	cnt1 += abs(d - a[-i])
	cnt2 += abs(d - 1 - a[-i])
	d -= 2
print(min(cnt1, cnt2))


n = int(input()) // 2
P = sorted(map(int, input().split()))
print(min(sum((abs(P[i] - 2 * i - 1) for i in range(n))), sum((abs(P[i] - 2 * i - 2) for i in range(n)))))


n = int(input())
a = [int(j) for j in input().split()]
a.sort()
moves1 = 0
moves2 = 0
for i in range(n // 2):
	moves1 += abs(2 * i + 1 - a[i])
	moves2 += abs(2 * i + 2 - a[i])
if moves2 > moves1:
	print(moves1)
else:
	print(moves2)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ev = [i for i in range(1, n + 1) if i % 2 == 0]
odd = [i for i in range(1, n + 1) if i % 2 == 1]
count_ev = 0
count_odd = 0
for i in range(n // 2):
	count_ev += abs(a[i] - ev[i])
	count_odd += abs(a[i] - odd[i])
print(min(count_ev, count_odd))


n = int(input())
(t1, t2) = (0, 0)
(k1, k2) = (1, 1)
a = list(map(int, input().split()))
a.sort()
for i in range(1, n // 2 + 1):
	t1 += abs(2 * i - a[i - 1])
	t2 += abs(2 * i - 1 - a[i - 1])
print(min(t1, t2))


def main():
	n = int(input())
	ans1 = 0
	ans2 = 0
	a = list(map(int, input().split()))
	a.sort()
	b1 = []
	b2 = []
	for i in range(1, n + 1):
		if i % 2 == 0:
			b1.append(i)
		else:
			b2.append(i)
	for i in range(n // 2):
		ans1 += abs(a[i] - b1[i])
	for i in range(n // 2):
		ans2 += abs(a[i] - b2[i])
	print(min(ans1, ans2))
main()


n = int(input())
chess = list(map(int, input().split()))
move1 = 0
move2 = 0
chess.sort()
for i in range(len(chess)):
	move1 += abs(chess[i] - (i * 2 + 1))
	move2 += abs(chess[i] - (i * 2 + 2))
print(min(move1, move2))


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	diff1 = 0
	diff2 = 0
	start = 1
	for i in range(n // 2):
		diff1 += abs(start - a[i])
		start += 2
	start = 2
	for i in range(n // 2):
		diff2 += abs(start - a[i])
		start += 2
	print(min(diff1, diff2))
	return
main()


n = int(input())
arr = sorted([int(i) for i in input().split()])
(a, b) = (0, 0)
for i in range(n // 2):
	a += abs(arr[i] - 1 - i * 2)
	b += abs(arr[i] - 2 - i * 2)
print(min(a, b))


n = int(input())
pp = list(map(int, input().split()))
pp = sorted(pp)
ans = 10000
for x in range(1, 3):
	cnt = 0
	for i in range(0, int(n / 2)):
		p = pp[i]
		q = x + i * 2
		cnt += abs(p - q)
	ans = min(ans, cnt)
print(ans)


n = int(input())
p = [int(x) for x in input().split(' ')]
p.sort()
e = 0
o = 0
for i in range(n // 2):
	e += abs(p[i] - (2 * i + 2))
	o += abs(p[i] - (2 * i + 1))
print(min(o, e))


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0] * (n // 2)
b[0] = 2
for i in range(1, n // 2):
	b[i] = b[i - 1] + 2
cnt = 0
for i in range(n // 2):
	cnt += abs(a[i] - b[i])
c = 0
for i in range(n // 2):
	c += abs(a[i] - (b[i] - 1))
print(min(c, cnt))


while True:
	n = int(input())
	B = input().split()
	odd = 0
	even = 0
	for i in range(0, n // 2):
		B[i] = int(B[i]) - 1
	B.sort()
	for i in range(0, n):
		if i % 2 == 0:
			even += abs(i - B[i // 2])
		else:
			odd += abs(i - B[i // 2])
	print(min(even, odd))
	break


n = int(input())
cl = sorted(list(map(int, input().split())))
count1 = 0
count2 = 0
pos1 = 1
pos2 = 2
for x in cl:
	count1 += abs(x - pos1)
	pos1 += 2
	count2 += abs(x - pos2)
	pos2 += 2
print(min(count1, count2))


from bisect import bisect_left, bisect_right

def tuple_input(type):
	return map(type, input().strip().split())
n = int(input())
p = list(tuple_input(int))
p.sort()
p = list(map(lambda x: x - 1, p))
t = [2 * i for i in range(n // 2)]
black = 0
for i in range(n // 2):
	black += abs(p[i] - t[i])
t = list(map(lambda x: x + 1, t))
white = 0
for i in range(n // 2):
	white += abs(p[i] - t[i])
print(min(black, white))


n = int(input())
s = sorted(list(map(int, input().split())))
ans = ans2 = 0
a = list(range(1, n + 1))
b = a[1::2]
a = a[::2]
for i in range(n // 2):
	ans += abs(s[i] - a[i])
	ans2 += abs(s[i] - b[i])
print(min(ans, ans2))


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
l = len(a)
a1 = []
a2 = []
for i in range(1, n, 2):
	a1.append(i)
for i in range(2, n + 1, 2):
	a2.append(i)
s1 = 0
s2 = 0
for i in range(l):
	s1 = s1 + abs(a1[i] - a[i])
for i in range(l):
	s2 = s2 + abs(a2[i] - a[i])
print(min(s1, s2))


n = int(input())
inp = sorted([int(x) for x in input().split()])
addd = 0
for i in range(int(n / 2)):
	addd += abs(inp[i] - (i * 2 + 1))
add = 0
for i in range(int(n / 2)):
	add += abs(inp[i] - (i * 2 + 2))
print(min(add, addd))


import copy

def chess_min_mov(n, positions):
	black_moves = 0
	black_positions = copy.copy(positions)
	for index in range(1, n + 1, 2):
		black_moves += abs(index - black_positions.pop(0))
	white_moves = 0
	for index in range(2, n + 1, 2):
		white_moves += abs(index - positions.pop(0))
	return min(black_moves, white_moves)
n = int(input())
positions = list(map(int, input().split(' ')))
print(chess_min_mov(n, sorted(positions)))


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


n = int(input())
arr = list(map(int, input().split(' ')))
arr = sorted(arr)
temp1 = 0
temp2 = 0
i = 0
for i in range(0, int(n / 2)):
	temp1 = temp1 + abs(int(arr[i]) - (2 * i + 1))
	temp2 = temp2 + abs(int(arr[i]) - (2 * i + 2))
print(min(temp1, temp2))


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	min_val = 10 ** 18
	val = 0
	for i in range(n // 2):
		val += abs(A[i] - (2 * i + 2))
	min_val = min(min_val, val)
	val = 0
	for i in range(n // 2):
		val += abs(A[i] - (2 * i + 1))
	min_val = min(min_val, val)
	print(min_val)
main()


n = int(input())
p = sorted([int(x) for x in input().split()])
moves_B = sum([abs(2 * i + 1 - p[i]) for i in range(n // 2)])
moves_W = sum([abs(2 * i + 2 - p[i]) for i in range(n // 2)])
print(min(moves_B, moves_W))


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

def sin():
	return int(input())
t = sin()
l = sorted(mul())
e = []
o = []
for i in range(int(t / 2)):
	o.append(2 * i + 1)
	e.append(2 * (i + 1))
z0 = zip(l, o)
z1 = zip(e, l)
(ec, oc) = (0, 0)
for (a, b) in z0:
	oc += abs(a - b)
for (a, b) in z1:
	ec += abs(a - b)
print(min(ec, oc))


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


n = int(input())
pos = [int(x) for x in input().split()]
pos.sort()
arr1 = [0] * (n // 2)
arr2 = [0] * (n // 2)
ans1 = [0] * (n // 2)
ans2 = [0] * (n // 2)
sum1 = sum2 = 0
for i in range(n // 2):
	arr1[i] = 2 * (i + 1) - 1
for i in range(n // 2):
	arr2[i] = 2 * (i + 1)
for i in range(n // 2):
	ans1[i] = abs(arr1[i] - pos[i])
	ans2[i] = abs(arr2[i] - pos[i])
for i in range(n // 2):
	sum1 += ans1[i]
	sum2 += ans2[i]
print(min(sum1, sum2))


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
l1 = [0] * (n + 1)
c = 0
for i in range(1, n + 1, 2):
	l1[i] = l[c]
	c += 1
s = 0
for i in range(1, n + 1, 2):
	s += abs(i - l1[i])
l1 = [0] * (n + 1)
c = n // 2 - 1
for i in range(n, 0, -2):
	l1[i] = l[c]
	c -= 1
s1 = 0
for i in range(n, 0, -2):
	s1 += abs(i - l1[i])
print(min(s, s1))


n = int(input())
p = [int(x) for x in input().split()]
p.sort()
b = 0
w = 0
i = 1
j = 2
for x in p:
	b += abs(x - i)
	w += abs(x - j)
	i += 2
	j += 2
print(min(b, w))


n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
(c1, c2) = (0, 0)
for i in range(n // 2):
	c1 = c1 + abs(2 * i + 1 - l[i])
	c2 = c2 + abs(2 * i + 2 - l[i])
print(min(c1, c2))


n = int(input())
t = list(map(int, input().split()))
t.sort()
u = 0
v = 0
e = 2
o = 1
for j in t:
	u += abs(e - j)
	v += abs(o - j)
	o += 2
	e += 2
print(min(v, u))


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


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m1 = 0
m2 = 0
for i in range(n // 2):
	m1 += abs(a[i] - (i * 2 + 1))
	m2 += abs(a[i] - (i * 2 + 2))
print(min(m1, m2))


n = int(input())
a = [0] * n
pos = list(map(int, input().split()))
for i in range(n // 2):
	a[pos[i] - 1] = 1
ans1 = 0
for i in range(n - 1):
	if i % 2 == 0:
		j = i
		while a[j] == 0:
			j += 1
		a[j] = 0
		ans1 += j - i
		a[i] = 1
	else:
		j = i
		while a[j] == 1:
			j += 1
		a[j] = 1
		ans1 += j - i
		a[i] = 0
a = [0] * n
for i in range(n // 2):
	a[pos[i] - 1] = 1
ans2 = 0
for i in range(1, n):
	if i % 2 == 1:
		j = i
		while a[-j] == 0:
			j += 1
		a[-j] = 0
		ans2 += j - i
		a[-i] = 1
	else:
		j = i
		while a[-j] == 1:
			j += 1
		a[-j] = 1
		ans2 += j - i
		a[-i] = 0
print(min(ans1, ans2))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
a1 = 0
a2 = 0
for i in range(0, int(n / 2)):
	a1 += abs(a[i] - (i * 2 + 1))
	a2 += abs(a[i] - i * 2 - 2)
print(min(a1, a2))


n = int(input(''))
data = sorted([int(a) for a in input('').split()])
move1 = 0
move2 = 0
for i in range(0, int(n / 2)):
	move1 += abs(data[i] - (2 * i + 1))
for i in range(0, int(n / 2)):
	move2 += abs(data[i] - (2 * i + 2))
if move1 < move2:
	print(move1)
else:
	print(move2)


n = int(input())
piece = list(map(int, input().split()))
ans1 = 0
ans2 = 0
piece = sorted(piece)
for i in range(len(piece)):
	ans1 += abs(piece[i] - 1 - i * 2)
	ans2 += abs(piece[i] - 1 - (i * 2 + 1))
print(min(ans1, ans2))


n = int(input())
a = [int(x) for x in input().split()]
even = 0
odd = 0
a.sort()
for i in range(len(a)):
	j = i + 1
	odd = odd + abs(2 * j - 1 - a[i])
	even = even + abs(a[i] - 2 * j)
print(min(even, odd))


n = int(input())
s = input().split()
k = int(n / 2)
a = [0] * k
for i in range(k):
	a[i] = int(s[i])
a = sorted(a)
m1 = 0
for i in range(k):
	m1 += abs(a[i] - (2 * i + 1))
m2 = 0
for i in range(k):
	m2 += abs(a[i] - (2 * i + 2))
print(min(m1, m2))


n = int(input())
l = list(map(int, input().split()))
odd = 0
even = 0
c = 0
l.sort()
for i in l:
	if i % 2 == 0:
		even += 1
	else:
		odd += 1
g = []
p = 0
a = 0
for i in range(1, n + 1):
	if i % 2 == a and i not in l:
		g.append(i)
for i in l:
	if i % 2 != a:
		if len(g) > 0:
			c += abs(g[0] - i)
		else:
			c = 999999999
			break
		g.pop(0)
b = 1
d = 0
g = []
for i in range(1, n + 1):
	if i % 2 == b and i not in l:
		g.append(i)
for i in l:
	if i % 2 != b:
		if len(g) > 0:
			d += abs(g[0] - i)
		else:
			d = 9999999999
			break
		g.pop(0)
print(min(c, d))


def cheess(n, p):
	a = 0
	for i in range(n // 2):
		a += abs(p[i] - 1 - i * 2)
	return a
n = int(input())
p = sorted([int(x) for x in input().split()])
ap = [n + 1 - x for x in p]
ap.reverse()
print(min(cheess(n, p), cheess(n, ap)))


t = int(input())
l = [int(i) for i in input().split()]
l.sort()
odd = [int(i) for i in range(1, t, 2)]
even = [int(i) for i in range(2, t + 1, 2)]
o = 0
e = 0
for i in range(t // 2):
	o += abs(odd[i] - l[i])
	e += abs(even[i] - l[i])
if o > e:
	print(e)
else:
	print(o)


n = int(input())
p = list(map(int, input().split()))
p.sort()
x = 0
y = 0
for i in range(n // 2):
	p[i] -= 1
	x += abs(p[i] - 2 * i)
	y += abs(p[i] - 2 * i - 1)
print(min(x, y))


n = int(input())
p = list(map(int, input().split()))
p.sort()
even = []
odd = []
for i in range(1, n + 1):
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd_ans = 0
even_ans = 0
for i in range(n // 2):
	odd_ans += abs(p[i] - odd[i])
	even_ans += abs(p[i] - even[i])
print(min(even_ans, odd_ans))


n = int(input())
pl = list(map(int, input().split()))
black = 0
white = 0
pl.sort()
for i in range(n // 2):
	white += abs(pl[i] - 1 - (2 * i + 1))
	black += abs(pl[i] - 1 - 2 * i)
print(min(black, white))


def solve_1(seq):
	last_free_cell = 1
	ans = 0
	for el in seq:
		ans += abs(el - last_free_cell)
		last_free_cell += 2
	return ans

def solve_2(seq):
	last_free_cell = 2
	ans = 0
	for el in seq:
		ans += abs(el - last_free_cell)
		last_free_cell += 2
	return ans
n = int(input())
data = list(map(int, input().split()))
data.sort()
print(min(solve_1(data), solve_2(data)))


n = int(input())
ns = [int(x) for x in input().split()]
ns.sort()
num = n // 2
ans1 = 0
for i in range(num):
	ans1 += abs(ns[i] - i * 2 - 2)
ans2 = 0
for i in range(num):
	ans2 += abs(ns[i] - i * 2 - 1)
print(min(ans1, ans2))


n = int(input())
alist = [int(x) for x in input().split()]
alist.sort()
t = 0
lc = []
ll = []
sumc = 0
suml = 0
h = int(n / 2)
for i in range(h):
	t = t + 2
	lc.append(t)
t = -1
for i in range(h):
	t = t + 2
	ll.append(t)
if n == 2:
	print(0)
else:
	for i in reversed(range(h)):
		sumc = sumc + abs(lc[i] - alist[i])
	for i in reversed(range(h)):
		suml = suml + abs(ll[i] - alist[i])
	if sumc < suml:
		print(sumc)
	else:
		print(suml)


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
n = int(input())
p = list(rint())
p.sort()
s = 0
for i in range(n // 2):
	s += abs((i + 1) * 2 - p[i])
seven = s
s = 0
for i in range(n // 2):
	s += abs(i * 2 + 1 - p[i])
sodd = s
print(min(seven, sodd))


n = int(input())
a = sorted(list(map(int, input().split())))
j = sum((abs(y - x) for (y, x) in zip(a, range(1, n, 2))))
l = sum((abs(y - x) for (y, x) in zip(a, range(2, n + 1, 2))))
print(min(j, l))


N = int(input())
chess = list(map(int, input().split()))
chess.sort()
steps1 = 0
steps2 = 0
for i in range(N, 1, -2):
	steps1 += abs(chess[int(i / 2) - 1] - i)
for i in range(N - 1, 0, -2):
	steps2 += abs(chess[i // 2] - i)
print(min(steps1, steps2))


a = int(input())
b = list(map(int, input().split()))
b.sort()
sumo = sume = 0
for i in range(len(b)):
	sumo += abs(b[i] - 2 * i - 1)
	sume += abs(b[i] - 2 * (i + 1))
print(min(sume, sumo))


n = int(input())
p = input().split(' ')
p = sorted([int(v) for v in p])
even = [(i + 1) * 2 for i in range(n // 2)]
odd = [1 + i * 2 for i in range(n // 2)]
e = 0
o = 0
for i in range(n // 2):
	e += abs(even[i] - p[i])
	o += abs(odd[i] - p[i])
print(min(e, o))


import math
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
even = [x * 2 + 2 for x in range(n // 2)]
odd = [x * 2 + 1 for x in range(n // 2)]
se = sum([int(math.fabs(l[i] - even[i])) for i in range(n // 2)])
so = sum([int(math.fabs(l[i] - odd[i])) for i in range(n // 2)])
print(min(se, so))


n = int(input())
p = list(map(int, input().split()))
l1 = list(range(1, n, 2))
l2 = list(range(2, n + 1, 2))
p = sorted(p)
l1 = sorted(l1)
l2 = sorted(l2)
s1 = sum([abs(a - b) for (a, b) in zip(p, l1)])
s2 = sum([abs(a - b) for (a, b) in zip(p, l2)])
print(min(s1, s2))