mod=998244353 table_size=3*10**5 fac=[1]*(table_size+1) finv=[1]*(table_size+1) for i in range(2,table_size+1): fac[i]=fac[i-1]*i%mod finv[table_size]=pow(fac[table_size],mod-2,mod) for i in range(table_size-1,-1,-1): finv[i]=finv[i+1]*(i+1)%mod def rebuild(n): global table_size,fac,finv fac+=[0]*(n-table_size) fac+=[0]*(n-table_size) finv+=[0]*(n-table_size) for i in range(table_size+1,n+1): fac[i]=fac[i-1]*i%mod finv[n]=inv(fac[n]) for i in range(n-1,table_size,-1): finv[i]=finv[i+1]*(i+1)%mod table_size=n def binom(n,k): if n<0 or k<0: return 0 if k>n: return 0 if n>table_size: rebuild(n+10**4) return (fac[n]*finv[k]%mod)*finv[n-k]%mod def fpow(x,k): res=1 while k: if k&1: res=res*x%mod x=x*x%mod k>>=1 return res def inv(a): if a