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

import copy
ans = 0
list_place_init = copy.copy(x_list)

def fusing_slimes(n, list_place):
    global ans
    global list_place_init
    if n == 3:
        p1 = (list_place[1] - list_place[0]) + (list_place[2] - list_place[1])
        p2 = (list_place[2] - list_place[1]) + (list_place[2] - list_place[0])
        ans += p1 + p2
    else:
        for i in range(n-1):
            ans += (list_place[i+1] - list_place[i])
            list_place.pop(i)
            fusing_slimes(n-1, list_place)
            list_place = copy.copy(list_place_init)

fusing_slimes(n, x_list)

print(ans % 1000000007)