import numpy as np
import copy

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

if N == 2:
    print(x[1]-x[0])
elif N == 3:
    print(2*(x[2]-x[1]) + x[2]-x[0] + x[1]-x[0])
else:
    l = [[x[i+j] - x[i] for i in range(N-j)] + [0]*(j-1) for j in range(1, N)]

    move = [0, 0, 0, 0, np.array([[2, 2, 5], [1, 3, 0], [2, 0, 0]])]
    move += [np.array([[1]*(i-1)] + [[0] * (i-1) for _ in range(2, i)]) for i in range(5, N+1)]
    
    for i in range(5, N+1):
        for j in range(i-1):
            nmove = np.insert(np.insert(move[i-1], i-2, 0, axis=0).T, j, 0, axis=0)
            for k in range(j):
                a = copy.copy(nmove[k])
                a = np.insert(a, j-k, 0)
                nmove[k] = np.delete(a, i-1, 0)
            move[i] += nmove.T
    
    print(np.sum(l*move[N]) % 1000000007)