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 x -> x)
let t_ = Array.init n2 (fun _ -> scanf "%d " (fun t -> t))

let rec count ar i x co =
 if i = n then co
 else if ar.(i) = x then count ar (i+1) x (co+1)
 else count ar (i+1) x co

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

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