N = gets.to_i
X = gets.split.map &:to_i
I = Array.new(N)
D = 10**9+7
t = 0
(1...N).to_a.permutation.each {|a|
  N.times {|i| I[i]=i+1 }
  a.each {|k|
    I[k-1] = i = I[k]
    t -= D  if D <= t += X[i-1]-X[k-1]
  }
}
p t