open Scanf
open Printf

let n = scanf "%d\n" (fun x -> x)
let s_ = Array.init n (fun _ -> scanf "%d " (fun s -> s))
let n2 = scanf "%d\n" (fun y -> y)
let t_ = Array.init n (fun _ -> scanf "%d " (fun t -> t))

let rec binary_search ar x =
 let len = Array.length ar in
 let i = len / 2 in
 if ar.(i) = x then 1
 else if len = 2 then (if ar.(0) = x then 1 else 0)
 else if ar.(i) > x then binary_search (Array.sub ar 0 i) x
 else 
  if (len mod 2 = 1) then binary_search (Array.sub ar (i+1) i) x
  else binary_search (Array.sub ar i i) x

let rec count ar1 ar2 i co =
 if i = n2 then co
 else
  let c = binary_search ar1 ar2.(i) in
  count ar1 ar2 (i+1) (c+co)

let () =
 count s_ t_ 0 0 |> printf "%d\n"