import copy

def function(xs):
    res=None
    l=len(xs)
    if l==2:
        res=xs[1]-xs[0]
    else:
        res=0
        for i in range(l-1):
            xstemp=copy.copy(xs)
            v=xstemp[i+1]-xstemp[i]
            xstemp.pop(i)
            res+=v+function(xstemp)
            
            
    return res
    
N=int(input())

data=input().split(" ")

Xs=[]

for x in data:
    Xs.append(int(x))



ans=function(Xs)

print(ans%(10**9+7))