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: Time Limit Exceeded)

'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(arr, i) {
      if (arr.length === 0) {
        return 0;
      }
      var t = arr[Math.floor(arr.length / 2)];
      if (i === t) {
        return 1;
      }
      if (i < t) {
        return binSearch(arr.splice(0, arr.length / 2), i);
      }
      if (i > t) {
        return binSearch(arr.splice(arr.length / 2, arr.length - 1), i);
      }
    }

    next(t.reduce(function(sum, i) {
      return sum + binSearch(s.concat(), 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([]);
}