#include int main(){ using namespace std; constexpr unsigned long MOD{1000000007}; unsigned long N; cin >> N; const auto mul_mod{[](auto a, auto b){return a * b % MOD;}}; vector A(N); for(auto&& i : A)cin >> i; inclusive_scan(begin(A), end(A), begin(A), mul_mod); vector coef(N, 3); coef.back() = 1; coef.rbegin()[1] = 2; inclusive_scan(rbegin(coef), rend(coef), rbegin(coef), mul_mod); cout << inner_product(begin(A), end(A), begin(coef), 0, plus<>{}, mul_mod) % MOD << endl; return 0; }