import scala.io.StdIn object Problem206 { def proc(N: Int, A: Seq[Int], B: Seq[Int], Q: Int): Seq[Int] = { val bitArrayA = Array.fill(N)(0) val bitArrayB = Array.fill(N)(0) A foreach { a => bitArrayA(N - a) = 1 } B foreach { b => bitArrayB(N - b) = 1 } var bitA = BigInt(bitArrayA.mkString(""), 2) val bitB = BigInt(bitArrayB.mkString(""), 2) for (i <- 0 until Q) yield { val count = (bitA & bitB).bitCount bitA >>= 1 count } } def main(args: Array[String]) { val LMN = StdIn.readLine().split(" ").map(_.toInt) val A = StdIn.readLine().split(" ").map(_.toInt) val B = StdIn.readLine().split(" ").map(_.toInt) val Q = StdIn.readLine().toInt val results = proc(LMN(2), A, B, Q) results.foreach(println) } }