Problem:
Search II

You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.

Input

In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.

Output

Print C in a line.

Constraints

Elements in S is sorted in ascending order

n ≤ 100000

q ≤ 50000

0 ≤ an element in S ≤ 109

0 ≤ an element in T ≤ 109

Sample Input 1

5
1 2 3 4 5
3
3 4 1

Sample Output 1

3

Sample Input 2

3
1 2 3
1
5

Sample Output 2

0

Sample Input 3

5
1 1 2 2 3
2
1 2

Sample Output 3

2

Notes

Solution in Rust (judge verdict: Accepted)

use std::io;

fn bin_search(target: &Vec<u64>, val: u64) -> bool {
    let mut st = 0;
    let mut end = target.len()-1;
    while st <= end {
        let idx = (end+st) / 2;
        if target[idx] == val {
            return true;
        } else if target[idx] < val {
            st = idx + 1;
        } else {
            end = idx - 1;
        }
    }
    false
}

/// 二分探索による調査。targetは昇順に整列済みであるとする
fn search_same(target: &Vec<u64>, src: &Vec<u64>) -> u32 {
    let mut cnt = 0;
    for v in src {
        if bin_search(target, *v) {
            cnt += 1;
        }
    }
    cnt
}

fn main() {
    let sin = io::stdin();
    
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let _n: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let s = buf.split_whitespace()
        .map(|v| v.parse::<u64>().unwrap())
        .collect::<Vec<u64>>();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let _q: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let t = buf.split_whitespace()
        .map(|v| v.parse::<u64>().unwrap())
        .collect::<Vec<u64>>();

    println!("{}", search_same(&s, &t));
}