n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

logand, logxor = [], []
until a.empty? || b.empty?
    if a[0] == b[0]
        logand << a.shift
        b.shift
    elsif a[0] > b[0]
        logxor << b.shift
    else
        logxor << a.shift
    end
end
a.each{|x| logxor << x}
b.each{|x| logxor << x}
puts "#{logand.length} #{logand.length + logxor.length}"

logand.each{|x| puts x}
until logand.empty? || logxor.empty?
    if logand[0] < logxor[0]
        puts logand.shift
    else
        puts logxor.shift
    end
end
logand.each{|x| puts x}
logxor.each{|x| puts x}
