#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #pragma region #include using namespace std; using ll = long long; using ull = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; using vi = vector; using vll = vector; using vvi = vector>; using vvll = vector>; using vvvi = vector>>; using vpi = vector>; using vpll = vector>; using vs = vector; using vb = vector; using vvb = vector>; using pi = pair; using pll = pair; template using spq = priority_queue, greater>; template using gpq = priority_queue; #define fi first #define se second #define pb push_back #define fore(p,a) for (auto p : a) #define overload4(a,b,c,d,name,...) name #define rep1(n) for (int i = 0; i < int (n); ++i) #define rep2(i,n) for (int i = 0; i < int (n); ++i) #define rep3(i,a,b) for (int i = a; i < int (b); ++i) #define rep4(i,a,b,c) for (int i = a; i < int (b); i += c) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(n) for (int i = n; i--;) #define rrep2(i,n) for (int i = n; i--;) #define rrep3(i,a,b) for (int i = b; i-- > (a);) #define rrep4(i,a,b,c) for (int i = (a) + ((b) - (a) - 1) / (c) * (c); i >= (a); i -= c) #define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(container) begin(container), end(container) #define rall(container) rbegin(container), rend(container) #define mvvi(name, row, column) vvi name(row, vi(column)) #define mvvll(name, row, column) vvll name(row, vll(column)) #define mvvb(name, row, column) vvb name(row, vb(column)) #define Max(...) max({__VA_ARGS__}) #define Min(...) min({__VA_ARGS__}) #define fin exit(0) #define popc __builtin_popcount #define inrange(x, l, r) ((l) <= (x) && (x) < (r)) #define sq(x) ((x) * (x)) #ifdef LOCAL template string internal_vectostr(vector v) { string ret; for (int i = 0; i < (int) v.size(); i++) ret += (i ? ", " : "") + to_string(v[i]); return ret; } #define dbg(x) cerr << "[DEBUG] " << __LINE__ << ": " << #x << " = " << x << endl #define dbv(x) cerr << "[DEBUG] " << __LINE__ << ": " << #x << " = { " << internal_vectostr(x) << " }" << endl #define tabout(tab, n, m) cout << "[DEBUG]\n"; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << tab[i][j] << ' '; cout << endl; } #else template void internal_vectostr(vector v) {} #define dbg(x) ((void) 0) #define dbv(x) ((void) 0) #define tabout(tab, n, m) ((void) 0) #endif constexpr int INF = 1001001001; constexpr ll LINF = 1LL << 60; constexpr double EPS = 1e-10; const double PI = acos(-1); template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll fact(ll x) { return x == 0 ? 1 : x * fact(x - 1); } ll comb(ll n, ll r) { if (r < 0 || n < r) return 0; ll ret = 1; for (ll i = 1; i <= r; i++) { ret *= n; n--; ret /= i; } return ret; } int Yes(bool f=1) { cout << (f ? "Yes" : "No") << '\n'; return 0; } int No() { Yes(0); return 0; } int YES(bool f=1) { cout << (f ? "YES" : "NO") << '\n'; return 0; } int NO() { YES(0); return 0; } int yes(bool f=1) { cout << (f ? "yes" : "no") << '\n'; return 0; } int no() { yes(0); return 0; } template int printvec(vector v) { for (int i = 0; i < (int) v.size(); i++) cout << (i ? " " : "") << v[i]; cout << '\n'; return 0; } struct IoInit { IoInit() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(15) << fixed; cerr << setprecision(15) << fixed; } } io_init; #pragma endregion #include #include using mint=atcoder::modint998244353; int main(){ string s; cin>>s; int n=s.size(); vector>>dp(n+1,vector>(3,vector(4))); vector dp1=dp; int cnt=0; rep(n)cnt+=s[i]=='?'; for(int i=0;i0)dp[i][2][j]+=dp[i-1][1][j]; } } if(s[i]=='1'){ for(int j=0;j<4;j++){ if(i>0)dp[i][1][j]+=dp[i-1][0][j]; } } if(s[i]=='?'){ dp[i][0][1]++; for(int j=0;j<3;j++){ if(i>0)dp[i][2][j+1]+=dp[i-1][1][j]; if(i>0)dp[i][1][j+1]+=dp[i-1][0][j]; } } for(int j=0;j<3;j++)for(int k=0;k<4;k++)dp[i+1][j][k]+=dp[i][j][k]; } mint ans; rep(4)dbg(dp[n][2][i].val()); ans+=atcoder::pow_mod(2,cnt,998244353)*dp[n][2][0]; if(cnt>=1)ans+=atcoder::pow_mod(2,cnt-1,998244353)*dp[n][2][1]; if(cnt>=2)ans+=atcoder::pow_mod(2,cnt-2,998244353)*dp[n][2][2]; if(cnt>=3)ans+=atcoder::pow_mod(2,cnt-3,998244353)*dp[n][2][3]; cout<