import numpy as np
N = int(input())
X = list(map(lambda x: int(x), input().split()))

dic = {}

class Node:
    def __init__(self, elm):
        self.elm = elm
        self.nexts = []
        self.next_costs = []
        self.prev = []
        
    def __str__(self):
        return str(self.elm)

root = Node(X)
dic[str(root)] = root

def reg(curr, co):
    if len(curr) == 1:
        return;
    cn = dic[str(curr)]
    costs = []
    for idx, x in enumerate(curr[:-1]):
        cost = curr[idx+1] - x + co
        cn.next_costs.append(cost)
        n = curr[:idx] + curr[idx+1:]
        if str(n) in dic:
            dic[str(n)].prev.append(cn)
            continue
        nn = Node(n)
        nn.prev.append(cn)
        dic[str(n)] = nn
        costs.append(reg(n, cost))
reg(X, 0)
cs = []
c = 0
for n in dic[str([max(X)])].prev:
    cs.append(n.next_costs[0])
c = np.mean(cs)
for i in range(2, N):
    c = c* i
print(int(c % ((10 ** 9) +7)))