N = int(input())
x = list(reversed(list(map(int,input().split()))))
mod = 10**9+7
x = [x[0]-i for i in x]

def rep(x,mod):
    count = 0
    if len(x) == 2:
        return x[1]
    for i in range(1,len(x)):
        count += ((x[i]-x[i-1]) + rep([x[j] for j in range(len(x)) if j != i],mod))%mod
    return count
print(rep(x,mod))