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

X = [X[i] - X[0] for i in range(N)]

mod = 1000000007

total = sum(X)
d = [X[i+1] - X[i] for i in range(N-1)]
ans = 0

for i in range(N):
    ansi = (total * (i + 1)) % mod
    ans += ansi % mod
    if(i != N - 1):
        total -= d[0] * (N - i - 1)

print(ans)

