import itertools
N = int(input())
x = list(map(int,input().split()))
mod = 10 ** 9 + 7
dist = [[0]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    dist[i][j] = abs(x[j] - x[i]) % mod
#print(dist)
perm = list(itertools.permutations(list(range(N - 1))))
#print(perm)
ans = 0
for p in perm:
  tmp = list(p)
  tmp.append(N-1)
  for i in range(N - 1):
    ans += dist[tmp[i]][tmp[i+1]]% mod
    
print(ans % mod)