N = int(input()) A = list(map(int,input().split())) MOD = 10**9+7 ans = A[0]+A[-1]+(N-1)*(A[1]+A[-2]) for i in range(2,N-2): ans += (N*(N-1)//2)*A[i] ans %= MOD print(ans)