import itertools
import math
n = int(input())
*x, = map(int, input().split())

p = 1/(n-1)
ev = 0

for v in itertools.permutations(x[0:n-1], n-1):
    v = list(v)
    v.append(3)
    m = 0
    for i in range(len(v)-1):
        m += abs(v[i]-v[i+1])

    ev += p*m

inf = 10**9+7
print(int(ev*math.factorial(n-1)%inf))
