import random
import math
# スライム数
n = int(input())

x = list(map(int, input().split()))
distance = 0

for i in range(n-1):
    k = random.randint(1, n-i-1)
    distance += x[k] - x[k-1]
    x[k-1] = x[k]
    for j in range(k, n-1):
        x[j] = x[j+1]

nfactorial = math.factorial(n-2)
nsum = int(math.pow(10, 9)) + 7
nresult = nfactorial % nsum

print(nresult)
