import sys input = sys.stdin.readline MOD = 998244353 PRIMITIVE_ROOT = 3 # ----------------- ModInt ----------------- class ModInt: __slots__ = ['x'] def __init__(self,x): self.x = x % MOD def __add__(self,other): return ModInt(self.x + (other.x if isinstance(other,ModInt) else other)) def __sub__(self,other): return ModInt(self.x - (other.x if isinstance(other,ModInt) else other)) def __mul__(self,other): return ModInt(self.x * (other.x if isinstance(other,ModInt) else other)) def __pow__(self,p): return ModInt(pow(self.x,p,MOD)) def inv(self): return ModInt(pow(self.x,MOD-2,MOD)) def __truediv__(self,other): return self*self.inv() if isinstance(other,ModInt) else self*ModInt(other).inv() def __iadd__(self,other): self.x=(self.x+(other.x if isinstance(other,ModInt) else other))%MOD; return self def val(self): return self.x # ----------------- NTT ----------------- def modinv(x): return pow(x,MOD-2,MOD) def ntt(a,invert): n=len(a); j=0 for i in range(1,n): bit=n>>1 while j&bit: j^=bit bit>>=1 j^=bit if in: return ModInt(0) return self.fact[n]*self.invfact[k]*self.invfact[n-k] # ----------------- Count increasing sequences ----------------- def count_inc_seq(A,C): n=len(A) if n==0: return [] if n==1: return [C[0]]*A[0] m=n//2 LA,LC=A[:m],C[:m] RA,RC=[A[i]-A[m-1] for i in range(m,n)],C[m:] Lseq=count_inc_seq(LA,LC) if not RA: return Lseq max_len=sum(RA)+len(RA)+10 binom=Binomial(max_len) tmp=[binom.C(RA[0]-1+i,i) for i in range(len(Lseq))] conv_res=convolution(tmp,Lseq) res=[ModInt(0)]*max(len(conv_res),RA[-1]) for i in range(len(conv_res)): res[i]=conv_res[i] return res # ----------------- Solve ----------------- def solve(): s=input().strip() n=len(s) a=s.count('A'); b=s.count('B') if a==0 or b==0: print(1); return lb,ub=[],[] h=0 for c in s: if c=='A': lb.append(0); ub.append(h+1) else: h+=1 C=[ModInt(1) for _ in range(len(lb))] tmp=count_inc_seq(ub,C) ans=ModInt(0) for x in tmp: ans+=x print(ans.val()) if __name__=="__main__": solve()