#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """5 # 0 1 6 7 8 # """ # sys.stdin = io.StringIO(_INPUT) def main(): N = int(input()) Y = sorted(list(map(int, input().split()))) d_min = 10**10 for k in range(1, N): # Y[:k] と Y[k:] に分割 i1 = (k-1)//2 y1 = Y[i1] i2 = k + (N-k-1)//2 y2 = Y[i2] if y1 == y2: d = 1 else: d = sum(min(abs(y-y1), abs(y-y2)) for y in Y) d_min = min(d_min, d) print(d_min) if __name__ == '__main__': main()