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 Perl (5.26.1) (judge verdict: Time Limit Exceeded)

use strict;
use warnings;
package Convolution;
use integer;
sub MOD(){998244353};
sub primitive_root(){3};
sub bsf($){
	my$x=shift;
	my$c=0;
	$c++until$x>>$c&1;
	return$c;
}
sub powermod($$){
	my($v,$w)=@_;
	my$r=1;
	$v%=MOD;
	while($w>0){
		$r=$r*$v%MOD if$w&1;
		$v=$v*$v%MOD;
		$w>>=1;
	}
	return$r;
}

my(@es,@ies,@sum_e,@sum_ie);
{
	my$cnt2=bsf(MOD-1);
	my$e=powermod(primitive_root,MOD-1>>$cnt2);
	my$ie=powermod($e,MOD-2);
	for(my$i=$cnt2;$i>=2;$i--){
		$es[$i-2]=$e;
		$ies[$i-2]=$ie;
		$e=$e*$e%MOD;
		$ie=$ie*$ie%MOD;
	}
	my$now=1;
	my$inow=1;
	for(0..$cnt2-3){
		$sum_e[$_]=$es[$_]*$now%MOD;
		$now=$now*$ies[$_]%MOD;
		$sum_ie[$_]=$ies[$_]*$inow%MOD;
		$inow=$inow*$es[$_]%MOD;
	}
}

sub butterfly($@){
	my$h=shift;
	my@a=@_;
	for my$ph(1..$h){
		my$w=1<<$ph-1;
		my$p=1<<$h-$ph;
		my$now=1;
		for my$s(0..$w-1){
			my$offset=$s<<$h-$ph+1;
			for($offset..$offset+$p-1){
				my$l=$a[$_];
				my$r=$a[$_+$p]*$now%MOD;
				$a[$_]=($l+$r)%MOD;
				$a[$_+$p]=($l-$r+MOD)%MOD;
			}
			$now=$now*$sum_e[bsf(~$s)]%MOD;
		}
	}
	return@a;
}
sub butterfly_inv($@){
	my$h=shift;
	my@a=@_;
	for(my$ph=$h;$ph>=1;$ph--){
		my$w=1<<$ph-1;
		my$p=1<<$h-$ph;
		my$inow=1;
		for my$s(0..$w-1){
			my$offset=$s<<$h-$ph+1;
			for($offset..$offset+$p-1){
				my$l=$a[$_];
				my$r=$a[$_+$p];
				$a[$_]=($l+$r)%MOD;
				$a[$_+$p]=($l-$r+MOD)*$inow%MOD;
			}
			$inow=$inow*$sum_ie[bsf(~$s)]%MOD;
		}
	}
	return@a;
}

sub convolution(\@\@){
	my@a=@{$_[0]};
	my@b=@{$_[1]};
	my$n=@a;
	my$m=@b;
	return()if$n==0||$m==0;
	my$h=0;
	$h++while$n+$m-1>1<<$h;
	my$z=1<<$h;
	$#a=$z-1;
	@a=butterfly($h,@a);
	$#b=$z-1;
	@b=butterfly($h,@b);
	$a[$_]=$a[$_]*$b[$_]%MOD for 0..$z-1;
	@a=butterfly_inv($h,@a);
	$#a=$n+$m-2;
	my$iz=powermod($z,MOD-2);
	$_=$_*$iz%MOD for@a;
	return@a;
}
no integer;
package main;
my($N,$M)=split$",<>;
my@a=split$",<>;
my@b=split$",<>;
print$_,$/for Convolution::convolution(@a,@b);