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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class F
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, M) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<long>().Select(x => new MInt(x)).ToArray();
            var B = Scanner.ScanEnumerable<long>().Select(x => new MInt(x)).ToArray();
            var c = Convolution.GetConvolution(A, B);
            Console.WriteLine(string.Join(" ", c));
        }

        public static class Convolution
        {
            private static bool IsFirst = true;
            private static bool IsInvFirst = true;

            public static IEnumerable<MInt> GetConvolution(IEnumerable<MInt> a, IEnumerable<MInt> b)
            {
                var (a1, b1) = (a.ToArray(), b.ToArray());
                var (n, m) = (a1.Length, b1.Length);
                var ret = new MInt[n + m - 1];
                if (System.Math.Min(n, m) <= 60)
                {
                    if (n < m)
                    {
                        (n, m) = (m, n);
                        (a1, b1) = (b1, a1);
                    }

                    for (var i = 0; i < n; i++)
                    {
                        for (var j = 0; j < m; j++)
                        {
                            ret[i + j] += a1[i] * b1[j];
                        }
                    }

                    return ret;
                }

                var z = 1 << CeilPow2(n + m - 1);
                var a2 = new MInt[z];
                for (var i = 0; i < a1.Length; i++) a2[i] = a1[i];
                a2 = Butterfly(a2).ToArray();
                var b2 = new MInt[z];
                for (var i = 0; i < b1.Length; i++) b2[i] = b1[i];
                b2 = Butterfly(b2).ToArray();
                for (var i = 0; i < z; i++) a2[i] *= b2[i];
                a2 = ButterflyInv(a2).ToArray();
                for (var i = 0; i < Math.Min(a2.Length, n + m - 1); i++) ret[i] = a2[i];
                for (var i = 0; i < ret.Length; i++) ret[i] /= (long)z;
                return ret;
            }

            private static IEnumerable<MInt> Butterfly(IEnumerable<MInt> a)
            {
                var m = MInt.Mod;
                var g = PrimitiveRoot(m);
                var ret = a.ToArray();
                var n = ret.Length;
                var h = CeilPow2(n);
                var sumE = new MInt[30];
                if (IsFirst)
                {
                    IsFirst = false;
                    var es = new MInt[30];
                    var ies = new MInt[30];
                    var count2 = BSF((uint)m - 1);
                    var e = Pow((MInt)g, (m - 1) >> count2);
                    var ie = MInt.GetInv(e);
                    for (var i = count2; i >= 2; i--)
                    {
                        es[i - 2] = e;
                        ies[i - 2] = ie;
                        e *= e;
                        ie *= ie;
                    }

                    var now = (MInt)1;
                    for (var i = 0; i < count2 - 2; i++)
                    {
                        sumE[i] = es[i] * now;
                        now *= ies[i];
                    }
                }

                for (var ph = 1; ph <= h; ph++)
                {
                    var w = 1 << (ph - 1);
                    var p = 1 << (h - ph);
                    var now = (MInt)1;
                    for (var s = 0; s < w; s++)
                    {
                        var offset = s << (h - ph + 1);
                        for (var i = 0; i < p; i++)
                        {
                            var l = ret[i + offset];
                            var r = ret[i + offset + p] * now;
                            ret[i + offset] = l + r;
                            ret[i + offset + p] = l - r;
                        }

                        now *= sumE[BSF(~(uint)s)];
                    }
                }

                return ret;
            }

            private static IEnumerable<MInt> ButterflyInv(IEnumerable<MInt> a)
            {
                var m = MInt.Mod;
                var g = PrimitiveRoot(m);
                var ret = a.ToArray();
                var n = ret.Length;
                var h = CeilPow2(n);
                var sumIe = new MInt[30];
                if (IsInvFirst)
                {
                    IsInvFirst = false;
                    var es = new MInt[30];
                    var ies = new MInt[30];
                    var count2 = BSF((uint)m - 1);
                    var e = Pow((MInt)g, (m - 1) >> count2);
                    var ie = MInt.GetInv(e);
                    for (var i = count2; i >= 2; i--)
                    {
                        es[i - 2] = e;
                        ies[i - 2] = ie;
                        e *= e;
                        ie *= ie;
                    }

                    var now = (MInt)1;
                    for (var i = 0; i < count2 - 2; i++)
                    {
                        sumIe[i] = ies[i] * now;
                        now *= es[i];
                    }
                }

                for (var ph = h; ph >= 1; ph--)
                {
                    var w = 1 << (ph - 1);
                    var p = 1 << (h - ph);
                    var inow = (MInt)1;
                    for (var s = 0; s < w; s++)
                    {
                        var offset = s << (h - ph + 1);
                        for (var i = 0; i < p; i++)
                        {
                            var l = ret[i + offset];
                            var r = ret[i + offset + p];
                            ret[i + offset] = l + r;
                            ret[i + offset + p] = (MInt.Mod + l - r) * inow;
                        }

                        inow *= sumIe[BSF(~(uint)s)];
                    }
                }

                return ret;
            }

            private static int BSF(uint n)
            {
                if (n == 0) throw new ArgumentException();
                var count = 0;
                while (n >> count == 0) count++;
                return count;
            }

            private static int CeilPow2(int n)
            {
                var x = 0;
                while (1 << x < n) x++;
                return x;
            }

            private static int PrimitiveRoot(int m)
            {
                switch (m)
                {
                    case 2:
                        return 1;
                    case 167772161:
                    case 469762049:
                        return 3;
                    case 754974721:
                        return 11;
                    case 998244353:
                        return 3;
                }

                var divs = new int[20];
                divs[0] = 2;
                var count = 1;
                var x = (m - 1) / 2;
                while (x % 2 == 0) x /= 2;
                for (var i = 3; i * i < x; i += 2)
                {
                    if (x % i != 0) continue;
                    divs[count++] = i;
                    while (x % i == 0) x /= i;
                }

                if (x > 1) divs[count++] = x;
                for (var i = 2; ; i++)
                {
                    var ok = true;
                    for (var j = 0; j < count && ok; j++)
                    {
                        if (PowMod(i, (m - 1) / divs[i], m) == 1) ok = false;
                    }

                    if (ok) return i;
                }
            }

            public static long PowMod(long x, long n, int m)
            {
                if (n < 0) throw new ArgumentException(nameof(n));
                if (m < 1) throw new ArgumentException(nameof(m));
                if (m == 1) return 0;
                uint r = 1;
                var y = (uint)(x % m >= 0 ? x % m : (x + m) % m);
                var um = (uint)m;
                while (n > 1)
                {
                    if (n % 1 == 1) r = r * y % um;
                    y = y * y % um;
                    n >>= 1;
                }

                return r;
            }

            public static MInt Pow(MInt x, long n)
            {
                var r = new MInt(1);
                while (n > 0)
                {
                    if ((n & 1) > 0) r *= x;
                    x *= x;
                    n >>= 1;
                }

                return r;
            }
        }

        public readonly struct MInt
        {
            public long Value => _data;
            public static int Mod => 998244353;
            private readonly long _data;
            public MInt(long data) => _data = (0 <= data ? data : data + Mod) % Mod;
            public static implicit operator long(MInt mint) => mint._data;
            public static implicit operator MInt(long val) => new MInt(val);
            public static MInt operator +(MInt a, MInt b) => a._data + b._data;
            public static MInt operator +(MInt a, long b) => a._data + b;
            public static MInt operator -(MInt a, MInt b) => a._data - b._data;
            public static MInt operator -(MInt a, long b) => a._data - b;
            public static MInt operator *(MInt a, MInt b) => a._data * b._data;
            public static MInt operator *(MInt a, long b) => a._data * (b % Mod);
            public static MInt operator /(MInt a, MInt b) => a._data * GetInv(b._data);
            public static MInt operator /(MInt a, long b) => a._data * GetInv(b);

            public static bool operator ==(MInt a, MInt b) => a._data == b._data;
            public static bool operator !=(MInt a, MInt b) => a._data != b._data;
            public static MInt operator &(MInt a, MInt b) => a._data & b._data;
            public static MInt operator &(MInt a, long b) => a._data & b;
            public static MInt operator |(MInt a, MInt b) => a._data | b._data;
            public static MInt operator |(MInt a, long b) => a._data | b;
            public override bool Equals(object obj) => _data.Equals(obj);
            public override int GetHashCode() => _data.GetHashCode();
            public override string ToString() => _data.ToString();

            public static long GetInv(long a)
            {
                a %= Mod;
                if (a < 0) a += Mod;
                if (a == 0) return 0;
                var (s, t, m0, m1) = ((long)Mod, a, 0L, 1L);
                while (t > 1)
                {
                    var u = s / t;
                    s -= t * u;
                    m0 -= m1 * u;
                    (s, t) = (t, s);
                    (m0, m1) = (m1, m0);
                }

                if (m0 < 0) m0 += Mod / s;
                return m0;
            }
        }


        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}