#include using namespace std; typedef long long ll; const int mod = 1e9 + 7, N = 2e5 + 10; int n; ll a[N],sum[N]; ll qmi(int a,int k) { ll sum = 1; while(k) { if(k & 1) sum = sum * a % mod; a = a * a % mod; k >>= 1; } return sum; } int main() { scanf("%d",&n); for(int i = 1;i <= n;i ++ ) scanf("%lld",&a[i]); sum[0] = 1; for(int i = 1;i <= n;i ++ ) sum[i] = (sum[i - 1] % mod * a[i] % mod) % mod; ll ans = 0; for(int i = 1;i <= n;i ++ ) { if(i != n) { ans += (sum[i] * 2ll % mod * qmi(3,n - i - 1) % mod) % mod; ans %= mod; } else { ans += sum[i] % mod; ans %= mod; } } printf("%lld\n",ans); return 0; }