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
memo2={}
def sol(xs):
  if tuple(xs) in memo2:
    return memo2[tuple(xs)]
  if len(xs)==2:
    return(xs[1]-xs[0])
  res=0
  for i,x in enumerate(xs[:-1]):
    xs_=xs.copy()
    xs_.pop(i)
    res+=xs_[i]-x+sol(xs_)
  memo2[tuple(xs)]=res
  return res
print(sol(xs))