#include #include "atcoder/modint.hpp" using mint = atcoder::modint998244353; #include "testlib.h" void solve() { std::string S = inf.readToken(format("[01]{%d, %d}", 1, 1'000'000)); inf.readEoln(); ensure(S[0] == '1'); std::reverse(S.begin(), S.end()); int n = S.size(); mint three = 3; mint c0 = mint(2) / 3; mint all_ = c0; auto t = c0; mint two = 1; mint ans = 0; for (int i = 0; i < n; i++) { if (S[i] == '1') { ans += two; all_ *= three; t *= c0; } else { ans += two * t; } three *= three; two *= 2; c0 *= c0; } std::cout << (ans * all_).val() << std::endl; } int main(int argc, char *argv[]) { std::cin.tie(0)->sync_with_stdio(0); registerValidation(argc, argv); solve(); inf.readEof(); }