#include using namespace std; int main() { int N; cin >> N; vector A( N ); for( int i = 0; i < N; i ++ ) cin >> A[i]; const long long MOD = 1000000007; vector x3( N ); x3[0] = 1; for( int i = 1; i < N; i++ ) x3[i] = x3[i - 1] * 3 % MOD; long long ans = 0; long long a = 1; for( int i = 0; i < N; i++ ) { a *= A[i]; a %= MOD; long long aa = a; int n = max( N - 2 - i, 0 ); aa *= x3[n]; aa %= MOD; if( N - 1 - i > 0 ) aa *= 2; aa %= MOD; ans += aa; ans %= MOD; } cout << ans << endl; }