import statistics from itertools import accumulate def main(): N = int(input()) Y = list(map(int, input().split())) sort_Y = sorted(Y) if len(set(Y)) == 1: print(1) exit() elif len(set(Y)) == 2: print(0) exit() A = list(accumulate(sort_Y)) m = Y[N // 2] ans = float('inf') first_half = 0 second_half = 0 for y in sort_Y: second_half += abs(m - y) for i in range(N-1): m1 = sort_Y[i // 2] m2 = sort_Y[(i + N) // 2] first_half += sort_Y[i] - m1 second_half -= m2 - sort_Y[i] ans = min(ans, first_half + second_half) print(ans) if __name__ == "__main__": main()