'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const [n,m] = readLine().split(' ').map(Number);
        const a = readLine().split(' ').map(Number);
        const b = readLine().split(' ').map(Number);
        const a0 = a.filter(num => num < 0);
        const a1 = a.filter(num => num >= 0);
        const b0 = b.filter(num => num < 0);
        const b1= b.filter(num => num >= 0);
        const a0_filter = a0.filter(num => num >= b0[0]);
        const b0_filter = b0.filter(num => num <= a0_filter[a0_filter.length - 1])
        const a00_filter = a0_filter.map(num => num *-1);
        const b00_filter = b0_filter.map(num => num *-1);
        const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);
        const b1_filter = b1.filter(num => num >= a1_filter[0]);
        console.log(count1(a00_filter.sort((a,b) => a - b), b00_filter.sort((a,b) => a - b),1) + count1(a1_filter, b1_filter,1) );
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function intersection(setA, setB) {
    let _intersection = new Set()
    for (let elem of setB) {
        if (setA.has(elem)) {
            _intersection.add(elem)
        }
    }
    return _intersection
}

function count1(a,b,opt = 0){
    if(a.length === 0 || b.length === 0) return 0;
    let globalMax = 0;
    const setB = new Set([...b]);
    const setA = new Set([...a]);
    let good_pos = intersection(setA, setB)
    let good_len = good_pos.size;
    const start_time = new Date();
    let j =0;
    let i = 0;
    let b_start = 0;
    while(i < b.length){
        // console.log('here', 'curr = ', j, 'b_start  = ', b_start, 'b_end = ', i)
        while(j < a.length && a[j] <= b[i]){
            // console.log(`curr = ${j}, good_len = ${good_len}`)
            if(good_pos.has(a[j])){
                good_len -= 1;
            }
            j += 1;
        }
        while(b_start < i && b[b_start] + j <= b[i]){
            b_start += 1
        }

        globalMax = Math.max(globalMax, Math.min(i - b_start + 1, j) + good_len);
        // console.log(`globalMax+ = ${globalMax}`)
        i++;
    }
    // console.log(`finish in: ${new Date() - start_time} with ${globalMax} `)
    return globalMax;
}

module.exports = count1

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = rns(),
        a = rns(),
        b = rns();
  const calc = () => {
    let sa = 0,
        sb = 0;
    for (; sa < n; sa++) {
      if (a[sa] > 0) break;
    }
    if (sa === n) return 0;
    for (; sb < m; sb++) {
      if (b[sb] > 0) break;
    }
    if (sb === m) return 0;
    let res = 0,
        pre = 0;
    for (let i = m - 1, j = n - 1, k = i; i >= sb; i--) {
      while (a[j] > b[i]) j--;
      if (j < sa || i < sb || i < 0) {
        res = Math.max(res, pre);
        break;
      }
      let num = j - sa + 1;
      for (; k >= 0 && b[i] - b[k] + 1 <= num; k--) {}
      res = Math.max(res, i - k + pre);
      if (a[j] === b[i]) pre++;
    }
    return res;
  };
  let res = calc();
  a.reverse();
  b.reverse();
  for (let i = 0; i < n; i++) a[i] = -a[i];
  for (let i = 0; i < m; i++) b[i] = -b[i];
  res += calc();
  return res;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r\n?/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var a1 = []
    var a2 = []
    var a = readline().split(' ').map((x, iii) => {
      x = parseInt(x)
      if (x > 0) a1.push(x)
      if (x < 0) a2.push(-x)
      return parseInt(x)
    })

    var b1 = []
    var b2 = []
    var b = readline().split(' ').map((x, iii) => {
      x = parseInt(x)
      if (x > 0) b1.push(x)
      if (x < 0) b2.push(-x)

      return parseInt(x)
    })

    var ans1 = solve(a1, b1)
    var ans2 = solve(a2.reverse(), b2.reverse())
    // console.log('-----------')
    console.log(ans1 + ans2)
  })
}

function solve(a, b) {
  var suffix = new Array(a.length + 1).fill(0)

  var right = b.length - 1
  for (let i = a.length - 1; i >= 0; i--) {
    suffix[i] = suffix[i + 1]
    while (right >= 0 && a[i] < b[right]) right--
    if (right >= 0 && a[i] === b[right]) suffix[i]++
  }

  var left = 0
  right = 0
  var ans = 0
  for (let i = 0; i < b.length; i++) {
    while (left < a.length && a[left] <= b[i] + left) left++
    while (right < b.length && b[right] - b[i] < left) right++
    // console.log(left, right, suffix[i])
    ans = Math.max(ans, right - i + suffix[left])
  }

  // console.log(suffix)
  return ans
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        l++
        var a1 = lines[l++].trim().split(' ').map(Number)
        var a2 = lines[l++].trim().split(' ').map(Number)
        console.log(solve(a1, a2))
    }
});

function solve(a, b) {
    const special = b.reduce((o, x) => {
        o[x] = 1
        return o
    }, {})
    const c = []
    a.forEach(x => {
        if (special[x]) c.push(x)
    })

    const sep = binarySearch(0, b.length - 1, x => b[x] < 0)
    let m1 = 0
    for (let i = sep + 1; i < b.length; i++) {
        const n = cover(0, b[i], a)
        const l1 = cover(b[i] - n + 1, b[i], b) // after pushing
        const l2 = cover(0, b[i], c) // before
        m1 = Math.max(m1, l1 - l2)
    }
    let m2 = 0
    for (let i = sep; i >= 0; i--) {
        const n = cover(b[i], 0, a)
        const l1 = cover(b[i], b[i] + n - 1, b)
        const l2 = cover(b[i], 0, c, false)
        m2 = Math.max(m2, l1 - l2)
    }
    // console.log(c.length, m1, m2)
    return c.length + m1 + m2
}
function cover(l, r, b, include = true) {
    const i = binarySearch(0, b.length - 1, x => b[x] < l)
    const j = binarySearch(0, b.length - 1, x => (include ? b[x] <= r : b[x] < r))
    return j - i
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

const solve = (box, goal) => {
  let res = 0;

  let mem = {};
  let already = goal.map(() => 0);
  box.forEach(b => (mem[b] = true));
  for (let i = 0; i < goal.length; i++) {
    if (mem[goal[i]]) already[i] = 1;
  }
  for (let i = goal.length - 2; i >= 0; i--) {
    already[i] = already[i + 1] + already[i];
  }
  already.push(0);

  let j = 0;
  for (let i = 0; i < goal.length; i++) {
    while (j < box.length && box[j] - j <= goal[i]) {
      j++;
    }
    let currentRes = null;
    let l = i,
      r = goal.length - 1;

    while (true) {
      if (l > r) break;
      const m = Math.floor((l + r) / 2);
      if (goal[m] <= goal[i] - 1 + j) {
        currentRes = m;
        l = m + 1;
      } else r = m - 1;
    }
    currentRes = currentRes === null ? 0 : currentRes - i + 1;
    res = Math.max(res, currentRes + already[currentRes + i]);
  }
  return res;
};

const main = () => {
  const start = new Date();
  let test = readInt();
  while (test--) {
    let [n, m] = readListInt();
    const box = readListInt();
    const goal = readListInt();
    const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));

    const boxLeft = box
      .filter(i => i < 0)
      .map(i => -i)
      .reverse();
    const goalLeft = goal
      .filter(i => i < 0)
      .map(i => -i)
      .reverse();

    const left = solve(boxLeft, goalLeft);
    console.log(left + right);
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});

process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const [n,m] = readLine().split(' ').map(Number);
        const a = readLine().split(' ').map(Number);
        const b = readLine().split(' ').map(Number);
        const a0 = a.filter(num => num < 0);
        const a1 = a.filter(num => num >= 0);
        const b0 = b.filter(num => num < 0);
        const b1= b.filter(num => num >= 0);
        const a0_filter = a0.filter(num => num >= b0[0]);
        const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);
        console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function count1(a,b,opt = 0){
    if(a.length === 0) return 0;
    let globalMax = 0;
    if(opt === 0){
        let j = a.length - 1;
        for(let i = b.length - 1; i >= 0; i--){
            a[j] = b[i];
            if(a[j] <= a[j-1]){
                let c = 1;
                for(let m = j-1; m >= 0 ; m--){
                    a[m] = a[j] - c;
                    if(a[m - 1] < a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = a.length - 1 ; k >= 0; k--){
                for(let n = b.length - 1; n >= 0; n--){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }
            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
            if(a[a.length - 1] - a.length + 1 <= b[0]) break;
        }
    }
    else {
        let j =0;
        for(let i = 0; i < b.length; i++){
            a[j] = b[i];
            if(a[j] >= a[j+1]){
                let c = 1;
                for(let m = j+1; m < a.length ; m++){
                    a[m] = a[j] + c;
                    if(a[m + 1] > a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = 0 ; k < a.length; k++){
                for(let n = 0; n < b.length; n++){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }

            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
            if(a[0] + a.length - 1 >= b[b.length - 1]) break;
        }
    }
    return globalMax;
}

module.exports = count1

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const [n,m] = readLine().split(' ').map(Number);
        const a = readLine().split(' ').map(Number);
        const b = readLine().split(' ').map(Number);
        const a0 = a.filter(num => num < 0);
        const a1 = a.filter(num => num >= 0);
        const b0 = b.filter(num => num < 0);
        const b1= b.filter(num => num >= 0);
        const a0_filter = a0.filter(num => num >= b0[0]);
        const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);
        console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function count1(a,b,opt = 0){
    if(a.length === 0) return 0;
    let globalMax = 0;
    if(opt === 0){
        let j = a.length - 1;
        for(let i = b.length - 1; i >= 0; i--){
            a[j] = b[i];
            if(a[j] <= a[j-1]){
                let c = 1;
                for(let m = j-1; m >= 0 ; m--){
                    a[m] = a[j] - c;
                    if(a[m - 1] < a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = a.length - 1 ; k >= 0; k--){
                for(let n = b.length - 1; n >= 0; n--){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }
            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
        }
    }
    else {
        let j =0;
        for(let i = 0; i < b.length; i++){
            a[j] = b[i];
            if(a[j] >= a[j+1]){
                let c = 1;
                for(let m = j+1; m < a.length ; m++){
                    a[m] = a[j] + c;
                    if(a[m + 1] > a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = 0 ; k < a.length; k++){
                for(let n = 0; n < b.length; n++){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }

            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
        }
    }
    return globalMax;
}

module.exports = count1

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const [n,m] = readLine().split(' ').map(Number);
        const a = readLine().split(' ').map(Number);
        const b = readLine().split(' ').map(Number);
        const a0 = a.filter(num => num < 0);
        const a1 = a.filter(num => num >= 0);
        const b0 = b.filter(num => num < 0);
        const b1= b.filter(num => num >= 0);
        const a0_filter = a0.filter(num => num >= b0[0]);
        const a1_filter = a1.filter(num => num <= b1[b1.length - 1]);
        console.log(count1(a0_filter, b0,0) + count1(a1_filter, b1,1) );
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function count1(a,b,opt = 0){
    if(a.length === 0) return 0;
    let globalMax = 0;
    if(opt === 0){
        let j = a.length - 1;
        for(let i = b.length - 1; i >= 0; i--){
            a[j] = b[i];
            if(a[j] <= a[j-1]){
                let c = 1;
                for(let m = j-1; m >= 0 ; m--){
                    a[m] = a[j] + c;
                    if(a[m - 1] < a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = a.length - 1 ; k >= 0; k--){
                for(let n = b.length - 1; n >= 0; n--){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }
            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
        }
    }
    else {
        let j =0;
        for(let i = 0; i < b.length; i++){
            a[j] = b[i];
            if(a[j] >= a[j+1]){
                let c = 1;
                for(let m = j+1; m < a.length ; m++){
                    a[m] = a[j] + c;
                    if(a[m + 1] > a[m]) break;
                    c++;
                }
            }
            // console.log(`a = ${a}, b = ${b}`);
            let localMax = 0;
            for(let k = 0 ; k < a.length; k++){
                for(let n = 0; n < b.length; n++){
                    if(a[k] === b[n]){
                        localMax++;
                        break;
                    }
                }

            }
            if(localMax>globalMax){
                globalMax = localMax;
            }
            // console.log(b, a, localMax,globalMax);
            if(globalMax === b.length || globalMax === a.length) break;
        }
    }
    return globalMax;
}

module.exports = count1

const solve = (box, goal) => {
  let res = 0;

  let mem = {};
  let already = goal.map(() => 0);
  box.forEach(b => (mem[b] = true));
  for (let i = 0; i < goal.length; i++) {
    if (mem[goal[i]]) already[i] = 1;
  }
  for (let i = goal.length - 2; i >= 0; i--) {
    already[i] = already[i + 1] + already[i];
  }
  already.push(0);

  let j = 0;
  for (let i = 0; i < goal.length; i++) {
    while (j < box.length && box[j] - j <= goal[i]) {
      j++;
    }
    let currentRes = 0;
    let l = i,
      r = goal.length - 1;

    while (true) {
      if (l > r) break;
      const m = Math.floor((l + r) / 2);
      if (goal[m] <= goal[i] - 1 + j) {
        currentRes = m;
        l = m + 1;
      } else r = m - 1;
    }
    currentRes = currentRes - i + 1;
    res = Math.max(res, currentRes + already[currentRes + i]);
  }
  return res;
};

const main = () => {
  const start = new Date();
  let test = readInt();
  while (test--) {
    let [n, m] = readListInt();
    const box = readListInt();
    const goal = readListInt();
    const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));

    const boxLeft = box
      .filter(i => i < 0)
      .map(i => -i)
      .reverse();
    const goalLeft = goal
      .filter(i => i < 0)
      .map(i => -i)
      .reverse();

    const left = solve(boxLeft, goalLeft);
    console.log(left + right);
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});

process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};

const solve = (box, goal) => {
  let mem = {};
  for (let i = 0; i < box.length; i++) {
    mem[box[i]] = true;
  }
  let res = 0;
  for (let i = 0; i < goal.length; i++) {
    if (mem[goal[i]]) res += 1;
  }

  for (let i = 0; i < goal.length; i++) {
    // Try to move to fill goal[i]
    // Find how many boxes we have to push to move to goal[i]
    let l = 0,
      r = box.length;
    let pos = null;
    while (true) {
      if (l > r) break;
      const m = Math.floor((l + r) / 2);
      if (box[m] <= goal[i]) {
        pos = m;
        l = m + 1;
      } else r = m - 1;
    }
    if (pos === null) continue;
    // Boxes now cover from goal[i] to goal[i] + pos
    const coverRange = goal[i] + pos;
    l = i;
    r = goal.length;
    pos = i;
    while (true) {
      if (l > r) break;
      const m = Math.floor((l + r) / 2);
      if (goal[m] <= coverRange) {
        pos = m;
        l = m + 1;
      } else r = m - 1;
    }
    const coverBoxes = pos - i + 1;
    // Calculate already covered goal from pos-th goal
    const already = goal.map(() => 0);
    for (let i = goal.length - 1; i >= 0; i--) {
      if (mem[goal[i]]) already[i] = 1;
    }
    for (let i = goal.length - 2; i >= 0; i--) {
      already[i] = already[i + 1] + already[i];
    }
    already.push(0);

    res = Math.max(res, coverBoxes + already[pos + 1]);
  }

  return res;
};

const main = () => {
  let test = readInt();
  while (test--) {
    const [n, m] = readListInt();
    const box = readListInt();
    const goal = readListInt();
    const left = solve(
      box
        .filter(i => i < 0)
        .map(i => -i)
        .reverse(),
      goal
        .filter(i => i < 0)
        .map(i => -i)
        .reverse()
    );
    const right = solve(box.filter(i => i > 0), goal.filter(i => i > 0));
    console.log(left + right);
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});

process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = rns(),
        a = rns(),
        b = rns();
  const calc = () => {
    let sa = 0,
        sb = 0;
    for (; sa < n; sa++) {
      if (a[sa] > 0) break;
    }
    if (sa === n) return 0;
    for (; sb < m; sb++) {
      if (b[sb] > 0) break;
    }
    if (sb === m) return 0;
    let res = 0,
        pre = 0;
    for (let i = m - 1, j = n - 1, k = i; i >= 0; i--) {
      while (a[j] > b[i]) j--;
      if (a[j] === b[i]) {
        pre = 1;
        j--;
        i--;
      }
      if (j < sa || i < sb || i < 0) {
        res = Math.max(res, pre);
        break;
      }
      let num = j - sa + 1;
      for (; k >= 0 && b[i] - b[k] + 1 <= num; k--) {}
      res = Math.max(res, i - k + pre);
    }
    return res;
  };
  let res = calc();
  a.reverse();
  b.reverse();
  for (let i = 0; i < n; i++) a[i] = -a[i];
  for (let i = 0; i < m; i++) b[i] = -b[i];
  res += calc();
  return res;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r\n?/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = rns(),
        a = rns(),
        b = rns();
  const calc = () => {
    let sa = 0,
        sb = 0;
    for (; sa < n; sa++) {
      if (a[sa] > 0) break;
    }
    if (sa === n) return 0;
    for (; sb < m; sb++) {
      if (b[sb] > 0) break;
    }
    if (sb === m) return 0;
    let res = 0,
        pre = 0;
    for (let i = m - 1, j = n - 1, k = i; i >= 0; i--) {
      while (a[j] > b[i]) j--;
      let flag = 0;
      if (a[j] === b[i]) {
        pre = 1;
        j--;
        flag = 1;
      }
      if (j < sa || flag && (i - 1 < sa || !i)) {
        res = Math.max(res, pre);
        break;
      }
      let num = j - sa + 1;
      for (; k >= 0 && b[i] - b[k] - flag < num; k--) {}
      res = Math.max(res, i - k - flag + pre);
    }
    return res;
  };
  let res = calc();
  a.reverse();
  b.reverse();
  for (let i = 0; i < n; i++) a[i] = -a[i];
  for (let i = 0; i < m; i++) b[i] = -b[i];
  res += calc();
  return res;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r\n?/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    // return Math.floor(n * m / 3) + ((n * m % 3) ? 1 : 0)
    if (n > m) return solve(m, n)
    // n < m
    if (!(n % 3) || !(m % 3)) return m * n / 3
    if (n === 1) return Math.floor(m / 3) + ((m % 3) ? 1 : 0)
    if (n === 2) return n * Math.floor(m / 3) + (m % 3)
    const r = n % 3
    return solve(n - r, m) + solve(r, m)
}

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline().split(' ').map(Number);
  var ans;

  ans = Math.ceil((n[0] * n[1]) / 3);
  print(ans);

}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
let n;
let m;
function solve() {
    if ((n % 3) == 0) {
        return m * Math.trunc(n / 3);
    }
    if ((m % 3) == 0) {
        return n * Math.trunc(m / 3);
    }
    let q1 = (n - n % 3) * (m - m % 3);
    let sum = Math.trunc(q1 / 3);
    let q2 = (m % 3) * (n - n % 3);
    sum += Math.trunc(q2 / 3);
    let q3 = (n % 3) * (m - m % 3);
    sum += Math.trunc(q3 / 3);
    let q4 = (n % 3) * (m % 3);
    sum += Math.max(1, Math.trunc(q4 / 2));
    return sum;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        m = nextInt();
        printf("%d\n", solve());
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1];
        var ans = (a * b + 2) / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t ; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1];
        var ans = (a * b + 2) / 3;
        console.log(Math.floor(ans));
    }
});

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [h, w] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (h < 2) console.log(Math.ceil(w / 3));
    else if (w < 2) console.log(Math.ceil(h / 3));
    else {
      console.log(Math.ceil((h * w) / 3));
    }
  }
};
solve();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var M = nextInt();
		var size = N * M;
		if(size % 3 == 0){
			myout(size / 3);
		}else{
			myout(Math.ceil(size / 3));
		}
	}
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********
function main() {
  let a = parseInt(readline())
  while(a--){
    var b = readline().split(' ').map(Number)
    var c = ((b[0] * b[1]) + 2) / 3
    print(Math.floor(c))
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********
function main() {
  var a = parseInt(readline())
  while(a--){
    var b = readline().split(' ').map(Number)
    var c = ((b[0] * b[1]) + 2) / 3
    print(Math.floor(c))
  }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    // return Math.floor(n * m / 3) + ((n * m % 3) ? 1 : 0)
    if (n > m) return solve(m, n)
    // n < m
    if (!(n % 3) || !(m % 3)) return m * n / 3
    if (n === 1 || n === 2) return n * (Math.floor(m / 3) + ((m % 3) ? 1 : 0))
    const r = n % 3
    return solve(n - r, m) + solve(r, m)
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (n === 1) {
            if (m === 1) return 0
            if (m === 2) return 1
            if (m % 3) {
                return Math.floor(m / 3) - 1 + 2
            } else {
                return Math.floor(m / 3)
            }
        }
        if (m & 1) {
            return Math.min(n * solve(1, m), m * solve(1, n))
        } else {
            return solve(n, m - 1) + solve(n, 1)
        }
    } else {
        if (n === 2 && m === 2) return 2
        if (m & 1) {
            return solve(n - 1, m) + solve(1, m)
        } else {
            return solve(n - 1, m - 1) + solve(1, n) + solve(1, m - 1)
        }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (n === 1) {
            if (m === 1) return 0
            if (m === 2) return 1
            return Math.floor(m / 3) + (m % 3 ? solve(n, m % 3) : 0)
        }
        if (m & 1) {
            return Math.min(n * solve(1, m), m * solve(1, n))
        } else {
            return solve(n, m - 1) + solve(n, 1)
        }
    } else {
        if (n === 2 && m === 2) return 2
        if (m & 1) {
            return solve(n - 1, m) + solve(1, m)
        } else {
            return solve(n - 1, m - 1) + solve(1, n) + solve(1, m - 1)
        }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (n === 1) return Math.floor(m / 2)
        if (m & 1) {
            return m * Math.floor(n / 2)
        } else {
            const h = m / 2
            return h & 1
                ? 2 * solve(n, h)
                : solve(n, h - 1) + solve(n, h + 1)
        }
    } else {
        const h = n / 2
        // if (m & 1) {
            return h & 1
                ? 2 * solve(h, m)
                : solve(h - 1, m) + solve(h + 1, m)
        // } else {
        // }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    return Math.min(solve2(n, m), solve1(n, m))
}
function solve2(n, m) {
    if (n > m) return solve2(m, n)
    // n < m
    if (n & 1) {
        if (m & 1) {
            if (n === 1) return Math.floor(m / 2)
            return m * Math.floor(n / 2)
        } else {
            if (n === 1) {
                if (m === 2) return 1
                if (m === 4) return 2
                const h = m / 2
                return h & 1
                    ? 2 * solve2(n, h)
                    : solve2(n, h - 1) + solve2(n, h + 1)
            }
            return m * Math.floor(n / 2)
        }
    } else {
        if (m & 1) {
            return n * Math.floor(m / 2)
        } else {
            const h = m / 2
            return h & 1 ? 2 * solve2(n, h) : solve2(n, h - 1) + solve2(n, h + 1)
        }
    }
}
function solve1(n, m) {
    if (n > m) return solve1(m, n)
    // n < m
    if (n & 1) {
        if (m & 1) {
            if (n === 1) return Math.floor(m / 2)
            return m * Math.floor(n / 2)
        } else {
            if (m === 2) return 1 // 1 2
            return 2 * solve1(n, m / 2)
        }
    } else {
        if (m & 1) {
            return n * Math.floor(m / 2)
        } else {
            if (m === 2) return 2 // 2 2
            return solve1(n, m / 2 - 1) + solve1(n, m / 2 + 1)
        }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (m & 1) {
            if (n === 1) return Math.floor(m / 2)
            return m * Math.floor(n / 2)
        } else {
            if (n === 1) {
                if (m === 2) return 1
                if (m === 4) return 2
                const h = m / 2
                return h & 1
                    ? 2 * solve(n, h)
                    : solve(n, h - 1) + solve(n, h + 1)
            }
            return m * Math.floor(n / 2)
        }
    } else {
        if (m & 1) {
            return n * Math.floor(m / 2)
        } else {
            const h = m / 2
            return h & 1 ? 2 * solve(n, h) : solve(n, h - 1) + solve(n, h + 1)
        }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (m & 1) {
            if (n === 1) return Math.floor(m / 2)
            return m * Math.floor(n / 2)
        } else {
            if (m === 2) return 1 // 1 2
            return 2 * solve(n, m / 2)
        }
    } else {
        if (m & 1) {
            return n * Math.floor(m / 2)
        } else {
            if (m === 2) return 2 // 2 2
            return solve(n, m / 2 - 1) + solve(n, m / 2 + 1)
        }
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // n < m
    if (n & 1) {
        if (n === 1) return Math.floor(m / 2)
        if (m & 1) {
            return m * Math.floor(n / 2)
        } else {
            return 2 * solve(n, m / 2)
        }
    } else {
        if (m & 1) {
            return n * Math.floor(m / 2)
        } else {
            return 2 * solve(n, m / 2)
        }
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1];
        var ans = a * b + (2 / 3);
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1];
        var ans = a * b + 2 / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[0], b = k[1];
        var ans = a * b + 2 / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[1], b = k[2];
        var ans = ((a * b) + 2) / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[1], b = k[1];
        var ans = ((a * b) + 2) / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[0], b = k[1];
        var ans = ((a * b) + 2) / 3;
        console.log(Math.floor(ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[0], b = k[1];
        var ans = ((a * b) + 2) / 3;
        console.log((ans));
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t ; i++){
        var k = lines[i].split('').map(Number);
        var a = k[0], b = k[1];
        var ans = ((a * b) + 2) / 3;
        console.log(Math.floor(ans));
    }
});

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [h, w] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (h < 2) console.log(Math.ceil(w / 3));
    else if (w < 2) console.log(Math.ceil(w / 3));
    else {
      console.log(Math.ceil((h * w) / 3));
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [h, w] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (h < 2) console.log(Math.ceil(w / 3));
    else if (w < 2) console.log(Math.ceil(w / 3));
    else {
      let t1 = Math.ceil(h / 3) * w;
      let t2 = Math.ceil(w / 3) * h;
      console.log(Math.min(t1, t2));
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [h, w] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (h < 2) console.log(Math.floor(w / 2));
    else if (w < 2) console.log(Math.floor(h / 2));
    else {
      let t1 = Math.floor(h / 2) * w;
      let t2 = Math.floor(w / 2) * h;
      console.log(Math.min(t1, t2));
    }
  }
};
solve();


var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
sb.sort((a,b)=>{return a-b});
sg.sort((a,b)=>{return a-b});
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=190;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var n=Number(readline())
var A=readline().split(' ').map(Number)
var m=Number(readline())
var B=readline().split(' ').map(Number)

A.sort((l,r)=>l-r)
B.sort((l,r)=>l-r)
var i=0, j=0, r=0;
while (i<A.length && j<B.length) {
  if (Math.abs(A[i]-B[j])<=1) {
   i++; j++; r++;
  } else if (A[i]<B[j]) {
   i++;
  } else if (A[i]>B[j]) ++j;
}

print(r)

var input = readline().split(' ').map(Number), n = input[0];
var a = readline().split(' ').map(Number);
var input = readline().split(' ').map(Number), m = input[0];
var b = readline().split(' ').map(Number);

a = a.sort(function(a,b) { return a - b;});
b = b.sort(function(a,b) { return a - b;});

var ida = 0;
var idb = 0;
var res = 0;
while (ida < n && idb < m) {
    if (a[ida] < b[idb] - 1) ida++;
    else if (a[ida] > b[idb] + 1) idb++;
    else {
        res++;
        ida++;
        idb++;
    }
}
write(res);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [n] = input[0].split(' ').map(x => parseInt(x));
  const boys = input[1].split(' ').map(x => parseInt(x));

  let [k] = input[2].split(' ').map(x => parseInt(x));
  const girls = input[3].split(' ').map(x => parseInt(x));

  boys.sort((a, b) => a - b); girls.sort((a, b) => a - b);
  let b = 0, g = 0;

  let answ = 0;
  while (b < boys.length && g < girls.length) {
    if (Math.abs( boys[b] - girls[g] ) <= 1) {
      answ += 1;
      b += 1; g += 1; continue;
    } else {
      if (boys[b] > girls[g]) g += 1;
      else b += 1;
    }
  }

  console.log(answ);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let b = readline();
  let bSkills = readline().split(' ');
  bSkills = bSkills.map(ele => parseInt(ele));
  let g = readline();
  let gSkills = readline().split(' ')
  gSkills = gSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  }
  console.log(count)
  return count;
}

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		if(!output[+input[i]]){
			output[+input[i]] = 1;
		}
		else{
			output[+input[i]]++;
		}
	}
}

var n = +readline(), boys = readline().split(" "), m = +readline(), girls = readline().split(" "),
boyslevs = {}, girlslevs = {}, pairs = 0;
maxb = Math.max.apply(null,boys);
maxg = Math.max.apply(null,girls);
minb = Math.min.apply(null,boys);
ming = Math.min.apply(null,girls);

if((maxb < ming-1) || (maxg < minb-1)){
	write(0);
}
else{
	countUniqueElements(boys,boyslevs);
	countUniqueElements(girls,girlslevs);

	for(level in boyslevs){
		level = +level;

		if(girlslevs[level-1]){
			if(boyslevs[level] > girlslevs[level-1]){
				pairs += girlslevs[level-1];
				boyslevs[level] -= girlslevs[level-1];
				delete girlslevs[level-1];
			}
			else if(boyslevs[level] == girlslevs[level-1]){
				pairs += boyslevs[level];
				delete girlslevs[level-1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level-1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level]){
				pairs += girlslevs[level];
				boyslevs[level] -= girlslevs[level];
				delete girlslevs[level];
			}
			else if(boyslevs[level] == girlslevs[level]){
				pairs += boyslevs[level];
				delete girlslevs[level];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level+1] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level+1]){
				pairs += girlslevs[level+1];
				boyslevs[level] -= girlslevs[level+1];
				delete girlslevs[level+1];
			}
			else if(boyslevs[level] == girlslevs[level+1]){
				pairs += boyslevs[level];
				delete girlslevs[level+1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level+1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}
	}

	write(pairs);
}

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

binaryHeap = function(comparator) {
  this.arr = [];
  this.cmp = comparator;

  this.swapIndices = function(idx1, idx2) {
    var tmp = this.arr[idx1];
    this.arr[idx1]=this.arr[idx2];
    this.arr[idx2]=tmp;
  };

  this.getLeft = function(val) {
    return val*2+1;
  };

  this.getRight = function(val) {
    return val*2+2;
  };

  this.getParent = function(val) {
    return (((val-1)/2)>>0);
  };

  this.clear = function() {
    this.arr = [];
  };

  this.size = function() {
    return this.arr.length;
  };

  this.empty = function() {
    if(this.arr.length==0) return true;
    return false;
  };

  this.push = function(val) {
    this.arr.push(val);

    var idx=this.arr.length-1;

    while(idx>0 && this.cmp(this.arr[idx], this.arr[this.getParent(idx)])) {
      this.swapIndices(idx, this.getParent(idx));
      idx=this.getParent(idx);
    }
  };

  this.pop = function() {
    this.swapIndices(0, this.arr.length-1);
    this.arr.pop();

    var idx=0, l, r;

    while(true) {
      l = this.getLeft(idx);
      r = this.getRight(idx);

      if(l>=this.arr.length) {
        break;
      }
      if(r>=this.arr.length) {
        if(this.cmp(this.arr[l], this.arr[idx])) {
          this.swapIndices(l, idx);
        }

        break;
      }

      if(this.cmp(this.arr[l], this.arr[idx]) && !this.cmp(this.arr[r], this.arr[l])) {
        this.swapIndices(l, idx);
        idx=l;
      }
      else if(this.cmp(this.arr[r], this.arr[idx]) && !this.cmp(this.arr[l], this.arr[r])) {
        this.swapIndices(r, idx);
        idx=r;
      }
      else {
        break;
      }
    }
  };

  this.top = function() {
    return this.arr[0];
  };
};

function cmpNumbers(a, b) {
  if(a<b) return -1;
  if(a==b) return 0;
  return 1;
}

function cmp2(a, b) {
  if(a<b) return true;
  return false;
}

function sortSubarray(arr, l, r) {
  var heap = new binaryHeap(cmp2);

  for(var i=l;i<=r;i++) {
    heap.push(arr[i]);
  }

  for(var i=l;i<=r;i++) {
    arr[i] = heap.top();
    heap.pop();
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = parseInt(token[i]);
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = parseInt(token[i]);
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function cmpNumbers(a, b) {
  if(a<b) return -1;
  if(a==b) return 0;
  return 1;
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort(cmpNumbers);

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = parseInt(token[i]);
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = parseInt(token[i]);
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

var ints = function() {
	return readline().split(' ').map(function(x) {
		return parseInt(x)
	})
}

var minus = function(a, b) {
	return a - b
}

readline()
var boys = ints()
readline()
var girls = ints()

boys.sort(minus)
girls.sort(minus)

var i = 0, j = 0, counter = 0

while (i < boys.length && j < girls.length) {
	if (Math.abs(boys[i] - girls[j]) <= 1) {
		i ++
		j ++
		counter ++
	} else if (boys[i] < girls[j])
		i ++
	else
		j++
}

print(counter)

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}
readline();
let firstGroup = readline().getNumArray().sort((a, b) => a - b);
readline();
let secondGroup = readline().getNumArray().sort((a, b) => a - b);
let counter = 0;

if (firstGroup.length > secondGroup.length) {
  const tempGroup = firstGroup;
  firstGroup = secondGroup;
  secondGroup = tempGroup;
}

for (let i = 0 ; i < firstGroup.length; i++) {
  for (let j = 0; j < secondGroup.length; j++) {
    if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {
      counter++;
      secondGroup.splice(j, 1);
      break;
    }
  }
}

write(counter);

var man = readline();
var str = readline().split(" ").sort((x,y)=>x-y);
var woman = readline();
var str2 = readline().split(" ").sort((x,y)=>x-y);
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="-";
				break;
			}
		}

	}

	print(res);

var input = [
  '4',
  '1 4 6 2',
  '5',
  '5 1 5 7 9'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = parseInt(d1Keys[i]);
  var prevKey = key-1;
  var nextKey = key+1;
  var t1 = Math.min(parseInt(d1[key]||0), parseInt(d2[prevKey]||0));
  d1[key]-= t1;
  if (d2[prevKey]!=null)
    d2[prevKey]-=t1;
  var t2 = Math.min(parseInt(d1[key]||0), parseInt(d2[key]||0));
  d1[key] -= t2;
  if (d2[key]!=null)
    d2[key]-=t2;
  var t3 = Math.min(parseInt(d1[key]||0), parseInt(d2[nextKey]||0));
  d1[key] -= t3;
  if (d2[nextKey]!=null)
    d2[nextKey]-=t3;

  ans+=t1+t2+t3;
  //print(ans);
}
//console.log(d1);
//console.log(d2);
print(ans);

function sa(girls,boys){

        girls.sort(function(a,b){ return a-b })
        boys.sort(function(a,b){ return a-b })

        var g=0;
        var b=0;
        var result = 0;
        while(g<girls.length && b < boys.length){
            if(Math.abs(girls[g] - boys[b]) <2){
                result++;
                g++;
                b++;
                continue;
            }
            if(girls[g] > boys[b]){
                b++;
            } else {
                g++;
            }
        }

        return result
    }

    readline();
    var girls = readline().split(" ").map(Number);
    readline();
    var boys = readline().split(" ").map(Number);

    print(sa(girls,boys));

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		if(!output[+input[i]]){
			output[+input[i]] = 1;
		}
		else{
			output[+input[i]]++;
		}
	}
}

var n = +readline(), boys = readline().split(" "), m = +readline(), girls = readline().split(" "),
boyslevs = {}, girlslevs = {}, pairs = 0;
maxb = Math.max.apply(null,boys);
maxg = Math.max.apply(null,girls);
minb = Math.min.apply(null,boys);
ming = Math.min.apply(null,girls);

if((maxb < ming) || (maxg < minb)){
	write(0);
}
else{
	countUniqueElements(boys,boyslevs);
	countUniqueElements(girls,girlslevs);

	for(level in boyslevs){
		level = +level;

		if(girlslevs[level-1]){
			if(boyslevs[level] > girlslevs[level-1]){
				pairs += girlslevs[level-1];
				boyslevs[level] -= girlslevs[level-1];
				delete girlslevs[level-1];
			}
			else if(boyslevs[level] == girlslevs[level-1]){
				pairs += boyslevs[level];
				delete girlslevs[level-1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level-1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level]){
				pairs += girlslevs[level];
				boyslevs[level] -= girlslevs[level];
				delete girlslevs[level];
			}
			else if(boyslevs[level] == girlslevs[level]){
				pairs += boyslevs[level];
				delete girlslevs[level];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level+1] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level+1]){
				pairs += girlslevs[level+1];
				boyslevs[level] -= girlslevs[level+1];
				delete girlslevs[level+1];
			}
			else if(boyslevs[level] == girlslevs[level+1]){
				pairs += boyslevs[level];
				delete girlslevs[level+1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level+1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}
	}

	write(pairs);
}

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort();

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = token[i];
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = token[i];
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort();

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = token[i];
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = token[i];
}

//sortSubarray(a,1,n);
//sortSubarray(b,1,m);

print(recurse(1,1));

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}
readline();
let firstGroup = readline().getNumArray().sort((a, b) => a - b);
readline();
let secondGroup = readline().getNumArray().sort((a, b) => a - b);
let counter = 0;

if (firstGroup.length > secondGroup.length) {
  const tempGroup = firstGroup;
  firstGroup = secondGroup;
  secondGroup = tempGroup;
}

for (let i = 0 ; i < firstGroup.length; i++) {
  for (let j = 0; j < secondGroup.length; j++) {
    if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {
      counter++;
      secondGroup.splice(j, 1);
    }
  }
}

write(counter);

var man = readline();
var str = readline().split(" ");
var woman = readline();
var str2 = readline().split(" ");
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="-";
				break;
			}
		}

	}

	print(res);

var man = readline();
var str = readline().split(" ");
var woman = readline();
var str2 = readline().split(" ");
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="";
				break;
			}
		}

	}

	print(res);

var input = [
  '4',
  '1 2 3 4',
  '4',
  '10 11 12 13'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = parseInt(d1Keys[i]);
  var prevKey = key-1;
  var nextKey = key+1;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  //print(nextKey);
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = [
  '2',
  '2 2',
  '1',
  '2'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = d1Keys[i];
  var prevKey = key-1;
  var nextKey = key+1;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = [
  '5',
  '1 1 1 1 1',
  '3',
  '1 2 3'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = d1Keys[i];
  var prevKey = key--;
  var nextKey = key++;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = readline().split(' ').map(Number), n = input[0];
var a = readline().split(' ').map(Number);
var input = readline().split(' ').map(Number), m = input[0];
var b = readline().split(' ').map(Number);

a = a.sort(function(a,b) { return a > b;});
b = b.sort(function(a,b) { return a > b;});

var ida = 0;
var idb = 0;
var res = 0;
while (ida < n && idb < m) {
    if (a[ida] < b[idb] - 1) ida++;
    else if (a[ida] > b[idb] + 1) idb++;
    else {
        res++;
        ida++;
        idb++;
    }
}
write(res);

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff==1){
                        count++;
                      //  console.log(j)
                        sg[j]=1000;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=1000;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],100);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],100);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg.splice(j,1);
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=190;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

function read() {
  let b = readline();
  let bSkills = readline().split(' ');
  boysSkills = boysSkills.map(ele => parseInt(ele));
  let g = readline();
  let girlsSkills = readline().split(' ')
  girlsSkills = girlsSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  } return count;
}

function read() {
  let b = readline();
  let bSkills = readline().split(' ');
  boysSkills = boysSkills.map(ele => parseInt(ele));
  let g = readline();
  let girlsSkills = readline().split(' ')
  girlsSkills = girlsSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  }
  console.log(count)
  return count;
}


const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos = []
        let min = 9999999
        let pos = 0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if (min > arr[i]) {
                min = arr[i]
                pos = i
            }
        }
        if (sum - min !== min && sum - min !== 0) {
            console.log("1")
            console.log(pos + 1)
            return
        }

        console.log("-1")
        return 0;
    }
});

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  switch (n) {
    case 1:
      console.log(-1);
      break;
    case 2:
      if (packets[0] === packets[1])
        console.log(-1);
      else {
        console.log(`${1}\n${1}`);
      }
      break;
    default:
      console.log(1);
      const minElement = Math.min.apply(null, packets);
      console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

const count = +readline();
const arr = readline().split(' ').map(function(v){return +v;});
const total = arr.reduce((p, e) => p+e);
switch(count) {
    case 1: {
        print(-1);
        break;
    }
    case 2: {
        if (arr[0] === arr[1]) {
            print(-1);
            break;
        }
    }
    default: {
        if (total % 2 != 0 ) {
            print(1);
            print(1);
            break;
        } else {
            const half = total / 2;
            kek = false;
            for(var i=0; i<count; i++) {
                if (arr[i] != half) {
                    print(1);
                    print(i+1);
                    kek = true;
                    break;
                }
            }
            if (kek) break;
        }
        print(-1);
    }
}

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            arrPos.push([arr[i],i])
        }

        arrPos=arrPos.sort(function sortNumber(a, b) {
            return a[0] - b[0];
        })
        let g = 0
        let currSum = 0
        let res= ""
        for (let i = 0; i < arrPos.length; i++) {
            g++
            currSum+=arrPos[i][0]
            res+=(arrPos[i][1]+1)+" "
            if (sum - arrPos[i][0] !== currSum&&g!== arrPos.length) {

                   console.log(g)
                   console.log(res)
                   return
            }
            sum-=arr[i]
        }

        console.log("-1")
        return 0;
    }
});

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray();
  if (n < 3)
    console.log(-1);
  else {
    console.log(1);
    console.log(packets[0]);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray();
  if (n < 3)
    console.log(-1);
  else {
    console.log(n - 1);
    packets.pop();
    console.log(packets.join(' '));
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  if (n < 3)
    console.log(-1);
  else {
    console.log(1);
    const minElement = Math.min.apply(null, packets);
    console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  switch (n) {
    case 1:
      console.log(-1);
      break;
    case 2:
      if (packets[0] === packets[1])
        console.log(-1);
      else {
        console.log(1);
        console.log(packets[0]);
      }
      break;
    default:
      console.log(1);
      const minElement = Math.min.apply(null, packets);
      console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  if (n < 3)
    console.log(-1);
  else {
    console.log(`${1}\n${1}`);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(10))
        let sum = 0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
        }
        let g = 0
        let currSum = 0
        let res= ""
        for (let i = 0; i < arr.length; i++) {
            g++
            currSum+=arr[i]
            res+=(i+1)+" "
            if (sum - arr[i] !== currSum&&g!== arr.length) {

                   console.log(g)
                   console.log(res)
                   return
            }
            sum-=arr[i]
        }

        console.log("-1")
        return 0;
    }
});

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(sum-min!==min){
            console.log("1")
            console.log(pos+1)
            return
        }

        console.log("-1")
        return 0;
    }
});

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(min-sum!==min){
            console.log("1")
            console.log(pos)
            return
        }

        console.log("-1")
        return 0;
    }
});

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(min-sum!==min){
            console.log("1")
            console.log(pos+1)
            return
        }

        console.log("-1")
        return 0;
    }
});


function toInt( s ) { return s.charCodeAt(0); }

function main()
{
    var s = readline();
    var t = "Bulbasaur";

    var a = new Array( 256 ).fill(0);
    var b = new Array( 256 ).fill( 0 );

    s.split('').forEach( (v) => a[toInt(v)]++ );
    t.split('').forEach( (v) => b[toInt(v)]++ );

    var ans = 1e9 + 5;
    for ( var i=0 ; i<256 ; i++ )
    {
        if ( b[i] > 0 )
        {
            var thiz = ~~( a[i] / b[i] );   // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )
            ans = Math.min( ans , thiz );
        }
    }
    print( ans );

} main();

function toInt( s ) { return s.charCodeAt(0); }

function main()
{
    var s = readline();
    var t = "Bulbasaur";

    var a = {} , b = {};

    s.split('').forEach( (v) => a[v] = a[v] ? a[v]+1 : 1 );
    t.split('').forEach( (v) => b[v] = b[v] ? b[v]+1 : 1 );

    var ans = 1e9 + 5;
    for ( var i in b )
    {
        var c1 = a[i] ? a[i] : 0;
        var c2 = b[i];
        var thiz = ~~( c1 / c2 );   // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )
        ans = Math.min( ans , thiz );
    }
    print( ans );

} main();

function main() {
    var s1 = readline();
    var lettersCounts = {};
    for(var i=0;i<s1.length;i++){
        if(lettersCounts[s1[i]]){
            lettersCounts[s1[i]]++;
        } else {
            lettersCounts[s1[i]] = 1;
        }
    }
   var array = [];
    var bulb = "Bulbasaur";
    for(var i=0;i<bulb.length;i++){
        if(bulb[i] == "u" || bulb[i] == "a"){
            array.push(Math.floor((lettersCounts[bulb[i]] || 0)/ 2));
        } else {
            array.push(lettersCounts[bulb[i]] || 0);
        }
    }
    print(Math.min(...array));
}

main()

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
let strArr = str.split('')
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 1, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})

let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        Object.keys(obj1).forEach(k1 => {
            if(k == k1) {
                arr.push(Math.floor(obj[k]/obj1[k1]))
            }
        })
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
    // console.log(i);

let strArr = str.split('')
// console.log(strArr)
let arr = [];
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})
let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        arr.push(obj[k])
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
let strArr = str.split('')
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})

let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        Object.keys(obj1).forEach(k1 => {
            if(k == k1) {
                arr.push(Math.floor(obj[k]/obj1[k1]))
            }
        })
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})