import sys
import copy
import bisect
import numpy as np

N=int(input())
x = list(map(int,input().split()))
dp = [[0]*(N+2) for _ in range(N+2)]
dp[1][0] = -1
dp[1][1] = -1
dp[1][2] = 1
MOD = 10**9+7
for i in range(2,N):
    for j in range(1,i+2):
        if i+1==j:
            dp[i][j] = (dp[i-1][j-1]*(i-0) + 1)%MOD
        elif j==1:
            dp[i][j] = (dp[i-1][j]*(i-1) - 1)%MOD
        else:
            #dp[i][j] = dp[i-1][j-1]*(j-1) + dp[i-1][j-2] * (i-j-1)
            dp[i][j] = (dp[i-1][j]*(i-j) + dp[i-1][j-1] * (j-1))%MOD
    print(dp[i])
res = 0
for i in range(N):
    res += dp[N-1][i+1]*x[i]
#for i in range(1,N):
#    res = (res*i)%MOD
print(res%MOD)
