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

a = 10**9+7

def solve(lst, past=0):
    print(lst)
    l = len(lst)
    if l == 2:
        return past + lst[1] - lst[0]
    else:
        out = 0
        for i in range(l-1):
            d = lst[i+1] - lst[i]
            out += solve(lst[0:i]+lst[i+1:l], d)
        return out

print(solve(x) % a)
            