import math

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main(N, X):
    ans = 0
    for i in range(N-1):
        ans += X[i+1] * math.factorial(N-1) /2

        for j in range(i+2, N):
            if N-1-(j-i+1)>=0 and j-i+1>=0:
                ans += X[j] * combinations_count(N-1, j-i+1) * math.factorial(j-i-1)
    print((ans- sum(X[-1:])*math.factorial(N-1)) % MOD)
main(N, X)
