# BZOJ3625: [Codeforces Round #250]小朋友和二叉树

2 3
1 2

3 10
9 4 3

5 10
13 10 6 4 15

1
3
9

0
0
1
1
0
2
4
2
6
15

0
0
0
1
0
1
0
2
0
5

## HINT

#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
inline char Getchar() {
}
}
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int p=998244353;
const int maxn=300010;
const int G=3;
const ll inv2=499122177;
ll pow(ll n,ll m) {
ll ans=1;
for(;m;m>>=1,(n*=n)%=p) if(m&1) (ans*=n)%=p;
return ans;
}
int wn[20];
void NTT(int* A,int len,int t) {
int j=len>>1,c=0;
rep(i,1,len-2) {
if(i<j) swap(A[i],A[j]);int k=len>>1;
while(j>=k) j-=k,k>>=1;j+=k;
}
for(int i=2;i<=len;i<<=1) {
c++;
for(int j=0;j<len;j+=i) {
int w=1;
for(int k=j;k<j+(i>>1);k++) {
int u=A[k],t=(ll)w*A[k+(i>>1)]%p;
A[k]=(u+t)%p;A[k+(i>>1)]=(u-t+p)%p;
w=((ll)w*wn[c])%p;
}
}
}
if(t<0) {
int inv=pow(len,p-2);
rep(i,1,len/2-1) swap(A[i],A[len-i]);
rep(i,0,len-1) A[i]=((ll)A[i]*inv)%p;
}
}
int T[maxn];
void getinv(int* A,int* B,int n) {
if(n==1) {B[0]=pow(A[0],p-2);return;}
getinv(A,B,n>>1);int len=n<<1;
rep(i,0,n-1) T[i]=A[i],T[i+n]=0;
NTT(B,len,1);NTT(T,len,1);
rep(i,0,len-1) B[i]=(ll)B[i]*(2-(ll)B[i]*T[i]%p+p)%p;
NTT(B,len,-1);rep(i,n,len-1) B[i]=0;
}
int revB[maxn];
void getsqrt(int* A,int* B,int n) {
if(n==1) {B[0]=1;return;}
getsqrt(A,B,n>>1);int len=n<<1;
rep(i,0,n-1) revB[i]=0;
getinv(B,revB,n);
rep(i,0,n-1) T[i]=A[i],T[i+n]=0;
NTT(B,len,1);NTT(T,len,1);NTT(revB,len,1);
rep(i,0,len-1) B[i]=(ll)inv2*(B[i]+(ll)T[i]*revB[i]%p)%p;
NTT(B,len,-1);rep(i,n,len-1) B[i]=0;
}
int A[maxn],B[maxn],ans[maxn];
int main() {
rep(i,1,19) wn[i]=pow(G,(p-1)/(1<<i));
while(len<=m) len<<=1;
A[0]=1;
rep(i,0,n-1) {