#include #include #include using namespace std; int main() { // 標準入出力の高速化 ios::sync_with_stdio(false); cin.tie(nullptr); string a; if (!(cin >> a)) return 0; int n = a.length(); long long mod = 998244353; // 1. 最初の '0' と 最後の '1' の位置を探す int first_zero = -1; for (int i = 0; i < n; ++i) { if (a[i] == '0') { first_zero = i; break; } } int last_one = -1; for (int i = n - 1; i >= 0; --i) { if (a[i] == '1') { last_one = i; break; } } // 0が1より左にない場合、変化は起きないので1通り if (first_zero == -1 || last_one == -1 || first_zero > last_one) { cout << 1 << endl; return 0; } // 2. 有効範囲 [first_zero, last_one] を走査してブロック計算 long long ans = 1; int i = first_zero; while (i <= last_one) { long long zero_count = 0; long long one_count = 0; // 連続する '0' を数える while (i <= last_one && a[i] == '0') { zero_count++; i++; } // 連続する '1' を数える while (i <= last_one && a[i] == '1') { one_count++; i++; } // ブロック (0...01...1) の組み合わせ数を掛ける if (zero_count > 0 && one_count > 0) { ans = (ans * (zero_count + one_count)) % mod; } } cout << ans << endl; return 0; }