//#define _GLIBCXX_DEBUG #include #include #include #include using namespace std; using namespace atcoder; using mint = modint1000000007; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vm = vector; using vvm = vector; using vpi = vector; using vvpi = vector; using vpl = vector; using vvpl = vector; const int inf = 1 << 30; const ll INF = 1LL << 60; #define rep(i,m,n) for (int i = m; i < (int)(n); i++) #define rrep(i,m,n) for (int i = m; i > (int)(n); i--) int main(){ int n; cin >> n; vl A(n); rep(i,0,n){ cin >> A[i]; } mint ju = 1, ans = 0; rep(i,0,n){ ju *= A[i]; if (n-2-i >= 0) ans += ju*2*mint(3).pow(n-2-i); else ans += ju; } cout << ans.val() << endl; }