# frozen_string_literal: true

require 'numo/narray'

class Convolution
  def initialize(mod = 998244353, primitive_root = 3)
    @mod = mod

    cnt2 = bsf(@mod - 1)
    e = primitive_root.pow((@mod-1) >> cnt2, @mod)
    ie = e.pow(@mod - 2, @mod)
    
    es = [0]*(cnt2-1)
    ies = [0]*(cnt2-1)
    cnt2.downto(2){ |i|
      es[i-2] = e
      ies[i-2] = ie
      e = e*e % @mod
      ie = ie*ie % @mod
    }
    now = inow = 1

    @sum_e = [0]*(cnt2-2)
    @sum_ie = [0]*(cnt2-2)
    (cnt2-2).times{ |i|
      @sum_e[i] = es[i]*now % @mod
      now = now*ies[i] % @mod
      @sum_ie[i] = ies[i]*inow % @mod
      inow = inow*es[i] % @mod
    }
  end

  def convolution(input_a, input_b)
    n = input_a.size
    m = input_b.size
    return [] if n==0 || m==0

    h = (n+m-2).bit_length
    z = 1 << h

    a = Numo::Int64.zeros(z)
    a.store(input_a)
    b = Numo::Int64.zeros(z)
    b.store(input_b)

    batterfly(a, h)
    batterfly(b, h)

    a.inplace * b
    a.inplace % @mod

    batterfly_inv(a, h)

    return (a[0 .. n+m-2]*z.pow(@mod-2, @mod) % @mod).to_a
  end

  def batterfly(a, h)
    1.upto(h){ |ph|
      w = 1 << (ph-1)
      p = 1 << (h-ph)
      now = 1
      w.times{ |s|
        offset = s << (h-ph+1)
        l_range = offset ... offset+p
        r_range = offset+p ... offset+p+p
        l = a[l_range].copy
        r = a[r_range].copy*now
        #a[l_range], a[r_range] = (l+r) % @mod, (l-r) % @mod
        a[l_range] = (l+r) % @mod
        a[r_range] = (l-r) % @mod
        now = now*@sum_e[bsf(~s)] % @mod
      }
    }
  end

  def batterfly_inv(a, h)
    h.downto(1){ |ph|
      w = 1 << (ph-1)
      p = 1 << (h-ph)
      inow = 1
      w.times{ |s|
        offset = s << (h-ph+1)
        l_range = offset ... offset+p
        r_range = offset+p ... offset+p+p
        l = a[l_range].copy
        r = a[r_range].copy
        #a[l_range], a[r_range] = (l+r) % @mod, (l-r)*inow % @mod
        a[l_range] = (l+r) % @mod
        a[r_range] = (l-r+@mod) % @mod *inow % @mod
        inow = inow*@sum_ie[bsf(~s)] % @mod
      }
    }
  end

  def bsf(x)
    (x & -x).bit_length - 1
  end
  protected :batterfly, :batterfly_inv, :bsf
end

_, a, b = $<.map{ |e| e.split.map &:to_i }

conv = Convolution.new
puts conv.convolution(a, b).join(?\s)
