Problem:
Hit and Blow

Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:

The number of numbers which have the same place with numbers A imagined (Hit)

The number of numbers included (but different place) in the numbers A imagined (Blow)

For example, if A imagined numbers:

9 1 8 2

and B chose:

4 1 5 9

A should say 1 Hit and 1 Blow.

Write a program which reads four numbers A imagined and four numbers B chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.

Input

The input consists of multiple datasets. Each dataset set consists of:

a1 a2 a3 a4
b1 b2 b3 b4

, where ai (0 ≤ ai ≤ 9) is i-th number A imagined and bi (0 ≤ bi ≤ 9) is i-th number B chose.

The input ends with EOF. The number of datasets is less than or equal to 50.

Output

For each dataset, print the number of Hit and Blow in a line. These two numbers should be separated by a space.

Sample Input

9 1 8 2
4 1 5 9
4 6 8 2
4 6 3 2

Output for the Sample Input

1 1
3 0

Solution in Scala (judge verdict: Accepted)

import scala.io.Source
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines.toList
    }yield in.split(" ").toList.map(_.toInt)

    if(lines.length <= 2){
      val tup = hitAndBlow(lines.head, lines.last)
      println(tup._1 + " " + tup._2)
    }
    else{
      mulHitAndBlow(lines, List()).reverse.foreach{tup => println(tup._1 + " " + tup._2)}
    }
  }

  @tailrec
  def mulHitAndBlow(list: List[List[Int]], tupList: List[(Int, Int)]): List[(Int, Int)]={
    if(list.isEmpty) tupList
    else mulHitAndBlow(list.tail.tail, hitAndBlow(list.head, list.tail.head) :: tupList)
  }

  def hitAndBlow(list1: List[Int], list2: List[Int]): (Int, Int) ={
    val hit = numOfHit(list1, list2, 0)
    (hit, numOfBlow(list1, list2, 0) - hit)
  }

  @tailrec
  def numOfHit(list1: List[Int], list2: List[Int], n: Int): Int={
    if(list1.isEmpty) n
    else if(list1.head == list2.head) numOfHit(list1.tail, list2.tail, n + 1)
    else numOfHit(list1.tail, list2.tail, n)
  }

  @tailrec
  def numOfBlow(list1: List[Int], list2: List[Int], n: Int): Int={
    if(list2.isEmpty) n
    else if(checkBlow(list1, list2.head)) numOfBlow(list1, list2.tail, n + 1)
    else numOfBlow(list1, list2.tail, n)
  }

  def checkBlow(list1: List[Int], n :Int): Boolean = list1.contains(n)
}