// correct #include #include #include using mint = atcoder::modint998244353; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string n_str; std::cin >> n_str; const int l = n_str.size(); std::vector n_digits(l); for (int i = 0; i < l; ++i) { n_digits[l - 1 - i] = n_str[i] - '0'; } // returns x^n auto nth_pow = [&](mint x) { mint res = 1; for (int i = 0; i < l; ++i) { if (n_digits[i]) res *= x; x *= x; } return res; }; mint ans = 0; // 1 { mint n = 0; for (int i = l - 1; i >= 0; --i) { n *= 2; n += n_digits[i]; } ans += 2 * n * nth_pow(3) / 3; } // 0 { // r^(2^i) mint pow_r_doubling = mint(3) / 2; // 2^i mint pow_2 = 1; mint ans_0 = 0; for (int i = 0; i < l; ++i) { if (n_digits[i] == 0) { ans_0 += pow_2; } else { ans_0 *= pow_r_doubling; } pow_r_doubling *= pow_r_doubling; pow_2 *= 2; } ans += ans_0 * nth_pow(2) * 4 / 9; } std::cout << ans.val() << std::endl; }