import itertools
import math
import copy

N=input()
p=input()
dist_total=0
plist_str=p.split(" ")
plist=[int(n) for n in plist_str]

lis = [x for x in range(int(N)-1)]
permutations_lis = itertools.permutations(lis)

for one_case in permutations_lis: 
  plist_=copy.copy(plist)
  for num in one_case:
    dist_total+=plist_[num+1]-plist_[num]
    dist_total%=1000000007
    plist_[num]=plist_[num+1]

print(dist_total)