You are given N blocks arranged in a row, each with a weight. Snuke will remove blocks N times, choosing one block each time. The cost of removing a block is the sum of the weights of the connected blocks. Find the total cost for all possible orders of removing the blocks, and calculate the sum modulo 10^9+7. Constraints: 1 ≤ N ≤ 10^5, 1 ≤ Ai ≤ 10^9. Input format: N, followed by N weights. Output the sum of total costs modulo 10^9+7 for all N! orders.

# Buggy version:
m=10**9+7
i=s=r=0
f=1
*a=open(0).read().split()
for x in a[1:]:i+=1;s+=pow(i,m-2,m);r+=int(x)*~-s+int(a[-i])*s;f=f*i
print(r*f%m)


# Fixed version:
m=10**9+7
i=s=r=0
f=1
_,*a=open(0).read().split()
for x in a:i+=1;s+=pow(i,m-2,m);r+=int(x)*~-s+int(a[-i])*s;f=f*i%m
print(r*f%m)

# Buggy version:
import math
N=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
#Nの階乗
x=math.factorial(N)%p
#0からにすると1/0でエラーになる
for i in range(1,N+1):
  #kは逆元
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  SUM.append(sum)
#SUMのi番目は1/1から1/iまで足した和になっている。
#k=i-1となる
#1/1を二回足してしまったので引く
for i in range(N):
  ans+= (number[i]*(SUM[i]+SUM[N-i]-x))%p
  ans= ans%p
#答え
print(ans)

# Fixed version:
import math
N=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
#Nの階乗
x=math.factorial(N)%p
#0からにすると1/0でエラーになる
for i in range(1,N+1):
  #kは逆元
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%p
  SUM.append(sum)
ans=0
#SUMのi番目は1/1から1/iまで足した和になっている。
#k=i-1となる
#1/1を二回足してしまったので引く
for i in range(N):
  ans+= (number[i]*(SUM[i]+SUM[N-i-1]-x))%p
  ans= ans%p
#答え
print(ans)

# Buggy version:
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(10**9 +7)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*x*(SUM[n-1-i]+SUM[i]-1)
  ans=ans%(p)
print(ans)


# Fixed version:
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(p)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(p)
print(ans)

# Buggy version:
ef multiply(x, y):
    return (x * y) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif x == 1:
        return 1
    elif x == 0:
        return 0
    else:
        # print(mod)
        tmp = power(x, y // 2)
        return (multiply(tmp, tmp) * [1, x][y % 2]) % mod


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

mod = 10 ** 9 + 7

plist = [0]
nfact = 1
N
tmp = 0
for i in range(1, N):
    tmp = (tmp + power(i + 1, mod - 2)) % mod
    nfact = (nfact * (i + 1)) % mod
    plist.append(tmp)

ans = 0
# print(plist)
# print(nfact)
for i, a in enumerate(A):
    # print(i, N - i - 1, N)
    tmp = (1 + plist[i] + plist[N - i - 1]) % mod
    ans = (ans + multiply(multiply(a, tmp), nfact)) % mod

print(ans)

# Fixed version:
def multiply(x, y):
    return (x * y) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif x == 1:
        return 1
    elif x == 0:
        return 0
    else:
        # print(mod)
        tmp = power(x, y // 2)
        return (multiply(tmp, tmp) * [1, x][y % 2]) % mod


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

mod = 10 ** 9 + 7

plist = [0]
nfact = 1
N
tmp = 0
for i in range(1, N):
    tmp = (tmp + power(i + 1, mod - 2)) % mod
    nfact = (nfact * (i + 1)) % mod
    plist.append(tmp)

ans = 0
# print(plist)
# print(nfact)
for i, a in enumerate(A):
    # print(i, N - i - 1, N)
    tmp = (1 + plist[i] + plist[N - i - 1]) % mod
    ans = (ans + multiply(multiply(a, tmp), nfact)) % mod

print(ans)

# Buggy version:
m=10**9+7
i=s=r=0
f=1
input()
a=map(int,input().split())
for x in a:i+=1;s+=pow(i,m-2,m);r+=x*~-s+a[-i]*s;f=f*i%m
print(r*f%m)


# Fixed version:
m=10**9+7
i=s=r=0
f=1
input()
a=input().split()
for x in a:s+=pow(i+1,m-2,m);r+=int(x)*~-s+int(a[~i])*s;i+=1;f=f*i%m
print(r*f%m)

# Buggy version:
N=int(input())
A=[int(i) for i in input().split()]
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]%P
Q=[0 for i in range(N)]
I=[inv(i) for i in range(1,N+2)]
U=[0 for i in range(N+2)]
for i in range(N):
    U[i+1]=(U[i]+I[i])%P
for j in range(N):
    Q[j]=(U[j+1]+U[N-j-1]-1)%P
ans=0
for i in range(N):
    ans+=A[i]*Q[i]
    ans=ans%P
print(ans)


# Fixed version:
N=int(input())
A=[int(i) for i in input().split()]
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]%P
Q=[0 for i in range(N)]
I=[inv(i) for i in range(1,N+2)]
U=[0 for i in range(N+2)]
Fact=[0 for i in range(N+1)]
Fact[0]=1
for i in range(N):
    Fact[i+1]=((i+1)*Fact[i])%P
for i in range(N+1):
    U[i+1]=(U[i]+I[i])%P
for j in range(N):
    Q[j]=(U[j+1]+U[N-j]-1)%P
ans=0
for j in range(N):
    ans+=A[j]*Q[j]
    ans=ans%P
print((ans*Fact[N])%P)

# Buggy version:
m=10**9+7
input()
i=s=r=0
f=1
a=map(int,input().split())
for _ in a:
 s+=pow(i+1,m-2,m)
 r+=a[i]*~-s+a[~i]*s
 i+=1
 f=f*i%m
print(r*f%m)

# Fixed version:
m=10**9+7
input()
i=s=r=0
f=1
a=input().split()
for _ in a:
 s+=pow(i+1,m-2,m)
 r+=int(a[i])*~-s+int(a[~i])*s
 i+=1
 f=f*i%m
print(r*f%m)

# Buggy version:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
#a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def extended_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    # return c0, a0, b0
    return a0

def quotient(p, q): #p: 分子, q: 分母
	return (extended_euclid(q, MOD) * p) % MOD

def factorial(i):
	if i == 1:
		return 1
	else:
		return (factorial(i-1) * i) % MOD

inv_list = [1]
for i in range(2, n+1):
	inv_list.append((inv_list[-1] + quotient(1, i)) % MOD)

#print(inv_list[-1])
#print(factorial(n))

ans = 0
for i in range(n):
	ans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD
	ans %= MOD
ans *= factorial(n)
ans %= MOD
print(ans)

# Fixed version:
import sys
sys.setrecursionlimit(10**7)

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

def extended_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 != 0:
        m = c0 % c1
        q = c0 // c1

        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    # return c0, a0, b0
    return a0

def quotient(p, q): #p: 分子, q: 分母
	return (extended_euclid(q, MOD) * p) % MOD

def factorial(i):
	if i == 1:
		return 1
	else:
		return (factorial(i-1) * i) % MOD

inv_list = [1]
for i in range(2, n+1):
	inv_list.append((inv_list[-1] + quotient(1, i)) % MOD)

#print(inv_list[-1])
#print(factorial(n))

ans = 0
for i in range(n):
	ans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD
	ans %= MOD
ans *= factorial(n)
ans %= MOD
print(ans)