// Validator #include "testlib.h" #include #include using namespace std; #include using mint = atcoder::modint1000000007; int main(int argc, char **argv) { registerValidation(argc, argv); int N = inf.readInt(2, 200000); inf.readEoln(); vector A = inf.readInts(N, 0, 1000000000); inf.readEoln(); inf.readEof(); mint ret = 0, prod = 1; const mint d23 = mint(2) / 3; for (int i = 0; i < N; i++) { ret *= 3; prod *= A[i]; ret += prod * (i == N - 1 ? 1 : d23); } cout << ret.val() << '\n'; }