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 JavaScript (judge verdict: Accepted)

'use strict';

waterfall([
  function(next) {
    lineReader(4, next);
  }, function(line, next) {
    var toInt = function(s) {
      return parseInt(s);
    }
    var s = line[1].split(' ').map(toInt);
    var t = line[3].split(' ').map(toInt);

    function binSearch(start, end, i) {
      // console.log(start, end)
      var arr = s;
      var t = arr[start + Math.floor((end - start) / 2)];
      if (i === t) {
        return 1;
      }
      if (start >= end) {
        return 0;
      }
      if (i < t) {
        return binSearch(start, start + Math.floor((end - start) / 2) - 1, i);
      }
      if (i > t) {
        return binSearch(start + Math.floor((end - start) / 2) + 1, end, i);
      }
    }

    next(t.reduce(function(sum, i) {
      // console.log(i, sum,'---------------')
      return sum + binSearch(0, s.length - 1, i);
    }, 0));
  }], function(result) {
    console.log(result);
    process.exit(0);
  });

function strMap(str, map) {
  var newStr = '';
  for (var i = 0; i < str.length; i++) {
    newStr += map(str.charAt(i), i);
  }
  return newStr;
}

function lineReader(limit, cb) {
  var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  var lines = [];
  var counter = 0;
  reader.on('line', function(line) {
    lines.push(line);
    ++counter;
    if (counter === limit) {
      reader.close();
      return cb(lines);
    }
  });
  reader.on('close', function() {});
  reader.on('error', function(err) {
    cb(err);
  });
}

function waterfall(tasks, cb) {
  var taskIndex = 0;
  function nextTask(args) {
    if (taskIndex === tasks.length)
      return cb.apply(null, args);

    var taskCallback = function() {
      var _arguments = arguments;
      nextTask(Object.keys(_arguments).reduce(function(memo, key) {
        memo.push(_arguments[key]);
        return memo;
      }, []));
    };
    args.push(taskCallback);
    var task = tasks[taskIndex++];
    task.apply(null, args);
  }
  nextTask([]);
}