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