import sys
input = sys.stdin.readline


def main():
    N = int(input())
    X = list(map(int, input().split()))
    D = [0 for i in range(N)]
    for i in range(N-1):
        D[i] = abs(X[i] - X[i+1])
    ans = 0
    for i in range(1, N):
        m = (i+1)*(N-1)
        if i == N-1:
            m -= 1
        d = D[i-1]
        x = d * m
        ans += x
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()
