#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 1000006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; constint P = 998244353; int n , m; char s[MAXN];
int dp[MAXN][25] , S[MAXN] , qm = 0 , bm = 0;
voidsolve(){ scanf("%s",s + 1); n = strlen( s + 1 ); rep( i , 1 , n ) S[i] = S[i - 1] + ( s[i] == 'B' ); int flg = 0; dp[n + 1][0] = 1; per( i , n , 1 ) { qm += s[i] == '?'; bm += s[i] == 'B'; if( s[i] != 'B' ) dp[i][0] = dp[i + 1][0]; if( s[i] != 'S' ) dp[i][1] = dp[i + 1][0]; rep( k , 1 , 22 ) { if( k > 1 && i + ( 1 << k - 2 ) + 1 > n ) break; if( s[i] != 'B' ) dp[i][k] = ( dp[i][k] + dp[i + 1][k] ) % P; if( k > 1 && s[i] != 'S' && S[i + ( 1 << k - 2 )] - S[i] == 0 ) dp[i][k] = ( dp[i][k] + dp[i + ( 1 << k - 2 ) + 1][k - 1] ) % P; } } int as = 1; rep( i , 1 , qm ) as = as * 2 % P; rep( k , 0 , 22 ) as = ( as + P - dp[1][k] ) % P; cout << as << endl; }