// WA mod とり忘れ #include #include using namespace std; #include using mint = atcoder::modint1000000007; int main() { int N; cin >> N; long long ret = 0; mint prod = 1; const mint d23 = mint(2) / 3; for (int i = 0; i < N; i++) { ret = (mint(ret) * 3).val(); int a; cin >> a; prod *= mint(a); ret = (mint(ret) + (prod * d23)).val(); } ret += (prod / 3).val(); cout << ret << '\n'; }