import itertools

n = int(input())
x = list(map(int, input().split()))

cnt = 0
slimes = [i for i in range(n)]
for i in itertools.permutations(slimes[:n-1], n-1):
  s = [i for i in range(n)]
  for index in i:
    current = s.index(index)
    next = s[current + 1]
    s.pop(current)
    cnt += x[next] - x[index]
    cnt %= (10**9 + 7)

print(cnt)
