import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val a = readLine.trim.split(' ').map(_.toInt)
  val b = readLine.trim.split(' ').map(_.toInt)
  val andArray = mutable.ArrayBuffer[Int]()
  val orArray = ArrayBuffer[Int]().also{_.appendAll(b)}
  for (i ← a){
    if (binarySearch(b, i)){
      andArray.append(i)
    }else {
      orArray.append(i)
    }
  }
  println(s"${andArray.length} ${orArray.length}")
  if (andArray.nonEmpty) println(andArray.mkString("\n"))
  if (orArray.nonEmpty) println(orArray.sorted.mkString("\n"))


  def binarySearch(array: Array[Int], target: Int): Boolean = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    if (right < array.length) array(right) == target
    else false
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

