typedef long long ll; typedef long double ld; #include using namespace std; #define int long long long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const ll MOD = 1e9+7; signed main(){ ll n; std::cin >> n; vector a(n); ll now = 1; ll ans = 0; for (int i = 0; i < n; i++) { std::cin >> a[i]; now *= a[i]; now %= MOD; ans += now*modpow(3,max(0ll,n-2-i),MOD)%MOD*(2*(i=n-1))%MOD; ans %= MOD; // std::cout << ans << std::endl; } std::cout << ans << std::endl; }