MOD = 10 ** 9 + 7
N = int(input())
X = list(map(int, input().split()))

ans = 0
ds1 = []
ds2 = []
for i in range(N-2, -1, -1):
    if i == N-2:
        ds1.append((X[N-1] - X[i]) % MOD)
    else:
        if ds1 == []:
            for d in ds2:
                for ii in range(i+1, N):
                    ds1.append((d + X[ii] - X[i]) % MOD)
            ds2 = []
        else:
            for d in ds1:
                for ii in range(i+1, N):
                    ds2.append((d + X[ii] - X[i]) % MOD)
            ds1 = []


print(sum(ds1) % MOD if ds2 == [] else sum(ds2) % MOD)