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

ans = 0

ans = [0] * N
for x in range(N - 2, -1, -1):
    for y in range(N - 1, x, -1):
        #print(x, y)
        ans[x] = (ans[x] + X[y] - X[x] + ans[y]) % (10**9 + 7)
        #print(ans)
        
print(sum(ans) % (10**9 + 7))
