let h()=Scanf.scanf"%d %d %d %d\n"(fun a b c d->[a;b;c;d]);;
let rec f()=
  let a,b=h(),h()in
  let rec z i(m,n)=function
    |[]->f(Printf.printf"%d %d\n"m n)
    |x::y->(
        let rec g j m n=function
          |[]->m,n
          |s::t->if s=x&&i=j then g(j+1)(m+1)n t else if s=x&&i<>j then g(j+1)m(n+1)t else g(j+1)m n t
        in
        z(i+1)(g 0 m n b)y
      )
  in
  z 0(0,0)a
;;try f()with _->()