//yukicoder@cpp17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ template T uPow(T z,T n, T mod){ T ans = 1; while(n != 0){ if(n%2){ ans*=z; if(mod)ans%=mod; } n >>= 1; z*=z; if(mod)z%=mod; } return ans; } /* function corner below */ /* Function corner above */ __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int main(){ int n;cin>>n; vector A(n); for(int i = 0; n > i; i++){ cin>>A[i]; } long long t = 1; for(int i = 0; n-1 > i; i++)t = (t*3)%MODx; long long ans = 0; long long nw = 1; for(int i = 0; n-1 > i; i++){ nw = (nw*A[i])%MODx; ans = (ans+((nw*((((t*2)%MODx)*uPow(3LL,MODx-2,MODx))%MODx))%MODx))%MODx; t = (t*uPow(3LL,MODx-2,MODx))%MODx; } nw = (nw*A[n-1])%MODx; ans = (ans+nw)%MODx; cout << ans << endl; }