from itertools import combinations
n=int(input())
xs=list(map(int,input().split()))
ub=1000000007
res=0
memo={0:1}
def frac(n):
  if n in memo:
    return memo[n]
  return frac(n-1)*n
def sol(xs):
  if len(xs)==2:
    return(xs[1]-xs[0])
  return sum(xs[i+1]-xs[i]+sol(xs[:i]+xs[i+1:]) for i in range(len(xs)))
print(sol(xs))