import itertools

N = int(input())
X = list(map(int, input().split()))

dict = {}
for i in itertools.combinations(range(N), 2):
    dict[i] = X[i[1]] - X[i[0]]

count = 0
for i in itertools.permutations(range(N-1)):
    for idx, j in enumerate(i):
        k = 1
        while j+k in i[:idx]:
            k += 1
        count += dict[(j, j+k)]
print(count % (10**9+7))