Problem:
Score : 100 points

Problem Statement

You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.

Constraints

1 \leq N, M \leq 524288

0 \leq a_i, b_i < 998244353

All values in Input are integer.

Input

Input is given from Standard Input in the following format:

N M
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{M-1}

Output

Print the answer in the following format:

c_0 c_1 ... c_{(N - 1) + (M - 1)}

Sample Input 1

4 5
1 2 3 4
5 6 7 8 9

Sample Output 1

5 16 34 60 70 70 59 36

Sample Input 2

1 1
10000000
10000000

Sample Output 2

871938225

Solution in C (GCC 9.2.1) (judge verdict: Accepted)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>

char buf[1<<24];
int nextint(){
	static int id = 0;
	if(id == 0)read(0, buf, 1<<24);
	int res = 0;
	while(buf[id]<'0' || '9'<buf[id])id++;
	while(id<1<<24 && '0'<=buf[id] && buf[id]<='9'){
		res *= 10;
		res += buf[id++] - '0';
	}if(id>=1<<24)return -1;
	return res;
}

int getint(){
	register char c = getchar();
	int res = 0;
	while(48<=c && c<=57){
		res *= 10;
		res += c - 48;
		c = getchar();
	}
	return res;
}

#define sz 1<<20
#define mod 998244353
#define pr 3

long modpow(long x, long y, long m){
	long res = 1l, tmp = x;
	while(y){
		if(y&1)res = res * tmp % m;
		tmp = tmp * tmp % m;
		y >>= 1;
	}
	return res;
}
int bit_rev(int x, int h){
	int res = 0;
	for(int i=0; i<h; i++){
		res <<= 1;
		res |= x&1;
		x >>= 1;
	}
	return res;
}
void dft(long a[], int h, bool sign){
	for(int i=0; i<1<<h; i++){
		int j = bit_rev(i, h);
		if(i < j){
			long tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
	for(int s=1; s<=h; s++){
		int m = 1<<s;
		long zeta = modpow(pr, (mod-1)>>s, mod);
		if(!sign)zeta = modpow(zeta, mod-2, mod);
		for(int k=0; k<1<<h; k+=m){
			long pow_zeta = 1;
			for(int j=0; j<m/2; j++){
				long t = pow_zeta * a[k+j+m/2] % mod,
					 u = a[k+j];
				a[k+j] = (u + t) % mod;
				a[k+j+m/2] = (mod + u - t) % mod;
				pow_zeta = zeta * pow_zeta % mod;
			}
		}
	}
}
int N, M;
long A[sz], B[sz];
int main(){
	//scanf("%d%d", &N, &M);
	N = nextint(); M = nextint();
	//for(int i=0; i<N; i++)scanf("%ld", &A[i]);
	//for(int i=0; i<M; i++)scanf("%ld", &B[i]);
	for(int i=0; i<N; i++)A[i] = nextint();
	for(int i=0; i<M; i++)B[i] = nextint();
	dft(A, 20, true); dft(B, 20, true);
	for(int i=0; i<sz; i++)A[i] = A[i] * B[i] % mod;
	dft(A, 20, false);
	long inv = modpow(sz, mod-2, mod);
	for(int i=0; i<N+M-1; i++){
		if(i)putchar(32);
		printf("%ld", A[i] * inv % mod);
	}putchar(10);
	return 0;
}