INF = 10 ** 9 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from heapq import heappop,heapify,heappush from bisect import bisect_left def main(): n = int(input()) Y = list(map(int,input().split())) Y.sort() if len(set(Y)) == 1: print(1) return ans = 0 a = 0 b = (n + 1)//2 for i in range(1,n): ans += abs(Y[i] - Y[b]) tmp = ans if n%2 == 0: for i in range(1,n - 1): if i%2 == 1: tmp += -Y[a] + 2 * Y[i] - Y[b] a += 1 b += 1 else: tmp += -Y[a] + 2 * Y[i] - Y[b] ans = min(tmp,ans) else: for i in range(1,n - 1): if i%2 == 1: tmp += -Y[a] + 2 * Y[i] - Y[b] a += 1 else: tmp += -Y[a] + 2 * Y[i] - Y[b] b += 1 ans = min(ans,tmp) print(ans) if __name__ == '__main__': main()