dist = 0

def fact(n):
    f = 1
    for i in range(2, n + 1):
        f = f * i
    return f

def distsum(n, *x):
    global dist
    y = list(x)
    for i in range(n - 1):
        dist = dist + (y[i + 1] - y[i])
    for i in range(n - 1):
        y = list(x)
        y.remove(y[i])
        if len(y) > 1:
            distsum(n - 1, *y)

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

distsum(N, *x)

a = dist
b = 1e9 + 7
if a < b:
    print(a)
else:
    print(a % b)