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 Rust (1.42.0) (judge verdict: Wrong Answer)

// https://atcoder.jp/contests/practice2/tasks/practice2_f
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

fn inv(a: i64, modulo: i64) -> i64 {
    pow(a, modulo - 2, modulo)
}

fn pow(a: i64, p: i64, modulo: i64) -> i64 {
    let mut p = p;
    let mut aa = a;
    let mut ret = 1;
    while p >= 1 {
        if p & 1 == 1 {
            ret *= aa;
            ret %= modulo;
        }
        p >>= 1;
        aa = aa * aa % modulo;
    }
    ret
}


/// O(NlogN)
fn ntt(f: &mut Vec<i64>, sign: i64, modulo: i64) {
    let n = f.len();
    assert!(n.is_power_of_two());
    let wlen = n.trailing_zeros() as usize;
    for i in 0..n {
        let mut j = i;
        let mut k = 0;
        for _ in 0..wlen {
            k = (k << 1) | (j & 1);
            j >>= 1;
        }
        if i < k {
            f.swap(i, k);
        }
    }

    let g = 3;
    let mut h = pow(g, (modulo-1)/ n as i64, modulo);
    if sign == -1 {
        h = inv(h, modulo);
    }

    for k in 1..=wlen {
        let block_size = 1usize<<k;
        let half = block_size / 2;
        let mut base = pow(h, (n / block_size) as i64, modulo);
        let mut w = 1;
        for head in 0..half {
            let mut s = head;
            while s < n {
                let l = f[s];
                let r = f[s+half] * w % modulo;
                f[s] = l + r;
                f[s] -= ifv!(f[s] >= modulo, modulo, 0);
                f[s+half] = l - r;
                f[s+half] += ifv!(f[s+half] < 0, modulo, 0);
                s += block_size;
            }
            w = w * base % modulo;
        }
        for i in 0..n {
            f[i] %= modulo;
        }

    }
}

fn ntt_convolution(g: &Vec<i64>, h: &Vec<i64>, modulo: i64) -> Vec<i64> {
    let n = (g.len() + h.len() + 1).next_power_of_two();
    let mut a = vec![0; n];
    let mut b = vec![0; n];
    for i in 0..g.len() {
        a[i] = g[i];
    }
    for i in 0..h.len() {
        b[i] = h[i];
    }

    ntt(&mut a, 1, modulo);
    ntt(&mut b, 1, modulo);
    for i in 0..n {
        a[i] = a[i] * b[i] % modulo;
    }
    ntt(&mut a, -1, modulo);

    let mut c = vec![0; n];
    let inv_n = inv(n as i64, modulo);
    for i in 0..n {
        c[i] = a[i] * inv_n % modulo;
    }
    c
}

// typedef NTT<167772161, 3> NTT_1;
// typedef NTT<469762049, 3> NTT_2;
// typedef NTT<1224736769, 3> NTT_3;
fn convolution(g: Vec<i64>, h: Vec<i64>, modulo: i64) -> Vec<i64> {
    let m1 = 167772161;
    let m2 = 469762049;
    let m3 = 1224736769;
    let x = ntt_convolution(&g, &h, m1);
    let y = ntt_convolution(&g, &h, m2);
    let z = ntt_convolution(&g, &h, m3);

    let m1_inv_m2 = inv(m1, m2);
    let m1m2_inv_m3 = inv(m1 * m2, m3);
    let m1m2_mod = m1 * m2 % modulo;

    let n = x.len();
    let mut c = vec![0; n];
    for i in 0..n {
        let v1 = (y[i] - x[i]) * m1_inv_m2 % m2;
        let v1 = ifv!(v1 < 0, v1 + m2, v1);
        let v2 = (z[i] - (x[i] + m1 * v1) % m3) * m1m2_inv_m3 % m3;
        let v2 = ifv!(v2 < 0, v2 + m3, v2);
        let v3 = (x[i] + m1 * v1 + m1m2_mod * v2) % modulo;
        c[i] = ifv!(v3 < 0, v3 + modulo, v3);
    }
    c
}

fn main() {
    input! {
        n: usize, m: usize,
        a: [i64; n],
        b: [i64; m]
    };
    let c = convolution(a, b, 998244353);

    println!("{}", join!(c[0..n+m-1], " "));
}