from itertools import accumulate N = int(input()) Y = [int(i) for i in input().split()] Y.sort() A = [0] + list(accumulate(Y)) def solve(l, r): m = l + (r - l) // 2 return (Y[m], Y[m] * (2 * m - l - r + 2) - 2 * A[m + 1] + A[l] + A[r]) mi = 1e20 for i in range(1, N): y1, a = solve(0, i) y2, b = solve(i, N) mi = min(mi, 1 if y1 == y2 else a + b) print(mi)