#include #include using namespace std; using namespace atcoder; const long nPrime = 1000000007; //const long nPrime = 998244353; typedef long long ll; int main() { long n; cin >> n; vector viNum(n), viOrd(n+1,2); for(long i = 0; i < n; i++){ cin >> viNum[i]; viOrd[i+1] = viOrd[i]*3; viOrd[i] %= nPrime; } long nAns = 0; long iThis = 1; for(long i = 0; i < n-1; i++){ iThis *= viNum[i]; iThis %= nPrime; nAns += iThis * viOrd[n-i-2]; nAns += nPrime; } nAns += iThis * viNum[n-1]; nAns %= nPrime; cout << nAns << endl; return 0; }