import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in a:
    cost = 0
    for j in a:
        d = abs(i-j)
        cost += d
    ans = max(ans,cost)
print(ans)