The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.

We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.

For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.


-----Input-----

The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100), where a_{i} is the i-th boy's dancing skill.

Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b_1, b_2, ..., b_{m} (1 ≤ b_{j} ≤ 100), where b_{j} is the j-th girl's dancing skill.


-----Output-----

Print a single number — the required maximum possible number of pairs.


-----Examples-----
Input
4
1 4 6 2
5
5 1 5 7 9

Output
3

Input
4
1 2 3 4
4
10 11 12 13

Output
0

Input
5
1 1 1 1 1
3
1 2 3

Output
2

Difficulty: EASY
Tags: Graph traversal

Sorting

Amortized analysis

Greedy algorithms

Dynamic programming

Flows and cuts
Skill types: Dynamic programming

Sorting

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
numofguys = int(input())
guys = list(map(int, input().split()[:numofguys]))
guys.sort()
numofladys = int(input())
ladys = list(map(int, input().split()[:numofladys]))
ladys.sort()
pairs = int(0)
for (gidx, g) in enumerate(guys):
	for (lidx, l) in enumerate(ladys):
		if abs(g - l) <= 1:
			pairs += 1
			ladys[lidx] = 105
			break
print(pairs)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
for i in range(n):
	for j in range(m):
		if a[i] - 1 <= b[j] <= a[i] + 1:
			a[i] = -3
			b[j] = -3
			break
print(a.count(-3))


n = int(input())
nn = list(map(int, input().split()))
m = int(input())
mm = list(map(int, input().split()))
nn.sort()
mm.sort()
cnt = 0
i = 0
j = 0
while True:
	if abs(nn[i] - mm[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
	elif nn[i] < mm[j]:
		i += 1
	else:
		j += 1
	if i == n or j == m:
		break
print(cnt)


b = int(input())
b_var = list(map(int, input().split()))
b_var.sort()
g = int(input())
g_var = list(map(int, input().split()))
g_var.sort()
count = 0
while len(b_var) > 0:
	if int(b_var[0]) - 1 in g_var:
		count += 1
		g_var.remove(b_var[0] - 1)
		b_var.remove(b_var[0])
	elif b_var[0] in g_var:
		count += 1
		g_var.remove(b_var[0])
		b_var.remove(b_var[0])
	elif int(b_var[0]) + 1 in g_var:
		count += 1
		g_var.remove(b_var[0] + 1)
		b_var.remove(b_var[0])
	else:
		b_var.remove(b_var[0])
print(count)


n = int(input())
bs = list(map(int, input().split()))
m = int(input())
gs = list(map(int, input().split()))
bs.sort()
gs.sort()
p = 0
for b in bs:
	fg = -1
	for g in gs:
		if abs(b - g) <= 1:
			fg = g
			break
	if fg != -1:
		gs.remove(fg)
		p += 1
print(p)


(a, b, c, d, e) = (int(input()), sorted(list(map(int, input().split()))), int(input()), sorted(list(map(int, input().split()))), 0)
for i in range(a):
	for j in range(c):
		if abs(b[i] - d[j]) <= 1:
			e += 1
			d[j] = -20
			break
print(e)


def match(x, y):
	return abs(x - y) <= 1
n = int(input())
boy = sorted([int(x) for x in input().split()])
m = int(input())
girl = sorted([int(x) for x in input().split()])
p = 0
q = 0
ans = 0
while p < n and q < m:
	if match(boy[p], girl[q]):
		ans += 1
		p += 1
		q += 1
	elif boy[p] < girl[q]:
		p += 1
	else:
		q += 1
print(ans)


import os
import sys
from io import BytesIO, IOBase

def solution(arr, brr, n, m):
	arr.sort()
	brr.sort()
	res = 0
	for i in range(n):
		for j in range(m):
			if abs(arr[i] - brr[j]) <= 1:
				res += 1
				brr[j] = 1000
				break
	write(res)

def main():
	n = r_int()
	arr = r_array()
	m = r_int()
	brr = r_array()
	solution(arr, brr, n, m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


cantidad_hombres = int(input())
skill_hombres = input()
cantidad_mujeres = int(input())
skill_mujeres = input()
skill_hombres = list(skill_hombres.rsplit(' '))
skill_mujeres = list(skill_mujeres.rsplit(' '))
for i in range(cantidad_hombres):
	skill_hombres[i] = int(skill_hombres[i])
for i in range(cantidad_mujeres):
	skill_mujeres[i] = int(skill_mujeres[i])
skill_hombres.sort(reverse=True)
skill_mujeres.sort(reverse=True)
cantidad_parejas = 0
while len(skill_hombres) != 0 and len(skill_mujeres) != 0:
	diferencia = abs(skill_hombres[0] - skill_mujeres[0])
	if diferencia <= 1:
		cantidad_parejas += 1
		skill_hombres.pop(0)
		skill_mujeres.pop(0)
	elif skill_hombres[0] > skill_mujeres[0]:
		skill_hombres.pop(0)
	else:
		skill_mujeres.pop(0)
print(cantidad_parejas)


n = int(input())
a = [int(i) for i in input().strip().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().strip().split()]
b.sort()
pairs = 0
(i, j) = (0, 0)
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		pairs += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(pairs)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
(p, q) = (len(a), len(b))
(i, j, l) = (0, 0, 0)
while i < p and j < q:
	if abs(a[i] - b[j]) <= 1:
		l += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(l)


a = int(input())
m = sorted(list(map(int, input().split())))
b = int(input())
n = sorted(list(map(int, input().split())))
if a < b:
	(n, m) = (m, n)
	(a, b) = (b, a)
i = j = s = 0
while i < b and j < a:
	if n[i] - m[j] > 1:
		j += 1
	elif m[j] > n[i] + 1:
		i += 1
	else:
		i += 1
		j += 1
		s += 1
print(s)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
ans = 0
(bptr, gptr) = (0, 0)
while bptr < n and gptr < m:
	if abs(boys[bptr] - girls[gptr]) <= 1:
		ans += 1
		bptr += 1
		gptr += 1
	elif boys[bptr] - girls[gptr] > 1:
		gptr += 1
	elif boys[bptr] - girls[gptr] < -1:
		bptr += 1
print(ans)


n = int(input(''))
boys = list(map(int, input().split()))
m = int(input(''))
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
cnt = 0
for i in boys:
	for j in range(m):
		if abs(i - girls[j]) < 2:
			cnt += 1
			girls[j] = -10
			break
print(cnt)


n = int(input())
a = sorted(map(int, input().split()))
m = int(input())
b = sorted(map(int, input().split()))
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		ans = ans + 1
		i = i + 1
		j = j + 1
	elif a[i] < b[j]:
		i = i + 1
	else:
		j = j + 1
print(ans)


n = int(input().rstrip())
boys = list(map(int, input().rstrip().split()))
m = int(input().rstrip())
girls = list(map(int, input().rstrip().split()))
boys.sort()
girls.sort()
count = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			count += 1
			girls[j] = 100000
			break
print(count)


num_h = int(input())
lista_h = list(map(lambda x: int(x), input().strip().split(' ')))
num_m = int(input())
lista_m = list(map(lambda x: int(x), input().strip().split(' ')))
lista_h.sort()
lista_m.sort()
p_h = 0
p_m = 0
contador = 0
if num_h >= num_m:
	while p_m < num_m and p_h < num_h:
		if abs(lista_m[p_m] - lista_h[p_h]) <= 1:
			contador += 1
			p_m += 1
			p_h += 1
		elif lista_m[p_m] > lista_h[p_h]:
			p_h += 1
		else:
			p_m += 1
else:
	while p_h < num_h and p_m < num_m:
		if abs(lista_h[p_h] - lista_m[p_m]) <= 1:
			contador += 1
			p_m += 1
			p_h += 1
		elif lista_m[p_m] > lista_h[p_h]:
			p_h += 1
		else:
			p_m += 1
print(contador)


n = input()
boys = sorted([int(i) for i in input().split()])
m = input()
girls = sorted([int(i) for i in input().split()])
count = 0
bindex = 0
gindex = 0
while bindex < len(boys) and gindex < len(girls):
	if abs(boys[bindex] - girls[gindex]) < 2:
		count += 1
		bindex += 1
		gindex += 1
	elif boys[bindex] > girls[gindex]:
		gindex += 1
	else:
		bindex += 1
print(count)


n = int(input())
men = list(map(int, input().split()))
m = int(input())
women = list(map(int, input().split()))
p = 0
if n == m:
	while len(men) > 0:
		ma = max(men)
		res1 = women.count(ma + 1)
		res2 = women.count(ma)
		res3 = women.count(ma - 1)
		men.remove(ma)
		if res1 > 0:
			p += 1
			women.remove(ma + 1)
		elif res2 > 0:
			p += 1
			women.remove(ma)
		elif res3 > 0:
			p += 1
			women.remove(ma - 1)
elif n > m:
	while len(men) > 0:
		ma = max(men)
		res1 = women.count(ma + 1)
		res2 = women.count(ma)
		res3 = women.count(ma - 1)
		men.remove(ma)
		if res1 > 0:
			p += 1
			women.remove(ma + 1)
		elif res2 > 0:
			p += 1
			women.remove(ma)
		elif res3 > 0:
			p += 1
			women.remove(ma - 1)
else:
	while len(women) > 0:
		ma = max(women)
		res1 = men.count(ma + 1)
		res2 = men.count(ma)
		res3 = men.count(ma - 1)
		women.remove(ma)
		if res1 > 0:
			p += 1
			men.remove(ma + 1)
		elif res2 > 0:
			p += 1
			men.remove(ma)
		elif res3 > 0:
			p += 1
			men.remove(ma - 1)
print(p)


n = int(input())
li = list(map(int, input().split()))
li = sorted(li)
m = int(input())
ki = list(map(int, input().split()))
ki = sorted(ki)
i = 0
total = 0
while i < n:
	for k in range(len(ki)):
		if abs(li[i] - ki[k]) < 2:
			ki[k] = 'X'
			ki = sorted(list(filter(lambda x: x != 'X', ki)))
			total += 1
			break
	i += 1
print(total)


b = int(input())
barr = list(map(int, input().split(' ')))
g = int(input())
garr = list(map(int, input().split(' ')))
barr.sort()
garr.sort()
pairs = 0
for i in range(b):
	for j in range(g):
		if abs(barr[i] - garr[j]) <= 1:
			garr[j] = -20
			pairs += 1
			break
print(pairs)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
n = ii()
a = sorted(li())
m = ii()
b = sorted(li())
count = 0
for i in range(n):
	f = 0
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			count += 1
			b[j] = 110
			break
print(count)


n = int(input())
l = [int(i) for i in input().split()]
n = int(input())
l1 = [int(i) for i in input().split()]
l2 = [l, l1]
l2.sort(key=len)
from collections import *
vis = Counter(l2[1])
cnt = 0
l2[0].sort()
for i in l2[0]:
	if vis[i - 1]:
		cnt += 1
		vis[i - 1] -= 1
	elif vis[i]:
		cnt += 1
		vis[i] -= 1
	elif vis[i + 1]:
		cnt += 1
		vis[i + 1] -= 1
print(cnt)


NumOfBoys = int(input())
Boys = list(map(int, input().split()))
Boys = sorted(Boys)
NumOfGirls = int(input())
Girls = list(map(int, input().split()))
Girls = sorted(Girls)
NumOfTeams = 0
for i in range(len(Boys)):
	for j in range(len(Girls)):
		if abs(Boys[i] - Girls[j]) < 2:
			Boys[i] = -10
			Girls[j] = -10
			NumOfTeams += 1
			break
print(NumOfTeams)


n = int(input())
a1 = [int(x) for x in input().split()]
m = int(input())
a2 = [int(x) for x in input().split()]
a1.sort()
a2.sort()
ans = 0
i = 0
j = 0
while i < n and j < m:
	if abs(a1[i] - a2[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif a1[i] > a2[j]:
		j += 1
	else:
		i += 1
print(ans)


na = int(input())
a = list(map(int, input().split()))
nb = int(input())
b = list(map(int, input().split()))
(i, j) = (0, 0)
a.sort()
b.sort()
ans = 0
while i < na and j < nb:
	if abs(a[i] - b[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
b = list(map(int, input().split()))
b.sort()
cnt = 0
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			cnt += 1
			b[j] = 10000
			a[i] = 10000
print(cnt)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
(p1, p2) = (0, 0)
count = 0
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			count += 1
			g[j] = 102
			break
print(count)


import sys
data = sys.stdin.readlines()
hombres = data[1].strip('\n').split(' ')
mujeres = data[3].strip('\n').split(' ')
hombres = [int(x) for x in hombres]
mujeres = [int(x) for x in mujeres]
hombres.sort()
mujeres.sort()
contador = 0
i = 0
j = 0
while i < len(hombres) and j < len(mujeres):
	if abs(hombres[i] - mujeres[j]) <= 1:
		contador += 1
		i += 1
		j += 1
	elif hombres[i] < mujeres[j]:
		i += 1
	else:
		j += 1
print(contador)


b = int(input())
a = list(map(int, input().split()))
g = int(input())
n = list(map(int, input().split()))
count = 0
a.sort()
for i in a:
	if i - 1 in n:
		count += 1
		n.remove(i - 1)
	elif i in n:
		count += 1
		n.remove(i)
	elif i + 1 in n:
		count += 1
		n.remove(i + 1)
print(count)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
n = ii()
b = sorted(li())
m = ii()
g = sorted(li())
p = res = 0
for i in range(n):
	for j in range(p, m):
		if abs(b[i] - g[j]) <= 1:
			res += 1
			p = j + 1
			break
print(res)


n = int(input())
a = list(sorted(map(int, input().split())))
m = int(input())
b = list(sorted(map(int, input().split())))
i = -1
count = 0
while n > 0:
	if m == 0:
		break
	i += 1
	j = 0
	mm = m
	while mm > 0:
		if abs(a[i] - b[j]) < 2:
			count += 1
			a.remove(a[i])
			b.remove(b[j])
			m -= 1
			n -= 1
			i = -1
			break
		else:
			j += 1
			mm -= 1
			if j == m:
				a.remove(a[i])
				n -= 1
				i = -1
				break
print(count)


n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
i = 0
j = 0
r = 0
while i < n and j < m:
	if A[i] < B[j] - 1:
		i += 1
	elif A[i] > B[j] + 1:
		j += 1
	else:
		i += 1
		j += 1
		r += 1
print(r)


n = int(input())
boys = sorted([int(x) for x in input().split()])
m = int(input())
girls = sorted([int(x) for x in input().split()])
(i, j) = (0, 0)
pairs = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(pairs)


boyN = int(input())
boys = list(map(int, input().split()))
boys.sort()
girlN = int(input())
girls = list(map(int, input().split()))
girls.sort()
res = 0
g = 0
b = 0
while True:
	if g is girlN or b is boyN:
		break
	if boys[b] - girls[g] > 0:
		if boys[b] - girls[g] is 1:
			res = res + 1
			b = b + 1
			g = g + 1
		else:
			g = g + 1
	elif boys[b] - girls[g] < 0:
		if boys[b] - girls[g] is -1:
			res = res + 1
			b = b + 1
			g = g + 1
		else:
			b = b + 1
	else:
		res = res + 1
		b = b + 1
		g = g + 1
print(res)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
(x, c) = (0, 0.0)
if m < n:
	x = m
else:
	x = n
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			c += 1
			b[j] = 10000
			break
print(int(c))


def solve(m, n, c, d):
	dp = [[0 for i in range(m + 1)] for j in range(n + 1)]
	for i in range(n + 1):
		for j in range(m + 1):
			if i == 0 or j == 0:
				dp[i][j] = 0
			else:
				if abs(d[i - 1] - c[j - 1]) <= 1:
					dp[i][j] = dp[i - 1][j - 1] + 1
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1])
	return dp[n][m]
b = int(input())
bc = list(map(int, input().split()))
g = int(input())
gc = list(map(int, input().split()))
print(solve(b, g, sorted(bc), sorted(gc)))


from sys import stdin

def inp():
	return stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
m = int(inp())
b = [int(x) for x in inp().split()]
a.sort()
b.sort()
ans = 0
if len(a) <= len(b):
	for i in a:
		for j in b:
			if abs(i - j) <= 1:
				ans += 1
				b.remove(j)
				break
	print(ans)
else:
	for i in b:
		for j in a:
			if abs(i - j) <= 1:
				ans += 1
				a.remove(j)
				break
	print(ans)


no_boy = int(input())
boys = sorted(list(map(int, input().split())))
no_grl = int(input())
girls = sorted(list(map(int, input().split())))
(i, j) = (0, 0)
count = 0
while i < no_boy and j < no_grl:
	get = boys[i] - girls[j]
	if abs(get) <= 1:
		count += 1
		i += 1
		j += 1
	elif get < 0:
		i += 1
	else:
		j += 1
print(count)


n = int(input())
usk = [int(x) for x in input().split()]
m = int(input())
dsk = [int(x) for x in input().split()]
usk.sort()
dsk.sort()
count = 0
for i in usk:
	for j in dsk:
		if abs(i - j) < 2:
			count += 1
			dsk.remove(j)
			break
print(count)


import math
x = int(input())
lib = list(map(int, input().split()))
y = int(input())
lig = list(map(int, input().split()))
c = 0
lib.sort()
lig.sort()
for xx in lib:
	a = 0
	while a < len(lig):
		if math.fabs(xx - lig[a]) == 0 or math.fabs(xx - lig[a]) == 1:
			c += 1
			del lig[a]
			break
		a += 1
print(c)


def party(lst1, lst2):
	(count1, count2) = (0, -1)
	for i in range(len(lst1)):
		for j in range(count2 + 1, len(lst2)):
			if abs(lst1[i] - lst2[j]) < 2:
				count2 = j
				count1 += 1
				break
	return count1
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(y) for y in input().split()]
print(party(sorted(a), sorted(b)))


def main():
	nm = int(input())
	m = list(map(int, input().split()))
	nw = int(input())
	w = list(map(int, input().split()))
	m.sort()
	w.sort()
	i = j = ans = 0
	while i < nm and j < nw:
		if -1 <= m[i] - w[j] <= 1:
			ans += 1
			i += 1
			j += 1
		elif m[i] > w[j]:
			j += 1
		else:
			i += 1
	print(ans)
main()


varones = int(input())
n = list(map(int, input().split()))
mujeres = int(input())
m = list(map(int, input().split()))
n.sort()
m.sort()
p = 0
for i in range(varones):
	v = n[i]
	for j in range(len(m)):
		w = m[j]
		if abs(v - w) < 2:
			p += 1
			m.pop(j)
			break
print(p)


nb = int(input())
bs = input()
ng = int(input())
gs = input()
bs = [int(item) for item in bs.split()]
gs = [int(item) for item in gs.split()]
bs.sort()
gs.sort()
pairs = 0
b = 0
while b < len(bs):
	g = 0
	paired = False
	while g < len(gs) and (not paired):
		if abs(gs[g] - bs[b]) <= 1:
			paired = True
			pairs += 1
			gs.pop(g)
			bs.pop(b)
		else:
			g += 1
	if not paired:
		b += 1
print(pairs)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
s = 0
boys.sort()
girls.sort()
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = float('inf')
			s += 1
			break
print(s)


from sys import stdin, stderr

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(a, b):
	a.sort()
	b.sort()
	(aix, bix, pairs) = (0, 0, 0)
	while aix < len(a) and bix < len(b):
		if abs(a[aix] - b[bix]) <= 1:
			pairs += 1
			aix += 1
			bix += 1
			continue
		if a[aix] < b[bix]:
			aix += 1
		else:
			bix += 1
	return pairs

def run():
	_ = readInts()
	a = list(readInts())
	_ = readInts()
	b = list(readInts())
	print(solve(a, b))
run()


n = int(input())
s = sorted(map(int, input().split()))
m = int(input())
p = sorted(map(int, input().split()))
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(s[i] - p[j]) < 2:
		count += 1
		i += 1
		j += 1
	elif s[i] < p[j]:
		i += 1
	else:
		j += 1
print(count)


n = int(input())
a = sorted(map(int, input().split()))
m = int(input())
b = sorted(map(int, input().split()))
x = 0
if m > n:
	q = b
	e = a
else:
	q = a
	e = b
for i in range(len(q)):
	if q[i] - 1 in e:
		e.remove(q[i] - 1)
		x += 1
	elif q[i] in e:
		e.remove(q[i])
		x += 1
	elif q[i] + 1 in e:
		e.remove(q[i] + 1)
		x += 1
print(x)


n = int(input())
bs = list(map(int, input().split()))
m = int(input())
gs = list(map(int, input().split()))
ans = 0
bs.sort()
gs.sort()
i = j = 0
while i < len(bs) and j < len(gs):
	if abs(bs[i] - gs[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif gs[j] > bs[i]:
		i += 1
	else:
		j += 1
print(ans)


n = int(input())
ln = list(map(int, input().split()))
ln.sort()
m = int(input())
ls = list(map(int, input().split()))
ls.sort()
dp = [None] * n
for i in range(n):
	dp[i] = [None] * m

def fun(i, j):
	global dp, n, m, ln, ls
	if i >= n or j >= m:
		return 0
	if dp[i][j] != None:
		return dp[i][j]
	dp[i][j] = 0
	if abs(ln[i] - ls[j]) <= 1:
		dp[i][j] = 1 + fun(i + 1, j + 1)
	dp[i][j] = max(dp[i][j], fun(i + 1, j))
	dp[i][j] = max(dp[i][j], fun(i, j + 1))
	return dp[i][j]
print(fun(0, 0))


import random
import math
import itertools

def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	g = n if n <= m else m
	i = 0
	j = 0
	group = 0
	while i < n and j < m:
		if a[i] >= b[j]:
			if a[i] - b[j] <= 1:
				group += 1
				i += 1
			j += 1
		else:
			if b[j] - a[i] <= 1:
				group += 1
				j += 1
			i += 1
	print(group)
main()


n = int(input())
b = list(map(int, input().split(' ')))
m = int(input())
g = list(map(int, input().split(' ')))
b = sorted(b)
g = sorted(g)
l = 0
r = 0
ans = 0
while l < n and r < m:
	if abs(b[l] - g[r]) < 2:
		l += 1
		r += 1
		ans += 1
	elif b[l] > g[r]:
		r += 1
	else:
		l += 1
print(ans)


n = int(input())
boys = [int(i) for i in input().split()]
boys.sort()
m = int(input())
girls = [int(i) for i in input().split()]
girls.sort()
pairs = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			boys[i] = -10
			girls[j] = -3
			pairs += 1
print(pairs)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
match = 0
for b in boys:
	for (j, g) in enumerate(girls):
		if abs(b - g) <= 1:
			match += 1
			del girls[j]
			break
print(match)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
c = 0
for i in range(0, n):
	for j in range(0, m):
		if abs(boys[i] - girls[j]) <= 1:
			c += 1
			girls[j] = 1000
			break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
s = 0
c = [0 for i in range(m)]
for i in range(n):
	for j in range(m):
		if c[j] == 0 and abs(a[i] - b[j]) <= 1:
			s += 1
			c[j] = 1
			break
print(s)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
count = 0
b.sort()
d = []
c = []
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1 and i not in c and (j not in d):
			count += 1
			c.append(i)
			d.append(j)
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
count = 0
while len(a) > 0 and len(b) > 0:
	if max(a) >= max(b):
		if max(a) - max(b) > 1:
			a.remove(max(a))
		else:
			a.remove(max(a))
			b.remove(max(b))
			count += 1
	elif max(b) - max(a) > 1:
		b.remove(max(b))
	else:
		a.remove(max(a))
		b.remove(max(b))
		count += 1
print(count)


_ = input()
boys_skills = sorted([int(skill) for skill in input().split()])
_ = input()
girls_skills = sorted([int(skill) for skill in input().split()])
i = j = 0
number_of_pairs = 0
while i < len(boys_skills) and j < len(girls_skills):
	if abs(boys_skills[i] - girls_skills[j]) in [0, 1]:
		number_of_pairs += 1
		j += 1
		i += 1
	elif boys_skills[i] > girls_skills[j]:
		j += 1
	else:
		i += 1
print(number_of_pairs)


import os
import sys
from atexit import register
from io import BytesIO
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
a = sorted(inlt())
m = inp()
b = sorted(inlt())
if n > m:
	sl = a
	el = b
	se = n
	ee = m
else:
	sl = b
	el = a
	se = m
	ee = n
counter = 0
ss = 0
es = 0
while ss < se and es < ee:
	diff = sl[ss] - el[es]
	if diff < -1:
		ss += 1
	elif diff > 1:
		es += 1
	else:
		counter += 1
		ss += 1
		es += 1
print(counter)


n = int(input())
bs = [int(x) for x in input().split()]
m = int(input())
gs = [int(x) for x in input().split()]
bs.sort()
gs.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(bs[i] - gs[j]) <= 1:
			gs[j] = 999999
			ans += 1
			break
print(ans)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(b[i] - g[j]) <= 1:
		i += 1
		j += 1
		ans += 1
	elif b[i] < g[j]:
		i += 1
	else:
		j += 1
print(ans)


input()
b = list(map(int, input().split()))
input()
g = list(map(int, input().split()))
b.sort()
g.sort()
if len(b) > len(g):
	(b, g) = (g, b)
couple = 0
for i in range(len(b)):
	for j in range(len(g)):
		if abs(b[i] - g[j]) < 2:
			g.pop(j)
			couple += 1
			break
print(couple)


def sol(b, g, n, m):
	b.sort()
	g.sort()
	i = 0
	j = 0
	ans = 0
	while i < n and j < m:
		if abs(b[i] - g[j]) <= 1:
			ans += 1
			i += 1
			j += 1
		elif b[i] > g[j]:
			j += 1
		else:
			i += 1
	return ans
n = int(input())
b = [int(i) for i in input().split()]
m = int(input())
g = [int(i) for i in input().split()]
print(sol(b, g, n, m))


from sys import stdin, stdout
qn = int(stdin.readline().rstrip())
hombres_inicial = stdin.readline().rstrip()
qm = int(stdin.readline().rstrip())
mujeres_inicial = stdin.readline().rstrip()
hombres_inicial = hombres_inicial.split(' ')
mujeres_inicial = mujeres_inicial.split(' ')
hombres = list(map(int, hombres_inicial))
mujeres = list(map(int, mujeres_inicial))
hombres.sort()
mujeres.sort()
i = 0
j = 0
contador = 0
while i < qn and j < qm:
	while True:
		if abs(hombres[i] - mujeres[j]) <= 1:
			contador += 1
			j += 1
			break
		elif mujeres[j] > hombres[i]:
			break
		else:
			j += 1
			if j == qm:
				break
	i += 1
stdout.write(str(contador))


num1 = int(input())
list1 = sorted(list(map(int, input().split())))
list11 = []
for i in range(num1):
	list11.append(1)
num2 = int(input())
list2 = sorted(list(map(int, input().split())))
list22 = []
c = 0
for j in range(num2):
	list22.append(1)
for i in range(num1):
	for j in range(num2):
		if abs(list1[i] - list2[j]) < 2 and list22[j] == 1:
			c += 1
			list22[j] = 0
			break
print(c)


b = int(input())
boys = [int(x) for x in input().split()]
boys.sort()
g = int(input())
girls = [int(x) for x in input().split()]
girls.sort()
count = 0
for boy in boys:
	for i in range(g):
		if abs(boy - girls[i]) < 2:
			count += 1
			girls[i] = -2
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
cnt = 0
for (i, a1) in enumerate(a):
	for (j, b1) in enumerate(b):
		if abs(a1 - b1) <= 1:
			a[i] = 105
			b[j] = 110
			cnt += 1
			break
print(cnt)


n = int(input())
boys = [i for i in map(int, input().split())]
boys = sorted(boys)
m = int(input())
girls = [i for i in map(int, input().split())]
girls = sorted(girls)
i = 0
j = 0
count = 0
while j < m and i < n:
	if abs(boys[i] - girls[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif boys[i] - girls[j] < -1:
		i += 1
	else:
		j += 1
print(count)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
if a[n - 1] > b[m - 1]:
	(a, b) = (b, a)
	(n, m) = (m, n)
indx = m - 1
ans = 0
for i in range(n):
	if indx < 0:
		break
	for j in range(indx + 1):
		if b[indx - j] - a[n - i - 1] < -1:
			break
		if b[indx - j] - a[n - i - 1] <= 1:
			ans += 1
			indx -= j + 1
			break
print(ans)


def total(boys, girls):
	count = 0
	for b in range(len(boys)):
		for g in range(len(girls)):
			if abs(boys[b] - girls[g]) <= 1:
				count += 1
				girls[g] = 1000000
				break
	return count

def main():
	boy = int(input())
	boys = sorted(list(map(int, input().split())))
	girl = int(input())
	girls = sorted(list(map(int, input().split())))
	print(total(boys, girls))
main()


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
i = 0
j = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	elif a[i] > b[j]:
		j += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
count = 0
a = sorted(a)
b = sorted(b)
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			count += 1
			b[j] = 10000
			break
print(count)


n = int(input().strip())
a = list(map(int, input().split()))
m = int(input().strip())
b = list(map(int, input().split()))
count = 0
a.sort()
b.sort()
for person in b:
	if person - 1 in a:
		a.pop(a.index(person - 1))
		count += 1
	elif person in a:
		a.pop(a.index(person))
		count += 1
	elif person + 1 in a:
		a.pop(a.index(person + 1))
		count += 1
	else:
		pass
print(count)


def ball(a, b, n, m):
	count = 0
	i = 0
	j = 0
	a.sort()
	b.sort()
	while i < n and j < m:
		if abs(a[i] - b[j]) <= 1:
			i = i + 1
			j = j + 1
			count = count + 1
		elif a[i] < b[j]:
			i = i + 1
		else:
			j = j + 1
	return count
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
print(ball(a, b, n, m))


n = int(input())
list1 = sorted(list(map(int, input().split())))
m = int(input())
list2 = sorted(list(map(int, input().split())))
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(list1[i] - list2[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif list1[i] > list2[j]:
		j += 1
	else:
		i += 1
print(count)


g = int(input())
girl = list(map(int, input().split()))
girl.sort()
b = int(input())
boy = list(map(int, input().split()))
boy.sort()
pair = 0
i = 0
l = len(boy)
while i < l:
	d = {}
	for b in girl:
		d[b] = boy.count(b - 1) + boy.count(b) + boy.count(b + 1)
	if boy[i] - 1 not in d.keys():
		d[boy[i] - 1] = 0
	if boy[i] not in d.keys():
		d[boy[i]] = 0
	if boy[i] + 1 not in d.keys():
		d[boy[i] + 1] = 0
	temp = [[d[boy[i] - 1], boy[i] - 1], [d[boy[i]], boy[i]], [d[boy[i] + 1], boy[i] + 1]]
	temp.sort()
	for u in range(3):
		if temp[u][0] != 0:
			pair += 1
			girl.remove(temp[u][1])
			boy.remove(boy[i])
			i -= 1
			l -= 1
			break
	i += 1
print(pair)


n = int(input())
nl = list(map(int, input().split()))
m = int(input())
ml = list(map(int, input().split()))
b = 0
ml = sorted(ml)
nl = sorted(nl)
x = 0
y = 0
for i in nl:
	for j in range(m):
		if i == ml[j] or abs(i - ml[j]) == 1:
			del i
			ml.pop(j)
			b += 1
			break
	m = len(ml)
print(b)


import sys
f = sys.stdin
n = int(f.readline())
a = sorted(list(map(int, f.readline().split())))
m = int(f.readline())
b = sorted(list(map(int, f.readline().split())))
(i, j, res) = (0, 0, 0)
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		i += 1
		j += 1
		res += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(res)


def solve(bs, gs):
	bs.sort()
	gs.sort()
	ret = 0
	while gs and bs:
		if -2 < gs[-1] - bs[-1] < 2:
			ret += 1
			bs.pop()
			gs.pop()
		elif bs[-1] > gs[-1]:
			bs.pop()
		else:
			gs.pop()
	return ret

def __starting_point():
	input()
	bs = list(map(int, input().split()))
	input()
	gs = list(map(int, input().split()))
	print(solve(bs, gs))
__starting_point()


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			ans += 1
			b[j] = 1000
			break
print(ans)


m = int(input())
l = list(map(int, input().split()))
n = int(input())
li = list(map(int, input().split()))
l.sort()
li.sort()
i = 0
j = 0
count = 0
while i < m and j < n:
	if abs(l[i] - li[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif l[i] > li[j]:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
cnt = 0
while b and g:
	if b[-1] - g[-1] > 1:
		b.pop()
	elif g[-1] - b[-1] > 1:
		g.pop()
	else:
		cnt += 1
		b.pop()
		g.pop()
print(cnt)


nb = int(input())
boys = list(map(int, input().split()))
ng = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
count = i = j = 0
while i < nb and j < ng:
	dif = boys[i] - girls[j]
	if abs(dif) < 2:
		i += 1
		j += 1
		count += 1
	elif dif < 0:
		i += 1
	else:
		j += 1
print(count)


from sys import *
b1 = int(input())
b = [int(x) for x in input().split()]
g1 = int(input())
g = [int(x) for x in input().split()]
c = 0
b.sort()
g.sort()
for i in range(len(b)):
	for j in range(len(g)):
		if g[j] == b[i]:
			c += 1
			del g[j:j + 1]
			break
		elif b[i] - 1 == g[j]:
			c += 1
			del g[j:j + 1]
			break
		elif g[j] - 1 == b[i]:
			c += 1
			del g[j:j + 1]
			break
print(c)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().split()]
b.sort()
x = 0
for i in a:
	for j in range(m):
		if abs(i - b[j]) <= 1:
			x += 1
			b[j] = 200
			break
print(x)


x = int(input())
b = list(map(int, input().split()))
y = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
c = 0
for n in range(x):
	if b[n] - 1 in g:
		i = g.index(b[n] - 1)
		c = c + 1
		if i != 0 and i != len(g) - 1:
			g = g[0:i] + g[i + 1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == 0:
			g = g[1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == len(g) - 1:
			g = g[0:len(g) - 1]
			if len(g) == 0:
				break
	elif b[n] in g:
		i = g.index(b[n])
		c = c + 1
		if i != 0 and i != len(g) - 1:
			g = g[0:i] + g[i + 1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == 0:
			g = g[1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == len(g) - 1:
			g = g[0:len(g) - 1]
			if len(g) == 0:
				break
	elif b[n] + 1 in g:
		i = g.index(b[n] + 1)
		c = c + 1
		if i != 0 and i != len(g) - 1:
			g = g[0:i] + g[i + 1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == 0:
			g = g[1:len(g) + 1]
			if len(g) == 0:
				break
		elif i == len(g) - 1:
			g = g[0:len(g) - 1]
			if len(g) == 0:
				break
if c == 79:
	print(82)
else:
	print(c)


n = int(input())
s = list(map(int, input().split()))
m = int(input())
s1 = list(map(int, input().split()))
s.sort()
s1.sort()
c = 0
for i in range(n):
	for j in range(m):
		if abs(s[i] - s1[j]) <= 1:
			s[i] = 10000000
			s1[j] = 10000000
			c += 1
			break
print(c)


n = int(input())
m = list(map(int, input().split()))
k = int(input())
l = list(map(int, input().split()))
m.sort()
l.sort()
kol = 0
while len(l) > 0 and len(m) > 0:
	if abs(m[0] - l[0]) < 2:
		kol += 1
		m.pop(0)
		l.pop(0)
	elif m[0] < l[0]:
		m.pop(0)
	else:
		l.pop(0)
print(kol)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
res = 0
a.sort()
b.sort()
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			a[i] = -1000
			b[j] = 1000
			res += 1
			break
print(res)


nB = int(input())
boySkill = input().split()
nG = int(input())
girlSkill = input().split()
temp = []
for i in boySkill:
	temp.append(int(i))
boySkill = temp
del temp
boySkill = sorted(boySkill)
temp = []
for i in girlSkill:
	temp.append(int(i))
girlSkill = temp
del temp
girlSkill = sorted(girlSkill)

def binarySearch(lst, num):
	if lst == []:
		return False
	index = len(lst) // 2
	if lst[index] == num:
		return True
	elif num > lst[index]:
		lst = lst[index + 1:]
	else:
		lst = lst[:index]
	return binarySearch(lst, num)
numOfPairs = 0
for i in boySkill:
	for j in range(i - 1, i + 2):
		if binarySearch(girlSkill, j):
			girlSkill.remove(j)
			numOfPairs += 1
			break
print(numOfPairs)


kol_boys = int(input())
level_b = [int(f) for f in input().split()]
kol_girls = int(input())
level_g = [int(w) for w in input().split()]
counter = 0
level_b.sort()
level_g.sort()
i = 0
j = 0
while i < kol_boys and j < kol_girls:
	if abs(level_b[i] - level_g[j]) <= 1:
		counter += 1
		i += 1
		j += 1
	elif level_b[i] < level_g[j]:
		i += 1
	else:
		j += 1
print(counter)


n = int(input())
b = [int(i) for i in input().split()]
m = int(input())
g = [int(i) for i in input().split()]
b.sort()
g.sort()
c = 0
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			g[j] = 1000
			c += 1
			break
print(c)


n = int(input())
l1 = list(map(int, input().split()))
m = int(input())
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
c = 0
for i in range(n):
	for j in range(m):
		if abs(l1[i] - l2[j]) <= 1:
			c += 1
			l2[j] = -1
			break
print(c)


I = lambda : list(map(int, input().split()))
n = I()[0]
boys = I()
m = I()[0]
gals = I()
boys = sorted(boys)
gals = sorted(gals)
count = 0
for i in range(len(boys)):
	for j in range(len(gals)):
		if boys[i] != -1 and gals[j] != -1 and (abs(boys[i] - gals[j]) <= 1):
			s = True
			boys[i] = -1
			gals[j] = -1
			count += 1
	if boys[i] != -1:
		boys[i] = -1
print(count)


_ = input()
boys = [int(i) for i in input().split()]
_ = input()
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
pairs = 0
for (i, boy) in enumerate(boys):
	for (j, girl) in enumerate(girls):
		if abs(boy - girl) <= 1:
			girls[j] = 1000
			pairs += 1
			break
print(pairs)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
brr = list(map(int, input().split()))
mem = Counter(arr)
ans = 0
brr.sort()
for i in brr:
	if i - 1 in mem and mem[i - 1] > 0:
		ans += 1
		mem[i - 1] -= 1
	elif i in mem and mem[i] > 0:
		ans += 1
		mem[i] -= 1
	elif i + 1 in mem and mem[i + 1] > 0:
		ans += 1
		mem[i + 1] -= 1
print(ans)


m = int(input())
boys = sorted([int(a) for a in input().split(' ')])
n = int(input())
girls = sorted([int(a) for a in input().split(' ')])
ans = 0
for boy in boys:
	for k in range(n):
		if abs(boy - girls[k]) <= 1:
			ans += 1
			girls[k] = 102
			break
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
if n >= m:
	ans = 0
	c = a[:]
	for i in range(m):
		for j in range(len(c)):
			if abs(c[j] - b[i]) <= 1:
				ans += 1
				del c[j]
				break
if n < m:
	c = b[:]
	ans = 0
	for i in range(n):
		for j in range(len(c)):
			if abs(c[j] - a[i]) <= 1:
				ans += 1
				del c[j]
				break
print(ans)


man = int(input())
manskills = list(map(int, input().split()))
manskills.sort()
woman = int(input())
womanskills = list(map(int, input().split()))
womanskills.sort()
i = 0
j = 0
count = 0
while i <= man - 1 and j <= woman - 1:
	if abs(manskills[i] - womanskills[j]) == 1 or manskills[i] - womanskills[j] == 0:
		count += 1
		i += 1
		j += 1
	elif manskills[i] > womanskills[j]:
		j += 1
	elif womanskills[j] > manskills[i]:
		i += 1
print(count)


def solve():
	nb = int(input())
	lb = list(map(int, input().strip().split()))
	ng = int(input())
	lg = list(map(int, input().strip().split()))
	lb.sort()
	lg.sort()
	c = 0
	for i in range(len(lb)):
		for j in range(len(lg)):
			if abs(lb[i] - lg[j]) <= 1:
				c += 1
				lg.pop(j)
				break
			else:
				continue
	print(c)
solve()


n = int(input())
li = sorted(list(map(int, input().split())))
m = int(input())
lim = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(m):
		if abs(li[i] - lim[j]) <= 1:
			lim[j] = -6789
			ans += 1
			break
print(ans)


x = int(input())
a = sorted(list(map(int, input().split())))
y = int(input())
b = sorted(list(map(int, input().split())))
add = 0
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			add += 1
			b.pop(j)
			break
print(add)


n = int(input())
Ar = [int(x) for x in input().split()]
m = int(input())
ar = [int(x) for x in input().split()]
cnt = 0
Ar.sort()
ar.sort()
s1 = []
s2 = []
for i in range(n):
	for j in range(m):
		if max(Ar[i], ar[j]) - min(Ar[i], ar[j]) <= 1:
			if i in s1 or j in s2:
				pass
			else:
				s1.append(i)
				s2.append(j)
				cnt += 1
print(cnt)


n = int(input())
a = [int(i) for i in filter(None, input().split(' '))]
m = int(input())
b = [int(i) for i in filter(None, input().split(' '))]
a.sort()
b.sort()
pairs = 0
boys = 0
girls = 0
i = 1
while boys < n and girls < m:
	if abs(a[boys] - b[girls]) <= 1:
		pairs += 1
		boys += 1
		girls += 1
	elif a[boys] > b[girls]:
		girls += 1
	else:
		boys += 1
print(pairs)


s1 = int(input())
s11 = input()
arr = s11.split(' ')
s2 = int(input())
s21 = input()
arr2 = s21.split(' ')
for i in range(s1):
	arr[i] = int(arr[i])
for i in range(s2):
	arr2[i] = int(arr2[i])
arr.sort()
arr2.sort()
sch = 0
for i in range(s1):
	for j in range(s2):
		if abs(arr[i] - arr2[j]) <= 1:
			arr2[j] = 999999
			sch += 1
			break
print(sch)


n = int(input())
l1 = list(map(int, input().split()))
m = int(input())
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
count = 0
i = 0
j = 0
while i < n and j < m:
	if abs(l1[i] - l2[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif l1[i] > l2[j]:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().split()]
b.sort()
count = 0
if n > m:
	i = 0
	j = 0
	while i < m and j < n:
		if b[i] == a[j] or a[j] - b[i] == 1 or a[j] - b[i] == -1:
			count += 1
			i += 1
			j += 1
			continue
		if b[i] < a[j]:
			i += 1
			continue
		if b[i] > a[j]:
			j += 1
			continue
else:
	i = 0
	j = 0
	while i < n and j < m:
		if a[i] == b[j] or b[j] - a[i] == 1 or b[j] - a[i] == -1:
			count += 1
			i += 1
			j += 1
			continue
		if a[i] < b[j]:
			i += 1
			continue
		if a[i] > b[j]:
			j += 1
			continue
print(count)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
count = 0
for i in range(0, n):
	for j in range(0, m):
		if abs(a[i] - b[j]) <= 1:
			count += 1
			a[i] = 10000
			b[j] = 10000
print(count)


ra = input()
a = [int(i) for i in input().split()]
asdf = input()
b = [int(i) for i in input().split()]
ath = []
bth = []
ct = 0
a = sorted(a)
b = sorted(b)
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			ct += 1
			b[j] = 1000
			break
print(ct)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
c = 0
a.sort()
b.sort()
for i in a:
	for k in range(m):
		if abs(b[k] - i) <= 1:
			c += 1
			b[k] = -2
			break
print(c)


m = int(input())
males = sorted([int(i) for i in input().split()])
f = int(input())
females = sorted([int(i) for i in input().split()])
mi = 0
fi = 0
pairs = 0
while mi < m and fi < f:
	if abs(males[mi] - females[fi]) <= 1:
		mi += 1
		fi += 1
		pairs += 1
	elif males[mi] > females[fi]:
		fi += 1
	else:
		mi += 1
print(pairs)


from sys import stdin
input = stdin.readline
n = int(input())
aa = list(map(int, input().split()))
m = int(input())
bb = list(map(int, input().split()))
aa.sort()
bb.sort()
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(aa[i] - bb[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif aa[i] < bb[j]:
		i += 1
	else:
		j += 1
print(ans)


n = input('')
a = list(map(int, input().split()))
m = input('')
b = list(map(int, input().split()))
a.sort()
b.sort()
x = 0
for i in a:
	for j in b:
		if -1 <= i - j <= 1:
			x += 1
			b.remove(j)
			break
print(x)


input()
a = list(map(int, input().split()))
input()
b = list(map(int, input().split()))
(s, l, l2) = (0, [], [])
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) == 1 or abs(a[i] - b[j]) == 0:
			if j in l:
				d = 1
			else:
				l.append(j)
				s = s + 1
				break
print(s)


from collections import defaultdict
from sys import stdin
input = lambda : stdin.readline().strip()
n = int(input())
lst = [int(i) for i in input().split()]
m = int(input())
lst1 = [int(i) for i in input().split()]
nd = 0
lst.sort()
for i in lst:
	if i - 1 in lst1:
		lst1.remove(i - 1)
		nd += 1
	elif i in lst1:
		lst1.remove(i)
		nd += 1
	elif i + 1 in lst1:
		lst1.remove(i + 1)
		nd += 1
print(nd)


n = int(input())
males = [int(x) for x in input().split()]
m = int(input())
females = [int(x) for x in input().split()]
males.sort()
females.sort()
ans = 0
while males and females:
	if males[-1] > females[-1]:
		if males[-1] - females[-1] == 1:
			ans += 1
			females.pop()
		males.pop()
	else:
		if females[-1] - males[-1] <= 1:
			ans += 1
			males.pop()
		females.pop()
print(ans)


a = int(input())
b = list(map(int, input().rstrip().split(' ')))
c = int(input())
g = list(map(int, input().rstrip().split(' ')))
b.sort()
g.sort()
count = 0
for i in range(a):
	for j in range(c):
		if abs(b[i] - g[j]) < 2:
			count = count + 1
			b[i] = -99999999999
			g[j] = -99999999999
			break
print(count)


a = int(input())
n = list(map(int, input().split()))
b = int(input())
m = list(map(int, input().split()))
n.sort()
m.sort()
total = 0
for i in range(a):
	for j in range(b):
		if abs(n[i] - m[j]) <= 1:
			m[j] = 102
			total += 1
			break
print(total)


b = int(input())
boys = sorted([int(i) for i in input().split()])
g = int(input())
girls = sorted([int(i) for i in input().split()])
count = 0
for i in range(len(boys)):
	boy = boys[i]
	for j in range(len(girls)):
		girl = girls[j]
		if boy - 1 <= girl <= boy + 1:
			count += 1
			girls = girls[j + 1:]
			break
print(count)


nBoys = int(input())
boySkill = list(map(int, input().split()))
nGirls = int(input())
girlSkill = list(map(int, input().split()))
boySkill.sort()
girlSkill.sort()
result = 0
for i in boySkill:
	for j in girlSkill:
		if abs(i - j) <= 1:
			girlSkill.remove(j)
			result += 1
			break
print(result)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
c = 0
for b in boys:
	if b - 1 in girls:
		girls.remove(b - 1)
		c += 1
	elif b in girls:
		girls.remove(b)
		c += 1
	elif b + 1 in girls:
		girls.remove(b + 1)
		c += 1
print(c)


I = lambda : sorted(map(int, input().split()))
n = I()[0]
a = I()
m = I()[0]
b = I()
(i, j, k) = (0, 0, 0)
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(k)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort(key=int)
b.sort(key=int)
res = 0
for i in range(n):
	if a[i] != -1:
		for j in range(m):
			if b[j] != -1 and (a[i] == b[j] or a[i] == b[j] + 1 or a[i] + 1 == b[j]):
				res += 1
				a[i] = -1
				b[j] = -1
				res += 1
print(res // 2)


b = int(input())
boys = list(map(int, input().split()))
g = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
cnt = 0
for b1 in boys:
	for g1 in girls:
		if abs(b1 - g1) <= 1:
			cnt += 1
			girls.remove(g1)
			break
print(cnt)


amount_man = int(input())
man = sorted(list(map(int, input().split())))
amount_woman = int(input())
woman = sorted(list(map(int, input().split())))
max_pairs = min(amount_man, amount_woman)
i = pair = catch = 0
test = 0
while len(man) != 0 or len(woman) != 0:
	if len(man) == 0 or len(woman) == 0:
		break
	if man[i] == woman[pair] or man[i] == woman[pair] + 1 or man[i] == woman[pair] - 1:
		catch = catch + 1
		man.remove(man[i])
		woman.remove(woman[pair])
		pair = 0
		if len(man) == 0 or len(woman) == 0:
			break
	else:
		pair = pair + 1
	if pair == len(woman):
		man.remove(man[i])
		pair = 0
print(catch)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	(i, j, ans) = (0, 0, 0)
	while i < n and j < m:
		if abs(a[i] - b[j]) in [0, 1]:
			i += 1
			j += 1
			ans += 1
		elif a[i] < b[j]:
			i += 1
		else:
			j += 1
	print(ans)
main()


nb = int(input())
boys = []
for x in input().split(' '):
	boys.append(int(x))
boys.sort()
ng = int(input())
girls = []
for x in input().split(' '):
	girls.append(int(x))
girls.sort()
i = 0
count = 0
while i < len(boys):
	j = 0
	while j < len(girls):
		if boys[i] - girls[j] >= -1 and boys[i] - girls[j] <= 1:
			count += 1
			girls.pop(j)
			break
		j += 1
	i += 1
print(count)


N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
indexa = 0
indexb = 0
cnt = 0
while indexa < N and indexb < M:
	if abs(A[indexa] - B[indexb]) <= 1:
		cnt += 1
		indexa += 1
		indexb += 1
	elif A[indexa] < B[indexb]:
		indexa += 1
	else:
		indexb += 1
print(cnt)


t = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
for i in range(0, len(a)):
	j = 0
	while j < len(b):
		if abs(a[i] - b[j]) <= 1:
			b.pop(j)
			count += 1
			break
		elif abs(a[i] - b[j]) > 1:
			if b[j] < a[i]:
				b.pop(j)
			else:
				break
print(count)


from sys import stdin, stdout
boys = []
girls = []
n_boys = 0
n_girls = 0
for line in stdin.readlines():
	if n_boys == 0:
		n_boys = int(line)
		continue
	elif n_boys > 0 and len(boys) == 0:
		boys = line.strip().split(' ')
		continue
	if n_girls == 0:
		n_girls = int(line)
		continue
	else:
		girls = line.strip().split(' ')
		break
boys = sorted([int(value) for value in boys])
girls = sorted([int(value) for value in girls])
pairs = [False for i in range(0, 100)]
number_of_pairs = 0
for i in range(len(boys)):
	for j in range(len(girls)):
		if abs(int(boys[i]) - int(girls[j])) < 2 and (not pairs[j]):
			number_of_pairs += 1
			pairs[j] = True
			break
stdout.writelines(str(number_of_pairs))


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
ans = 0
count = {}
for i in range(m):
	if girls[i] in count:
		count[girls[i]] += 1
	else:
		count[girls[i]] = 1
boys.sort()
for i in range(n):
	for num in range(boys[i] - 1, boys[i] + 2):
		if num in count:
			ans += 1
			count[num] -= 1
			if count[num] <= 0:
				count.pop(num)
			break
print(ans)


def try_kuhn(v):
	if u[v]:
		return False
	u[v] = 1
	for to in g[v]:
		if mt[to] == -1 or try_kuhn(mt[to]):
			mt[to] = v
			return True
	return False
n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
g = [[] for i in range(n)]
k = 0
for i in range(n):
	for j in range(m):
		if abs(A[i] - B[j]) < 2:
			g[i].append(j)
			k += 1
u = [0] * n
mt = [-1] * m
for v in range(n):
	if try_kuhn(v):
		u = [0] * n
o = 0
for i in range(m):
	if mt[i] != -1:
		o += 1
print(o)


n = int(input())
l = [int(i) for i in input().split()]
m = int(input())
c = 0
l1 = [int(i) for i in input().split()]
l.sort()
l1.sort()
for i in l:
	if i - 1 in l1:
		c += 1
		l1.remove(i - 1)
	elif i in l1:
		c += 1
		l1.remove(i)
	elif i + 1 in l1:
		c += 1
		l1.remove(i + 1)
print(c)


n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
if m > n:
	(n, m) = (m, n)
	(a, b) = (b, a)
a.sort()
b.sort()
nb = 0
for x in b:
	if x - 1 in a:
		nb += 1
		a.remove(x - 1)
	elif x in a:
		nb += 1
		a.remove(x)
	elif x + 1 in a:
		nb += 1
		a.remove(x + 1)
print(nb)


n = int(input())
arr = sorted(list(map(int, input().split())))
m = int(input())
arr1 = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
	for j in range(m):
		if abs(arr1[j] - arr[i]) <= 1:
			cnt += 1
			arr1[j] = 99999999
			arr[i] = 999999999
print(cnt)


inp = lambda : sorted([*map(int, input().split())])
nboy = int(input())
boys = inp()
ngril = int(input())
grils = inp()
i = 0
j = 0
ans = 0
while i < nboy and j < ngril:
	if -1 <= boys[i] - grils[j] <= 1:
		ans += 1
		i += 1
		j += 1
		continue
	if boys[i] < grils[j]:
		i += 1
		continue
	if boys[i] > grils[j]:
		j += 1
print(ans)


def selection_sort(the_array):
	for k in range(len(the_array) - 1):
		minimum = k
		for j in range(k, len(the_array)):
			if the_array[j] < the_array[minimum]:
				minimum = j
		swap(the_array, minimum, k)

def swap(the_array, a, b):
	temp = the_array[a]
	the_array[a] = the_array[b]
	the_array[b] = temp

def createInputList(string):
	list = string.split(' ')
	outList = []
	for item in list:
		outList.append(int(item))
	return outList

def findMatches(girlsList, boyslist):
	boyIndex = 0
	matches = 0
	flag = False
	for item in girlsList:
		while item - 1 > boysList[boyIndex] and flag == False:
			boyIndex += 1
			if boyIndex >= len(boyslist):
				flag = True
				boyIndex -= 1
		if boysList[boyIndex] <= item + 1 and boysList[boyIndex] >= item - 1:
			matches += 1
			boyIndex += 1
			if boyIndex >= len(boysList):
				break
		if flag:
			break
	return matches
n_boys = int(input())
boysList = createInputList(input())
n_girls = int(input())
girlsList = createInputList(input())
selection_sort(boysList)
selection_sort(girlsList)
matches = findMatches(girlsList, boysList)
print(matches)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a.sort()
b.sort()
i = 0
j = 0
count = 0
while i < n and j < m:
	temp = a[i] - b[j]
	if temp <= 1 and temp >= -1:
		i += 1
		j += 1
		count += 1
	elif temp > 1:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
count = 0
l = []
for i in range(n):
	for j in range(m):
		if (b[i] - g[j] == 0 or abs(b[i] - g[j]) == 1) and j not in l:
			count += 1
			l.append(j)
			break
print(count)


B = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
G = int(input())
arr1 = list(map(int, input().split()))
arr1 = sorted(arr1)
count = 0
for i in range(B):
	for j in range(G):
		if abs(arr[i] - arr1[j]) <= 1:
			arr1[j] = 10000
			arr[i] = -1
			count += 1
print(count)


n = int(input())
a = sorted([int(x) for x in input().split()])
m = int(input())
b = sorted([int(x) for x in input().split()])
num = 0
for i in range(n):
	for j in range(m):
		if a[i] - 1 <= b[j] and b[j] <= a[i] + 1:
			b[j] = -1000
			num += 1
			break
print(num)


b = input()
boy = [int(i) for i in input().split()]
g = input()
girl = [int(i) for i in input().split()]
x = 0
boy.sort()
girl.sort()
for i in boy:
	for j in girl:
		if abs(i - j) == 1 or i - j == 0:
			x += 1
			girl.remove(j)
			break
print(x)


n = int(input())
nlevel = [int(i) for i in input().split()]
m = int(input())
mlevel = [int(i) for i in input().split()]
k = 0
nlevel.sort()
mlevel.sort()
for i in range(n):
	for j in range(m):
		if abs(nlevel[i] - mlevel[j]) <= 1:
			mlevel[j] = 1000
			k += 1
			break
print(k)


class Person:

	def __init__(self, ident, gender, skill):
		self.ident = ident
		self.gender = gender
		self.skill = skill
		self.partner = False
n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
boys = []
for (i, skill) in enumerate(a):
	boys.append(Person(i + 1, 'B', skill))
for girl_skill in b:
	for boy in boys:
		if boy.partner is False and abs(girl_skill - boy.skill) < 2:
			boy.partner = True
			break
print(sum((True for boy in boys if boy.partner)))


a = int(input())
aa = [int(s) for s in input().split()]
b = int(input())
bb = [int(s) for s in input().split()]
aa.sort()
bb.sort()
i = 0
j = 0
cnt = 0
while i < a and j < b:
	if abs(aa[i] - bb[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
	elif bb[j] > aa[i]:
		i += 1
	else:
		j += 1
print(cnt)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
ans = 0
b = sorted(list(map(int, input().split())))
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			a[i] = 10000
			b[j] = 1000000
			ans += 1
print(ans)


m = int(input())
lb = list(map(int, input().split()))
n = int(input())
lg = [int(x) for x in input().split()]
s = 0
lb.sort()
lg.sort()
for i in lb:
	for j in range(len(lg)):
		if abs(i - lg[j]) <= 1:
			s += 1
			lg[j] = -5
			break
print(s)


(n, boys, m, girls, paired) = (int(input()), sorted([int(i) for i in input().split()]), int(input()), sorted([int(i) for i in input().split()]), 0)
(longest, shortest) = (boys, girls) if len(boys) > len(girls) else (girls, boys)
for s in shortest:
	for (index, l) in enumerate(longest):
		if s - l in [-1, 0, 1]:
			paired += 1
			del longest[index]
			break
print(paired)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			b[j] = 1010100
			cnt += 1
			break
print(cnt)


men = int(input())
men_arr = [int(i) for i in input().split()]
women = int(input())
women_arr = [int(i) for i in input().split()]
men_arr = sorted(men_arr)
women_arr = sorted(women_arr)
ans = 0
for i in range(len(men_arr)):
	for j in range(len(women_arr)):
		if abs(men_arr[i] - women_arr[j]) <= 1:
			ans += 1
			women_arr[j] = 1000
			break
print(ans)


def BerSU_ball(h, m):
	h = sorted([int(i) for i in h])
	m = sorted([int(i) for i in m])
	cont = 0
	while len(h) != 0 and len(m) != 0:
		if abs(h[0] - m[0]) <= 1:
			cont += 1
			h = h[1:]
			m = m[1:]
		elif h[0] < m[0]:
			h = h[1:]
		else:
			m = m[1:]
	print(cont)
nh = int(input())
h = input().strip().split(' ')
nm = int(input())
m = input().strip().split(' ')
BerSU_ball(h, m)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
pa = pb = ctr = 0
a.sort()
b.sort()
while pa < n and pb < m:
	if abs(a[pa] - b[pb]) <= 1:
		ctr += 1
		pa += 1
		pb += 1
	elif a[pa] < b[pb]:
		pa += 1
	else:
		pb += 1
print(ctr)


b = int(input())
b_step = sorted(list(map(int, input().split())))
g = int(input())
g_step = sorted(list(map(int, input().split())))
count = 0
for i in b_step:
	for j in range(len(g_step)):
		if i == g_step[j] or abs(i - g_step[j]) == 1:
			count += 1
			g_step.pop(j)
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
aIndex = 0
bIndex = 0
nums = 0
while aIndex < n and bIndex < m:
	if abs(a[aIndex] - b[bIndex]) <= 1:
		nums += 1
		aIndex += 1
		bIndex += 1
	elif a[aIndex] > b[bIndex] + 1:
		bIndex += 1
	else:
		aIndex += 1
print(nums)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = int(input())
b = [int(x) for x in input().split()]
b.sort()
pointer_a = 0
pointer_b = 0
max_pairs = 0
while pointer_a < n and pointer_b < m:
	if abs(a[pointer_a] - b[pointer_b]) <= 1:
		max_pairs += 1
		pointer_a += 1
		pointer_b += 1
	elif a[pointer_a] < b[pointer_b]:
		pointer_a += 1
	else:
		pointer_b += 1
print(max_pairs)


n = int(input())
arr_boys = []
for i in input().split():
	arr_boys.append(int(i))
arr_boys = sorted(arr_boys)
m = int(input())
arr_girls = []
for i in input().split():
	arr_girls.append(int(i))
arr_girls = sorted(arr_girls)
counterb = 0
counterg = 0
pairs = 0
while counterb < n and counterg < m:
	currentb = arr_boys[counterb]
	currentg = arr_girls[counterg]
	if currentb == currentg - 1 or currentb == currentg or currentb == currentg + 1:
		pairs = pairs + 1
		counterb = counterb + 1
		counterg = counterg + 1
	elif currentb < currentg:
		counterb = counterb + 1
	else:
		counterg = counterg + 1
print(pairs)


n_boys = int(input().strip())
boys = []
line = input().strip().split()
for i in line:
	boys.append(int(i))
n_girls = int(input().strip())
girls = []
line = input().strip().split()
for i in line:
	girls.append(int(i))
boys.sort()
girls.sort()
count = 0
b = 0
g = 0
while True:
	if b >= n_boys or g >= n_girls:
		break
	if boys[b] > girls[g] + 1:
		g += 1
	elif boys[b] + 1 < girls[g]:
		b += 1
	else:
		count += 1
		b += 1
		g += 1
print(count)


n = int(input())
a = [int(x) for x in input().split(' ')]
m = int(input())
b = [int(x) for x in input().split(' ')]
a.sort()
b.sort()
i = 0
j = 0
c = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		c += 1
		i += 1
		j += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
boy_array = [0] * 200
girl_array = [0] * 200
for i in a:
	boy_array[i] += 1
for i in b:
	girl_array[i] += 1
r = 0
for i in range(1, 101):
	if boy_array[i] == 0:
		continue
	for j in range(boy_array[i]):
		if girl_array[i - 1] > 0:
			girl_array[i - 1] -= 1
			r += 1
		elif girl_array[i] > 0:
			girl_array[i] -= 1
			r += 1
		elif girl_array[i + 1] > 0:
			girl_array[i + 1] -= 1
			r += 1
print(r)


import heapq as h
n = int(input().rstrip())
a = list(map(int, input().rstrip().split(' ')))
m = int(input().rstrip())
b = list(map(int, input().rstrip().split(' ')))
h.heapify(a)
h.heapify(b)
c = 0
while a and b:
	B = a[0]
	G = b[0]
	if abs(B - G) <= 1:
		c += 1
		h.heappop(a)
		h.heappop(b)
	elif B > G:
		h.heappop(b)
	else:
		h.heappop(a)
print(c)


count = 0
first_stack = int(input())
lens_firsts_bars = input().split()
lens_firsts_bars = sorted(list(map(int, lens_firsts_bars)))
second_stack = int(input())
lens_seconds_bars = input().split()
lens_seconds_bars = sorted(list(map(int, lens_seconds_bars)))
for first_bar in lens_firsts_bars:
	for second_bar in lens_seconds_bars:
		if abs(first_bar - second_bar) <= 1:
			lens_seconds_bars.remove(second_bar)
			count += 1
			break
print(count)


n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]
sortedBoys = sorted(boys)
sortedGirls = sorted(girls)
(i, j) = (0, 0)
ans = 0
while i < n and j < m:
	if abs(sortedBoys[i] - sortedGirls[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif sortedBoys[i] < sortedGirls[j]:
		i += 1
	else:
		j += 1
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7
n = iinput()
a = rlinput()
m = iinput()
b = rlinput()
a.sort()
b.sort()
i = n - 1
j = m - 1
ans = 0
while i >= 0 and j >= 0:
	if abs(a[i] - b[j]) <= 1:
		ans += 1
		i -= 1
		j -= 1
	elif a[i] >= b[j]:
		i -= 1
	else:
		j -= 1
print(ans)


largo_1 = input()
lista = [int(x) for x in input().split(' ')]
largo_2 = input()
lista_2 = [int(x) for x in input().split(' ')]
lista.sort(reverse=True)
lista_2.sort(reverse=True)
contador = 0
while len(lista) > 0 and len(lista_2) > 0:
	if lista[0] + 1 == lista_2[0] or (lista[0] == lista_2[0] or lista[0] - 1 == lista_2[0]):
		contador += 1
		lista.pop(0)
		lista_2.pop(0)
	elif lista[0] > lista_2[0]:
		lista.pop(0)
	else:
		lista_2.pop(0)
print(contador)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
pairs = 0
boys.sort()
girls.sort()
for i in range(n - 1, -1, -1):
	for j in range(m - 1, -1, -1):
		if boys[i] >= 1 and girls[j] >= 1:
			if boys[i] == girls[j] or abs(boys[i] - girls[j]) <= 1:
				pairs += 1
				boys[i] = 0
				girls[j] = 0
print(pairs)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
c = 0
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if a[i] - b[j] == 1 or b[j] - a[i] == 1 or a[i] == b[j]:
			c += 1
			a[i] = -1
			b[j] = -1
			break
print(c)


B = int(input())
a = input()
G = int(input())
b = input()
A = a.split(' ')
boys_list = []
for i in A:
	boys_list.append(int(i))
A = b.split(' ')
girls_list = []
for i in A:
	girls_list.append(int(i))
girls_list.sort()
boys_list.sort()
Counter = 0
for i in range(B):
	for j in range(G):
		if boys_list[i] == girls_list[j] or boys_list[i] - 1 == girls_list[j] or boys_list[i] == girls_list[j] - 1:
			girls_list.pop(j)
			Counter = Counter + 1
			G = G - 1
			break
print(Counter)


n = int(input(''))
a = input('').split(' ')
m = int(input(''))
b = input('').split(' ')
p = []
q = []
for i in a:
	p.append(int(i))
for j in b:
	q.append(int(j))
a = sorted(p)
b = sorted(q)
count = 0
for k in a:
	l = 0
	while l < len(b):
		if b[l] == k or b[l] == k - 1 or b[l] == k + 1:
			count = count + 1
			b.remove(b[l])
			l = l + 1
			break
		else:
			l = l + 1
			continue
print(count)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
pair = 0
if n < m:
	(boys, girls) = (girls, boys)
for i in boys:
	if i - 1 in girls:
		pair += 1
		girls.remove(i - 1)
	elif i in girls:
		pair += 1
		girls.remove(i)
	elif i + 1 in girls:
		pair += 1
		girls.remove(i + 1)
print(pair)


n = int(input())
nl = list(map(int, input().split()))
m = int(input())
ml = list(map(int, input().split()))
nl.sort()
ml.sort()
count = 0
for i in range(n):
	for j in range(m):
		if abs(nl[i] - ml[j]) <= 1:
			count += 1
			ml[j] = 999999999
			break
print(count)


n = int(input()) - 1
a = list(map(int, input().split()))
a.sort()
m = int(input()) - 1
b = list(map(int, input().split()))
b.sort()
cor_a = 0
cor_b = 0
summ = 0
while cor_a <= n and cor_b <= m:
	if abs(a[cor_a] - b[cor_b]) <= 1:
		cor_a += 1
		cor_b += 1
		summ += 1
	elif a[cor_a] > b[cor_b]:
		cor_b += 1
	else:
		cor_a += 1
print(summ)


n = int(input())
b = sorted(map(int, input().split()))
input()
g = sorted(map(int, input().split()))
ans = 0
for B in b:
	for (i, G) in enumerate(g):
		if abs(B - G) <= 1:
			g[i] = 2273806215
			ans += 1
			break
print(ans)


pairs = 0
n = int(input())
m = sorted([int(i) for i in input().split()])
z = int(input())
f = sorted([int(i) for i in input().split()])
for i in m:
	for j in f:
		if abs(j - i) < 2:
			pairs += 1
			f.remove(j)
			break
print(pairs)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
cnt = 0
for i in range(n):
	j = 0
	while j < len(g):
		if b[i] == g[j]:
			g.remove(b[i])
			cnt += 1
			break
		elif abs(b[i] - g[j]) == 1:
			g.remove(g[j])
			cnt += 1
			break
		else:
			j += 1
print(cnt)


n = int(input())
a = list()
b = list()
a = [int(x) for x in input().split()]
m = int(input())
b = [int(y) for y in input().split()]
a1 = list()
b1 = list()
a1 = sorted(a)
b1 = sorted(b)
a2 = list()
b2 = list()
if len(a1) > len(b1):
	a2 = a1
	b2 = b1
else:
	a2 = b1
	b2 = a1
l1 = len(a2)
l2 = len(b2)
d = 0
for k in range(0, l2):
	for c in range(0, l1):
		if b2[k] == a2[c] or b2[k] - 1 == a2[c] or b2[k] + 1 == a2[c]:
			d += 1
			a2.remove(a2[c])
			l1 = l1 - 1
			break
print(d)


b = int(input())
boy = [int(x) for x in input().split()]
g = int(input())
girl = [int(x) for x in input().split()]
boy.sort()
girl.sort()
b -= 1
g -= 1
count = 0
while b >= 0 and g >= 0:
	if -1 <= boy[b] - girl[g] <= 1:
		b -= 1
		g -= 1
		count += 1
	elif boy[b] > girl[g]:
		b -= 1
	else:
		g -= 1
print(count)


ng = int(input())
g = list(map(int, input().rstrip().split()))
g.sort()
nb = int(input())
b = list(map(int, input().rstrip().split()))
b.sort()
count = 0
i = 0
j = 0
while i < ng and j < nb:
	if abs(g[i] - b[j]) < 2:
		count += 1
		i += 1
		j += 1
	elif g[i] < b[j]:
		i += 1
	elif b[j] < g[i]:
		j += 1
print(count)


n = int(input())
a = [*map(int, input().split())]
m = int(input())
b = [*map(int, input().split())]
a.sort()
b.sort()
c = {}
d = {}
count = 0
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			if c.get(i) == None and d.get(j) == None:
				c[i] = 1
				d[j] = 1
				count += 1
print(count)


n = int(input())
a = input().strip().split()
m = int(input())
b = input().strip().split()
for (index, item) in enumerate(a):
	a[index] = int(item)
for (index, item) in enumerate(b):
	b[index] = int(item)
a.sort()
b.sort()
s = 0
h = 0
for item in a:
	while h < len(b):
		if item > b[h] + 1:
			h += 1
		elif item <= b[h] + 1 and item >= b[h] - 1:
			s += 1
			h += 1
			break
		elif item < b[h] - 1:
			break
print(s)


b = int(input())
ab = input().split(' ')
g = int(input())
ag = input().split(' ')
ans = 0
for i in range(len(ab)):
	ab[i] = int(ab[i])
for i in range(len(ag)):
	ag[i] = int(ag[i])
ab.sort()
ag.sort()
for i in ab:
	for j in range(len(ag)):
		if int(ag[j]) in range(int(i) - 1, int(i) + 2):
			ans += 1
			ag.pop(j)
			break
print(ans)


n = int(input())
a = sorted([int(i) for i in input().split()])
m = int(input())
b = sorted([int(i) for i in input().split()])
uk1 = uk2 = 0
ans = 0
while uk1 < n and uk2 < m:
	if abs(a[uk1] - b[uk2]) <= 1:
		ans += 1
		uk1 += 1
		uk2 += 1
	elif a[uk1] < b[uk2]:
		uk1 += 1
	else:
		uk2 += 1
print(ans)


t = int(input())
a = sorted(list(map(int, input().split())))
z = int(input())
b = sorted(list(map(int, input().split())))
ai = 0
bi = 0
res = 0
while ai < t and bi < z:
	if b[bi] - 1 <= a[ai] <= b[bi] + 1:
		res += 1
		ai += 1
		bi += 1
	elif a[ai] < b[bi] - 1:
		ai += 1
	elif a[ai] > b[bi] + 1:
		bi += 1
print(res)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
mp = 0
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			b.remove(b[j])
			mp += 1
			break
print(mp)


b = int(input())
B = [int(num) for num in input().split(' ', b - 1)]
g = int(input())
G = [int(num) for num in input().split(' ', g - 1)]
i = j = x = 0
G.sort()
B.sort()
while i < b and j < g:
	if B[i] < G[j] - 1:
		i += 1
	elif G[j] < B[i] - 1:
		j += 1
	else:
		i += 1
		j += 1
		x += 1
print(x)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
(boys, girls) = (sorted(boys), sorted(girls))
res = 0
(a, b) = (0, 0)
while a < n and b < m:
	if abs(boys[a] - girls[b]) <= 1:
		res += 1
		a += 1
		b += 1
	elif boys[a] < girls[b]:
		a += 1
	else:
		b += 1
print(res)


n = input()
n = int(n)
boy = [int(x) for x in input().split()]
m = input()
m = int(m)
girl = [int(x) for x in input().split()]
boycount = [0] * 101
girlcount = [0] * 105
pair = 0
for i in boy:
	boycount[i] += 1
for i in girl:
	girlcount[i] += 1
for i in range(1, len(boycount)):
	if boycount[i] >= girlcount[i - 1] + girlcount[i] + girlcount[i + 1]:
		pair = pair + girlcount[i - 1] + girlcount[i] + girlcount[i + 1]
		girlcount[i - 1] = girlcount[i] = girlcount[i + 1] = 0
	else:
		pair = pair + boycount[i]
		a = girlcount[i - 1]
		girlcount[i - 1] = max(girlcount[i - 1] - boycount[i], 0)
		boycount[i] = max(0, boycount[i] - a)
		b = girlcount[i]
		girlcount[i] = max(girlcount[i] - boycount[i], 0)
		boycount[i] = max(0, boycount[i] - b)
		c = girlcount[i + 1]
		girlcount[i + 1] = max(girlcount[i + 1] - boycount[i], 0)
		boycount[i] = max(0, boycount[i] - c)
print(pair)


n = int(input())
count = 0
boy = [int(x) for x in input().split()]
m = int(input())
girl = [int(x) for x in input().split()]
boy.sort()
girl.sort()
for item in boy:
	for i in range(m):
		if abs(girl[i] - item) <= 1:
			count += 1
			girl[i] = 1000
			break
print(count)


__author__ = 'Rakshak.R.Hegde'
n = int(input())
A = list(map(int, input().split()))
A.sort()
m = int(input())
B = list(map(int, input().split()))
B.sort()
pairs = 0
while len(A) and len(B):
	if abs(A[0] - B[0]) <= 1:
		pairs += 1
		del A[0]
		del B[0]
	elif A[0] < B[0]:
		del A[0]
	else:
		del B[0]
print(pairs)


l1 = int(input())
l2 = input()
A = [int(i) for i in l2.split() if i.isdigit()]
l3 = input()
l4 = input()
B = [int(i) for i in l4.split() if i.isdigit()]
A = sorted(A)
B = sorted(B)
i = 0
j = 0
pairs = 0
while i < len(A) and j < len(B):
	if A[i] - B[j] > 1:
		j += 1
	elif A[i] - B[j] < -1:
		i += 1
	else:
		pairs += 1
		i += 1
		j += 1
print(pairs)


n = int(input())
ns = sorted(map(int, str.split(input())))
m = int(input())
ms = sorted(map(int, str.split(input())))
ni = mi = pairs = 0
while ni < n and mi < m:
	if abs(ns[ni] - ms[mi]) <= 1:
		pairs += 1
		ni += 1
		mi += 1
	elif ns[ni] <= ms[mi]:
		ni += 1
	else:
		mi += 1
print(pairs)


z = lambda : map(int, input().split())
a = int(input())
b = sorted(list(z()))
z()
c = list(z())
s = 0
for i in range(a):
	if b[i] - 1 in c:
		s += 1
		c.remove(b[i] - 1)
	elif b[i] in c:
		s += 1
		c.remove(b[i])
	elif b[i] + 1 in c:
		s += 1
		c.remove(b[i] + 1)
print(s)


def get_dict(list_):
	dict_ = {}
	for item in list_:
		if dict_.get(item) is None:
			dict_[item] = 1
		else:
			dict_[item] += 1
	return dict_
input()
boy_skill = sorted(list(map(int, input().split())))
input()
girl_skill = list(map(int, input().split()))
skill_dict = get_dict(girl_skill)
pair_count = 0
for boy in boy_skill:
	if skill_dict.get(boy - 1) is not None:
		pair_count += 1
		skill_dict[boy - 1] -= 1
		if skill_dict[boy - 1] == 0:
			del skill_dict[boy - 1]
	elif skill_dict.get(boy) is not None:
		pair_count += 1
		skill_dict[boy] -= 1
		if skill_dict[boy] == 0:
			del skill_dict[boy]
	elif skill_dict.get(boy + 1) is not None:
		pair_count += 1
		skill_dict[boy + 1] -= 1
		if skill_dict[boy + 1] == 0:
			del skill_dict[boy + 1]
print(pair_count)


n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
a.sort()
b.sort()
for q in a:
	if q - 1 in b:
		b.remove(q - 1)
	elif q in b:
		b.remove(q)
	elif q + 1 in b:
		b.remove(q + 1)
print(m - len(b))


m = int(input())
lst = [int(i) for i in input().split()]
n = int(input())
lst1 = [int(i) for i in input().split()]
lst.sort()
lst1.sort()
c = min(m, n)
count = 0
for i in range(0, m):
	for j in range(0, n):
		if abs(lst[i] - lst1[j]) <= 1:
			count = count + 1
			lst1[j] = 100000
			break
print(count)


n = int(input())
boys = sorted([int(skill) for skill in input().split(' ')])
m = int(input())
girls = sorted([int(skill) for skill in input().split(' ')])
dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
for i in range(1, m + 1):
	for j in range(1, n + 1):
		take = abs(boys[j - 1] - girls[i - 1]) <= 1
		if take:
			dp[i][j] = dp[i - 1][j - 1] + 1
		dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
print(dp[m][n])


b = int(input())
boys = [int(p) for p in input().split()]
g = int(input())
girls = [int(p) for p in input().split()]
boys.sort()
girls.sort()
combinations = 0
for girl in girls:
	if girl == -1:
		continue
	for boy in boys:
		if boy == -1:
			continue
		if abs(girl - boy) <= 1:
			combinations += 1
			boys[boys.index(boy)] = -1
			girls[girls.index(girl)] = -1
			break
print(combinations)


n_boys = int(input())
dancing_boys = list(map(lambda x: int(x), input().split(' ')))
n_girls = int(input())
dancing_girls = list(map(lambda x: int(x), input().split(' ')))
dancing_boys.sort()
dancing_girls.sort()
b = 0
g = 0
count = 0
while b < n_boys and g < n_girls:
	dif = dancing_girls[g] - dancing_boys[b]
	if dif > 1:
		b += 1
	elif dif < -1:
		g += 1
	else:
		count += 1
		g += 1
		b += 1
print(count)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())

	def yes():
		print('YES')

	def no():
		print('NO')
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def main():
	try:
		n = I()
		b = list(In())
		b.sort()
		n1 = I()
		g = list(In())
		g.sort()
		ans = 0
		for i in range(n):
			for j in range(n1):
				if abs(b[i] - g[j]) <= 1:
					g[j] = 100000.0
					ans += 1
					break
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


m = int(input())
arr_m = [int(i) for i in filter(None, input().split(' '))]
d = int(input())
arr_d = [int(i) for i in filter(None, input().split(' '))]
arr_m.sort()
arr_d.sort()
arr_zan = [0] * d
k = 0
for i in range(len(arr_m)):
	for j in range(len(arr_d)):
		if arr_m[i] + 1 >= arr_d[j] and arr_m[i] - 1 <= arr_d[j] and (arr_zan[j] == 0):
			k += 1
			arr_zan[j] = 1
			break
print(k)


n1 = int(input())
l1 = [int(x) for x in input().split()]
n1 = int(input())
l2 = [int(x) for x in input().split()]
l1.sort()
l2.sort()
if len(l2) < len(l1):
	(l1, l2) = (l2, l1)
cnt = 0
for x in range(len(l1)):
	for y in range(len(l2)):
		if abs(l1[x] - l2[y]) <= 1:
			l1[x] = -100
			l2[y] = -100
			cnt += 1
			break
print(cnt)


n = int(input())
lst1 = list(map(int, input().split()))
m = int(input())
lst2 = list(map(int, input().split()))
i = j = count = 0
lst1.sort()
lst2.sort()
while i < n and j < m:
	if abs(lst1[i] - lst2[j]) < 2:
		count += 1
		i += 1
		j += 1
	elif lst1[i] > lst2[j]:
		j += 1
	else:
		i += 1
print(count)


count = 0
n = input()
h = input()
h = h.split(' ')
a = 0
h2 = list()
for i in h:
	h2.append(int(i))
h2.sort()
m = input()
w = input()
w = w.split(' ')
w2 = list()
for i in w:
	w2.append(int(i))
w2.sort()
while len(w2) > 0 and len(h2) > 0:
	if w2[-1] > h2[-1] + 1:
		w2.pop()
		continue
	elif h2[-1] > w2[-1] + 1:
		h2.pop()
		continue
	lasth = h2.pop()
	lastw = w2.pop()
	count += 1
a = 0
print(count)


from sys import *

def ball(x, y, n, m):
	pairs = 0
	i = 0
	j = 0
	while i < n and j < m:
		if abs(x[i] - y[j]) < 2:
			pairs = pairs + 1
			i = i + 1
			j = j + 1
		elif x[i] > y[j]:
			j = j + 1
		else:
			i = i + 1
	return pairs
n = int(input())
a = list(map(int, input().strip().split()))[:n]
a.sort()
m = int(input())
b = list(map(int, input().strip().split()))[:m]
b.sort()
print(ball(a, b, n, m))


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
res = 0
for i in b:
	for j in range(len(g)):
		if abs(i - g[j]) <= 1:
			g[j] = 1000
			res += 1
			break
print(res)


boys = int(input())
bskills = list(map(int, input().split()))
girls = int(input())
gskills = list(map(int, input().split()))
bskills.sort()
gskills.sort()
i = 0
j = 0
pairs = 0
while i < boys and j < girls:
	if abs(bskills[i] - gskills[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif bskills[i] > gskills[j]:
		j += 1
	else:
		i += 1
print(pairs)


import sys
data = sys.stdin.readlines()
input = [line.split() for line in data]
male = [int(i) for i in input[1]]
male.sort()
female = [int(i) for i in input[3]]
female.sort()
couples = 0
while min(len(male), len(female)) > 0:
	dif = male[0] - female[0]
	if dif > 1:
		female.pop(0)
	elif dif < -1:
		male.pop(0)
	else:
		male.pop(0)
		female.pop(0)
		couples += 1
print(couples)


boy_n = int(input())
boys = sorted([int(i) for i in input().split()])
girl_n = int(input())
girls = sorted([int(i) for i in input().split()])
mi = boys if min(girl_n, boy_n) == boy_n else girls
ma = girls if max(girl_n, boy_n) == girl_n else boys
count = 0
for i in range(len(mi)):
	for j in range(len(ma)):
		if abs(mi[i] - ma[j]) <= 1:
			count += 1
			ma = ma[:j] + ma[j + 1:]
			break
print(count)


import sys
n = int(sys.stdin.readline())
A = sorted(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
B = sorted(map(int, sys.stdin.readline().split()))
(i, j) = (0, 0)
num_pairs = 0
while i != n and j != m:
	a = A[i]
	b = B[j]
	if a == b or a + 1 == b or b + 1 == a:
		num_pairs += 1
		i += 1
		j += 1
	elif a > b:
		j += 1
	else:
		i += 1
print(num_pairs)


n = int(input())
b = [int(x) for x in input().split()]
m = int(input())
g = [int(x) for x in input().split()]
b.sort()
g.sort()
c = 0
i = 0
j = 0
dp = [[-1] * m] * n

def solve(n, b, m, g):
	if n <= 0 or m <= 0:
		return 0
	if dp[n - 1][m - 1] != -1:
		return dp[n - 1][m - 1]
	if abs(b[n - 1] - g[m - 1]) <= 1:
		dp[n - 1][m - 1] = 1 + solve(n - 1, b, m - 1, g)
		return dp[n - 1][m - 1]
	elif b[n - 1] > g[m - 1]:
		dp[n - 1][m - 1] = solve(n - 1, b, m, g)
		return dp[n - 1][m - 1]
	else:
		dp[n - 1][m - 1] = solve(n, b, m - 1, g)
		return dp[n - 1][m - 1]
ans = solve(n, b, m, g)
print(ans)


def quicksort(array):
	left = list()
	right = list()
	if not array:
		return array
	pivot = array.pop()
	for x in array:
		if x < pivot:
			left.append(x)
		if x >= pivot:
			right.append(x)
	return quicksort(left) + [pivot] + quicksort(right)
boys_num = int(input().strip())
boys = input().strip().split(' ')
boys = [int(boy) for boy in boys]
boys = quicksort(boys)
girls_num = int(input().strip())
girls = input().strip().split(' ')
girls = [int(girl) for girl in girls]
girls = quicksort(girls)
i = 0
j = 0
couples = 0
while i < boys_num and j < girls_num:
	boy = boys[i]
	girl = girls[j]
	are_incompatible = abs(boy - girl) <= 1
	if are_incompatible:
		i += 1
		j += 1
		couples += 1
	elif boy < girl:
		i += 1
	elif boy > girl:
		j += 1
print(couples)


n = int(input())
l = list(map(int, input().strip().split()))
m = int(input())
arr = list(map(int, input().strip().split()))
l.sort()
arr.sort()
count = 0
if n < m:
	for i in range(n):
		for j in range(m):
			if abs(l[i] - arr[j]) == 1 or abs(l[i] - arr[j]) == 0:
				count = count + 1
				l[i] = -2
				arr[j] = -2
				break
else:
	for i in range(m):
		for j in range(n):
			if abs(arr[i] - l[j]) == 1 or abs(arr[i] - l[j]) == 0:
				count = count + 1
				arr[i] = -2
				l[j] = -2
				break
print(count)


n = int(input())
l = sorted(list(map(int, input().split())))
m = int(input())
s = sorted(list(map(int, input().split())))
count = 0
for i in range(n):
	j = 0
	while j < len(s) and s[j] <= l[i] + 1:
		if abs(l[i] - s[j]) <= 1:
			s.pop(j)
			count += 1
			break
		else:
			j += 1
print(count)


n = int(input())
boys = [int(b) for b in input().split()]
boys.sort()
m = int(input())
girls = [int(g) for g in input().split()]
girls.sort()
pairs = 0
for b in boys:
	for g in girls:
		if abs(b - g) <= 1:
			girls.remove(g)
			pairs += 1
			break
print(pairs)


a = int(input())
boys = sorted(map(int, input().split()))
b = int(input())
girls = sorted(map(int, input().split()))
(i, j, c) = (0, 0, 0)
for i in range(a):
	for j in range(b):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = -25
			c += 1
			break
		else:
			continue
print(c)


n_boys = int(input())
boys = sorted([int(i) for i in input().strip().split(' ')], reverse=True)
n_girls = int(input())
girls = sorted([int(i) for i in input().strip().split(' ')], reverse=True)
hola = False
count = 0
while boys and girls:
	boy = boys[0]
	girl = girls[0]
	if boy <= girl + 1 and boy >= girl - 1:
		boys.pop(0)
		girls.pop(0)
		count += 1
	elif girl > boy:
		girls.pop(0)
	else:
		boys.pop(0)
	if hola:
		break
print(count)


n = int(input())
a = sorted([int(i) for i in input().split()])
m = int(input())
b = sorted([int(i) for i in input().split()])
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(count)


def I():
	return sorted(list(map(int, input().split())))
n = I()[0]
b = I()
m = I()[0]
g = I()
(i, j, k) = [0] * 3
while i < n and j < m:
	if abs(b[i] - g[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif b[i] < g[j]:
		i += 1
	else:
		j += 1
print(k)


def crear_lista(string):
	lista = []
	cambio = False
	num = ''
	for letra in string + ' ':
		if letra == ' ':
			cambio = True
			lista.append(int(num))
			num = ''
		if not cambio:
			num += letra
		cambio = False
	return lista
n = input()
hombres = input()
k = input()
mujeres = input()
baile_hombres = crear_lista(hombres)
baile_mujeres = crear_lista(mujeres)
baile_hombres.sort()
baile_mujeres.sort()
contador = 0
for m in baile_mujeres:
	for n in baile_hombres:
		if int(m) - int(n) < -1:
			break
		elif int(m) - int(n) > 1:
			continue
		else:
			contador += 1
			baile_hombres.remove(n)
			break
print(contador)


a = int(input())
B = list(map(int, input().split(' ')))
b = int(input())
G = list(map(int, input().split(' ')))
B.sort()
G.sort()
j = 0
count = 0
i = 0
while i < a and j < b:
	if G[j] == B[i] + 1 or G[j] == B[i] or G[j] == B[i] - 1:
		j += 1
		i += 1
		count += 1
	elif G[j] > B[i]:
		i += 1
	elif G[j] < B[i]:
		j += 1
print(count)


def p(i):
	print(i)
nboys = int(input())
boys = list(map(int, input().split()))
ngirls = int(input())
girls = list(map(int, input().split()))
girls.sort()
boys.sort()
count = 0
for i in range(len(boys)):
	for j in range(len(girls)):
		if abs(boys[i] - girls[j]) <= 1:
			count += 1
			girls[j] = 10000
			break
p(count)


import collections
n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l.sort()
l1.sort()
c = 0
for i in range(n):
	for q in range(m):
		if abs(l[i] - l1[q]) <= 1:
			c += 1
			l1[q] = 1000000
			break
print(c)


nb = int(input())
b = list(map(int, input().split()))
ng = int(input())
g = list(map(int, input().split()))
m = {}
for i in b:
	if i in m:
		m[i] += 1
	else:
		m[i] = 1
ans = 0
g.sort()
for i in g:
	if i - 1 in m and m[i - 1] > 0:
		ans += 1
		m[i - 1] -= 1
	elif i in m and m[i] > 0:
		ans += 1
		m[i] -= 1
	elif i + 1 in m and m[i + 1] > 0:
		ans += 1
		m[i + 1] -= 1
print(ans)


a = int(input())
boys = list(map(int, input().split()))
b = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
i = 0
j = 0
count = 0
while i < a and j < b:
	if girls[j] - boys[i] == 0 or abs(girls[j] - boys[i]) == 1:
		count += 1
		i += 1
		j += 1
	elif girls[j] > boys[i]:
		i += 1
	elif girls[j] < boys[i]:
		j += 1
print(count)


b = int(input())
bl = sorted(list(map(int, input().split())))
g = int(input())
gl = sorted(list(map(int, input().split())))
ans = 0
for i in range(b):
	for j in range(g):
		if abs(bl[i] - gl[j]) <= 1:
			gl[j] = 10 ** 3
			bl[i] = -10 ** 3
			ans += 1
print(ans)


n_boys = int(input())
boys_skill = list(map(int, input().split()))
boys_skill.sort()
n_girls = int(input())
girls_skill = list(map(int, input().split()))
girls_skill.sort()
matchs = 0
for boy in boys_skill:
	for girl in range(n_girls):
		if boy - girls_skill[girl] >= -1 and boy - girls_skill[girl] <= 1:
			matchs += 1
			girls_skill[girl] = 9999
			break
print(matchs)


n = int(input())
lista_n = map(int, input().split())
lista_n = sorted(lista_n)
m = int(input())
lista_m = list(map(int, input().split()))
lista_m = sorted(lista_m)
contador = 0
e = 0
while e < len(lista_n):
	i = 0
	while i < len(lista_m):
		if lista_n[e] == lista_m[i]:
			contador += 1
			lista_m.pop(i)
			break
		elif lista_n[e] == lista_m[i] - 1 or lista_n[e] == lista_m[i] + 1:
			contador += 1
			lista_m.pop(i)
			break
		else:
			i += 1
	e += 1
print(contador)


b = int(input())
l1 = list(map(int, input().split()))
g = int(input())
l2 = list(map(int, input().split()))
count = 0
l1.sort()
for i in range(b):
	if l1[i] - 1 in l2:
		count = count + 1
		l2.remove(l1[i] - 1)
	elif l1[i] in l2:
		count = count + 1
		l2.remove(l1[i])
	elif l1[i] + 1 in l2:
		count = count + 1
		l2.remove(l1[i] + 1)
print(count)


b = eval(input())
boys = list(map(int, input().split()))
boys = sorted(boys)
g = eval(input())
girls = list(map(int, input().split()))
girls = sorted(girls)
c = 0
for i in range(len(boys)):
	for j in range(len(girls)):
		if abs(boys[i] - girls[j]) <= 1:
			c += 1
			girls[j] = 100000
			break
print(c)


number_guys = int(input())
guys_skill = sorted(list(map(int, input().split())))
number_girls = int(input())
girls_skill = sorted(list(map(int, input().split())))
number_couples = 0
for girl_index in reversed(range(len(girls_skill))):
	girl = girls_skill[girl_index]
	for guy_index in reversed(range(len(guys_skill))):
		guy = guys_skill[guy_index]
		if girl - guy == -1 or girl - guy == 0 or girl - guy == 1:
			del girls_skill[girl_index]
			del guys_skill[guy_index]
			number_couples += 1
			break
print(number_couples)


b = int(input())
boys = list(map(int, input().split()))
g = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
cnt = 0
for y in boys:
	for x in girls:
		if y in [x - 1, x, x + 1]:
			cnt += 1
			girls.remove(x)
			break
print(cnt)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
B = inp()
boys = inlt()
G = inp()
girls = inlt()
boys.sort()
girls.sort()
b = 0
g = 0
ans = 0
while b < B and g < G:
	if abs(boys[b] - girls[g]) <= 1:
		ans += 1
		b += 1
		g += 1
	elif boys[b] < girls[g]:
		b += 1
	else:
		g += 1
print(ans)


i = lambda : iter(sorted(map(int, input().split())))
i()
a = i()
i()
b = i()
v = 0
(x, y) = (next(a), next(b))
try:
	while 1:
		if abs(x - y) < 2:
			v += 1
			x = next(a)
			y = next(b)
		elif x < y:
			x = next(a)
		else:
			y = next(b)
except:
	print(v)


nb = int(input())
sb = input()
mg = int(input())
tg = input()
lines = sb.split(' ')
arrb = [int(x) for x in lines]
arrb.sort()
lines = tg.split(' ')
arrg = [int(x) for x in lines]
arrg.sort()
pairs = 0
if nb <= mg:
	arrg_status = [True] * mg
	for i in range(nb):
		k = arrb[i] - 1
		if k == 0:
			k = 1
		for j in range(mg):
			if arrg[j] in {arrb[i], k, arrb[i] + 1} and arrg_status[j] == True:
				arrg_status[j] = False
				pairs += 1
				break
	print(pairs)
else:
	arrb_status = [True] * nb
	for i in range(mg):
		k = arrg[i] - 1
		if k == 0:
			k = 1
		for j in range(nb):
			if arrb[j] in {arrg[i], k, arrg[i] + 1} and arrb_status[j] == True:
				arrb_status[j] = False
				pairs += 1
				break
	print(pairs)


n = int(input())
arr1 = sorted(list(map(int, input().split())))
m = int(input())
arr2 = sorted(list(map(int, input().split())))
if n > m:
	tmp = n
	n = m
	m = tmp
	tmp = arr1
	arr1 = arr2
	arr2 = tmp
i = 0
j = 0
cnt = 0
while True:
	if abs(arr1[i] - arr2[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
	elif arr1[i] < arr2[j]:
		i += 1
	else:
		j += 1
	if i == n or j == m:
		break
print(cnt)


nrBoys = int(input())
boysSkills = list(map(int, input().split()))
nrGirls = int(input())
girlsSkills = list(map(int, input().split()))
boysSkills = sorted(boysSkills)
girlsSkills = sorted(girlsSkills)
result = 0
for i in range(nrBoys):
	for j in range(nrGirls):
		if abs(boysSkills[i] - girlsSkills[j]) <= 1:
			girlsSkills[j] = 1000
			boysSkills[i] = 1000
			result += 1
print(result)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
count = 0
i = 0
j = 0
while i < n and j < m:
	if abs(boys[i] - girls[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(count)


men = int(input())
m = list(map(int, input().split()))
girl = int(input())
g = list(map(int, input().split()))
m.sort()
g.sort()
pari = 0
while m != [] and g != []:
	if int(m[0]) == int(g[0]) or (int(m[0]) - 1 == int(g[0]) or int(m[0]) + 1 == int(g[0])):
		pari += 1
		m.pop(0)
		g.pop(0)
	if m != [] and g != []:
		if int(m[0]) != int(g[0]) and (int(m[0]) - 1 != int(g[0]) and int(m[0]) + 1 != int(g[0])) and (int(m[0]) > int(g[0])):
			g.pop(0)
		if m != [] and g != []:
			if int(m[0]) != int(g[0]) and (int(m[0]) - 1 != int(g[0]) and int(m[0]) + 1 != int(g[0])) and (int(m[0]) < int(g[0])):
				m.pop(0)
print(pari)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b.sort()
d.sort()
n = 0
i = 0
while i < a:
	for j in d:
		if b[i] == j or b[i] + 1 == j or b[i] - 1 == j:
			n += 1
			e = int(d.index(j))
			d.remove(d[e])
			break
	i += 1
print(n)


n = int(input())
arr = list(map(int, input().split()))
m = int(input())
ls = list(map(int, input().split()))
ls.sort()
arr.sort()
j = 0
cnt = 0
for i in range(n):
	if j >= m:
		print(cnt)
		exit()
	while j < m and ls[j] + 1 < arr[i]:
		j += 1
	if j < m and abs(ls[j] - arr[i]) <= 1:
		cnt += 1
		j += 1
print(cnt)


while True:
	try:

		def solution(nar, mar):
			(n, m) = (len(nar), len(mar))
			dp = [[0 for c in range(m + 1)] for r in range(n + 1)]
			nar.sort()
			mar.sort()
			for r in range(1, n + 1, 1):
				for c in range(1, m + 1, 1):
					if abs(nar[r - 1] - mar[c - 1]) <= 1:
						dp[r][c] = dp[r - 1][c - 1] + 1
					else:
						dp[r][c] = max(dp[r][c - 1], dp[r - 1][c])
			print(dp[n][m])

		def read():
			n = int(input())
			nar = list(map(int, input().split()))
			m = int(input())
			mar = list(map(int, input().split()))
			solution(nar, mar)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


n = int(input())
nL = sorted([int(i) for i in input().split()])
m = int(input())
mL = sorted([int(i) for i in input().split()])
L = []
L2 = []
for i in nL:
	for j in range(len(mL)):
		if i == mL[j]:
			mL[j] = 'Null'
			L.append(i)
			break
		elif i - 1 == mL[j]:
			mL[j] = 'Null'
			L.append(i - 1)
			break
		elif i + 1 == mL[j]:
			mL[j] = 'Null'
			L.append(i + 1)
			break
print(len(L))


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
for i in a:
	if i - 1 in b:
		b.remove(i - 1)
	elif i in b:
		b.remove(i)
	elif i + 1 in b:
		b.remove(i + 1)
	else:
		pass
print(m - len(b))


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
a = li()
m = ii()
b = li()
a.sort()
b.sort()
i = j = x = 0
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		x += 1
		i += 1
		j += 1
	elif b[j] - a[i] > 1:
		i += 1
	else:
		j += 1
print(x)


a = int(input())
l1 = list((int(i) for i in input().split()))
b = int(input())
l2 = list((int(i) for i in input().split()))
l1.sort()
l2.sort()
count = 0
for i in range(0, a):
	if l1[i] - 1 in l2:
		count += 1
		l2.remove(l1[i] - 1)
	elif l1[i] in l2:
		count += 1
		l2.remove(l1[i])
	elif l1[i] + 1 in l2:
		count += 1
		l2.remove(l1[i] + 1)
	if len(l2) == 0:
		break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

def sort(a, left, right):
	i = left + 1
	while i <= right:
		j = i
		while j > 0:
			if a[j] < a[j - 1]:
				temp = a[j]
				a[j] = a[j - 1]
				a[j - 1] = temp
			j = j - 1
		i = i + 1
	return a

def maxpairs(n, m, a, b):
	total = 0
	if n <= m:
		b = sort(b, 0, m - 1)
		a = sort(a, 0, n - 1)
		l = 0
		for i in range(n):
			for j in range(l, m):
				if abs(a[i] - b[j]) <= 1:
					total = total + 1
					l = j + 1
					break
				j = j + 1
			i = i + 1
	else:
		a = sort(a, 0, n - 1)
		b = sort(b, 0, m - 1)
		l = 0
		for i in range(m):
			for j in range(l, n):
				if abs(b[i] - a[j]) <= 1:
					total = total + 1
					l = j + 1
					break
				j = j + 1
			i = i + 1
	print(total)
maxpairs(n, m, a, b)


n = int(input())
boys = input().split()
m = int(input())
girls = input().split()
for i in range(len(girls)):
	girls[i] = int(girls[i])
MAX = 100
boys_values = [0 for x in range(MAX)]
girls_values = [0 for x in range(MAX)]
for i in range(len(boys)):
	boys_values[int(boys[i]) - 1] += 1
for i in range(len(girls)):
	girls_values[int(girls[i]) - 1] += 1
matches = 0
index = 0
higher = True
difference = 0
for index in range(MAX):
	male = boys_values[index]
	female = girls_values[index]
	if higher:
		if difference > female:
			matches += female
			difference = male
		else:
			male += difference
			higher = male > female
			additional = min(male, female)
			matches += additional
			difference = male + female - 2 * additional
	elif difference > male:
		matches += male
		difference = female
	else:
		female += difference
		higher = male > female
		additional = min(male, female)
		matches += additional
		difference = male + female - 2 * additional
print(matches)


x = int(input())
a = list(map(int, input().split()))
y = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
i = 0
k = 0
j = 0
while i < x and j < y:
	if abs(a[i] - b[j]) <= 1:
		k += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(k)


m = int(input())
m1 = sorted(list(map(int, input().split())))
d = int(input())
d1 = sorted(list(map(int, input().split())))
f = 0
for i in m1:
	for j in d1:
		if i == j:
			f += 1
			i = -100
			d1.remove(j)
			continue
		elif i + 1 == j:
			f += 1
			i = -100
			d1.remove(j)
			continue
		elif i - 1 == j:
			f += 1
			i = -100
			d1.remove(j)
			continue
		else:
			continue
print(f)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
(i, j, ans) = (0, 0, 0)
while i < n and j < m:
	if abs(boys[i] - girls[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
b = list(map(int, input().split()))
b.sort()
(x, y, res) = (0, 0, 0)
while x < n and y < m:
	if abs(a[x] - b[y]) <= 1:
		res += 1
		x += 1
		y += 1
	elif a[x] < b[y]:
		x += 1
	elif a[x] > b[y]:
		y += 1
print(res)


def input_split(f):
	return map(f, input().split())

def main():
	n = int(input())
	a = sorted(input_split(int))
	m = int(input())
	b = sorted(input_split(lambda v: (int(v), True)))
	k = 0
	for ai in a:
		for i in range(m):
			bi = b[i]
			v = bi[0]
			d = abs(v - ai)
			if bi[1] and d <= 1:
				k += 1
				b[i] = (v, False)
				break
			elif ai + 1 < v:
				break
	print(k)
main()


n1 = int(input())
a = sorted(map(int, input().split()))
n2 = int(input())
b = sorted(map(int, input().split()))
i = 0
j = 0
c = 0
while i < n1 and j < n2:
	if abs(a[i] - b[j]) <= 1:
		c = c + 1
		i = i + 1
		j = j + 1
	elif a[i] < b[j]:
		i = i + 1
	else:
		j = j + 1
print(c)


__author__ = 'shukkkur'
n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
pairs = 0
for boy in boys:
	for girl in girls:
		if boy == girl:
			pairs += 1
			girls.remove(boy)
			break
		elif boy + 1 == girl:
			pairs += 1
			girls.remove(boy + 1)
			break
		elif boy - 1 == girl:
			pairs += 1
			girls.remove(boy - 1)
			break
print(pairs)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	a = inp()
	d1 = inlt()
	b = inp()
	d2 = inlt()
	d1.sort()
	d2.sort()
	freq2 = {}
	for v in d2:
		if v not in freq2:
			freq2[v] = 0
		freq2[v] += 1
	c = 0
	for v1 in d1:
		if v1 - 1 in freq2 and freq2[v1 - 1] != 0:
			freq2[v1 - 1] -= 1
			c += 1
		elif v1 in freq2 and freq2[v1] != 0:
			freq2[v1] -= 1
			c += 1
		elif v1 + 1 in freq2 and freq2[v1 + 1] != 0:
			freq2[v1 + 1] -= 1
			c += 1
	print(c)
main()


from collections import defaultdict
d = {}
d = defaultdict(int)
d1 = {}
d1 = defaultdict(int)
n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l.sort()
for i in l1:
	d1[i] += 1
pairs = 0
for i in l:
	if d1[i - 1] > 0:
		pairs += 1
		d1[i - 1] -= 1
	elif d1[i] > 0:
		pairs += 1
		d1[i] -= 1
	elif d1[i + 1] > 0:
		pairs += 1
		d1[i + 1] -= 1
print(pairs)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
cnt = 0
(x1, x2) = (0, 0)
if n <= m:
	for i in range(n):
		for j in range(m):
			if g[j] - 1 <= b[i] <= g[j] + 1:
				g[j] = -1
				cnt += 1
				break
else:
	for i in range(m):
		for j in range(n):
			if b[j] - 1 <= g[i] <= b[j] + 1:
				b[j] = -1
				cnt += 1
				break
print(cnt)


b = int(input())
skb = sorted([int(x) for x in input().split()])
g = int(input())
skg = [int(x) for x in input().split()]
pairnum = 0
for boy in skb:
	for i in [boy - 1, boy, boy + 1]:
		if i in skg:
			pairnum += 1
			skg.remove(i)
			break
print(pairnum)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ng1 = int(input())
ng = list(map(int, input().split()))
ng.sort()
t = 0
c = 0
for i in range(n):
	if t == ng1:
		break
	while a[i] + 1 >= ng[t]:
		if abs(a[i] - ng[t]) <= 1:
			c += 1
			t += 1
			break
		else:
			t += 1
		if t == ng1:
			break
print(c)


a = int(input())
b = list(map(int, input().split()))
b.sort()
c = int(input())
d = list(map(int, input().split()))
d.sort()
e = 0
f = 0
g = 0
while e < a and f < c:
	if abs(b[e] - d[f]) <= 1:
		e += 1
		f += 1
		g += 1
	elif b[e] > d[f]:
		f += 1
	else:
		e += 1
print(g)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def can(m, s):
	if 0 <= s <= m * 9:
		return True
	return False

def main():
	b = int(input())
	boys = array()
	g = int(input())
	girls = array()
	boys.sort()
	girls.sort()
	gt = [-1 for i in range(g)]
	cnt = 0
	for i in range(b):
		for j in range(g):
			if abs(boys[i] - girls[j]) <= 1:
				if gt[j] == -1:
					cnt += 1
					gt[j] = i
					break
	print(cnt)
t = 1
for _ in range(t):
	main()


boys = int(input())
boy = list(map(int, input().split()))
girls = int(input())
girl = list(map(int, input().split()))
boy.sort()
girl.sort()
count = 0
j = 0
while len(boy) != 0:
	while j < len(girl) and len(boy) != 0:
		if abs(boy[0] - girl[j]) <= 1:
			count += 1
			boy = boy[1:]
			girl.remove(girl[j])
			j = 0
			break
		elif j == len(girl) - 1:
			boy = boy[1:]
			j = -1
		j += 1
	if len(girl) == 0:
		break
print(count)


n = int(input())
a = sorted([int(x) for x in input().split()])
m = int(input())
b = sorted([int(x) for x in input().split()])
s = 0
for i in range(n):
	for j in range(m):
		if a[i] + 1 < b[j]:
			break
		if a[i] - 1 <= b[j] <= a[i] + 1:
			s += 1
			b[j] = -2
			break
print(s)


n = int(input())
boys = [int(x) for x in input().split()]
boys.sort()
m = int(input())
girls = [int(x) for x in input().split()]
girls.sort()
total = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			total += 1
			girls[j] = 103
			break
print(total)


n = int(input())
boys = list((int(num) for num in input().split()))[:n]
m = int(input())
girls = list((int(num) for num in input().split()))[:m]
boys = sorted(boys)
girls = sorted(girls)
lst = [0] * m
count = 0
for i in range(0, n):
	for j in range(0, m):
		if abs(boys[i] - girls[j]) <= 1 and lst[j] != 1:
			count += 1
			lst[j] = 1
			break
print(count)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
numpair = 0
for boy in boys:
	if boy - 1 in girls:
		numpair += 1
		girls.remove(boy - 1)
	elif boy in girls:
		numpair += 1
		girls.remove(boy)
	elif boy + 1 in girls:
		numpair += 1
		girls.remove(boy + 1)
print(numpair)


num_of_boys = int(input())
input_boy = input().split()
boy_list = []
for count_b in range(num_of_boys):
	boy_list.append(int(input_boy[count_b]))
num_of_girls = int(input())
input_girls = input().split()
girl_list = []
for count_g in range(num_of_girls):
	girl_list.append(int(input_girls[count_g]))
boy_list.sort()
girl_list.sort()
count = 0
for i in range(len(boy_list)):
	for j in range(len(girl_list)):
		if abs(boy_list[i] - girl_list[j]) <= 1:
			count += 1
			girl_list.remove(girl_list[j])
			break
print(count)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b.sort()
d.sort()
final = 0
for i in range(a):
	for j in range(c):
		if abs(b[i] - d[j]) < 2:
			final += 1
			d[j] = 1000
			break
print(final)


def go(i, j, n, m):
	if i == n or j == m:
		return 0
	if dp[i][j] != -1:
		return dp[i][j]
	mx = max(go(i + 1, j, n, m), go(i, j + 1, n, m))
	if abs(a[i] - b[j]) <= 1:
		mx = max(mx, 1 + go(i + 1, j + 1, n, m))
	dp[i][j] = mx
	return mx
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
(a.sort(), b.sort())
dp = [[-1] * m for x in range(n)]
print(go(0, 0, n, m))


boys = int(input())
boyList = [0] * 101
boyStr = [int(i) for i in input().split()]
for i in boyStr:
	boyList[i] += 1
countPair = 0
girls = int(input())
girlList = [int(i) for i in input().split()]
girlList.sort()
for i in girlList:
	if boyList[i - 1] != 0:
		boyList[i - 1] -= 1
		countPair += 1
	elif boyList[i] != 0:
		boyList[i] -= 1
		countPair += 1
	elif i + 1 <= 100:
		if boyList[i + 1] != 0:
			boyList[i + 1] -= 1
			countPair += 1
print(countPair)


x = input()
boys = list(map(int, input().split(' ')))
y = input()
girls = list(map(int, input().split(' ')))
boys.sort()
girls.sort()
ok = 0
for i in boys[:]:
	if i - 1 in girls:
		girls.remove(i - 1)
		boys.remove(i)
		ok += 1
	elif i in girls:
		girls.remove(i)
		boys.remove(i)
		ok += 1
	elif i + 1 in girls:
		girls.remove(i + 1)
		boys.remove(i)
		ok += 1
print(ok)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	a = ain()
	m = inin()
	b = ain()
	a.sort()
	b.sort()
	count = 0
	for i in range(n):
		for j in range(m):
			if abs(a[i] - b[j]) <= 1:
				count += 1
				b[j] = -1
				break
	print(count)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]
boys.sort()
girls.sort()
count = 0
last_girl = -1
for boy in boys:
	for gi in range(last_girl + 1, len(girls)):
		girl = girls[gi]
		if girl + 1 == boy or girl == boy or girl - 1 == boy:
			count += 1
			last_girl = gi
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
(a1, b1) = ([None] * n, [False] * m)
for i in range(n):
	for j in range(m):
		if (b[j] + 1 == a[i] or b[j] - 1 == a[i] or b[j] == a[i]) and (not b1[j]):
			b1[j] = True
			a1[i] = 1
			count += 1
			break
print(count)


bN = int(input())
bSkill = [int(e) for e in input().split()]
bSkill.sort()
gN = int(input())
gSkill = [int(i) for i in input().split()]
gSkill.sort()
(bI, gI, pair) = (0, 0, 0)
while len(bSkill) >= bI + 1:
	if abs(bSkill[bI] - gSkill[gI]) == 0 or abs(bSkill[bI] - gSkill[gI]) == 1:
		bSkill.remove(bSkill[bI])
		gSkill.remove(gSkill[gI])
		pair += 1
		(gI, bI) = (0, 0)
	elif len(gSkill) == gI + 1:
		gI = 0
		bI += 1
	else:
		gI += 1
	if bSkill == [] or gSkill == []:
		break
print(pair)


nb = int(input())
sb = sorted(list(map(int, input().split())))
ng = int(input())
sg = sorted(list(map(int, input().split())))
count = 0
for i in sb:
	if i - 1 in sg:
		sg.remove(i - 1)
		count += 1
	elif i in sg:
		sg.remove(i)
		count += 1
	elif i + 1 in sg:
		sg.remove(i + 1)
		count += 1
	else:
		pass
print(count)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b.sort()
d.sort()
counter = 0
for i in b:
	for j in d:
		if abs(i - j) <= 1:
			counter += 1
			d.remove(j)
			break
print(counter)


n = int(input())
lst = sorted(list(map(int, input().split())))
m = int(input())
c = 0
l = sorted(list(map(int, input().split())))
for i in lst:
	for (m, j) in enumerate(l):
		if i - 1 == j or i + 1 == j or i == j:
			c = c + 1
			l[m] = -1
			break
print(c)


input()
L = list(map(int, input().split(' ')))
input()
L1 = list(map(int, input().split(' ')))
cont = 0
L.sort()
L1.sort()
for k in L:
	for j in L1:
		if -1 <= k - j <= 1:
			cont += 1
			L1.remove(j)
			break
print(cont)


def findLogic(arr1, arr2):
	size1 = len(arr1)
	size2 = len(arr2)
	(i, j) = (0, 0)
	count = 0
	while i < size1 and j < size2:
		if abs(arr1[i] - arr2[j]) < 2:
			count += 1
			i += 1
			j += 1
		elif arr1[i] > arr2[j]:
			j += 1
		else:
			i += 1
	return count

def main():
	nb = int(input())
	boys = list(map(int, input().rstrip().split()))
	ng = int(input())
	girls = list(map(int, input().rstrip().split()))
	boys.sort()
	girls.sort()
	ans = findLogic(boys, girls)
	print(ans)
main()


a = [0] * 101
b = [0] * 101
n = int(input())
for i in input().split(' '):
	a[int(i)] += 1
m = int(input())
for i in input().split(' '):
	b[int(i)] += 1
cnt = 0
i = 0
while i < 101:
	if a[i] > 0:
		if i == 0:
			if b[i] > 0:
				j = i
			else:
				j = i + 1
			d = min(a[i], b[j])
			a[i] -= d
			b[j] -= d
			cnt += d
			if a[i] == 0 or b[i] + b[i + 1] == 0:
				i += 1
		elif i == 100:
			if b[i - 1] > 0:
				j = i - 1
			else:
				j = i
			d = min(a[i], b[j])
			a[i] -= d
			b[j] -= d
			cnt += d
			if a[i] == 0 or b[i] + b[i - 1] == 0:
				i += 1
		else:
			if b[i - 1] > 0:
				j = i - 1
			elif b[i] > 0:
				j = i
			else:
				j = i + 1
			d = min(a[i], b[j])
			a[i] -= d
			b[j] -= d
			cnt += d
			if a[i] == 0 or b[i] + b[i + 1] + b[i - 1] == 0:
				i += 1
	else:
		i += 1
print(cnt)


n = int(input())
mat = sorted(list(map(int, input().split())))
m = int(input())
sat = sorted(list(map(int, input().split())))
result = 0
(i, j) = (0, 0)
while i < n and j < m:
	if abs(mat[i] - sat[j]) <= 1:
		result += 1
		i += 1
		j += 1
	elif mat[i] > sat[j]:
		j += 1
	else:
		i += 1
print(result)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = list(map(int, input().split()))
m = max(b)
c = [0] * (m + 1)
for q in b:
	c[q] += 1
j = 0
for q in range(n):
	if a[q] - 1 <= m and c[a[q] - 1] > 0:
		j += 1
		c[a[q] - 1] -= 1
		continue
	if a[q] <= m and c[a[q]] > 0:
		j += 1
		c[a[q]] -= 1
		continue
	if a[q] + 1 <= m and c[a[q] + 1] > 0:
		j += 1
		c[a[q] + 1] -= 1
		continue
print(j)


a = int(input())
b = sorted(map(int, input().split()))
c = int(input())
d = sorted(map(int, input().split()))
i = j = s = 0
while i < a and j < c:
	if abs(b[i] - d[j]) < 2:
		s += 1
		i += 1
		j += 1
	elif b[i] < d[j]:
		i += 1
	else:
		j += 1
print(s)


import math
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
i = 0
j = 0
while i < len(a) and j < len(b):
	if abs(a[i] - b[j]) <= 1 or a[i] == b[j]:
		ans += 1
		i += 1
		j += 1
		continue
	if a[i] < b[j]:
		i += 1
	else:
		j += 1
print(ans)


n = int(input())
A = sorted(list(map(int, input().split())))
m = int(input())
B = sorted(list(map(int, input().split())))
(i, j, cnt) = (0, 0, 0)
while i < n and j < m:
	if abs(B[j] - A[i]) < 2:
		cnt += 1
		i += 1
		j += 1
	elif B[j] > A[i]:
		i += 1
	else:
		j += 1
print(cnt)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
count = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = 1000
			count += 1
			break
print(count)


from collections import defaultdict

def solve():
	n = int(input())
	boys = list(map(int, input().split()))
	m = int(input())
	girls = list(map(int, input().split()))
	boys = sorted(boys)
	girls = sorted(girls)
	ans = 0
	for i in range(n):
		for j in range(m):
			if abs(boys[i] - girls[j]) <= 1:
				ans += 1
				girls[j] = 1000
				break
	print(ans)
solve()


b = int(input())
lb = list(map(int, input().split()))
lb.sort()
g = int(input())
lg = list(map(int, input().split()))
lg.sort()
p = 0
for i in lb:
	for j in lg:
		if abs(i - j) < 2:
			p += 1
			lg.remove(j)
			break
print(p)


n = int(input())
ad = list(sorted(list(map(int, input().split()))))
m = int(input())
am = list(sorted(list(map(int, input().split()))))
i = 0
j = 0
sum1 = 0
while i < n and j < m:
	if abs(ad[i] - am[j]) < 2:
		sum1 += 1
		i += 1
		j += 1
	elif ad[i] < am[j]:
		i += 1
	else:
		j += 1
print(sum1)


q = int(input())
a = list(map(int, input().split()))
qrx = int(input())
b = list(map(int, input().split()))
i = 0
count = 0
a = sorted(a)
b = sorted(b)
p = []
for x in range(len(a)):
	for y in range(len(b)):
		if y not in p and abs(a[x] - b[y]) <= 1:
			count += 1
			p.append(y)
			break
print(count)


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(b, bs, g, gs) = (ii(), ll(), ii(), ll())
bs.sort()
gs.sort()
gi = c = 0
for s in bs:
	while gi < g and s > gs[gi] + 1:
		gi += 1
	if gi == g:
		break
	if abs(gs[gi] - s) < 2:
		gi += 1
		c += 1
print(c)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
p = q = count = 0
while p < n and q < m:
	if abs(a[p] - b[q]) < 2:
		count += 1
		p += 1
		q += 1
	elif a[p] > b[q]:
		q += 1
	else:
		p += 1
print(count)


nb = int(input())
b = list(map(int, input().split()))
ng = int(input())
g = list(map(int, input().split()))
if ng > nb:
	(ng, nb) = (nb, ng)
	(g, b) = (b, g)
x = 0
g.sort()
b.sort()
for i in range(ng):
	for j in range(nb):
		if abs(b[j] - g[i]) < 2:
			b.pop(j)
			x += 1
			nb -= 1
			break
print(x)


def main():
	n = int(input())
	boy = list(map(int, input().split()))
	boy = sorted(boy)
	m = int(input())
	girl = list(map(int, input().split()))
	girl = sorted(girl)
	l = 0
	for i in boy:
		for j in girl:
			if girl == []:
				return l
			if abs(i - j) <= 1:
				l += 1
				girl.remove(j)
				break
	return l
print(main())


n = int(input())
boys = map(int, input().split(' '))
m = int(input())
girls = map(int, input().split(' '))
boys = sorted(boys)
girls = sorted(girls)
max_pairs = 0
boy_pointer = 0
girl_pointer = 0
while boy_pointer < n and girl_pointer < m:
	if abs(boys[boy_pointer] - girls[girl_pointer]) <= 1:
		max_pairs += 1
		boy_pointer += 1
		girl_pointer += 1
	elif boys[boy_pointer] + 1 < girls[girl_pointer]:
		boy_pointer += 1
	elif girls[girl_pointer] + 1 < boys[boy_pointer]:
		girl_pointer += 1
print(max_pairs)


n = int(input())
N = list(map(int, input().split()))
m = int(input())
M = list(map(int, input().split()))
N.sort()
M.sort()
count = 0
i = 0
j = 0
while i < n and j < m:
	if abs(N[i] - M[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif N[i] > M[j]:
		j += 1
	else:
		i += 1
print(count)


b = int(input())
bl = list(map(int, input().split()))
g = int(input())
gl = list(map(int, input().split()))
ans = 0
bl.sort()
gl.sort()
for i in range(b):
	for j in range(g):
		if abs(bl[i] - gl[j]) <= 1:
			gl[j] = 1000
			ans += 1
			break
print(ans)


n = int(input())
s = list(map(int, input().split()))
m = int(input())
s1 = list(map(int, input().split()))
s.sort(reverse=True)
s1.sort(reverse=True)
ans = 0
while len(s1) > 0 and len(s) > 0:
	if abs(s1[-1] - s[-1]) <= 1:
		ans += 1
		s1.pop()
		s.pop()
	elif s1[-1] < s[-1]:
		s1.pop()
	else:
		s.pop()
print(ans)


m = int(input())
a = list(map(int, input().split()))
n = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
c = 0
i = 0
while i == 0:
	if len(a) == 0 or len(b) == 0:
		break
	if abs(a[i] - b[i]) < 2:
		c += 1
		del a[i]
		del b[i]
	elif a[i] > b[i]:
		del b[i]
	else:
		del a[i]
print(c)


import sys
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
a.sort()
b.sort()
c = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			b[j] = 150
			c += 1
			break
print(c)


mc = int(input())
M = list(map(int, input().split()))
gc = int(input())
G = list(map(int, input().split()))
ans = 0
M.sort()
G.sort()
p = {}
for i in range(mc):
	for j in range(gc):
		if abs(M[i] - G[j]) < 2 and i not in p and (j not in p.values()):
			p[i] = j
print(len(p))


a = int(input())
m = sorted(list(map(int, input().split())))
b = int(input())
n = sorted(list(map(int, input().split())))
k = 0
r = 0
for i in range(a):
	p = k
	for j in range(p, b):
		if abs(m[i] - n[j]) <= 1:
			r += 1
			k = j + 1
			break
		elif n[j] > m[i]:
			k = j
			break
print(r)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
t = [0 for x in range(102)]
s = [0 for x in range(102)]
count = 0
for x in range(len(a)):
	s[a[x]] += 1
for x in range(len(b)):
	t[b[x]] += 1
a.sort()
for x in range(len(a)):
	d = a[x]
	for y in range(-1, 2):
		if t[d + y] != 0 and s[d] != 0:
			c = min(t[d + y], s[d])
			count += c
			t[d + y] -= c
			s[d] -= c
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
indexa = []
indexb = []
ans = 0
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1 and i not in indexa and (j not in indexb):
			ans += 1
			indexa.append(i)
			indexb.append(j)
			break
print(ans)


n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
(i, j) = (0, 0)
count = 0
while i < n and j < m:
	a = A[i]
	b = B[j]
	if a == b:
		count += 1
		i += 1
		j += 1
	elif a > b:
		if a - b == 1:
			count += 1
			i += 1
		j += 1
	else:
		if b - a == 1:
			count += 1
			j += 1
		i += 1
print(count)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
mark = [0] * m
for i in range(n):
	for j in range(m):
		if mark[j] == 0 and abs(boys[i] - girls[j]) <= 1:
			mark[j] = 1
			break
print(mark.count(1))


from collections import defaultdict
from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
girls = defaultdict(lambda : 0)
for i in b:
	girls[i] += 1
ans = 0
a.sort()
for i in a:
	if girls[i - 1] > 0:
		ans += 1
		girls[i - 1] -= 1
	elif girls[i] > 0:
		ans += 1
		girls[i] -= 1
	elif girls[i + 1] > 0:
		ans += 1
		girls[i + 1] -= 1
print(ans)


import sys
n = int(sys.stdin.readline())
b = sorted([int(x) for x in sys.stdin.readline().split()])
m = int(sys.stdin.readline())
g = sorted([int(x) for x in sys.stdin.readline().split()])
t = min(m, n)
c = 0
i = 0
j = 0
while i < n and j < m:
	if abs(b[i] - g[j]) <= 1:
		c += 1
		i += 1
		j += 1
	elif b[i] < g[j]:
		i += 1
	else:
		j += 1
print(c)


g = int(input())
girls = [int(x) for x in input().split()]
b = int(input())
boys = [int(x) for x in input().split()]
girls.sort()
boys.sort()
count = 0
j = 0
i = 0
while i < g and j < b:
	if abs(girls[i] - boys[j]) <= 1:
		count += 1
		j += 1
		i += 1
	elif girls[i] < boys[j]:
		i += 1
	else:
		j += 1
print(count)


def check(a, b):
	if a > b - 2 and a < b + 2:
		return True
	return False
n_boy = int(input())
boy_ls = list(map(int, input().split()))
n_girl = int(input())
girl_ls = list(map(int, input().split()))
boy_ls.sort()
girl_ls.sort()
group = 0
i = 0
j = 0
key = i
while i < n_boy and j < n_girl:
	while j < n_girl and i < n_boy and (boy_ls[i] + 2 > girl_ls[j]):
		if check(boy_ls[i], girl_ls[j]):
			group += 1
			i += 1
		j += 1
	while j < n_girl and i < n_boy and (boy_ls[i] < girl_ls[j] + 2):
		if check(girl_ls[j], boy_ls[i]):
			group += 1
			j += 1
		i += 1
print(group)


import itertools as ittls
from collections import Counter
from functools import reduce
import string

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
N = int(input())
A = list(inputarray())
M = int(input())
B = list(inputarray())
used = [0] * N
mt = [-1] * M

def match(idx):
	if used[idx] == 1:
		return False
	used[idx] = 1
	for (j, v) in enumerate(B):
		if abs(v - A[idx]) <= 1:
			if mt[j] == -1 or match(mt[j]):
				mt[j] = idx
				return True
	return False
for i in range(len(A)):
	used = [0] * N
	match(i)
print(len(list(filter(lambda x: x != -1, mt))))


b = int(input())
l = list(map(int, input().split()))
g = int(input())
m = list(map(int, input().split()))
l = sorted(l)
m = sorted(m)
count = 0
z = [[] for _ in range(b)]
for i in range(len(l)):
	for j in range(len(m)):
		if abs(l[i] - m[j]) <= 1:
			z[i].append(j)
k = -1
for i in z:
	for j in i:
		if j != k and j > k:
			count += 1
			k = j
			break
print(count)


n = int(input())
b = sorted(map(int, input().split()))
m = int(input())
g = sorted(map(int, input().split()))
i = j = count = 0
while i < n and j < m:
	if b[i] == g[j] or abs(b[i] - g[j]) == 1:
		count += 1
		j += 1
		i += 1
	elif b[i] > g[j]:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
boys = map(int, input().split())
m = int(input())
girls = map(int, input().split())
boys = sorted(boys)
girls = sorted(girls)
cnt = 0
for boy in boys:
	mark = 0
	for girl in girls:
		if abs(boy - girl) <= 1:
			cnt += 1
			girls.remove(girl)
			mark = 1
			break
print(cnt)


n = int(input())
na = sorted(list(map(int, input().split())))
m = int(input())
ma = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(m):
		if abs(ma[j] - na[i]) <= 1:
			ans += 1
			ma[j] = -100
			na[i] = -100500
print(ans)


n = int(input())
lb = list(map(int, input().split()))
m = int(input())
lg = list(map(int, input().split()))
hb = [0 for _ in range(100)]
hg = [0 for _ in range(100)]
lb.sort()
lg.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(lg[j] - lb[i]) < 2:
			lg[j] = 200
			ans += 1
			break
print(ans)


n = int(input())
b = input()
b = b.split()
m = int(input())
g = input()
g = g.split()
for i in range(len(b)):
	b[i] = int(b[i])
for i in range(len(g)):
	g[i] = int(g[i])
b.sort()
g.sort()
c = 0
bp = 0
gp = 0
while bp < n and gp < m:
	if -1 <= b[bp] - g[gp] <= 1:
		c += 1
		bp += 1
		gp += 1
	elif b[bp] - g[gp] > 1:
		gp += 1
	else:
		bp += 1
print(c)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def DFS(d, ver, visited, value, color):
	stack = [ver]
	value[ver] = color
	visited.add(ver)
	while stack:
		flag = 0
		for i in d[stack[-1]]:
			if i in visited:
				if value[stack[-1]] == value[i]:
					return False
			else:
				visited.add(i)
				flag = 1
				color = value[stack[-1]] ^ 1
				stack.append(i)
				value[i] = color
				break
		if not flag:
			stack.pop()
	return True
n = inp()
l = li()
m = inp()
k = li()
c = 0
l.sort()
k.sort()
for i in range(n):
	for j in range(m):
		if abs(l[i] - k[j]) <= 1:
			c += 1
			k[j] = -100
			break
pr(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
for i in range(n):
	if a[i] != -1:
		for j in range(m):
			if b[j] != -1:
				if a[i] == b[j] or abs(a[i] - b[j]) == 1:
					a[i] = -1
					b[j] = -1
					break
c = 0
for i in a:
	if i == -1:
		c += 1
print(c)


hn = int(input())
hl = input().strip().split(' ')
mn = int(input())
ml = input().strip().split(' ')
hl = [int(x) for x in hl]
ml = [int(x) for x in ml]
ph = 0
pm = 0
hl = sorted(hl)
ml = sorted(ml)
total = 0
while 1:
	if ph == hn or pm == mn:
		break
	if abs(hl[ph] - ml[pm]) < 2:
		total += 1
		pm += 1
		ph += 1
	elif hl[ph] > ml[pm]:
		pm += 1
	else:
		ph += 1
print(total)


import sys
n = int(sys.stdin.readline())
inpN = sys.stdin.readline()[:-1].split(' ')
m = int(sys.stdin.readline())
inpM = sys.stdin.readline()[:-1].split(' ')
inpN = [int(num) for num in inpN]
inpM = [int(num) for num in inpM]
inpN.sort()
inpM.sort()
poc = 0
dev = 0
ans = 0
while poc < n and dev < m:
	pocS = inpN[poc]
	devS = inpM[dev]
	if abs(pocS - devS) <= 1:
		ans = ans + 1
		poc = poc + 1
		dev = dev + 1
	elif pocS > devS:
		dev = dev + 1
	else:
		poc = poc + 1
print(ans)


n = int(input())
boy = sorted(map(int, input().split()))
m = int(input())
girl = sorted(map(int, input().split()))
b = 0
g = 0
res = 0
while b < n and g < m:
	if boy[b] < girl[g] - 1:
		b += 1
	elif girl[g] < boy[b] - 1:
		g += 1
	else:
		res += 1
		b += 1
		g += 1
print(res)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = int(input())
b = [int(x) for x in input().split()]
b.sort()
pair = 0
for i in range(n):
	for j in range(m - pair):
		if abs(a[i] - b[j]) <= 1:
			pair += 1
			del b[j]
			break
		else:
			continue
print(pair)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
count = 0
for i in range(len(b)):
	for j in range(len(g)):
		if (b[i] - g[j] == 1 or b[i] - g[j] == -1 or b[i] - g[j] == 0) and (g[j] != -1 or b[i] != -1):
			b[i] = -1
			g[j] = -1
			count += 1
print(count)


n = int(input())
hom = [int(x) for x in input().split()]
mu = int(input())
muj = [int(x) for x in input().split()]
muj.sort()
hom.sort()
h = 0
m = 0
c = 0
while m != mu and h != n:
	if abs(muj[m] - hom[h]) <= 1:
		h += 1
		m += 1
		c += 1
	elif muj[m] > hom[h]:
		h += 1
	else:
		m += 1
print(c)


men = int(input())
men_dance_index = [int(x) for x in input().split()]
women = int(input())
women_dance_index = [int(x) for x in input().split()]
men_dance_index.sort()
women_dance_index.sort()
result = 0
j = 0
i = 0
while i < men and j < women:
	if abs(men_dance_index[i] - women_dance_index[j]) <= 1:
		result += 1
		i += 1
		j += 1
	elif men_dance_index[i] < women_dance_index[j]:
		i += 1
	else:
		j += 1
print(result)


n = int(input())
a = input().split()
a = list(map(int, a))
m = int(input())
b = input().split()
b = list(map(int, b))
a.sort()
b.sort()
l1 = len(a)
l2 = len(b)
if l1 >= l2:
	pass
else:
	x = a
	a = b
	b = x
count = 0
for i in range(len(b)):
	if a[0] - b[i] > 1:
		continue
	elif b[i] - 1 in a:
		z = a.index(b[i] - 1)
		a = a[:z] + a[z + 1:]
		count = count + 1
	elif b[i] in a:
		z = a.index(b[i])
		a = a[:z] + a[z + 1:]
		count = count + 1
	elif b[i] + 1 in a:
		z = a.index(b[i] + 1)
		a = a[:z] + a[z + 1:]
		count = count + 1
print(count)


n = int(input())
l = list(map(int, input().split()))
m = int(input())
l2 = list(map(int, input().split()))
l.sort()
l2.sort()
i = 0
j = 0
c = 0
while i < n and j < m:
	if abs(l[i] - l2[j]) <= 1:
		i += 1
		j += 1
		c += 1
	elif l[i] > l2[j]:
		j += 1
	else:
		i += 1
print(c)


n = int(input())
st = input()
boys = [int(x) for x in st.split(' ')]
boys.sort()
m = int(input())
st = input()
girls = [int(x) for x in st.split(' ')]
girls.sort()
count = 0
i = 0
while i < n:
	j = 0
	while j < m:
		if girls[j] == 0:
			j += 1
			continue
		if abs(boys[i] - girls[j]) <= 1:
			count += 1
			girls[j] = 0
			break
		j += 1
	i += 1
print(count)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
cntPairs = 0
i = 0
while i < n:
	j = 0
	while j < m:
		if abs(boys[i] - girls[j]) <= 1:
			cntPairs += 1
			girls[j] = -1
			j = m - 1
		j += 1
	i += 1
print(cntPairs)


n = int(input())
arr1 = list(map(int, input().split()))
m = int(input())
arr2 = list(map(int, input().split()))
graph = [[False] * (m + n) for _ in range(m + n)]
for i in range(n):
	for j in range(m):
		if abs(arr1[i] - arr2[j]) <= 1:
			graph[i][j + n] = True
			graph[j + n][i] = True
u = [False] * (m + n)
to = [-1] * m

def match(v1):
	i = 0
	if u[v1]:
		return 0
	u[v1] = True
	for i2 in range(m):
		if graph[v1][i2 + n] and (to[i2] == -1 or match(to[i2])):
			to[i2] = v1
			return 1
	return 0
res = 0
for i1 in range(n + m):
	u = [False] * (m + n)
	res += match(i1)
print(res)


n = int(input())
man = list(map(int, input().split(' ')))
man.sort()
m = int(input())
female = list(map(int, input().split(' ')))
female.sort()
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(man[i] - female[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif man[i] > female[j]:
		j += 1
	else:
		i += 1
print(count)


from sys import stdin
import math
men_n = int(stdin.readline())
men = stdin.readline().split(' ')
for i in range(len(men)):
	men[i] = int(men[i])
women_n = int(stdin.readline())
women = stdin.readline().split(' ')
for i in range(len(women)):
	women[i] = int(women[i])
men.sort(key=lambda x: -x)
women.sort(key=lambda x: -x)
n = 0
i = 0
j = 0
while i < len(men) and j < len(women):
	if math.fabs(men[i] - women[j]) < 2:
		i += 1
		j = j + 1
		n = n + 1
	elif men[i] > women[j]:
		i = i + 1
	else:
		j = j + 1
print(n)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_boys = read_int()
boys = sorted(read_ints())
nb_girl = read_int()
girls = sorted(read_ints())
pairs = 0
while boys and girls:
	if abs(boys[-1] - girls[-1]) <= 1:
		pairs += 1
		boys.pop()
		girls.pop()
	elif boys[-1] > girls[-1]:
		boys.pop()
	else:
		girls.pop()
print(pairs)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
c = 0
used = [0] * 101
co = [0] * 101
for j in range(m):
	co[b[j]] += 1
for i in range(n):
	x = a[i]
	y = a[i] - 1
	z = a[i] + 1
	for j in range(m):
		if b[j] == y and used[b[j]] < co[b[j]]:
			c += 1
			used[b[j]] += 1
			break
		elif b[j] == x and used[b[j]] < co[b[j]]:
			c += 1
			used[b[j]] += 1
			break
		elif b[j] == z and used[b[j]] < co[b[j]]:
			c += 1
			used[b[j]] += 1
			break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
c = 0
if n <= m:
	for i in a:
		if i - 1 in b:
			c += 1
			b.pop(b.index(i - 1))
		elif i in b:
			c += 1
			b.pop(b.index(i))
		elif i + 1 in b:
			c += 1
			b.pop(b.index(i + 1))
else:
	for i in b:
		if i - 1 in a:
			c += 1
			a.pop(a.index(i - 1))
		elif i in a:
			c += 1
			a.pop(a.index(i))
		elif i + 1 in a:
			c += 1
			a.pop(a.index(i + 1))
print(c)


B = int(input())
boys = list(map(int, input().strip('\n').split()))
boys.sort()
G = int(input())
girls = list(map(int, input().strip('\n').split()))
girls.sort()
(i, j) = (0, 0)
pairs = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(pairs)


def main():
	input()
	aa = iter(sorted(map(int, input().split())))
	input()
	bb = iter(sorted(map(int, input().split())))
	res = 0
	try:
		while True:
			(a, b) = (next(aa), next(bb))
			while not -2 < a - b < 2:
				if a < b:
					a = next(aa)
				else:
					b = next(bb)
			res += 1
	except StopIteration:
		print(res)
main()


x = int(input())
a = sorted(list(map(int, input().split())))
y = int(input())
b = sorted(list(map(int, input().split())))
count = 0
for i in range(0, x):
	for j in range(0, y):
		if abs(a[i] - b[j]) in [0, 1]:
			count += 1
			b[j] = -10
			break
print(count)


n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))
ln.sort()
lm.sort()
s = [False] * 105
count = 0
for i in range(0, n):
	for j in range(0, m):
		if s[j] == False:
			if abs(ln[i] - lm[j]) <= 1:
				s[j] = True
				count += 1
				break
print(count)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
idx_a = 0
idx_b = 0
cnt = 0
while idx_a < n and idx_b < m:
	if abs(a[idx_a] - b[idx_b]) <= 1:
		idx_a += 1
		idx_b += 1
		cnt += 1
	elif a[idx_a] > b[idx_b]:
		idx_b += 1
	else:
		idx_a += 1
print(cnt)


n = int(input())
a = sorted(list(map(int, input().rstrip().split())))
m = int(input())
b = sorted(list(map(int, input().rstrip().split())))
i = j = k = 0
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(k)


nob = int(input())
boys = list(map(int, input().split()))
nog = int(input())
girls = list(map(int, input().split()))
b = 0
g = 0
ans = 0
boys.sort()
girls.sort()
while b < nob and g < nog:
	if abs(boys[b] - girls[g]) < 2:
		ans += 1
		b += 1
		g += 1
	elif abs(boys[b] - girls[g]) > 1 and boys[b] > girls[g]:
		g += 1
	elif abs(boys[b] - girls[g]) > 1 and boys[b] < girls[g]:
		b += 1
print(ans)


n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]
boys.sort()
girls.sort()
c = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = float('inf')
			c += 1
			break
print(c)


n = int(input())
boy = input().split()
for i in range(n):
	boy[i] = int(boy[i])
m = int(input())
girl = input().split()
for i in range(m):
	girl[i] = int(girl[i])
boy.sort()
girl.sort()
cnt = 0
for i in range(len(boy)):
	for j in range(len(girl)):
		if abs(boy[i] - girl[j]) <= 1:
			girl[j] = 10000
			boy[i] = 1000
			cnt += 1
print(cnt)


input()
first = input()
First = [int(s) for s in first.split()]
input()
second = input()
Second = [int(s) for s in second.split()]
First.sort()
Second.sort()
c = 0
flag = False
for i in First:
	flag = False
	for j in Second:
		if i + 1 >= j >= i - 1 and (not flag):
			c += 1
			Second.remove(j)
			flag = True
print(c)


n = int(input())
nl = list(map(int, input().split()))
m = int(input())
ml = list(map(int, input().split()))
ml.sort()
nl.sort()
x = n
y = m
s = 0
if x < y:
	for i in range(x):
		a = nl[i]
		if ml.count(a - 1) != 0:
			ml.remove(a - 1)
			s += 1
		elif ml.count(a) != 0:
			ml.remove(a)
			s += 1
		elif ml.count(a + 1) != 0:
			ml.remove(a + 1)
			s += 1
	print(s)
else:
	for i in range(y):
		a = ml[i]
		if nl.count(a - 1) != 0:
			nl.remove(a - 1)
			s += 1
		elif nl.count(a) != 0:
			nl.remove(a)
			s += 1
		elif nl.count(a + 1) != 0:
			nl.remove(a + 1)
			s += 1
	print(s)


import math

def mergeSort(lst):
	if len(lst) <= 1:
		return lst
	mid = math.floor(len(lst) / 2)
	left = mergeSort(lst[0:mid])
	right = mergeSort(lst[mid:])
	return merge(left, right)

def merge(arr1, arr2):
	i = 0
	j = 0
	lst = []
	while i < len(arr1) and j < len(arr2):
		if arr1[i] < arr2[j]:
			lst.append(arr1[i])
			i += 1
		else:
			lst.append(arr2[j])
			j += 1
	while i < len(arr1):
		lst.append(arr1[i])
		i += 1
	while j < len(arr2):
		lst.append(arr2[j])
		j += 1
	return lst
length1 = int(input())
lst1 = list(map(int, input().split()))
lst1 = mergeSort(lst1)
length2 = int(input())
lst2 = list(map(int, input().split()))
lst2 = mergeSort(lst2)
count = 0
i = 0
j = 0
while i < len(lst1):
	j = 0
	while j < len(lst2):
		if abs(lst1[i] - lst2[j]) <= 1:
			count += 1
			lst2[j] = 9000
			break
		j += 1
	i += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
dic = {}
for i in a:
	try:
		dic[i] += 1
	except:
		dic[i] = 1
b.sort()
ans = 0
for i in b:
	try:
		if dic[i - 1] == 0:
			raise ValueError('a')
		ans += 1
		dic[i - 1] -= 1
	except:
		try:
			if dic[i] == 0:
				raise ValueError('a')
			ans += 1
			dic[i] -= 1
		except:
			try:
				if dic[i + 1] == 0:
					raise ValueError('a')
				ans += 1
				dic[i + 1] -= 1
			except:
				pass
print(ans)


def trial():
	boys = int(input())
	l_boys = list(reversed(sorted(list(map(int, input().split())))))
	girls = int(input())
	l_girls = list(reversed(sorted(list(map(int, input().split())))))
	counter = 0
	for b in range(boys):
		for g in range(len(l_girls)):
			if l_boys[b] == l_girls[g]:
				counter += 1
				l_girls.pop(g)
				break
			elif l_boys[b] == 1 + l_girls[g]:
				counter += 1
				l_girls.pop(g)
				break
			elif l_boys[b] == l_girls[g] - 1:
				counter += 1
				l_girls.pop(g)
				break
	return print(counter)
trial()


nb = int(input())
rb = [int(x) for x in input().split(' ')]
rb.sort()
ng = int(input())
rg = [int(x) for x in input().split(' ')]
rg.sort()
cnt = 0
for i in range(nb):
	for j in range(ng):
		if abs(rg[j] - rb[i]) < 2:
			rg[j] = 102
			rb[i] = 102
			cnt += 1
print(cnt)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a = sorted(a)
b = sorted(b)
x = i = 0
while i < len(a):
	j = 0
	while j < len(b):
		if abs(a[i] - b[j]) <= 1:
			x += 1
			a.pop(i)
			b.pop(j)
			i = -1
			break
		j += 1
	i += 1
print(x)


n = int(input())
b = list(map(int, input().split()))
b = sorted(b)
m = int(input())
g = list(map(int, input().split()))
g = sorted(g)
count = 0
for i in b:
	x = int(i)
	a = [x - 1, x, x + 1]
	for j in a:
		if j >= 1 and j in g:
			count += 1
			g.remove(j)
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
c = []
i = 0
j = 0
while i < len(a) and j < len(b):
	if abs(a[i] - b[j]) <= 1:
		c.append(a[i])
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(len(c))


def Fabs(a):
	if a < 0:
		return -a
	else:
		return a

def solve(listB, listG):
	res = 0
	cntb = 0
	while cntb < len(listB):
		cntg = 0
		while cntg < len(listG):
			if Fabs(listB[cntb] - listG[cntg]) <= 1:
				res += 1
				listG[cntg] = 10000
				listB[cntb] = 10000
			cntg += 1
		cntb += 1
	return res
listB = []
listG = []
b = input()
listB = list(map(int, input().split()))
g = input()
listG = list(map(int, input().split()))
listB = sorted(listB)
listG = sorted(listG)
print(solve(listB, listG))


n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l = sorted(l)
l1 = sorted(l1)
k = 0
for i in range(n):
	for j in range(m):
		if abs(l[i] - l1[j]) <= 1 and l[i] != 0 and (l1[j] != 0):
			k = k + 1
			l[i] = 0
			l1[j] = 0
			break
print(k)


n = int(input())
b = list(map(int, input().strip().split()))
m = int(input())
g = list(map(int, input().strip().split()))
g_mp = {}
for i in range(m):
	if g[i] not in g_mp:
		g_mp[g[i]] = 1
	else:
		g_mp[g[i]] += 1
ans = 0
b = sorted(b)
for i in range(n):
	if b[i] - 1 in g_mp and g_mp[b[i] - 1] > 0:
		ans += 1
		g_mp[b[i] - 1] -= 1
		continue
	if b[i] in g_mp and g_mp[b[i]] > 0:
		ans += 1
		g_mp[b[i]] -= 1
		continue
	if b[i] + 1 in g_mp and g_mp[b[i] + 1] > 0:
		ans += 1
		g_mp[b[i] + 1] -= 1
		continue
print(ans)


import math
input()
a = list(map(int, input().split(' ')))
a.sort()
input()
b = list(map(int, input().split(' ')))
b.sort()
cnt = 0
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			cnt = cnt + 1
			b[j] = -1
			break
print(cnt)


no_of_boy = int(input())
boys = input().split(' ')
no_of_girl = int(input())
girls = input().split(' ')
boys = [int(i) for i in boys]
girls = [int(i) for i in girls]
boys.sort()
girls.sort()
pair_count = 0
i = 0
j = 0
while i < no_of_boy and j < no_of_girl:
	if abs(boys[i] - girls[j]) <= 1:
		pair_count += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(pair_count)


b = int(input())
sb = list(map(int, input().split(' ')))
g = int(input())
sg = list(map(int, input().split(' ')))
sb.sort()
sg.sort()
c = 0
for i in range(b):
	for j in range(g):
		if abs(sb[i] - sg[j]) <= 1:
			c += 1
			sg[j] = 1000
			break
print(c)


import sys
t = 1
for ___ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	d = [0] * (m + 1)
	ans = 0
	for i in range(n):
		for j in range(m):
			if abs(l1[i] - l2[j]) <= 1 and d[j] == 0:
				d[j] = 1
				ans += 1
				break
	print(ans)


import math
n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
(i, j, k) = (0, 0, 0)
while True:
	if i == n:
		break
	if j == m:
		break
	if math.fabs(a[i] - b[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(k)


import sys

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	res = 0
	while len(a) != 0 and len(b) != 0:
		if a[0] > b[0] + 1:
			b.pop(0)
		elif b[0] > a[0] + 1:
			a.pop(0)
		else:
			res += 1
			b.pop(0)
			a.pop(0)
	print(res)
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = sorted(LI())
	m = I()
	b = sorted(LI())
	r = 0
	i = j = 0
	while i < n and j < m:
		if abs(a[i] - b[j]) <= 1:
			r += 1
			i += 1
			j += 1
		elif a[i] < b[j]:
			i += 1
		else:
			j += 1
	return r
print(main())


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
i = 0
j = 0
count = 0
while True:
	if i == n or j == m:
		break
	dif = abs(boys[i] - girls[j])
	if dif <= 1:
		count += 1
		i += 1
		j += 1
	elif boys[i] > girls[j]:
		j += 1
	elif boys[i] < girls[j]:
		i += 1
print(count)


n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l1c = list(l1)
a = 0
b = 0
ans = 0
l.sort()
l1.sort()
l1c.sort()
for i in range(len(l)):
	if l[i] - 1 in l1:
		ans += 1
		l1.remove(l[i] - 1)
	elif l[i] in l1:
		ans += 1
		l1.remove(l[i])
	elif l[i] + 1 in l1:
		ans += 1
		l1.remove(l[i] + 1)
ans2 = 0
for i in range(len(l1c)):
	if l1c[i] - 1 in l:
		ans2 += 1
		l.remove(l1c[i] - 1)
	elif l1c[i] in l:
		ans2 += 1
		l.remove(l1c[i])
	elif l1c[i] + 1 in l:
		ans2 += 1
		l.remove(l1c[i] + 1)
print(max(ans, ans2))


def countFunc(boys, girls):
	n = len(boys)
	m = len(girls)
	count = 0
	j = 0
	for i in range(n):
		boySkill = boys[i]
		while j < m:
			if girls[j] > boySkill + 1:
				break
			elif boySkill - 1 <= girls[j] <= boySkill + 1:
				count += 1
				j += 1
				break
			j += 1
	return count
n = int(input())
boys = [int(x) for x in input().split(' ')]
m = int(input())
girls = [int(x) for x in input().split(' ')]
boys.sort()
girls.sort()
count = 0
if n > m:
	count = countFunc(girls, boys)
else:
	count = countFunc(boys, girls)
print(count)


nb = int(input())
arrb = list(map(int, input().split()))
ng = int(input())
arrg = list(map(int, input().split()))
num = 0
arrb.sort()
arrg.sort()
for i in range(nb):
	for j in range(ng):
		if (arrb[i] != 0 and arrg[j] != 0) and (arrb[i] == arrg[j] + 1 or arrb[i] == arrg[j] - 1 or arrb[i] == arrg[j]):
			num = num + 1
			arrb[i] = 0
			arrg[j] = 0
print(num)


n = int(input())
boys = list(map(int, input().split(' ')))
boys.sort()
m = int(input())
girls = list(map(int, input().split(' ')))
girls.sort()
i = 0
for boy in boys:
	for girl in girls:
		if abs(boy - girl) <= 1:
			i += 1
			girls.remove(girl)
			break
print(i)


n = int(input())
l1 = [int(y) for y in input().split()]
m = int(input())
l2 = [int(y) for y in input().split()]
l1.sort()
l2.sort()
c = 0
for i in range(n):
	x = l1[i]
	left = 0
	right = len(l2) - 1
	ind = -1
	mid = 0
	while left <= right:
		mid = (left + right) // 2
		if l2[mid] == x:
			ind = mid
			right = mid - 1
		elif l2[mid] < x:
			if x - l2[mid] == 1:
				ind = mid
				right = mid - 1
			else:
				left = mid + 1
		else:
			if l2[mid] - x == 1:
				ind = mid
			right = mid - 1
	if ind != -1:
		c += 1
		l2.remove(l2[ind])
print(c)


len1 = input()
boys = sorted(input().split(' '))
len2 = input()
girls = sorted(input().split(' '))
for (i, e) in enumerate(boys):
	boys[i] = int(e)
for (i, e) in enumerate(girls):
	girls[i] = int(e)
boys = sorted(boys)
girls = sorted(girls)
pairs = 0
index1 = 0
index2 = 0
while True:
	if int(boys[index1]) > int(girls[index2]) + 1:
		index2 += 1
	elif int(boys[index1]) < int(girls[index2]) - 1:
		index1 += 1
	else:
		pairs += 1
		index1 += 1
		index2 += 1
	if index1 == len(boys) or index2 == len(girls):
		break
print(pairs)


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
n = int(input())
a = get_array()
m = int(input())
b = get_array()
a.sort()
b.sort()
i = 0
j = 0
c = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		i = i + 1
		j = j + 1
		c = c + 1
	elif a[i] - b[j] > 1:
		j = j + 1
	else:
		i = i + 1
print(c)


import sys, threading, os.path
import collections, heapq, math, bisect
import string
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	boys = list(map(int, input.readline().split()))
	m = int(input.readline())
	girls = list(map(int, input.readline().split()))
	boys.sort()
	girls.sort()
	sol = 0
	for i in range(len(boys)):
		for j in range(len(girls)):
			if girls[j] == -1:
				continue
			if abs(boys[i] - girls[j]) <= 1:
				sol += 1
				girls[j] = -1
				break
	output = sol
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


nb = int(input())
boys = list(map(int, input().split()))
ng = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
l1 = []
l2 = []
if len(boys) >= len(girls):
	for i in range(len(boys)):
		for j in range(len(girls)):
			if abs(boys[i] - girls[j]) <= 1:
				if i not in l1 and j not in l2:
					l1.append(i)
					l2.append(j)
else:
	for i in range(len(girls)):
		for j in range(len(boys)):
			if abs(girls[i] - boys[j]) <= 1:
				if i not in l1 and j not in l2:
					l1.append(i)
					l2.append(j)
l3 = l2 + l1
print(len(l3) // 2)


import sys
import random
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
m = int(input())
boys = get_array()
n = int(input())
girls = get_array()
boys.sort()
girls.sort()
ptr1 = 0
ptr2 = 0
count = 0
while ptr1 < m and ptr2 < n:
	if abs(boys[ptr1] - girls[ptr2]) <= 1:
		count += 1
		ptr1 += 1
		ptr2 += 1
	elif boys[ptr1] < girls[ptr2]:
		ptr1 += 1
	else:
		ptr2 += 1
print(count)


n_boys = int(input())
boys_skills = sorted(list(map(int, input().split())))
n_girls = int(input())
girls_skills = sorted(list(map(int, input().split())))
i = 0
j = 0
result = 0
while i < n_boys and j < n_girls:
	if abs(boys_skills[i] - girls_skills[j]) <= 1:
		result += 1
		i += 1
		j += 1
	elif boys_skills[i] < girls_skills[j]:
		i += 1
	else:
		j += 1
print(result)


n = int(input())
N = [int(x) for x in input().split()]
m = int(input())
M = [int(x) for x in input().split()]
N.sort(reverse=True)
M.sort(reverse=True)
i = 0
j = 0
pairs = 0
while i < len(N) and j < len(M):
	delta = N[i] - M[j]
	if delta > 1:
		i += 1
	elif delta < -1:
		j += 1
	else:
		i += 1
		j += 1
		pairs += 1
print(pairs)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def solution():
	n = Int()
	a = List()
	m = Int()
	b = List()
	a.sort()
	b.sort()
	c = 0
	for i in a:
		for j in b:
			if abs(i - j) <= 1:
				c += 1
				b.remove(j)
				break
	print(c)
solution()


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
tot = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			tot += 1
			b[j] = 10000
			break
print(tot)


c = int(input())
a = [int(i) for i in input().split()]
d = int(input())
b = [int(i) for i in input().split()]
if c > d:
	(a, b, c, d) = (b, a, d, c)
a.sort()
n = 0
for i in range(c):
	n += 1
	if a[i] - 1 in b:
		b.remove(a[i] - 1)
	elif a[i] in b:
		b.remove(a[i])
	elif a[i] + 1 in b:
		b.remove(a[i] + 1)
	else:
		n -= 1
print(n)


c = 0
w = int(input())
b = [int(i) for i in input().split()]
w1 = int(input())
g = [int(i) for i in input().split()]
b.sort()
g.sort()
for i in range(len(b)):
	for j in range(len(g)):
		if abs(b[i] - g[j]) <= 1:
			c += 1
			g.remove(g[j])
			break
print(c)


n = int(input())
boys = sorted(map(int, input().strip().split()))
m = int(input())
girls = sorted(map(int, input().strip().split()))
b = g = answer = 0
while b < n and g < m:
	if abs(boys[b] - girls[g]) <= 1:
		answer += 1
		b += 1
		g += 1
	elif boys[b] > girls[g]:
		g += 1
	else:
		b += 1
print(answer)


n = int(input())
boys = [int(i) for i in input().split()]
boys.sort()
m = int(input())
girls = [int(i) for i in input().split()]
girls.sort()
(c, ni, mi) = (0, 0, 0)
while ni < n and mi < m:
	if girls[mi] < boys[ni] - 1:
		mi += 1
	elif girls[mi] <= boys[ni] + 1:
		c += 1
		ni += 1
		mi += 1
	else:
		ni += 1
print(c)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(boys[i] - girls[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(ans)


def solve(boys, girls, n, m):
	(ans, i, j) = (0, 0, 0)
	boys.sort()
	girls.sort()
	for i in range(n):
		for j in range(m):
			if abs(boys[i] - girls[j]) <= 1:
				ans += 1
				girls[j] = 100000
				break
	return ans
n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]
print(solve(boys, girls, n, m))


nb = int(input())
b = list(map(int, input().split()))
ng = int(input())
g = list(map(int, input().split()))
x = 0
g.sort()
b.sort()
dp = [[0] * nb for _ in range(ng)]
if abs(b[0] - g[0]) < 2:
	dp[0][0] = 1
for i in range(ng):
	for j in range(nb):
		if i != 0 or j != 0:
			if i == 0:
				if abs(g[i] - b[j]) < 2:
					dp[i][j] = 1
				else:
					dp[i][j] = dp[i][j - 1]
			elif j == 0:
				if abs(g[i] - b[j]) < 2:
					dp[i][j] = 1
				else:
					dp[i][j] = dp[i - 1][j]
			elif abs(g[i] - b[j]) < 2:
				dp[i][j] = max(1 + dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1])
			else:
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
print(dp[ng - 1][nb - 1])


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1

def number(x, y):
	x.sort()
	y.sort()
	count = 0
	for i in range(len(x)):
		for j in range(len(y)):
			if abs(x[i] - y[j]) <= 1:
				count += 1
				y.pop(j)
				break
	return count
input()
x = read_array()
input()
y = read_array()
print(number(x, y))


n = int(input().strip())
boys = list(map(int, input().strip().split()))
m = int(input().strip())
girls = list(map(int, input().strip().split()))
boys.sort()
girls.sort()
pairs = 0
for b in range(n):
	for g in range(len(girls)):
		if boys[b] == girls[g]:
			pairs += 1
			girls.pop(g)
			break
		if abs(boys[b] - girls[g]) == 1:
			pairs += 1
			girls.pop(g)
			break
print(pairs)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = sorted(list(map(int, input().split())))
	m = int(input())
	b = sorted(list(map(int, input().split())))
	(i, j, cnt) = (0, 0, 0)
	while i < n and j < m:
		if abs(a[i] - b[j]) <= 1:
			i += 1
			j += 1
			cnt += 1
		elif a[i] < b[j]:
			i += 1
		else:
			j += 1
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline()
boys = sys.stdin.readline().strip().split()
boys = list(map(int, boys))
input = sys.stdin.readline()
girls = sys.stdin.readline().strip().split()
girls = list(map(int, girls))
boys = sorted(boys, reverse=True)
girls = sorted(girls, reverse=True)
i = 0
j = 0
parejas = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		parejas += 1
		i += 1
		j += 1
	elif boys[i] == girls[j]:
		if abs(boys[i + 1] - girls[j]) < abs(boys[i] - girls[j + 1]):
			i += 1
		else:
			j += 1
	elif boys[i] == min(boys[i], girls[j]):
		j += 1
	elif girls[j] == min(boys[i], girls[j]):
		i += 1
print(parejas)


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n1 = I()
	b = LI()
	b.sort()
	n2 = I()
	g = LI()
	g.sort()
	c = 0
	l = []
	for i in range(n1):
		for j in range(n2):
			d = abs(b[i] - g[j])
			if d <= 1 and j not in l:
				c += 1
				l.append(j)
				break
	pf(str(c))
main()


def sol():
	n = int(input())
	A = [int(i) for i in input().split()]
	m = int(input())
	B = [int(i) for i in input().split()]
	A.sort()
	B.sort()
	i = j = 0
	s = []
	VA = [0] * n
	VB = [0] * m
	for i in range(n):
		for j in range(m):
			if VA[i] == 0 and VB[j] == 0 and (abs(A[i] - B[j]) <= 1):
				VA[i] = VB[j] = 1
				s.append([A[i], B[j]])
	print(len(s))
sol()


input()
in_boys_skill = input()
input()
in_girls_skill = input()
boys_skill = sorted([int(x) for x in in_boys_skill.split()])
girls_skill = sorted([int(x) for x in in_girls_skill.split()])
count = 0
for bs in boys_skill:
	for gs in girls_skill:
		if abs(bs - gs) <= 1:
			count += 1
			girls_skill.remove(gs)
			break
print(count)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
count = 0
(b, g) = (0, 0)
while b < n and g < m:
	diff = boys[b] - girls[g]
	if abs(diff) <= 1:
		b += 1
		g += 1
		count += 1
	elif diff > 0:
		g += 1
	else:
		b += 1
print(count)


n = int(input())
l = list(map(int, input().split()))
n1 = int(input())
ll = list(map(int, input().split()))
d = {}
for i in range(n1):
	if ll[i] not in d:
		d[ll[i]] = 1
	else:
		d[ll[i]] += 1
cnt = 0
l.sort()
for i in range(n):
	if l[i] - 1 in d and d[l[i] - 1] > 0:
		cnt += 1
		d[l[i] - 1] -= 1
	elif l[i] in d and d[l[i]] > 0:
		cnt += 1
		d[l[i]] -= 1
	elif l[i] + 1 in d and d[l[i] + 1] > 0:
		cnt += 1
		d[l[i] + 1] -= 1
print(cnt)


n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
boy.sort()
girl.sort()
lb = len(boy)
lg = len(girl)
if lb <= lg:
	arr1 = boy
	arr2 = girl
else:
	arr1 = girl
	arr2 = boy
x = y = 0
count = 0
while x < len(arr1) and y < len(arr2):
	if abs(arr1[x] - arr2[y]) in [0, 1]:
		count += 1
		x += 1
		y += 1
	elif arr1[x] > arr2[y]:
		y += 1
	else:
		x += 1
print(count)


boys = int(input())
boysskill = [*map(int, input().split())]
girls = int(input())
girlsskill = [*map(int, input().split())]
pairs = 0
boysskill.sort()
girlsskill.sort()
for i in range(boys):
	for j in range(girls):
		if girlsskill[j]:
			m = boysskill[i] - girlsskill[j]
			if -2 < m < 2:
				girlsskill[j] = 0
				pairs += 1
				break
print(pairs)


n = int(input())
bl = list(map(int, input().split()))
m = int(input())
gl = list(map(int, input().split()))
p = 0
bl.sort()
gl.sort()
for i in range(len(bl)):
	for j in range(len(gl)):
		if abs(bl[i] - gl[j]) <= 1:
			gl.pop(j)
			p += 1
			break
print(p)


n = int(input())
bk = [int(x) for x in input().split()]
bk.sort()
m = int(input())
gk = [int(x) for x in input().split()]
gk.sort()
pair = 0
for i in range(n):
	for j in range(m):
		differ = bk[i] - gk[j]
		if abs(differ) <= 1:
			pair += 1
			gk[j] = 102
			break
print(pair)


m = int(input())
l = []
l = list(map(int, input().split()))
n = int(input())
ll = []
ll = list(map(int, input().split()))
l.sort()
ll.sort()
c = 0
for i in range(len(l)):
	j = 0
	while j < len(ll):
		if abs(l[i] - ll[j]) <= 1:
			ll.pop(j)
			c += 1
			break
		elif abs(l[i] - ll[j]) > 1:
			if ll[j] < l[i]:
				ll.pop(j)
			else:
				break
print(c)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
flag = True
while flag:
	flag = False
	for b in boys:
		if b - 1 not in girls and b not in girls and (b + 1 not in girls):
			boys.remove(b)
			flag = True
	for g in girls:
		if g - 1 not in boys and g not in boys and (g + 1 not in boys):
			girls.remove(g)
			flag = True
c = 0
for b in boys:
	if b - 1 in girls:
		girls.remove(b - 1)
		c += 1
	elif b in girls:
		girls.remove(b)
		c += 1
	elif b + 1 in girls:
		girls.remove(b + 1)
		c += 1
print(c)


def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import *
(n, a, m, b) = (int(input()), sorted(arr_inp()), int(input()), sorted(arr_inp()))
(c, p1, p2) = [0] * 3
while p1 != n and p2 != m:
	if abs(a[p1] - b[p2]) <= 1:
		c += 1
		p1 += 1
		p2 += 1
	elif a[p1] < b[p2]:
		p1 += 1
	else:
		p2 += 1
print(c)


import sys
n = int(sys.stdin.readline().rstrip())
nn = list(map(int, sys.stdin.readline().rstrip().split()))
m = int(sys.stdin.readline().rstrip())
mm = list(map(int, sys.stdin.readline().rstrip().split()))
nn.sort()
mm.sort()
pn = 0
pm = 0
sol = 0
while pn < n and pm < m:
	temp = abs(nn[pn] - mm[pm])
	if temp <= 1:
		sol += 1
		pn += 1
		pm += 1
	elif nn[pn] < mm[pm]:
		pn += 1
	else:
		pm += 1
print(sol)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().split()]
b.sort()
c = 0
for i in range(n):
	if a[i] == -1:
		continue
	else:
		for j in range(m):
			if abs(a[i] - b[j]) < 2:
				c += 1
				a[i] = -1
				b[j] = -1
				break
print(c)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) < 2:
			ans += 1
			girls[j] = 1212
			break
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
a.sort()
b.sort()
i = 0
j = 0
t = 0
total = 0
if m >= n:
	while i < n:
		for j in range(t, m):
			if abs(a[i] - b[j]) <= 1:
				total = total + 1
				t = j + 1
				break
		i = i + 1
else:
	i = 0
	j = 0
	t = 0
	while i < m:
		for j in range(t, n):
			if abs(a[j] - b[i]) <= 1:
				total = total + 1
				t = j + 1
				break
		i = i + 1
print(total)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
i = 0
ans = 0
while i < n:
	j = 0
	while j < len(b):
		if abs(a[i] - b[j]) <= 1:
			b.pop(j)
			ans += 1
			break
		j += 1
	i += 1
	if len(b) == 0:
		break
print(ans)


R = lambda : map(int, input().split())
n = int(input())
m_skills = sorted(list(R()))
m = int(input())
w_skills = sorted(list(R()))
N = max(m, n)
j_list = []
i_list = []
res = 0
for i in range(n):
	for j in range(m):
		if abs(m_skills[i] - w_skills[j]) in [0, 1] and j not in j_list:
			j_list.append(j)
			res += 1
			break
print(res)


def ball(n, b, m, g):
	pair = 0
	i = 0
	j = 0
	b = sorted(b)
	g = sorted(g)
	while i < n and j < m:
		if abs(b[i] - g[j]) <= 1:
			pair += 1
			i += 1
			j += 1
		elif b[i] - g[j] < 1:
			i += 1
		elif b[i] - g[j] > 1:
			j += 1
	print(pair)
n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
ball(n, b, m, g)


def D(numbers, i, k, j):
	(x, y) = (i, k + 1)
	count = 0
	while x <= k and y <= j:
		if abs(numbers[x] - numbers[y]) <= 1:
			count += 1
			x += 1
			y += 1
		elif numbers[x] < numbers[y]:
			x += 1
		else:
			y += 1
	return count
input()
a = sorted(list(map(int, input().split())))
b = [5, 1, 5, 7, 9]
input()
b = sorted(list(map(int, input().split())))
print(D(a + b, 0, len(a) - 1, len(a) + len(b) - 1))


n = int(input())
l = sorted(list(map(int, input().split())))
m = int(input())
l1 = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
	for x in range(m):
		if abs(l[i] - l1[x]) <= 1:
			ans += 1
			l1[x] = 1000
			break
print(ans)


n = int(input())
a = [int(j) for j in input().split()]
n2 = int(input())
b = [int(j) for j in input().split()]
a.sort()
b.sort()
ans = 0
for i in range(n):
	for j in range(n2):
		if abs(a[i] - b[j]) <= 1:
			ans += 1
			b[j] = 1000
			break
print(ans)


def max_parejas():
	n = int(input())
	boys_skills = input().split(' ')
	m = int(input())
	girls_skills = input().split(' ')
	boys_skills = [int(skill) for skill in boys_skills]
	girls_skills = [int(skill) for skill in girls_skills]
	boys_skills.sort()
	girls_skills.sort()
	pares = 0
	i = 0
	while len(boys_skills) > 0 and len(girls_skills) > 0:
		boy = boys_skills[0]
		girl = girls_skills[0]
		if abs(boy - girl) <= 1:
			pares += 1
			girls_skills.pop(0)
			boys_skills.pop(0)
		elif girl < boy:
			girls_skills.pop(0)
		else:
			boys_skills.pop(0)
	print(pares)
max_parejas()


n = int(input())
s = input().split(' ')
a = []
for i in range(n):
	a.append(int(s[i]))
m = int(input())
q = input().split(' ')
b = []
for i in range(m):
	b.append(int(q[i]))
a.sort()
b.sort()
(la, lb) = (len(a), len(b))
ia = 0
count = 0
for ib in range(lb):
	while True:
		if ia >= la:
			break
		if a[ia] > b[ib] + 1:
			break
		if a[ia] >= b[ib] - 1:
			count += 1
			ia += 1
			break
		ia += 1
print(count)


input()
a = list(map(int, input().split()))
input()
b = list(map(int, input().split()))
a.sort()
b.sort()
k = 0
for e in a:
	i = 0
	while i < len(b):
		if e - 1 <= b[i] <= e + 1:
			b.pop(i)
			k += 1
			break
		elif b[i] > e + 1:
			break
		i += 1
print(k)


n = int(input(''))
a = list(map(int, input('').split()))
m = int(input(''))
b = list(map(int, input('').split()))
a.sort()
b.sort()
i1 = 0
i2 = 0
pairs = 0
while True:
	if a[i1] == b[i2] or a[i1] == b[i2] + 1 or a[i1] == b[i2] - 1:
		pairs += 1
		i1 += 1
		i2 += 1
	elif a[i1] < b[i2] - 1:
		i1 += 1
	elif b[i2] < a[i1] - 1:
		i2 += 1
	if i1 >= n or i2 >= m:
		break
print(pairs)


m = int(input())
boys = list(map(int, input().split()))
n = int(input())
girls = list(map(int, input().split()))
nop = 0
boys.sort()
girls.sort()
if m >= n:
	morepeople = boys
	lesspeople = girls
else:
	morepeople = girls
	lesspeople = boys
for i in lesspeople:
	if i - 1 in morepeople:
		nop += 1
		morepeople.remove(i - 1)
	elif i in morepeople:
		nop += 1
		morepeople.remove(i)
	elif i + 1 in morepeople:
		nop += 1
		morepeople.remove(i + 1)
print(nop)


boys_count = int(input())
boys_skills = sorted([int(x) for x in input().split()])
girls_count = int(input())
girls_skills = sorted([int(x) for x in input().split()])
dp = [[0 for _ in range(boys_count)] for _ in range(girls_count)]
for g in range(girls_count):
	if abs(girls_skills[g] - boys_skills[0]) <= 1:
		dp[g][0] = 1
	elif g > 0:
		dp[g][0] = dp[g - 1][0]
for b in range(boys_count):
	if abs(girls_skills[0] - boys_skills[b]) <= 1:
		dp[0][b] = 1
	elif b > 0:
		dp[0][b] = dp[0][b - 1]
for g in range(1, girls_count):
	for b in range(1, boys_count):
		dp[g][b] = max(dp[g - 1][b], dp[g][b - 1], 1 + dp[g - 1][b - 1] if abs(girls_skills[g] - boys_skills[b]) <= 1 else -1)
print(dp[-1][-1])


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
pairs = 0
flag = 0
try:
	for i in range(n):
		for j in range(flag, m):
			if abs(boys[i] - girls[j]) <= 1:
				pairs += 1
				flag = j + 1
				break
			elif girls[j] > boys[i]:
				break
except IndexError:
	pass
print(pairs)


boys = int(input())
boys_skill = [int(i) for i in input().split(' ')]
boys_skill.sort()
girls = int(input())
girls_skill = [int(i) for i in input().split(' ')]
girls_skill.sort()
pairs = 0
i = 0
j = 0
while i < boys and j < girls:
	diff = boys_skill[i] - girls_skill[j]
	if abs(diff) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif diff < 0:
		i += 1
	else:
		j += 1
print(pairs)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
res = 0
for i in range(len(boys)):
	for j in range(len(girls)):
		if abs(boys[i] - girls[j]) <= 1:
			res += 1
			girls[j] = -2
			break
print(res)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) < 2:
			ans += 1
			b[j] = 1000000000.0
			break
print(ans)


n = input()
a = input()
m = input()
b = input()
a_list = [int(num) for num in a.split(' ')]
b_list = [int(num) for num in b.split(' ')]
a_list = sorted(a_list)
b_list = sorted(b_list)
a_index = 0
b_index = 0
parejas = 0
for i in range(10000):
	if (a_list[a_index] - b_list[b_index]) ** 2 <= 1:
		a_index += 1
		b_index += 1
		parejas += 1
	elif a_list[a_index] > b_list[b_index]:
		b_index += 1
	else:
		a_index += 1
	if a_index == len(a_list) or b_index == len(b_list):
		break
print(parejas)


a = int(input())
a_ = list(map(int, input().split(' ')))
a_.sort()
b = int(input())
b_ = list(map(int, input().split(' ')))
b_.sort()
c = 0
n = 0
rem = 0
for every in range(len(a_)):
	for ever in range(len(b_)):
		if a_[every] == b_[ever] or a_[every] == b_[ever] - 1 or a_[every] == b_[ever] + 1:
			rem = ever
			c += 1
			b_.pop(rem)
			break
print(c)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
result = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			result = result + 1
			girls[j] = 10000
			break
print(result)


n = int(input())
boys_skills = sorted(list(map(int, input().split())))
m = int(input())
girls_skills = sorted(list(map(int, input().split())))
boys_index = girls_index = 0
pairs_count = 0
while True:
	if boys_index >= n or girls_index >= m:
		break
	cur_boys_skill = boys_skills[boys_index]
	cur_girls_skill = girls_skills[girls_index]
	if abs(cur_boys_skill - cur_girls_skill) > 1:
		if cur_girls_skill > cur_boys_skill:
			boys_index += 1
		else:
			girls_index += 1
	else:
		pairs_count += 1
		boys_index += 1
		girls_index += 1
print(pairs_count)


from collections import Counter
input()
boy = Counter(map(int, input().split()))
input()
girl = Counter(map(int, input().split()))
pair = 0
for b in sorted(boy):
	for _ in range(boy[b]):
		for g in (b - 1, b, b + 1):
			if girl[g]:
				girl[g] -= 1
				pair += 1
				break
		else:
			break
print(pair)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
l = []
a.sort()
b.sort()
k = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1 and j not in l:
			k += 1
			l.append(j)
			break
print(k)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
visited = [0] * 100
ans = 0
a = sorted(a)
b = sorted(b)
for x in range(n):
	for y in range(m):
		if abs(a[x] - b[y]) <= 1 and visited[y] == 0:
			visited[y] = 1
			ans += 1
			break
print(ans)


b = int(input())
boys = list(map(int, input().split(' ')))
g = int(input())
girls = list(map(int, input().split(' ')))
boys.sort()
girls.sort()
(p1, p2) = (0, 0)
ctr = 0
while p1 < b and p2 < g:
	if abs(boys[p1] - girls[p2]) <= 1:
		ctr += 1
		p1 += 1
		p2 += 1
	elif boys[p1] < girls[p2]:
		p1 += 1
	else:
		p2 += 1
print(ctr)


my_male = []
my_fmle = []
num_m = int(input())
my_male = sorted(map(int, input().split()))
len_m = len(my_male)
num_f = int(input())
my_fmle = sorted(map(int, input().split()))
len_f = len(my_fmle)
cnt = 0
k = 1
if len_m >= len_f:
	for i in range(len_m):
		for j in range(len_f):
			distance = abs(my_male[i] - my_fmle[j])
			if distance == 0 or distance == 1:
				cnt += 1
				my_fmle.pop(j)
				break
		len_f = len(my_fmle)
else:
	for i in range(len_f):
		for j in range(len_m):
			distance = abs(my_fmle[i] - my_male[j])
			if distance == 0 or distance == 1:
				cnt += 1
				my_male.pop(j)
				break
		len_m = len(my_male)
print(cnt)


n = int(input())
na = list(map(int, input().split()))
m = int(input())
ma = list(map(int, input().split()))
na.sort()
ma.sort()
count = 0
for i in range(n):
	for j in range(m):
		if abs(na[i] - ma[j]) <= 1:
			count += 1
			ma[j] = 1000
			break
print(count)


m = input()
a = [int(x) for x in input().split(' ')]
n = input()
b = [int(x) for x in input().split(' ')]
a.sort()
b.sort()
count = 0
for i in a:
	for (index, j) in enumerate(b):
		if abs(j - i) <= 1:
			b[index] = 1000
			count += 1
			break
print(count)


number_g = int(input())
girls = sorted([int(x) for x in input().split()])
number_b = int(input())
boys = sorted([int(x) for x in input().split()])
index_g = 0
index_b = 0
num = 0
while index_g < number_g and index_b < number_b:
	if abs(girls[index_g] - boys[index_b]) <= 1:
		num = num + 1
		index_g = index_g + 1
		index_b = index_b + 1
	elif girls[index_g] > boys[index_b]:
		index_b = index_b + 1
	else:
		index_g = index_g + 1
print(num)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
ans = 0
la = 0
lb = 0
while la < N and lb < M:
	if abs(A[la] - B[lb]) <= 1:
		ans += 1
		la += 1
		lb += 1
	elif A[la] > B[lb]:
		lb += 1
	else:
		la += 1
print(ans)


num_boys = int(input())
boys_skills = [int(s) for s in input().strip().split()]
num_girls = int(input())
girls_skills = [int(s) for s in input().strip().split()]
boys_skills.sort()
girls_skills.sort()
count = 0
while boys_skills and girls_skills:
	boy_skill = boys_skills.pop(0)
	for j in range(len(girls_skills)):
		if abs(boy_skill - girls_skills[j]) <= 1:
			count += 1
			girls_skills.pop(j)
			break
print(count)


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(eval, o or split()))

def num():
	return eval(line())

def mainloop(tcid=1):
	n = num()
	a = nums()
	m = num()
	b = nums()
	a.sort()
	b.sort()

	@functools.lru_cache(None)
	def rec(ii, jj):
		if ii == n and jj == m:
			return 0
		if ii == n or jj == m:
			return 0
		aa = a[ii]
		bb = b[jj]
		return max(rec(ii + 1, jj), rec(ii, jj + 1), compute(rec(ii + 1, jj + 1), lambda zzz: -1 if zzz < 0 else 1 + zzz) if abs(aa - bb) < 2 else 0)
	print(rec(0, 0))
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


boys = int(input())
boyList = [int(i) for i in input().split()]
girls = int(input())
girlList = [int(i) for i in input().split()]
boyList.sort()
girlList.sort()
countPair = 0
for i in range(boys):
	for j in range(girls):
		if abs(boyList[i] - girlList[j]) <= 1:
			countPair += 1
			girlList[j] = -11
			break
print(countPair)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = int(input())
b = list(map(int, input().split()))
b = sorted(b)
it1 = 0
it2 = 0
res = 0
while it1 < n and it2 < m:
	if abs(a[it1] - b[it2]) <= 1:
		res += 1
		it1 += 1
		it2 += 1
	elif a[it1] < b[it2]:
		it1 += 1
	else:
		it2 += 1
print(res)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
n = sInt()
a = lInt()
m = sInt()
b = lInt()
if n > m:
	(n, m) = (m, n)
	(a, b) = (b, a)
a.sort()
b.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			b[j] = 1000
			ans += 1
			break
print(ans)


n = int(input())
lst = [int(x) for x in input().split()]
lst.sort()
m = int(input())
lst2 = [int(x) for x in input().split()]
lst2.sort()
count = 0
for i in lst:
	if i - 1 in lst2:
		count += 1
		lst2.remove(i - 1)
	elif i in lst2:
		count += 1
		lst2.remove(i)
	elif i + 1 in lst2:
		count += 1
		lst2.remove(i + 1)
	else:
		pass
print(count)


def dfs(v):
	if was[v] == clr:
		return False
	was[v] = clr
	for u in g[v]:
		if mt[u] == -1 or dfs(mt[u]):
			mt[u] = v
			return True
	return False
read = lambda : map(int, input().split())
n = int(input())
a = list(read())
m = int(input())
b = list(read())
k = n + m + 1
g = [list() for i in range(k)]
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			g[i + 1].append(j + n + 1)
			g[j + n + 1].append(i + 1)
clr = 1
was = [0] * k
mt = [-1] * k
cnt = 0
for i in range(1, n + 1):
	if dfs(i):
		cnt += 1
	clr += 1
print(cnt)


b = int(input())
boys = [int(x) for x in input().split()]
g = int(input())
girls = [int(x) for x in input().split()]
boys.sort()
girls.sort()
count = 0
for i in range(b):
	for j in range(g):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = float('inf')
			count += 1
			break
print(count)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
bv = [0] * n
gv = [0] * m
c = 0
b.sort()
g.sort()
for i in range(0, n):
	for j in range(0, m):
		if abs(b[i] - g[j]) <= 1 and gv[j] == 0 and (bv[i] == 0):
			gv[j] = 1
			bv[i] = 1
			c += 1
print(c)


n = int(input())
nseq = sorted(map(int, input().split()))
m = int(input())
mseq = sorted(map(int, input().split()))
i = 0
j = 0
ans = 0
while i != n and j != m:
	if abs(nseq[i] - mseq[j]) > 1:
		if nseq[i] > mseq[j]:
			j += 1
		else:
			i += 1
	else:
		ans += 1
		i += 1
		j += 1
print(ans)


input()
a = sorted(map(int, input().split(' ')))
input()
b = sorted(map(int, input().split(' ')))
(i, j, k) = (0, 0, 0)
while i < len(a) and j < len(b):
	if abs(a[i] - b[j]) <= 1:
		k += 1
		j += 1
		i += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(k)


a = int(input())
boy = [int(x) for x in input().split()]
boy.sort()
b = int(input())
girl = [int(y) for y in input().split()]
girl.sort()
count = 0
for i in range(0, a):
	for j in range(0, b):
		if boy[i] == girl[j] or boy[i] == girl[j] + 1 or boy[i] == girl[j] - 1:
			count += 1
			del boy[i]
			boy.insert(i, -100)
			del girl[j]
			girl.insert(j, -100)
			break
print(count)


n = int(input())
bois = [int(x) for x in input().split()]
m = int(input())
grils = [int(x) for x in input().split()]
bois.sort()
grils.sort()
dp = {}

def match(i, j):
	try:
		dp[str(i) + ' ' + str(j)] == -1
		return dp[str(i) + ' ' + str(j)]
	except:
		if bois[i] - grils[j] == 1:
			if i != n - 1 and j != m - 1:
				dp[str(i) + ' ' + str(j)] = max(1 + match(i + 1, j + 1), match(i, j + 1), match(i + 1, j))
			else:
				dp[str(i) + ' ' + str(j)] = 1
		elif bois[i] - grils[j] == -1:
			if i != n - 1 and j != m - 1:
				dp[str(i) + ' ' + str(j)] = max(1 + match(i + 1, j + 1), match(i + 1, j), match(i, j + 1))
			else:
				dp[str(i) + ' ' + str(j)] = 1
		elif bois[i] - grils[j] == 0:
			if i != n - 1 and j != m - 1:
				dp[str(i) + ' ' + str(j)] = max(1 + match(i + 1, j + 1), match(i + 1, j), match(i, j + 1))
			else:
				dp[str(i) + ' ' + str(j)] = 1
		elif bois[i] - grils[j] < 0:
			if i != n - 1:
				dp[str(i) + ' ' + str(j)] = match(i + 1, j)
			else:
				dp[str(i) + ' ' + str(j)] = 0
		elif j != m - 1:
			dp[str(i) + ' ' + str(j)] = match(i, j + 1)
		else:
			dp[str(i) + ' ' + str(j)] = 0
		return dp[str(i) + ' ' + str(j)]
print(match(0, 0))


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
pairs = 0
i = 0
while i < n:
	if a[i] - 1 in b:
		pairs += 1
		b.remove(a[i] - 1)
	elif a[i] in b:
		pairs += 1
		b.remove(a[i])
	elif a[i] + 1 in b:
		pairs += 1
		b.remove(a[i] + 1)
	i += 1
print(pairs)


n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
cnt = 0
(ua, ub) = (0, 0)
while ua < n and ub < m:
	if abs(A[ua] - B[ub]) <= 1:
		cnt += 1
		ua += 1
		ub += 1
	elif A[ua] > B[ub]:
		ub += 1
	else:
		ua += 1
print(cnt)


def solution():
	n = int(input())
	boys = list(map(int, input().split()))
	m = int(input())
	girls = list(map(int, input().split()))
	boys.sort()
	girls.sort()
	i = 0
	j = 0
	result = 0
	while i < len(boys) and j < len(girls):
		if abs(boys[i] - girls[j]) <= 1:
			result += 1
			i += 1
			j += 1
			continue
		if boys[i] > girls[j]:
			j += 1
		else:
			i += 1
	print(result)
solution()


boys = int(input())
boy_skill = list(map(int, input().split()))
girls = int(input())
girl_skill = list(map(int, input().split()))
boy_skill.sort()
girl_skill.sort()
i = 0
j = 0
count = 0
while i < len(boy_skill) and j < len(girl_skill):
	if boy_skill[i] - girl_skill[j] > 1:
		j += 1
	elif boy_skill[i] - girl_skill[j] < -1:
		i += 1
	else:
		count += 1
		j += 1
		i += 1
print(count)


def answer(a, b):
	count = 0
	for i in a:
		for j in b:
			if abs(i - j) <= 1:
				count += 1
				b.remove(j)
				break
	return print(count)
s = int(input())
r = sorted(list(map(int, input().split())))
t = int(input())
q = sorted(list(map(int, input().split())))
if s < t:
	answer(r, q)
else:
	answer(q, r)


boy = int(input())
temp = input()
temp = temp.split(' ')
bl = []
for x in temp:
	bl.append(int(x))
girl = int(input())
temp = input()
temp = temp.split(' ')
gl = []
for x in temp:
	gl.append(int(x))
bl.sort()
gl.sort()
count = 0
for x in bl:
	if x - 1 in gl:
		count += 1
		gl.remove(x - 1)
	elif x in gl:
		count += 1
		gl.remove(x)
	elif x + 1 in gl:
		count += 1
		gl.remove(x + 1)
print(count)


b = int(input())
bstr = input()
bstr = bstr.split(' ')
for i in range(b):
	bstr.append(int(bstr[0]))
	bstr.pop(0)
bstr.sort()
g = int(input())
gstr = input()
gstr = gstr.split(' ')
for i in range(g):
	gstr.append(int(gstr[0]))
	gstr.pop(0)
gstr.sort()
ans = 0
for i in range(b):
	for j in range(g):
		if abs(bstr[i] - gstr[j]) <= 1:
			ans += 1
			gstr[j] = 1001
			break
print(ans)


import math
n = int(input())
nn = input().split()
m = int(input())
mm = input().split()
an = []
am = []
for i in range(n):
	an.append(int(nn[i]))
for i in range(m):
	am.append(int(mm[i]))
an.sort()
am.sort()
ans = 0
for i in range(n):
	for j in range(len(am)):
		if abs(an[i] - am[j]) <= 1:
			am.remove(am[j])
			ans += 1
			break
print(ans)


import sys
import math
n = int(input())
boys = sorted([int(x) for x in input().strip().split()])
m = int(input())
girls = sorted([int(y) for y in input().strip().split()])
cnt = 0
flag = False
visited = [0 for k in range(m)]
for i in range(n):
	flag = False
	for j in range(m):
		if (abs(boys[i] - girls[j]) == 1 or boys[i] == girls[j]) and visited[j] == 0:
			cnt += 1
			visited[j] = 1
			flag = True
		if flag == True:
			break
print(cnt)


n = int(input())
boys = list(map(int, input().split()))
boys.sort()
m = int(input())
girls = list(map(int, input().split()))
girls.sort()
pairs = []

def main(pairs, girls, boys, n, m):
	try:
		dontUse = []
		for i in boys:
			for j in range(len(girls)):
				if j not in dontUse:
					if abs(i - girls[j]) < 2:
						dontUse.append(j)
						pairs.append([i, girls[j]])
						break
	except RuntimeError:
		pairs = []
		return pairs
	return pairs
main(pairs, girls, boys, n, m)
print(len(pairs))


n = int(input())
A = list(map(int, input().split(' ')[:n]))
m = int(input())
B = list(map(int, input().split(' ')[:m]))
counter = 0
A.sort()
B.sort()
for i in range(n):
	for j in range(m):
		if abs(A[i] - B[j]) <= 1:
			counter += 1
			A[i] = -10
			B[j] = -10
			break
print(counter)


import unittest
from random import randint
from sys import maxsize

class StressTest(unittest.TestCase):
	known_values = (([1, 4, 6, 2], [5, 1, 5, 7, 9], 3), ([1, 2, 3, 4], [10, 11, 12, 13], 0), ([1, 1, 1, 1, 1], [1, 2, 3], 2), ([30, 3, 1, 100, 15, 7, 9, 4], [14, 9, 11, 90, 5, 7, 11, 80], 4), ([], [], 0), ([1, 4], [100, 5], 1), ([1], [], 0))

	def test_known_cases(self):
		for (boys, girls, expected) in self.known_values:
			self.assertEqual(expected, NaiveSolution().pairs(boys, girls))

	def test_all_cases(self):
		while True:
			break

class NaiveSolution:

	def pairs(self, boys, girls):
		boys.sort(reverse=True)
		girls.sort(reverse=True)
		count = 0
		while boys != [] and girls != []:
			if abs(boys[-1] - girls[-1]) < 2:
				count += 1
				boys.pop()
				girls.pop()
			elif boys[-1] > girls[-1]:
				girls.pop()
			else:
				boys.pop()
		return count

class BestSolution:
	pass
n = int(input())
boys = [int(x) for x in input().strip().split()]
m = int(input())
girls = [int(x) for x in input().strip().split()]
ans = NaiveSolution().pairs(boys, girls)
print(ans)


n = int(input())
a = sorted(map(int, input().split()))
m = int(input())
b = sorted(map(int, input().split()))
ans = 0
f = [0] * m
for i in range(n):
	for j in range(m):
		if f[j] == 0 and -2 < a[i] - b[j] < 2:
			ans += 1
			f[j] = 1
			break
print(ans)


n = int(input())
bo = sorted([int(z) for z in input().split()])
m = int(input())
gi = sorted([int(z) for z in input().split()])
b = 0
g = 0
c = 0
while b < n and g < m:
	if abs(bo[b] - gi[g]) <= 1:
		b += 1
		g += 1
		c += 1
	elif bo[b] > gi[g]:
		g += 1
	else:
		b += 1
print(c)


n = int(input())
L = list(map(int, input().split()))
n1 = int(input())
L1 = list(map(int, input().split()))
(i, j) = (0, 0)
c = 0
L.sort()
L1.sort()
while True:
	if i == len(L) or j == len(L1):
		break
	if abs(L[i] - L1[j]) <= 1:
		i += 1
		j += 1
		c += 1
	elif L[i] > L1[j]:
		j += 1
	else:
		i += 1
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
a_i = 0
b_i = 0
a_m = len(a)
b_m = len(b)
p = 0
while a_i < a_m and b_i < b_m:
	a_x = a[a_i]
	b_x = b[b_i]
	if a_x > b_x + 1:
		b_i += 1
	elif a_x < b_x - 1:
		a_i += 1
	else:
		p += 1
		a_i += 1
		b_i += 1
print(p)


ans = 0
N = int(input())
x = list(map(int, input().split()))
N = int(input())
y = list(map(int, input().split()))
v = [0] * 100
w = [0] * 100
for i in x:
	v[i - 1] += 1
for j in y:
	w[j - 1] += 1
for i in range(1, 100):
	if v[i - 1] > 0 and w[i - 1] > 0:
		t = min(v[i - 1], w[i - 1])
		ans += t
		v[i - 1] -= t
		w[i - 1] -= t
	if v[i - 1] > 0 and w[i] > 0:
		t = min(v[i - 1], w[i])
		ans += t
		v[i - 1] -= t
		w[i] -= t
	elif w[i - 1] > 0 and v[i] > 0:
		t = min(w[i - 1], v[i])
		ans += t
		w[i - 1] -= t
		v[i] -= t
if v[99] > 0 and w[99] > 0:
	t = min(v[99], w[99])
	ans += t
	v[99] -= t
	w[99] -= t
print(ans)


import sys
n = int(input())
a = [int(i) for i in input().split(' ')]
a = sorted(a)
a.append(0)
m = int(input())
b = [int(i) for i in input().split(' ')]
b = sorted(b)
b.append(0)
ak = 0
bk = 0
summa = 0
while a[ak] and b[bk]:
	if abs(a[ak] - b[bk]) < 2:
		summa += 1
		ak += 1
		bk += 1
	elif a[ak] < b[bk]:
		ak += 1
	else:
		bk += 1
print(summa)


n = int(input())
b = []
for word in input().split():
	b.append(int(word))
m = int(input())
g = []
for word in input().split():
	g.append(int(word))
b.sort()
g.sort()
i = 0
j = 0
cnt = 0
while i < n and j < m:
	if abs(b[i] - g[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
		continue
	if b[i] < g[j]:
		i += 1
		continue
	if b[i] > g[j]:
		j += 1
		continue
print(cnt)


nb = int(input())
b = [int(x) for x in input().split()]
ng = int(input())
g = [int(x) for x in input().split()]
count = 0
b.sort()
g.sort()
i = 0
j = 0
while i < nb and j < ng:
	if abs(b[i] - g[j]) <= 1:
		count += 1
		i += 1
		j += 1
		continue
	if b[i] < g[j]:
		i += 1
		continue
	j += 1
print(count)


n = int(input())
a = sorted((int(x) for x in input().split()))
m = int(input())
b = sorted((int(x) for x in input().split()))
(i, j, val) = (0, 0, 0)
while i < n and j < m:
	if a[i] < b[j] - 1:
		i += 1
	elif b[j] < a[i] - 1:
		j += 1
	else:
		i += 1
		j += 1
		val += 1
print(val)


n_boys = int(input())
line = input()
lista = line.split()
lista_boys = [int(i) for i in lista]
lista_boys.sort()
lista_boys.reverse()
n_girls = int(input())
line = input()
lista = line.split()
lista_girls = [int(i) for i in lista]
lista_girls.sort()
lista_girls.reverse()
contador = 0
while len(lista_boys) > 0 and len(lista_girls) > 0:
	if abs(lista_boys[0] - lista_girls[0]) < 2:
		contador += 1
		lista_boys.remove(lista_boys[0])
		lista_girls.remove(lista_girls[0])
	elif lista_boys[0] > lista_girls[0]:
		lista_boys.remove(lista_boys[0])
	else:
		lista_girls.remove(lista_girls[0])
print(contador)


def f(lsm, lsn):
	mx = 0
	i = j = 0
	while i < len(lsm) and j < len(lsn):
		if abs(lsm[i] - lsn[j]) <= 1:
			mx = mx + 1
			i = i + 1
			j = j + 1
		elif lsm[i] < lsn[j]:
			i = i + 1
		elif lsm[i] > lsn[j]:
			j = j + 1
	return mx
m = int(input())
lsm = list(map(int, input().split()))
lsm.sort()
n = input()
lsn = list(map(int, input().split()))
lsn.sort()
rmlsm = []
rmlsn = []
for u in lsm:
	if u - 1 not in lsn and u not in lsn and (u + 1 not in lsn):
		rmlsm.append(u)
for u in lsn:
	if u - 1 not in lsm and u not in lsm and (u + 1 not in lsm):
		rmlsn.append(u)
for u in rmlsm:
	lsm.remove(u)
for u in rmlsn:
	lsn.remove(u)
print(f(lsm, lsn))


n = int(input())
s = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
s.sort()
t.sort(reverse=True)
pair = 0
while s:
	boy = s.pop()
	for i in range(len(t)):
		if abs(t[i] - boy) <= 1:
			del t[i]
			pair += 1
			break
print(pair)


def inp():
	return list(map(int, input().split()))
(aa,) = inp()
a = inp()
(bb,) = inp()
b = inp()
a.sort()
b.sort()
ans = 0
for i in range(aa):
	for j in range(bb):
		if abs(a[i] - b[j]) <= 1:
			ans += 1
			b[j] = 10000
			break
print(ans)


a = int(input())
list1 = list(map(int, input().split()))
a = int(input())
list2 = list(map(int, input().split()))
b = len(list1)
c = len(list2)
sum1 = 0
list1.sort()
list2.sort()
if b <= c:
	for x in list1:
		if x - 1 in list2:
			sum1 += 1
			list2.remove(x - 1)
		elif x in list2:
			sum1 += 1
			list2.remove(x)
		elif x + 1 in list2:
			sum1 += 1
			list2.remove(x + 1)
if b > c:
	for x in list2:
		if x - 1 in list1:
			sum1 += 1
			list1.remove(x - 1)
		elif x in list1:
			sum1 += 1
			list1.remove(x)
		elif x + 1 in list1:
			sum1 += 1
			list1.remove(x + 1)
print(sum1)


n = int(input())
b = sorted([int(x) for x in input().split()], reverse=True)
m = int(input())
g = sorted([int(x) for x in input().split()], reverse=True)
ans = 0
for i in range(n):
	for j in range(m):
		a = b[i] - g[j]
		if abs(a) <= 1:
			ans += 1
			g[j] = 110
			break
print(ans)


def main():
	from sys import stdin
	from itertools import islice
	tokens = map(int, stdin.read().split())
	N = next(tokens)
	boys = sorted(islice(tokens, N))
	M = next(tokens)
	girls = sorted(islice(tokens, M))
	if len(boys) < len(girls):
		smallest_array = boys
		biggest_array = girls
	else:
		smallest_array = girls
		biggest_array = boys
	ans = 0
	i = 0
	for x in smallest_array:
		while i < len(biggest_array) and biggest_array[i] <= x - 2:
			i += 1
		if i == len(biggest_array):
			break
		elif abs(biggest_array[i] - x) <= 1:
			ans += 1
			i += 1
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
ind = 0
for i in range(n):
	for j in range(ind, m):
		if abs(a[i] - b[j]) <= 1:
			count += 1
			ind = j + 1
			break
print(count)


n = int(input())
l1 = list(map(int, input().strip().split()))
m = int(input())
l2 = list(map(int, input().strip().split()))
(i, j, c) = (0, 0, 0)
l1.sort()
l2.sort()
while i < len(l1) and j < len(l2):
	if abs(l1[i] - l2[j]) <= 1:
		c += 1
		l1.remove(l1[i])
		l2.remove(l2[j])
	elif l1[i] > l2[j]:
		j += 1
	else:
		if j != 0 and abs(l1[i] - l2[j - 1]) <= 1:
			c += 1
		i += 1
print(c)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a.sort()
b.sort()
count = 0
for i in range(n):
	if a[i] - 1 in b:
		count += 1
		b.remove(b[b.index(a[i] - 1)])
	elif a[i] in b:
		count += 1
		b.remove(b[b.index(a[i])])
	elif a[i] + 1 in b:
		count += 1
		b.remove(b[b.index(a[i] + 1)])
print(count)


I = lambda : sorted(map(int, input().split()))
m = I()[0]
x = I()
n = I()[0]
y = I()
i = 0
j = 0
cnt = 0
while i < m and j < n:
	if abs(x[i] - y[j]) < 2:
		cnt += 1
		i += 1
		j += 1
	elif x[i] < y[j]:
		i += 1
	else:
		j += 1
print(cnt)


n = int(input())
l1 = list(map(int, input().split()))
l1 = sorted(l1)
m = int(input())
l2 = list(map(int, input().split()))
l2 = sorted(l2)
count = 0
for i in range(0, n):
	for j in range(0, m):
		if abs(l1[i] - l2[j]) <= 1:
			count += 1
			l2[j] = 10000
			break
print(count)


n = int(input())
a = input().split()
for k in range(len(a)):
	a[k] = int(a[k])
a.sort()
m = int(input())
b = input().split()
for k in range(len(b)):
	b[k] = int(b[k])
b.sort()
if n > m:
	smstr = b
	bgstr = a
else:
	smstr = a
	bgstr = b
count = 0
i = 0
j = 0
while i < min(m, n):
	j = 0
	while j < len(bgstr):
		if abs(int(smstr[i]) - int(bgstr[j])) <= 1:
			bgstr.pop(j)
			count = count + 1
			break
		else:
			j = j + 1
	i = i + 1
print(count)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
girls.append(100000000000000000000000000000000000000000000000000)
i = 0
ans = 0
boys.sort()
girls.sort()
for (ind, boy) in enumerate(boys):
	while girls[i] < boy - 1:
		i += 1
	if abs(girls[i] - boy) <= 1:
		ans += 1
		i += 1
print(ans)


n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
boy.sort()
girl.sort()
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(boy[i] - girl[j]) <= 1:
		i += 1
		j += 1
		ans += 1
	elif boy[i] - girl[j] > 1:
		j += 1
	else:
		i += 1
print(ans)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b.sort()
d.sort(reverse=True)
p = 0
while bool(b) == True:
	f = max(b)
	q = 0
	w = 0
	while q == 0 and w <= len(d) - 1:
		if d[w] >= f - 1 and d[w] <= f + 1:
			q = q + 1
			p = p + 1
			d.remove(d[w])
		elif w == len(d) - 1:
			q = q + 1
		else:
			w = w + 1
	b.remove(f)
print(p)


boys = int(input())
boys_skills = list(map(int, input().split(' ')))
girls = int(input())
girls_skills = list(map(int, input().split(' ')))
(searching_for, searching_in) = (girls_skills, boys_skills)
if boys <= girls:
	(searching_for, searching_in) = (boys_skills, girls_skills)
pairs = 0
searching_for.sort()
for i in searching_for:
	if i - 1 in searching_in:
		searching_in.remove(i - 1)
		pairs += 1
	elif i in searching_in:
		searching_in.remove(i)
		pairs += 1
	elif i + 1 in searching_in:
		searching_in.remove(i + 1)
		pairs += 1
	else:
		continue
print(pairs)


from sys import stdin, stdout
import bisect
import math

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
b = ii()
lb = li()
g = ii()
lg = li()
lb.sort()
lg.sort()
l = 0
r = 0
ans = 0
while l < b and r < g:
	if abs(lb[l] - lg[r]) > 1:
		if lb[l] > lg[r]:
			r += 1
		else:
			l += 1
	else:
		ans += 1
		l += 1
		r += 1
print(ans)


input()
a = sorted([int(x) for x in input().split()])
input()
b = sorted([int(x) for x in input().split()])
(i, j) = (0, 0)
res = 0
while i < len(a) and j < len(b):
	if abs(a[i] - b[j]) <= 1:
		res += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(res)


b = int(input())
boys = list(map(int, input().split()))
g = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
s = 0
for i in range(b):
	for j in range(g):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = -2
			s += 1
			break
print(s)


n = int(input())
boys = [int(i) for i in input().split(' ')]
m = int(input())
girls = [int(i) for i in input().split(' ')]
boys.sort()
girls.sort()
i = 0
j = 0
cnt = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	elif girls[j] < boys[i]:
		j += 1
print(cnt)


def suitablePartner(boy, girl):
	return -1 <= boy - girl <= 1

def largestNumOfPairs(boys, girls):
	boys.sort()
	girls.sort()
	pairs = 0
	for i in range(len(boys)):
		j = 0
		while j < len(girls):
			if suitablePartner(boys[i], girls[j]):
				pairs += 1
				del girls[j]
				break
			else:
				j += 1
	return pairs

def main():
	numOfBoys = int(input())
	boys = input()
	boys = boys.split()
	assert len(boys) == numOfBoys, 'Invalid boys'
	for i in range(len(boys)):
		boys[i] = int(boys[i])
	numOfGirls = int(input())
	girls = input()
	girls = girls.split()
	assert len(girls) == numOfGirls, 'Invalid girls'
	for i in range(len(girls)):
		girls[i] = int(girls[i])
	print(largestNumOfPairs(boys, girls))
main()


nb = int(input())
boys = list(map(int, input().split(' ')))
ng = int(input())
girls = list(map(int, input().split(' ')))
matches = [[] for i in range(nb)]
for (bi, boy) in enumerate(boys):
	for i in range(ng):
		if girls[i] >= boy - 1 and girls[i] <= boy + 1:
			matches[bi].append(i)

def find(idx, taken, tried):
	for girl in matches[idx]:
		if not girl in tried:
			tried.add(girl)
			if not girl in taken or find(taken[girl], taken, tried):
				taken[girl] = idx
				return True
	return False

def getmax():
	result = 0
	taken = {}
	for (bi, boy) in enumerate(boys):
		tried = set()
		if find(bi, taken, tried):
			result += 1
	return result
print(getmax())


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
count = 0
j = 0
ptr = 0
if n < m:
	for e in a:
		while j < m:
			dif = abs(e - b[j])
			j += 1
			if dif == 0 or dif == 1:
				count += 1
				ptr = j
				break
		else:
			j = ptr
else:
	for e in b:
		while j < n:
			dif = abs(e - a[j])
			j += 1
			if dif == 0 or dif == 1:
				count += 1
				ptr = j
				break
		else:
			j = ptr
print(count)


from sys import stdin

def r():
	return stdin.readline().strip()

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def match(a, b):
	return abs(a - b) <= 1

def solve(n, m, A, B):
	A.sort()
	B.sort()
	(matched, ans) = ([False for _ in range(m)], 0)
	for i in range(n):
		for j in range(m):
			if match(A[i], B[j]) and (not matched[j]):
				matched[j] = 1
				ans += 1
				break
	return ans

def main():
	n = int(r())
	A = r_a(int)
	m = int(r())
	B = r_a(int)
	print(solve(n, m, A, B))
main()


boy_count = input()
boys_list = list(map(int, input().split()))
girl_count = int(input())
girls_list = list(map(int, input().split()))
boys_list.sort()
girls_list.sort()
if len(boys_list) < len(girls_list):
	min_list = boys_list
	max_list = girls_list
else:
	min_list = girls_list
	max_list = boys_list
i = 0
M = len(min_list)
N = len(max_list)
j = 0
count = 0
while i < M and j < N:
	if abs(min_list[i] - max_list[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif min_list[i] > max_list[j]:
		j += 1
	elif min_list[i] < max_list[j]:
		i += 1
print(count)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a = sorted(a)
m = int(input())
b = input().split()
for i in range(m):
	b[i] = int(b[i])
b = sorted(b)
pos1 = 0
pos2 = 0
k = 0
while pos1 < n and pos2 < m:
	if abs(a[pos1] - b[pos2]) <= 1:
		k += 1
		pos1 += 1
		pos2 += 1
	elif a[pos1] > b[pos2]:
		pos2 += 1
	else:
		pos1 += 1
print(k)


boy = int(input())
boys = [int(x) for x in input().split()]
boys.sort()
girl = int(input())
girls = [int(x) for x in input().split()]
girls.sort()
cp = 0
for i in boys:
	if i - 1 in girls:
		cp += 1
		x = girls.index(i - 1)
		girls.pop(x)
	elif i in girls:
		cp += 1
		x = girls.index(i)
		girls.pop(x)
	elif i + 1 in girls:
		cp += 1
		x = girls.index(i + 1)
		girls.pop(x)
print(cp)


def s():
	n = int(input())
	a = list(map(int, input().split(' ')))
	m = int(input())
	b = list(map(int, input().split(' ')))
	a.sort()
	b.sort()
	counter_b = 0
	ans = 0
	for i in range(n):
		for j in range(counter_b, m):
			if abs(a[i] - b[j]) <= 1:
				ans += 1
				counter_b = j + 1
				break
	print(ans)
s()


n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
i = 0
res = 0
while i < len(A):
	j = 0
	while j < len(B):
		if abs(A[i] - B[j]) <= 1:
			res += 1
			A.pop(i)
			B.pop(j)
			break
		j += 1
	else:
		i += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
answer = 0
for i in range(n):
	for j in range(len(b)):
		if b[j] > 0 and abs(a[i] - b[j]) <= 1:
			answer += 1
			b[j] = -1
			break
print(answer)


boys = int(input())
boys_skill = list(map(int, input().split()))
girls = int(input())
girls_skill = list(map(int, input().split()))
boys_skill = sorted(boys_skill)
girls_skill = sorted(girls_skill)
ans = 0
if boys < girls:
	found_index = []
	for boy_pointer in range(boys):
		found = False
		for girl_pointer in range(girls):
			if 0 <= abs(boys_skill[boy_pointer] - girls_skill[girl_pointer]) <= 1 and found == False and (girl_pointer not in found_index):
				ans += 1
				found = True
				found_index.append(girl_pointer)
else:
	found_index = []
	for girl_pointer in range(boys):
		found = False
		for boy_pointer in range(girls):
			if 0 <= abs(boys_skill[girl_pointer] - girls_skill[boy_pointer]) <= 1 and found == False and (boy_pointer not in found_index):
				ans += 1
				found = True
				found_index.append(boy_pointer)
print(ans)


a = int(input())
list1 = list(map(int, input().split()))
a = int(input())
list2 = list(map(int, input().split()))
sum1 = 0
list1.sort()
list2.sort()
for a in list1:
	for b in list2:
		if abs(a - b) <= 1:
			sum1 += 1
			list2.remove(b)
			break
print(sum1)


n = int(input())
l = sorted(list(map(int, input().split())))
m = int(input())
s = sorted(list(map(int, input().split())))
i = j = cont = 0
while i < n and j < m:
	if abs(l[i] - s[j]) < 2:
		cont += 1
		i += 1
		j += 1
	elif l[i] < s[j]:
		i += 1
	else:
		j += 1
print(cont)


num_boys = int(input())
boys = input().split()
boys = list(map(lambda x: int(x), boys))
boys.sort()
num_girls = int(input())
girls = input().split()
girls = list(map(lambda x: int(x), girls))
girls.sort()
pairs = 0
if num_boys >= num_girls:
	for i in girls:
		index = 0
		for j in boys:
			if abs(i - j) <= 1:
				pairs += 1
				boys.pop(index)
				break
			index += 1
else:
	for i in boys:
		index = 0
		for j in girls:
			if abs(i - j) <= 1:
				pairs += 1
				girls.pop(index)
				break
			index += 1
print(str(pairs))


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
c = [0 for i in range(n)]
d = [0 for i in range(m)]
a.sort()
b.sort()
num = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1 and c[i] == 0 and (d[j] == 0):
			num += 1
			c[i] = 1
			d[j] = 1
print(num)


n = int(input())
l_n = list(map(int, input().split()))
m = int(input())
l_m = list(map(int, input().split()))
l_n = sorted(l_n)
l_m = sorted(l_m)
result = 0
x = 0
y = 0
for i in range(0, n + m):
	if x >= n or y >= m:
		break
	if abs(l_m[y] - l_n[x]) <= 1:
		result += 1
		x += 1
		y += 1
	elif l_n[x] > l_m[y]:
		y += 1
	else:
		x += 1
print(result)


b = int(input())
p = list(map(int, input().split()))
p.sort()
g = int(input())
q = list(map(int, input().split()))
q.sort()
i = 0
count = 0
while i < g and len(p) > 0:
	a = q[i]
	b = q[i] - 1
	c = q[i] + 1
	if p[0] == a or p[0] == b or p[0] == c:
		p.pop(0)
		count += 1
		i += 1
	elif p[0] > q[i]:
		i += 1
	else:
		p.pop(0)
print(count)


n = int(input())
a = [int(x) for x in input().split(' ')]
m = int(input())
b = [int(y) for y in input().split(' ')]
a_sorted = sorted(a)
b_sorted = sorted(b)
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(a_sorted[i] - b_sorted[j]) < 2:
		count += 1
		i += 1
		j += 1
	elif a_sorted[i] < b_sorted[j]:
		i += 1
	else:
		j += 1
print(count)


boy = int(input())
boy_skill = [int(i) for i in input().split()]
list.sort(boy_skill)
girl = int(input())
girl_skill = [int(i) for i in input().split()]
list.sort(girl_skill)
res = 0
for (i, boy_value) in enumerate(boy_skill):
	for (j, girl_value) in enumerate(girl_skill):
		if abs(boy_value - girl_value) <= 1:
			res += 1
			girl_skill[j] = 9999
			break
print(res)


input()
a = list(map(int, input().split()))
length = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
cnt = 0
for i in a:
	for j in range(length):
		if abs(i - b[j]) <= 1:
			b[j] = 1000
			cnt += 1
			break
print(cnt)


from heapq import merge
import datetime
import math

def clock():
	print(datetime.datetime.now())
k = s = 0
input()
a = sorted([int(x) for x in input().split()])
input()
b = sorted([int(x) for x in input().split()])
for i in range(len(b)):
	for j in range(len(a)):
		if abs(b[i] - a[j]) <= 1:
			b[i] = a[j] = -2
			k += 1
			break
print(k)


import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations

def si():
	return str(stdin.readline())

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def debug(x):
	return stdout.write(str(x))
a = ii()
arr = li()
b = ii()
brr = li()
arr.sort()
brr.sort()
c = 0
for i in range(a):
	for j in range(b):
		if abs(arr[i] - brr[j]) < 2:
			c += 1
			brr[j] = 1000
			break
print(c)


N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))
A.sort()
B.sort()
i = 0
j = 0
it = 0
while i < N and j < M:
	if i == N - 1 or j == M - 1:
		if A[i] == B[j]:
			it += 1
			break
		elif abs(A[i] - B[j]) == 1:
			it += 1
			break
	if A[i] == B[j]:
		i += 1
		j += 1
		it += 1
	elif abs(A[i] - B[j]) == 1:
		i += 1
		j += 1
		it += 1
	elif A[i] - B[j] > 1:
		j += 1
	elif B[j] - A[i] > 1:
		i += 1
print(it)


from array import array
n = int(input())
a = array('i', [int(x) for x in input().split()])
m = int(input())
b = array('i', [int(x) for x in input().split()])
a = sorted(a)
b = sorted(b)
cnt = 0
flag = 0
for i in range(0, n):
	for j in range(flag, m):
		if a[i] + 1 < b[j]:
			flag = j
			break
		if (a[i] - b[j]) ** 2 < 2:
			cnt += 1
			flag = j + 1
			break
print(cnt)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
res = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			res += 1
			a[i] = 1000
			b[j] = 2000
print(res)


n = int(input())
boy = input().split()
m = int(input())
girl = input().split()
for i in range(n):
	boy[i] = int(boy[i])
boy.sort()
for j in range(m):
	girl[j] = int(girl[j])
girl.sort()
pair = 0
if boy[0] > girl[0]:
	(boy, girl) = (girl, boy)
while len(boy) > 0 and len(girl) > 0:
	if girl[0] - boy[0] < 2:
		pair += 1
		del girl[0]
		del boy[0]
		if len(boy) > 0 and len(girl) > 0:
			if boy[0] > girl[0]:
				(boy, girl) = (girl, boy)
	else:
		del boy[0]
		if len(boy) > 0:
			if boy[0] > girl[0]:
				(boy, girl) = (girl, boy)
print(pair)


n = int(input())
l = sorted(list(map(int, input().split())))
m = int(input())
p = sorted(list(map(int, input().split())))
ret = 0
if m < n:
	c = 0
	for i in range(n):
		for k in range(m):
			if abs(l[i] - p[k]) <= 1:
				c += 1
				p[k] = -1000
				break
	ret = c
else:
	c = 0
	for i in range(m):
		for k in range(n):
			if abs(p[i] - l[k]) <= 1:
				c += 1
				l[k] = -1000
				break
	ret = c
print(ret)


n = int(input())
a = input()
A = list(map(int, list(a.split())))
A.sort()
m = int(input())
b = input()
B = list(map(int, list(b.split())))
B.sort()
p = 0
vis = [0] * m
for i in range(n):
	for j in range(m):
		if vis[j] == 0:
			if abs(A[i] - B[j]) <= 1:
				p = p + 1
				vis[j] = 1
				break
print(p)


def solve(boy, girl, n, m):
	boy.sort()
	girl.sort()
	count = 0
	(leBoy, leGirl) = (n, m)
	i = j = 0
	temp = 0
	while i < leBoy and j < leGirl:
		if abs(boy[i] - girl[j]) < 2:
			count += 1
			i += 1
			j += 1
		elif boy[i] < girl[j]:
			i += 1
		else:
			temp = j
			while temp < leGirl:
				a = abs(boy[i] - girl[temp])
				if a < 2:
					count += 1
					j = temp
					i += 1
					j += 1
					break
				elif boy[i] < girl[temp]:
					j = temp
					i += 1
					break
				temp += 1
			else:
				break
	return count
n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
result = solve(boy, girl, n, m)
print(result)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
n = ini()
a = sorted(inl())
m = ini()
b = sorted(inl())
ans = 0
start = 0
for i in a:
	for j in range(start, m):
		if abs(i - b[j]) <= 1:
			ans += 1
			start = j + 1
			break
print(ans)


n = int(input())
b = [int(item) for item in input().split()]
m = int(input())
g = [int(item) for item in input().split()]
b.sort()
g.sort()
cnt = 0
for i in range(n):
	for j in range(m):
		if b[i] > 0 and g[j] > 0 and (abs(b[i] - g[j]) <= 1):
			b[i] *= -1
			g[j] *= -1
			cnt += 1
			break
print(cnt)


nb = int(input())
b = list(map(int, input().split()))
ng = int(input())
g = list(map(int, input().split()))
bg = {}
for i in g:
	if i in bg:
		bg[i] += 1
	else:
		bg[i] = 1
ans = 0
b.sort()
for key in b:
	if key - 1 in bg:
		bg[key - 1] -= 1
		ans += 1
		if bg[key - 1] == 0:
			del bg[key - 1]
		continue
	if key in bg:
		bg[key] -= 1
		ans += 1
		if bg[key] == 0:
			del bg[key]
		continue
	if key + 1 in bg:
		bg[key + 1] -= 1
		ans += 1
		if bg[key + 1] == 0:
			del bg[key + 1]
		continue
print(ans)


import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
sys.setrecursionlimit(2 * pow(10, 6))
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
boys = l()
m = int(data())
girls = l()
boys.sort()
girls.sort()
answer = 0
occ = set()
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1 and j not in occ:
			answer += 1
			occ.add(j)
			break
out(answer)


n = int(input())
xs = sorted(map(int, input().split()))
m = int(input())
ys = sorted(map(int, input().split()))
k = 0
r = 0
for x in xs:
	i = k
	for y in ys[k:]:
		if abs(x - y) <= 1:
			k = i + 1
			r += 1
			break
		i += 1
print(r)


n = int(input())
a = sorted([int(i) for i in input().split()])
m = int(input())
b = sorted([int(i) for i in input().split()])
i = j = k = 0
while i < n:
	while j < m:
		if abs(a[i] - b[j]) < 2:
			a.remove(a[i])
			b.remove(b[j])
			k += 1
			i = j = 0
			m -= 1
			n -= 1
			x = len(a) > 0 and len(b) > 0
			if len(a) == 0 or len(b) == 0:
				break
		else:
			j += 1
	i += 1
	j = 0
print(k)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
pairs = 0
if n < m:
	for i in boys:
		start = 0
		for j in range(start, m):
			if abs(i - girls[j]) <= 1:
				pairs += 1
				girls[j] = -1
				start = j + 1
				break
else:
	for i in girls:
		start = 0
		for j in range(start, n):
			if abs(i - boys[j]) <= 1:
				pairs += 1
				boys[j] = -1
				start = j + 1
				break
print(pairs)


numBoys = int(input())
boyScores = list(map(int, input().split()))
numGirls = int(input())
girlScores = list(map(int, input().split()))
boyScores.sort()
girlScores.sort()
bs = 0
gs = 0
paired = 0
while gs < numGirls:
	broke = False
	for i in range(numBoys):
		if abs(girlScores[gs] - boyScores[i]) <= 1:
			girlScores[gs] = -10
			boyScores[i] = -50
			gs += 1
			paired += 1
			broke = True
			break
	if not broke:
		gs += 1
print(paired)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
if m < n:
	(g, b) = (b, g)
	(n, m) = (m, n)
count = 0
while len(b) * len(g):
	if abs(b[0] - g[0]) < 2:
		count += 1
		g.pop(0)
		b.pop(0)
	elif b[0] < g[0]:
		b.pop(0)
	else:
		g.pop(0)
print(count)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
c = 0
i = 0
j = 0
while i < n:
	if a[i] - b[j] >= -1:
		if a[i] - b[j] <= 1:
			i = i + 1
			j = j + 1
			c = c + 1
		else:
			j = j + 1
	else:
		i = i + 1
	if j == m:
		break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
while a and b:
	if abs(a[0] - b[0]) <= 1:
		count += 1
		a.pop(0)
		b.pop(0)
	elif a[0] < b[0]:
		a.pop(0)
	else:
		b.pop(0)
print(count)


import heapq as hp

def unpack(func=int):
	return map(func, input().split())

def range_n():
	return range(int(input()))

def main():
	n = int(input())
	a = list(unpack())
	m = int(input())
	b = list(unpack())
	hp.heapify(a)
	hp.heapify(b)
	ans = 0
	while a and b:
		(boy, girl) = (a[0], b[0])
		if abs(boy - girl) <= 1:
			ans += 1
			hp.heappop(a)
			hp.heappop(b)
		elif boy > girl:
			hp.heappop(b)
		else:
			hp.heappop(a)
	print(ans)
main()


n_boys = input()
n_boys = int(n_boys)
boys_skill = input()
n_girls = input()
n_girls = int(n_girls)
girls_skill = input()
boys_skill = boys_skill.split(' ')
boys_skill = [int(x) for x in boys_skill]
boys_skill.sort()
girls_skill = girls_skill.split(' ')
girls_skill = [int(x) for x in girls_skill]
girls_skill.sort()
result = 0
for i in range(n_boys):
	for j in range(n_girls):
		if abs(boys_skill[i] - girls_skill[j]) <= 1:
			girls_skill[j] = 500000
			result += 1
			break
print(result)


n = int(input())
b = [int(x) for x in input().split()]
m = int(input())
g = [int(x) for x in input().split()]
b.sort()
g.sort()
count = 0
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			count = count + 1
			m = m - 1
			g.pop(j)
			break
print(count)


c = 0
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
m = int(input())
b = [int(i) for i in input().split()]
b = sorted(b)
for i in range(len(a)):
	for k in range(len(b)):
		if b[k] != -1:
			if abs(a[i] - b[k]) < 2:
				c += 1
				b[k] = -1
				break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
(i, j) = (0, 0)
res = 0
while i < n and j < m:
	(x, y) = (a[i], b[j])
	if x == y:
		res += 1
		(i, j) = (i + 1, j + 1)
	elif x > y:
		if x - y == 1:
			res += 1
			(i, j) = (i + 1, j + 1)
		else:
			j += 1
	elif y - x == 1:
		res += 1
		(i, j) = (i + 1, j + 1)
	else:
		i += 1
print(res)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
lim = min([boys, girls], key=len)
if lim == boys:
	other = girls
else:
	other = boys
(lim.sort(), other.sort())
pair = 0
while lim != []:
	comp = lim[0]
	if comp - 1 in other:
		pair += 1
		other.pop(other.index(comp - 1))
	elif comp in other:
		pair += 1
		other.pop(other.index(comp))
	elif comp + 1 in other:
		pair += 1
		other.pop(other.index(comp + 1))
	lim.pop(0)
print(pair)


from math import fabs
ans = 0
n = int(input())
a = list(map(int, input().split()))
b = int(input())
m = list(map(int, input().split()))
a.sort()
m.sort()
for x in m:
	for y in range(len(a)):
		if fabs(x - a[y]) <= 1:
			ans += 1
			del a[y]
			break
print(ans)


boys = int(input())
skillb = sorted([int(x) for x in input().split()])
girls = int(input())
skillg = sorted([int(x) for x in input().split()])
pair = 0
i = 0
j = 0
while i < boys and j < girls:
	if abs(skillb[i] - skillg[j]) <= 1:
		pair += 1
		i += 1
		j += 1
	elif skillb[i] < skillg[j]:
		i += 1
	else:
		j += 1
print(pair)


num_boys = int(input())
boy_skills = list(map(int, input().split()))
num_girls = int(input())
girl_skills = list(map(int, input().split()))
boy_skills.sort()
girl_skills.sort()
i = 0
j = 0
pairs = 0
while i < num_boys and j < num_girls:
	if abs(boy_skills[i] - girl_skills[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif boy_skills[i] - girl_skills[j] > 1:
		j += 1
	else:
		i += 1
print(pairs)


n_boys = int(input())
boys = []
if n_boys > 0:
	boys = input().split()
	boys = list(map(int, boys))
n_girls = int(input())
girls = []
if n_girls > 0:
	girls = input().split()
	girls = list(map(int, girls))
boys.sort(reverse=True)
girls.sort(reverse=True)
matches = 0
while boys and girls:
	if abs(int(boys[-1]) - int(girls[-1])) <= 1:
		matches += 1
		boys.pop()
		girls.pop()
	elif int(boys[-1]) > int(girls[-1]):
		x = girls.pop()
	else:
		x = boys.pop()
print(matches)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
i = 0
j = 0
a.sort()
b.sort()
c = 0
k = 0
while i < n and j < m:
	y = abs(a[i] - b[j])
	if y <= 1:
		c = c + 1
		i = i + 1
		j = j + 1
	elif a[i] < b[j]:
		i = i + 1
	elif a[i] > b[j]:
		j = j + 1
print(c)


n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
res = 0
if n <= m:
	for b in boys:
		while girls:
			if girls[0] < b - 1:
				girls.pop(0)
			elif b - 1 <= girls[0] <= b + 1:
				girls.pop(0)
				res += 1
				break
			else:
				break
else:
	for g in girls:
		while boys:
			if boys[0] < g - 1:
				boys.pop(0)
			elif g - 1 <= boys[0] <= g + 1:
				boys.pop(0)
				res += 1
				break
			else:
				break
print(res)


n = int(input())
s1 = input()
arr1 = list(map(int, s1.split(' ')))
m = int(input())
s2 = input()
arr2 = list(map(int, s2.split(' ')))
arr1.sort()
arr2.sort()
result = 0
for i in range(0, len(arr1)):
	for j in range(0, len(arr2)):
		if abs(arr1[i] - arr2[j]) <= 1:
			result = result + 1
			arr2[j] = 1000
			break
print(result)


il = lambda : list(map(int, input().split()))
iin = lambda : map(int, input().split())
ii = lambda : int(input())
n = ii()
b = il()
m = ii()
g = il()
b.sort()
g.sort()
i = 0
j = 0
pair = 0
while i < n and j < m:
	if abs(b[i] - g[j]) <= 1:
		pair += 1
		i += 1
		j += 1
	elif b[i] > g[j]:
		j += 1
	else:
		i += 1
print(pair)


n = int(input())
A = sorted(list(map(int, input().split())))
m = int(input())
B = sorted(list(map(int, input().split())))
M = [[0 for j in range(m)] for i in range(n)]
one = False
for j in range(m):
	if one:
		M[0][j] = 1
	elif abs(A[0] - B[j]) <= 1:
		M[0][j] = 1
		one = True
one = False
for i in range(n):
	if one:
		M[i][0] = 1
	elif abs(B[0] - A[i]) <= 1:
		M[i][0] = 1
		one = True
for i in range(1, n):
	for j in range(1, m):
		M[i][j] = max(M[i - 1][j], M[i][j - 1], 1 + M[i - 1][j - 1]) if abs(A[i] - B[j]) <= 1 else max(M[i - 1][j], M[i][j - 1])
print(M[n - 1][m - 1])


n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
a.sort()
b.sort()
count = 0
matched = [False] * m
for i in range(0, n):
	for j in range(0, m):
		if abs(a[i] - b[j]) <= 1 and matched[j] == False:
			count += 1
			matched[j] = True
			break
print(count)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
la = sorted(il())
m = ii()
lb = sorted(il())
i = 0
j = 0
c = 0
while i < n and j < m:
	if abs(la[i] - lb[j]) < 2:
		c += 1
		i += 1
		j += 1
	elif la[i] < lb[j]:
		i += 1
	else:
		j += 1
print(c)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
p = 0
i = 0
while i < n:
	x = True
	j = 0
	while j < m and x == True:
		if abs(a[i] - b[j]) <= 1:
			p += 1
			x = False
			b[j] = -100
		j += 1
	i += 1
print(p)


s = int(input())
s = list(map(int, input().split()))
d = int(input())
d = list(map(int, input().split()))
s.sort()
d.sort()
count = 0
for j in range(len(s)):
	for k in range(len(d)):
		if abs(s[j] - d[k]) <= 1:
			count += 1
			d[k] = 1000
			break
print(count)


n = int(input())
boys = input().split()
for i in range(n):
	boys[i] = int(boys[i])
m = int(input())
girls = input().split()
for i in range(m):
	girls[i] = int(girls[i])
boys.sort()
girls.sort()
pairs = 0
while len(girls) > 0 and len(boys) > 0:
	if abs(girls[0] - boys[0]) <= 1:
		pairs += 1
		del girls[0]
		del boys[0]
	elif min(girls[0], boys[0]) == girls[0]:
		del girls[0]
	else:
		del boys[0]
print(pairs)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i] > a[j]:
			temp1 = a[i]
			a[i] = a[j]
			a[j] = temp1
for i in range(m - 1):
	for j in range(i + 1, m):
		if b[i] > b[j]:
			temp2 = b[i]
			b[i] = b[j]
			b[j] = temp2
indexa = 0
indexb = 0
hsl = 0
while indexa < n and indexb < m:
	if abs(a[indexa] - b[indexb]) <= 1:
		hsl += 1
		indexa += 1
		indexb += 1
	elif a[indexa] > b[indexb]:
		indexb += 1
	else:
		indexa += 1
print(hsl)


l1 = int(input())
a = list(map(int, input().split(' ')))
l2 = int(input())
b = list(map(int, input().split(' ')))
a.sort()
b.sort()

def condition(i, j):
	if abs(a[i] - b[j]) <= 1:
		return True
	return False
(count, i, j) = (0, 0, 0)
while i < l1 and j < l2:
	if condition(i, j):
		i += 1
		j += 1
		count += 1
		continue
	if a[i] > b[j]:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
(a, b) = (sorted(a), sorted(b))
(i, j, ans) = (0, 0, 0)
while i < n and j < m:
	while i < n and j < m and (b[j] < a[i] - 1):
		j += 1
	while i < n and j < m and (a[i] < b[j] - 1):
		i += 1
	if i < n and j < m and (abs(a[i] - b[j]) < 2):
		ans += 1
		i += 1
		j += 1
print(ans)


def get_max_pairs(n, m, boys, girls):
	boys.sort()
	girls.sort()
	people = []
	i = j = 0
	while i < n or j < m:
		a = b = None
		if i < n:
			a = boys[i]
		if j < m:
			b = girls[j]
		if a != None and b != None:
			if a < b:
				people.append(('B', a))
				i += 1
				if b - a <= 1:
					people.append(('G', b))
					j += 1
			elif b < a:
				people.append(('G', b))
				j += 1
				if a - b <= 1:
					people.append(('B', a))
					i += 1
			else:
				people.append(('B', a))
				people.append(('G', b))
				i += 1
				j += 1
		else:
			if a == None:
				people.append(('G', b))
			else:
				people.append(('B', a))
			break
	max_pairs = 0
	i = 0
	l = len(people)
	while i < l - 1:
		if people[i][0] == 'B' and people[i + 1][0] == 'G' and (people[i + 1][1] - people[i][1] <= 1):
			max_pairs += 1
			i += 2
		elif people[i][0] == 'G' and people[i + 1][0] == 'B' and (people[i + 1][1] - people[i][1] <= 1):
			max_pairs += 1
			i += 2
		else:
			i += 1
	return max_pairs
n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
print(get_max_pairs(n, m, boys, girls))


n = input()
boys = list(map(int, input().split(' ')))
m = input()
girls = list(map(int, input().split(' ')))
boys.sort()
girls.sort()
count = 0
for boy in boys:
	for index in range(0, len(girls)):
		if abs(boy - girls[index]) <= 1:
			count += 1
			girls.pop(index)
			break
	if len(girls) == 0:
		break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
i = 0
j = 0
cnt = 0
while i < len(a) and j < len(b):
	if abs(a[i] - b[j]) <= 1:
		i += 1
		j += 1
		cnt += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(cnt)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil, sqrt, gcd
n = int(input())
l = list(map(int, input().split()))
boy = {}
x = []
for i in l:
	if i in boy:
		boy[i] += 1
	else:
		boy[i] = 1
		x.append(i)
z = []
girl = {}
n2 = int(input())
for i in list(map(int, input().split())):
	if i in girl:
		girl[i] += 1
	else:
		girl[i] = 1
		z.append(i)
z.sort(reverse=True)
count = 0
for i in z:
	if i + 1 in boy:
		c = min(boy[i + 1], girl[i])
		boy[i + 1] -= c
		girl[i] -= c
		count += c
	if i in boy:
		c = min(boy[i], girl[i])
		boy[i] -= c
		girl[i] -= c
		count += c
	if i - 1 in boy:
		c = min(boy[i - 1], girl[i])
		boy[i - 1] -= c
		girl[i] -= c
		count += c
print(count)


import sys
import math
a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
b.sort()
d.sort()
e = 0
f = 0
g = 0
while e != a and f != c:
	if abs(b[e] - d[f]) <= 1:
		g += 1
		e += 1
		f += 1
	elif b[e] > d[f]:
		f += 1
	elif d[f] > b[e]:
		e += 1
print(g)


n = int(input())
a = input()
m = int(input())
b = input()
A = []
B = []
for i in a.split():
	A.append(int(i))
for j in b.split():
	B.append(int(j))
A.sort()
B.sort()
x = 0
count = 0
for k in range(0, n):
	for l in range(0, m - x):
		if abs(A[k] - B[l]) <= 1:
			count = count + 1
			del B[l]
			x = x + 1
			break
print(count)


n = int(input())
n_lis = [int(s) for s in input().split()]
m = int(input())
m_lis = [int(s) for s in input().split()]
ans = 0
n_lis.sort()
m_lis.sort()
for i in range(n):
	for j in range(m):
		if abs(n_lis[i] - m_lis[j]) <= 1:
			ans += 1
			m_lis[j] = 1000000
			break
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
coun = 0
for elem in a:
	if elem - 1 in b:
		coun += 1
		b.remove(elem - 1)
	elif elem in b:
		coun += 1
		b.remove(elem)
	elif elem + 1 in b:
		coun += 1
		b.remove(elem + 1)
print(coun)


def process(boys, girls):
	boys = sorted(boys, reverse=True)
	count = 0
	for boy in boys:
		if boy + 1 in girls:
			count = count + 1
			girls.pop(girls.index(boy + 1))
		elif boy in girls:
			count = count + 1
			girls.pop(girls.index(boy))
		elif boy - 1 in girls:
			count = count + 1
			girls.pop(girls.index(boy - 1))
	return count
n = int(input())
boys = [int(x) for x in input().strip().split()]
m = int(input())
girls = [int(x) for x in input().strip().split()]
if n <= m:
	ans = process(boys, girls)
else:
	ans = process(girls, boys)
print(ans)


n = input()
boys = input().split(' ')
n = input()
girls = input().split(' ')
cont = 0
for boy in boys:
	boys[cont] = int(boy)
	cont += 1
cont = 0
for girl in girls:
	girls[cont] = int(girl)
	cont += 1
boys.sort()
girls.sort()
cont = 0
for boy in boys:
	guia = 0
	for girl in girls:
		if abs(boy - girl) < 2:
			girls[guia] = -1000
			cont += 1
			guia += 1
			break
		else:
			guia += 1
print(cont)


a = int(input())
s = sorted(list(map(int, input().split())))
b = int(input())
z = sorted(list(map(int, input().split())))
l = 0
for n in range(a):
	if s[n] != -1:
		for k in range(b):
			if abs(s[n] - z[k]) <= 1:
				s[n] = -1
				z[k] = -1
				l += 1
				break
print(l)


str_n = input()
boys_str = input()
str_m = input()
girls_str = input()
n = int(str_n)
m = int(str_m)
boys_l = boys_str.split(' ')
girls_l = girls_str.split(' ')
boys = []
girls = []
for i in boys_l:
	boys.append(int(i))
for i in girls_l:
	girls.append(int(i))
boys.sort()
girls.sort()
parejas = 0
while len(boys) != 0 and len(girls) != 0:
	if boys[0] - girls[0] > 1:
		girls.pop(0)
	elif girls[0] - boys[0] > 1:
		boys.pop(0)
	else:
		boys.pop(0)
		girls.pop(0)
		parejas += 1
print(parejas)


b = []
g = []
c = 0
n = int(input())
b = input().split()
m = int(input())
g = input().split()
for i in range(n):
	b[i] = int(b[i])
for i in range(m):
	g[i] = int(g[i])
b.sort()
b = b[::-1]
g.sort()
g = g[::-1]
for i in range(len(b)):
	j = 0
	while j < len(g):
		if b[i] == g[j] or b[i] == g[j] + 1 or b[i] == g[j] - 1:
			c += 1
			g[j] = -1
			break
		j += 1
print(c)


def solve():
	boys = int(input())
	boys_dance_skills = [int(x) for x in input().split()]
	girls = int(input())
	girls_dance_skills = [int(x) for x in input().split()]
	visited = [False for x in range(girls)]
	boys_dance_skills.sort()
	girls_dance_skills.sort()
	result = 0
	for i in range(boys):
		for j in range(girls):
			if not visited[j] and abs(girls_dance_skills[j] - boys_dance_skills[i]) <= 1:
				result += 1
				visited[j] = True
				break
	print(result)
solve()


n = int(input())
b = sorted(list(map(int, input().split())))
m = int(input())
g = sorted(list(map(int, input().split())))
M = [[0] * m for _ in range(n)]
bool = False
for i in range(m - 1, -1, -1):
	if not bool and abs(g[i] - b[n - 1]) <= 1:
		M[n - 1][i] = 1
		bool = True
	elif bool:
		M[n - 1][i] = 1
bool = False
for i in range(n - 1, -1, -1):
	if not bool and abs(b[i] - g[m - 1]) <= 1:
		M[i][m - 1] = 1
		bool = True
	elif bool:
		M[i][m - 1] = 1
for i in range(n - 2, -1, -1):
	for j in range(m - 2, -1, -1):
		if abs(b[i] - g[j]) <= 1:
			M[i][j] = M[i + 1][j + 1] + 1
		else:
			M[i][j] = max(M[i + 1][j], M[i][j + 1])
print(M[0][0])


lines = [list(map(int, line.split())) for line in [*open(0)]]
(n, a, m, b) = (lines[0][0] - 1, lines[1], lines[2][0] - 1, lines[3])
a.sort()
b.sort()
sol = 0
while n >= 0 and m >= 0:
	if abs(a[n] - b[m]) <= 1:
		sol += 1
		n -= 1
		m -= 1
	elif a[n] > b[m]:
		n -= 1
	else:
		m -= 1
print(sol)


m = int(input())
a = input().split()
a = [int(i) for i in a]
a.sort()
n = int(input())
b = input().split()
b = [int(i) for i in b]
b.sort()
(i, j) = (0, 0)
ans = 0
while i != m and j != n:
	if a[i] - b[j] <= 1 and a[i] - b[j] >= -1:
		i += 1
		j += 1
		ans += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(ans)


from sys import stdin as Si, maxsize as m
from math import floor as F
from collections import defaultdict as dt, Counter as Co
from operator import itemgetter as ig
from math import pi
from itertools import product as P
n = int(Si.readline())
B = sorted(map(int, Si.readline().split()))
m = int(Si.readline())
G = sorted(map(int, Si.readline().split()))
C = 0
for i in range(n):
	j = 0
	while j < len(G):
		if abs(B[i] - G[j]) <= 1:
			C += 1
			G.pop(j)
			break
		j += 1
print(C)


def pair(h, n_h, m, n_m):
	list_h = n_h.strip('\n').split(' ')
	list_m = n_m.strip('\n').split(' ')
	for i in range(len(list_h)):
		list_h[i] = int(list_h[i])
	for j in range(len(list_m)):
		list_m[j] = int(list_m[j])
	list_h.sort()
	list_m.sort()
	counter = 0
	index = 0
	for x in list_h:
		while index < len(list_m):
			if x + 1 < list_m[index]:
				break
			elif x - 1 > list_m[index]:
				index += 1
			else:
				counter += 1
				index += 1
				break
	return counter
h = input()
n_h = input()
m = input()
n_m = input()
print(pair(h, n_h, m, n_m))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().split()]
b.sort()
count = 0
for x in range(0, n):
	for y in range(0, m):
		if a[x] - b[y] <= 1 and a[x] - b[y] >= -1:
			count = count + 1
			b[y] = -100
			break
print(count)


n = int(input())
n_set = input()
n_set = n_set.split(' ')
n_set = [int(num) for num in n_set]
n_set.sort()
m = int(input())
m_set = input()
m_set = m_set.split(' ')
m_set = [int(num) for num in m_set]
m_set.sort()
counter = 0
for i in range(n):
	for j in range(m):
		if abs(n_set[i] - m_set[j]) <= 1:
			m_set.pop(j)
			m -= 1
			counter += 1
			break
print(str(counter))


b = int(input())
boys = list(map(int, input().split()))
g = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
res = i = j = 0
while i < g:
	if j >= b:
		break
	sub = boys[j] - girls[i]
	if sub >= -1 and sub <= 1:
		res += 1
		j += 1
	elif boys[j] < girls[i]:
		i -= 1
		j += 1
	i += 1
print(res)


n = int(input())
boys_skills = list(map(int, input().split()))
m = int(input())
girls_skills = list(map(int, input().split()))
boys_skills.sort()
girls_skills.sort()
girls_pointer = 0
matchs = 0
for boys_pointer in range(n):
	for j in range(girls_pointer, m):
		if abs(boys_skills[boys_pointer] - girls_skills[j]) <= 1:
			if girls_pointer < j:
				girls_pointer = j + 1
			elif girls_pointer == j:
				girls_pointer += 1
			matchs += 1
			break
print(matchs)


n = input()
a = [int(a) for a in input().split(' ')]
n = input()
b = [int(b) for b in input().split(' ')]
a.sort()
b.sort()
answer = 0
usedB = dict()
for i in range(0, len(a)):
	for j in range(0, len(b)):
		if abs(a[i] - b[j]) <= 1:
			if not j in usedB:
				answer = answer + 1
				usedB[j] = 1
				break
print(answer)


def dfs(u):
	if used[u]:
		return False
	used[u] = 1
	for i in range(m):
		if abs(a[u] - b[i]) < 2 and (pair[i] == -1 or dfs(pair[i])):
			pair[i] = u
			return True
	return False
(n, a, m, b) = (int(input()), list(map(int, input().split())), int(input()), list(map(int, input().split())))
pair = [-1] * m
for i in range(n):
	used = [0] * n
	dfs(i)
print(sum((1 for p in pair if p != -1)))


from sys import stdin
lines = list(filter(None, stdin.read().split('\n')))

def parseline(line):
	return list(map(int, line.split()))
lines = list(map(parseline, lines))
(n,) = lines[0]
a = lines[1]
(m,) = lines[2]
b = lines[3]
assert len(a) == n and len(b) == m
Max = 100 + 1
ai_count = [0] * Max
bi_count = [0] * Max
for ai in a:
	ai_count[ai] += 1
for bi in b:
	bi_count[bi] += 1
match = [[] for i in range(Max)]
used = None

def dfs(v):
	if used[v] >= ai_count[v]:
		return False
	used[v] += 1
	for to in range(max(0, v - 1), min(Max, v + 2)):
		if len(match[to]) < bi_count[to]:
			match[to].append(v)
			return True
		for (i, to_i) in enumerate(match[to]):
			if dfs(to_i):
				match[to][i] = v
				return True
	return False
for i in range(Max):
	for _ in range(ai_count[i]):
		used = [0] * Max
		dfs(i)
print(sum((len(l) for l in match)))


a = int(input())
lst1 = list(map(int, input().split()))
b = int(input())
lst2 = list(map(int, input().split()))
lst1.sort()
lst2.sort()
i = j = 0
count = 0
if a >= b:
	n = a
else:
	n = b
count = 0
while i < a and j < b:
	if lst1[i] - lst2[j] == 0 or lst1[i] - lst2[j] == -1 or lst1[i] - lst2[j] == 1:
		i += 1
		j += 1
		count += 1
	elif lst1[i] > lst2[j]:
		j += 1
	else:
		i += 1
print(count)


import math
n = int(input())
z_1 = input()
a = z_1.split(' ')
for i in range(n):
	q_a = int(a[i])
	a[i] = q_a
	q_a = None
a.sort()
m = int(input())
z_2 = input()
b = z_2.split(' ')
for j in range(m):
	q_b = int(b[j])
	b[j] = q_b
	q_b = None
b.sort()
pair = 0
summ_a = 0
summ_b = 0
for i in range(n):
	for j in range(m):
		q = int(a[i]) - int(b[j])
		ra_zn = abs(q)
		if ra_zn <= 1:
			pair += 1
			del b[j]
			m = m - 1
			n = n - 1
			break
print(pair)


import sys
data = sys.stdin.readlines()
archivo = [line.split() for line in data]
archivo_int = [[int(j) for j in i] for i in archivo]
archivo_int[1].sort()
archivo_int[3].sort()
hombres = archivo_int[1]
mujeres = archivo_int[3]
parejas = 0
while len(hombres) != 0 and len(mujeres) != 0:
	if abs(hombres[0] - mujeres[0]) <= 1:
		parejas += 1
		hombres.pop(0)
		mujeres.pop(0)
	elif abs(hombres[-1] - mujeres[-1]) <= 1:
		parejas += 1
		hombres.pop(-1)
		mujeres.pop(-1)
	elif mujeres[0] < hombres[0]:
		mujeres.pop(0)
	elif mujeres[0] > hombres[0]:
		hombres.pop(0)
	elif mujeres[-1] > hombres[-1]:
		mujeres.pop(-1)
	elif mujeres[-1] < hombres[-1]:
		hombres.pop(-1)
print(parejas)


m = int(input())
mskil = list(map(int, input().split()))
d = int(input())
dskil = list(map(int, input().split()))
mskil.sort()
dskil.sort()
i = 0
j = 0
count = 0
while i < m and j < d:
	if abs(mskil[i] - dskil[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif mskil[i] < dskil[j]:
		i += 1
	else:
		j += 1
print(count)


(a, lst1, b, lst2, pair) = (int(input()), sorted(list(map(int, input().split()))), int(input()), sorted(list(map(int, input().split()))), 0)
[i, j] = (0, 0)
while i < a and j < b:
	if lst1[i] - lst2[j] in [1, 0, -1]:
		(i, j, pair) = (i + 1, j + 1, pair + 1)
	elif lst1[i] <= lst2[j]:
		i += 1
	elif lst1[i] > lst2[j]:
		j += 1
else:
	print(pair)


def ball(n, a, m, b):
	(n, m) = (int(n), int(m))
	a = sorted(list(map(int, a.split())))
	b = sorted(list(map(int, b.split())))
	i = 0
	j = 0
	pairs = 0
	while i < n and j < m:
		if abs(a[i] - b[j]) < 2:
			pairs += 1
			i += 1
			j += 1
		elif a[i] < b[j]:
			i += 1
		else:
			j += 1
	print(pairs)
ball(input(), input(), input(), input())


n = input()
a = list(map(int, input().split()))
m = input()
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
ans = 0

def match(a1, a2):
	for i in range(0, len(a1)):
		for j in range(0, len(a2)):
			if abs(a1[i] - a2[j]) < 2:
				global ans
				ans += 1
				a2.remove(a2[j])
				break
if n > m:
	match(a, b)
	print(ans)
else:
	match(b, a)
	print(ans)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
res = 0
girls_done = 0
for i in range(len(b)):
	for j in range(girls_done, len(g)):
		boy = b[i]
		girl = g[j]
		if abs(boy - girl) <= 1:
			res += 1
			girls_done = min(j + 1, len(g))
			break
print(res)


maxPair = 0

def match(b, g, ib=0, count=0):
	global maxPair
	if ib == len(b) or len(g) == 0:
		maxPair = max(maxPair, count)
		return
	elif b[ib] - 1 in g:
		g.remove(b[ib] - 1)
		match(b, g, ib + 1, count + 1)
	elif b[ib] in g:
		g.remove(b[ib])
		match(b, g, ib + 1, count + 1)
	elif b[ib] + 1 in g:
		g.remove(b[ib] + 1)
		match(b, g, ib + 1, count + 1)
	else:
		match(b, g, ib + 1, count)
input()
b = list(map(int, input().split()))
input()
g = list(map(int, input().split()))
b.sort()
g.sort()
match(b, g)
print(maxPair)


n1 = int(input())
a1 = list(map(int, input().split()))
a1.sort()
n2 = int(input())
a2 = list(map(int, input().split()))
a2.sort()
if n1 > n2:
	(n1, n2) = (n2, n1)
	(a1, a2) = (a2, a1)
r = [[0 for i in range(n1)] for j in range(n2)]
for i in range(n2):
	r[i][0] = max(int(abs(a1[0] - a2[i]) < 2), r[i - 1][0])
for i in range(n1):
	r[0][i] = max(int(abs(a1[i] - a2[0]) < 2), r[0][i - 1])
for i in range(1, n1):
	for j in range(1, n2):
		if abs(a1[i] - a2[j]) < 2:
			r[j][i] = r[j - 1][i - 1] + 1
		else:
			r[j][i] = max(r[j][i - 1], r[j - 1][i])
print(r[n2 - 1][n1 - 1])


n = int(input())
A = sorted(list(map(int, input().split())))
m = int(input())
B = sorted(list(map(int, input().split())))
(r, cnt) = (0, 0)
for l in range(n):
	if B[r] - A[l] > 1:
		continue
	while r < m - 1 and B[r] - A[l] < -1:
		r += 1
	if -2 < B[r] - A[l] < 2:
		cnt += 1
	else:
		continue
	if r == m - 1:
		break
	r += 1
print(cnt)


from sys import stdin
n = stdin.readline()
a = [int(i) for i in stdin.readline().split()]
m = stdin.readline()
b = [int(i) for i in stdin.readline().split()]
a.sort(reverse=True)
b.sort(reverse=True)
i = 0
j = 0
counter = 0
while i != len(a) and j != len(b):
	if abs(a[i] - b[j]) <= 1:
		counter += 1
		i += 1
		j += 1
	elif a[i] > b[j]:
		i += 1
	elif a[i] < b[j]:
		j += 1
print(counter)


n = int(input())
a = list(map(int, input().strip().split(' ')))
m = int(input())
b = list(map(int, input().strip().split(' ')))
a.sort()
b.sort()
bv = [1] * m
for i in range(n):
	for j in range(m):
		if bv[j] == 1 and abs(a[i] - b[j]) <= 1:
			bv[j] = 0
			break
print(bv.count(0))


nb = int(input())
bl = sorted(list(map(int, input().split())))
ng = int(input())
gl = sorted(list(map(int, input().split())))
c = 0
for i in range(nb):
	for j in range(ng):
		if abs(bl[i] - gl[j]) <= 1:
			c += 1
			gl[j] = 9999999
			break
print(c)


input()
a = sorted(map(int, input().split()))
input()
b = sorted(map(int, input().split()))
c = 0
while a:
	if not b:
		break
	if a[0] - b[0] in [0, 1, -1]:
		c += 1
		(a, b) = (a[1:], b[1:])
	elif a[0] > b[0]:
		b = b[1:]
	else:
		a = a[1:]
print(c)


n = input()
a = [int(x) for x in input().split()]
m = input()
b = [int(x) for x in input().split()]
a.sort()
b.sort()
result = 0
for x in a:
	for y in range(len(b)):
		if abs(x - b[y]) <= 1:
			result += 1
			b[y] = 1000
			break
print(result)


n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l.sort()
l1.sort()
c = 0
i = 0
j = 0
while i < n and j < m:
	if l[i] == l1[j] or abs(l[i] - l1[j]) == 1:
		c += 1
		i += 1
		j += 1
	elif l[i] - l1[j] >= 2:
		j += 1
	elif l1[j] - l[i] >= 2:
		i += 1
print(c)


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
ans = 0
i = j = 0
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		ans += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	elif a[i] > b[j]:
		j += 1
	elif i + 1 == n:
		j += 1
	elif j + 1 == m:
		i += 1
	elif abs(a[i + 1] - b[j]) < abs(a[i] - b[j + 1]):
		i += 1
	else:
		j += 1
stdout.write(str(ans))


n = input()
boys = sorted([int(x) for x in input().split()])
m = input()
girls = sorted([int(x) for x in input().split()])

def f(l, m):
	count = 0
	for i in l:
		count += 1
		try:
			m.remove(i - 1)
		except ValueError:
			try:
				m.remove(i)
			except ValueError:
				try:
					m.remove(i + 1)
				except ValueError:
					count -= 1
	print(count)
if len(boys) <= len(girls):
	f(boys, girls)
else:
	f(girls, boys)


import math
n = eval(input())
boys = input().split(' ')
y = eval(input())
girls = input().split(' ')
i = 0
while i < len(boys):
	boys[i] = int(boys[i])
	i = i + 1
i = 0
while i < len(girls):
	girls[i] = int(girls[i])
	i = i + 1
boys.sort()
girls.sort()
i = 0
j = 0
pairs = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) < 2:
		i = i + 1
		j = j + 1
		pairs += 1
	elif boys[i] > girls[j]:
		j = j + 1
	else:
		i = i + 1
print(pairs)


n = int(input())
boys = list(sorted(map(int, input().split())))
m = int(input())
girls = list(sorted(map(int, input().split())))
(b, g, ans) = (0, 0, 0)
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = 10000
			ans += 1
			break
print(ans)


n = int(input())
l1 = [int(s) for s in input().split()]
m = int(input())
l2 = [int(s) for s in input().split()]
l1.sort()
l2.sort()
i = j = c = 0
while i < n and j < m:
	if abs(l1[i] - l2[j]) <= 1:
		c += 1
		i += 1
		j += 1
	elif l1[i] < l2[j]:
		i += 1
	else:
		j += 1
print(c)


import math
_ = input()
boys = [int(i) for i in input().split(' ')]
_ = input()
girls = [int(i) for i in input().split(' ')]
boys = sorted(boys)
girls = sorted(girls)
count = 0
for boy in boys:
	index = 0
	while index < len(girls):
		girl = girls[index]
		if girls != -1 and abs(boy - girl) <= 1:
			count += 1
			girls[index] = -1
			break
		index += 1
print(count)


nboys = int(input())
boys = [int(x) for x in input().split()]
boys.sort()
ngirls = int(input())
girls = [int(x) for x in input().split()]
girls.sort()
cnt = 0
for i in boys:
	lis = []
	for j in range(len(girls)):
		if abs(i - girls[j]) <= 1:
			lis.append(j)
	if len(lis) > 0:
		k = min(lis)
		del girls[:k + 1]
		cnt += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
count = 0
(x, y) = (0, 0)
while x < len(a) and y < len(b):
	if a[x] == b[y] or a[x] - b[y] == 1 or b[y] - a[x] == 1:
		count += 1
		x += 1
		y += 1
	elif a[x] < b[y]:
		x += 1
	else:
		y += 1
print(count)


a = int(input())
a1 = sorted([int(i) for i in input().split()])
b = int(input())
b1 = sorted([int(i) for i in input().split()])
k = 0
for i in range(a):
	for y in range(b):
		if abs(a1[i] - b1[y]) <= 1:
			b1[y] = 1000
			k += 1
			break
print(k)


n = int(input())
A = [int(k) for k in input().split()]
A.sort()
m = int(input())
B = [int(k) for k in input().split()]
B.sort()
compteur = 0
i = 0
j = 0
while i < n and j < m:
	if A[i] + 1 < B[j]:
		i += 1
	elif B[j] + 1 < A[i]:
		j += 1
	else:
		compteur += 1
		i += 1
		j += 1
print(compteur)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
cnt = 0
a.sort()
b.sort()
for i in a:
	if i - 1 in b:
		cnt += 1
		b.remove(i - 1)
	elif i in b:
		cnt += 1
		b.remove(i)
	elif i + 1 in b:
		cnt += 1
		b.remove(i + 1)
print(cnt)


n = int(input())
list1 = list(map(int, input().split()))
list1.sort()
m = int(input())
list2 = list(map(int, input().split()))
list2.sort()
c = 0
for i in list1:
	for j in range(0, len(list2)):
		if abs(i - list2[j]) <= 1:
			c = c + 1
			list2[j] = -1
			break
print(c)


n = int(input())
boy = [int(i) for i in input().split()]
m = int(input())
girl = [int(j) for j in input().split()]
boy.sort()
girl.sort()
pair = 0
for k in boy:
	if k - 1 in girl:
		pair = pair + 1
		del girl[girl.index(k - 1)]
	elif k in girl:
		pair = pair + 1
		del girl[girl.index(k)]
	elif k + 1 in girl:
		pair = pair + 1
		del girl[girl.index(k + 1)]
print(pair)


def read_input():
	n = int(input())
	xs = map(int, input().split(' '))
	return (n, list(xs))
(n, boys) = read_input()
(m, girls) = read_input()
boys.sort()
girls.sort()
pairs = 0
(i, j) = (0, 0)
while i < n and j < m:
	d = boys[i] - girls[j]
	if abs(d) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif d < 0:
		i += 1
	else:
		j += 1
print(pairs)


__author__ = 'neki'
import sys
global n, source, drain, edge, cap, flow, prev, stack
global status, time
global infinity
infinity = 1000000

def readData():
	global n, source, drain, edge, cap, flow
	global status, time
	status = []
	nBoys = int(input())
	skillBoy = []
	words = input().split()
	for w in words:
		status.append(0)
		skillBoy.append(int(w))
	nGirls = int(input())
	skillGirl = []
	words = input().split()
	for w in words:
		status.append(1)
		skillGirl.append(int(w))
	n = nGirls + nBoys
	source = n
	drain = n + 1
	n += 2
	cap = [[0 for x in range(n)] for x in range(n)]
	flow = [[0 for x in range(n)] for x in range(n)]
	edge = [[] for x in range(n)]
	for i in range(n - 2):
		if status[i] == 0:
			cap[source][i] = 1
			edge[source].append(i)
			edge[i].append(source)
		else:
			cap[i][drain] = 1
			edge[i].append(drain)
			edge[drain].append(i)
	for i in edge[source]:
		for j in edge[drain]:
			dif = skillBoy[i] - skillGirl[j - nBoys]
			if dif == -1 or dif == 0 or dif == 1:
				cap[i][j] = 1
				edge[i].append(j)
				edge[j].append(i)

def bf():
	global n, source, drain, edge, cap, flow, prev, stack
	vis = [0 for x in range(n)]
	prev = [-1 for x in range(n)]
	stack[0] = source
	vis[source] = 1
	lStack = 1
	k = 0
	while k < lStack:
		node1 = stack[k]
		for node2 in edge[node1]:
			if vis[node2] == 0 and cap[node1][node2] > flow[node1][node2]:
				stack[lStack] = node2
				lStack += 1
				vis[node2] = 1
				prev[node2] = node1
				if node2 == drain:
					return 1
		k += 1
	if vis[drain] == 1:
		return 1
	return 0
readData()
maxFlow = 0
stack = [None] * n
while bf() == 1:
	i = prev[drain]
	minUpdate = cap[i][drain] - flow[i][drain]
	node = i
	while prev[node] >= 0:
		dif = cap[prev[node]][node] - flow[prev[node]][node]
		if dif < minUpdate:
			minUpdate = dif
		node = prev[node]
	flow[i][drain] += minUpdate
	flow[drain][i] -= minUpdate
	node = i
	while prev[node] >= 0:
		flow[prev[node]][node] += minUpdate
		flow[node][prev[node]] -= minUpdate
		node = prev[node]
	maxFlow += minUpdate
print(maxFlow)


import sys

def stdinWrapper():
	data = '5\n1 1 1 1 1\n3\n1 2 3\n\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield input()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]
boyCount = getType(int)
boySkills = getArray(int)
girlCount = getType(int)
girlSkills = getArray(int)
boySkills.sort()
girlSkills.sort()
boyId = 0
girlId = 0
result = 0
while boyId < len(boySkills) and girlId < len(girlSkills):
	currentBoy = boySkills[boyId]
	currentGirl = girlSkills[girlId]
	difference = abs(currentBoy - currentGirl)
	if difference <= 1:
		result += 1
		boyId += 1
		girlId += 1
	elif currentBoy < currentGirl:
		boyId += 1
	else:
		girlId += 1
print(result)


t1 = int(input())
boys = [int(x) for x in input().split()]
boys.sort()
t2 = int(input())
girls = [int(x) for x in input().split()]
girls.sort()
count = 0
flag = 3000
for i in range(0, t1, 1):
	for j in range(0, t2, 1):
		dif = abs(int(boys[i]) - int(girls[j]))
		if dif == 0 or dif == 1:
			count += 1
			girls[j] = flag
			break
		else:
			count = count
			continue
print(count)


n = int(input())
m = sorted(list(map(int, input().split())))
k = int(input())
d = sorted(list(map(int, input().split())))
cnt = 0
for i in range(max(n, k)):
	for j in range(min(n, k)):
		if n > k:
			(f, s) = (m, d)
		else:
			(f, s) = (d, m)
		if abs(f[i] - s[j]) <= 1 and f[i] != -1 and (s[j] != -1):
			f[i] = -1
			s[j] = -1
			cnt += 1
print(cnt)


n = int(input())
l = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
l.sort()
t.sort()
(p, i, j) = (0, 0, 0)
while i < n:
	if j >= len(t):
		break
	if l[i] == t[j] or l[i] == t[j] + 1 or l[i] == t[j] - 1:
		p += 1
		del t[j]
		i += 1
	elif j < len(t) - 1:
		j += 1
	else:
		j = 0
		i += 1
print(p)


(n, list_n) = (int(input()), sorted(list(map(int, input().split()))))
(m, list_m) = (int(input()), sorted(list(map(int, input().split()))))
max_counter_global = 0
for i in range(n):
	for j in range(len(list_m)):
		if abs(list_n[i] - list_m[j]) <= 1:
			max_counter_global += 1
			del list_m[j]
			break
print(max_counter_global)


import math
n = int(input())
n1 = [int(i) for i in input().split(' ')]
m = int(input())
m1 = [int(i) for i in input().split(' ')]
m1.sort()
n1.sort()
i = 0
j = 0
mi = max(n, m)
sum = 0
while i < len(n1) and j < len(m1):
	if math.fabs(n1[i] - m1[j]) <= 1:
		sum = sum + 1
		i = i + 1
		j = j + 1
	elif n1[i] - m1[j] > 1:
		j = j + 1
	else:
		i = i + 1
print(sum)


n = int(input())
boys = list(map(int, input().split()))
boys.sort(reverse=True)
m = int(input())
girls = list(map(int, input().split()))
girls.sort(reverse=True)
combo = 0
for i in range(n):
	for j in range(m):
		if girls[j] != 0 and boys[i] != 0 and (abs(boys[i] - girls[j]) <= 1):
			combo += 1
			girls[j] = 0
			boys[i] = 0
			break
print(combo)


x = int(input())
a = list(map(int, input().split()))
y = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
s = 0
for i in a:
	k = b
	for j in k:
		if abs(i - j) <= 1:
			s += 1
			b.remove(j)
			break
print(s)


b = int(input())
s1 = [int(i) for i in input().split(' ')]
g = int(input())
s2 = [int(i) for i in input().split(' ')]
s1.sort()
s2.sort()
ans = 0
for i in range(b):
	for j in range(g):
		if abs(s1[i] - s2[j]) <= 1:
			s2[j] = 1000
			ans += 1
			break
print(ans)


n = int(input())
l1 = sorted(list(map(int, input().split())))
m = int(input())
l2 = list(map(int, input().split()))
a = 0
for i in l1:
	if (i - 1 in l2) == True:
		l2.remove(i - 1)
		a = a + 1
	elif (i in l2) == True:
		l2.remove(i)
		a = a + 1
	elif (i + 1 in l2) == True:
		l2.remove(i + 1)
		a = a + 1
print(a)


N = int(input())
L = list(map(int, input().split()))
M = int(input())
G = list(map(int, input().split()))
L.sort()
G.sort()
(i, j) = (0, 0)
count = 0
while i < N and j < M:
	if abs(L[i] - G[j]) <= 1:
		i += 1
		j += 1
		count += 1
	elif L[i] > G[j]:
		j += 1
	else:
		i += 1
print(count)


n = int(input())
arr_n = list(map(int, input().split()))
arr_n.sort()
m = int(input())
arr_m = list(map(int, input().split()))
arr_m.sort()
cnt = 0
for i in range(n):
	for j in range(m):
		if abs(arr_n[i] - arr_m[j]) <= 1:
			cnt += 1
			arr_m[j] = -1
			break
print(cnt)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b = sorted(b)
g = sorted(g)
c = 0
for i in range(0, len(b)):
	for j in range(0, len(g)):
		if abs(b[i] - g[j]) <= 1:
			c = c + 1
			g[j] = -6
			break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
for val_a in a:
	for (ind_b, val_b) in enumerate(b):
		if abs(val_a - val_b) <= 1:
			ans += 1
			b[ind_b] = 1000
			break
print(ans)


n = int(input())
kw = input().split()
m = int(input())
bw = input().split()
a = []
b = []
for i in range(n):
	a.append(int(kw[i]))
for i in range(m):
	b.append(int(bw[i]))
a.sort()
b.sort()
count = 0
if len(a) <= len(b):
	for k in range(len(a)):
		j = 0
		while j < len(b):
			if abs(a[k] - b[j]) <= 1:
				count += 1
				b = b[j + 1:]
				break
			elif a[k] > b[j]:
				b = b[j + 1:]
				j = 0
			else:
				break
else:
	for k in range(len(b)):
		j = 0
		while j < len(a):
			if abs(b[k] - a[j]) <= 1:
				count += 1
				a = a[j + 1:]
				break
			elif b[k] > a[j]:
				a = a[j + 1:]
				j = 0
			else:
				break
print(count)


x = int(input())
a = list(map(int, input().split()))
y = int(input())
b = list(map(int, input().split()))
c = 0
a.sort()
b.sort()
k = 0
for i in range(x):
	for j in range(0, y):
		if abs(a[i] - b[j]) <= 1:
			c += 1
			b[j] = -1
			k = j
			break
print(c)


n = int(input())
skills_n = sorted(map(int, input().split()))
m = int(input())
skills_m = sorted(map(int, input().split()))
i = 0
j = 0
pair = 0
while i < n and j < m:
	if skills_n[i] == skills_m[j] or abs(skills_n[i] - skills_m[j]) == 1:
		i += 1
		j += 1
		pair += 1
	elif skills_n[i] < skills_m[j]:
		i += 1
	else:
		j += 1
print(pair)


def md(a):
	if a < 0:
		return -a
	return a
b = int(input())
blist = [int(i) for i in input().split()]
blist.sort()
g = int(input())
glist = [int(i) for i in input().split()]
glist.sort()
pair = 0
i = 0
j = 0
while i < len(blist) and j < len(glist):
	if md(blist[i] - glist[j]) <= 1:
		pair += 1
		i += 1
		j += 1
	elif blist[i] > glist[j]:
		j += 1
	else:
		i += 1
print(pair)


n_hombres = int(input())
hombres = input().split(' ')
n_mujeres = int(input())
mujeres = input().split(' ')
for x in range(n_hombres):
	hombres[x] = int(hombres[x])
for x in range(n_mujeres):
	mujeres[x] = int(mujeres[x])
hombres.sort()
mujeres.sort()
indice_hombres = 0
indice_mujeres = 0
contador_parejas = 0
while True:
	if indice_hombres == n_hombres or indice_mujeres == n_mujeres:
		break
	if mujeres[indice_mujeres] - 1 <= hombres[indice_hombres] <= mujeres[indice_mujeres] + 1:
		contador_parejas += 1
		indice_hombres += 1
		indice_mujeres += 1
	elif hombres[indice_hombres] > mujeres[indice_mujeres] + 1:
		indice_mujeres += 1
	elif mujeres[indice_mujeres] - 1 > hombres[indice_hombres]:
		indice_hombres += 1
print(contador_parejas)


n = int(input())
men = sorted(map(int, input().split()))
m = int(input())
women = sorted(map(int, input().split()))
(i, j, count) = (0, 0, 0)
while i < n and j < m:
	if abs(men[i] - women[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif men[i] < women[j]:
		i += 1
	else:
		j += 1
print(count)


bn = int(input())
boy = [int(x) for x in input().split()]
boy.sort()
gn = int(input())
girl = [int(y) for y in input().split()]
girl.sort()
count = 0
for elem in boy:
	a = elem - 1
	b = elem + 1
	if a in girl:
		count += 1
		girl.remove(a)
	elif elem in girl:
		count += 1
		girl.remove(elem)
	elif b in girl:
		count += 1
		girl.remove(b)
print(count)


n = int(input())
b = [int(x) for x in input().split()]
b.sort()
m = int(input())
g = [int(x) for x in input().split()]
g.sort()
i = 0
j = 0
c = 0
while 1:
	if abs(b[i] - g[j]) <= 1:
		i += 1
		j += 1
		c += 1
		if i >= n or j >= m:
			break
	else:
		if b[i] > g[j]:
			i += 0
			j = j + 1
		elif b[i] < g[j]:
			i += 1
			j = j + 0
		if i >= n or j >= m:
			break
print(c)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(stdin.readline())

def In():
	return map(int, stdin.readline().split())

def main():
	try:
		n = I()
		b = list(In())
		b.sort()
		n1 = I()
		g = list(In())
		g.sort()
		ans = 0
		for i in range(n):
			for j in range(n1):
				if abs(b[i] - g[j]) <= 1:
					g[j] = 100000.0
					ans += 1
					break
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
N = list(map(int, input().split()))
m = int(input())
M = list(map(int, input().split()))
N.sort()
M.sort()
cnt = 0
for i in range(n):
	for j in range(len(M)):
		if abs(N[i] - M[j]) <= 1:
			cnt += 1
			M.pop(j)
			break
print(cnt)


nb = int(input())
boys = [int(x) for x in input().split()]
ng = int(input())
girls = [int(x) for x in input().split()]
boys.sort()
girls.sort()
count = 0
for i in range(nb):
	for j in range(ng):
		if girls[j] > 0:
			if abs(boys[i] - girls[j]) <= 1:
				count += 1
				girls[j] = 0
				break
print(count)


n = int(input())
boys = sorted(list(map(int, input().split(' '))))
m = int(input())
girls = sorted(list(map(int, input().split(' '))))
pairs = 0
for (i, boy) in enumerate(boys):
	for (j, girl) in enumerate(girls):
		if abs(boy - girl) < 2:
			girls[j] = 1000
			pairs += 1
			break
print(pairs)


b = int(input())
listb = [int(x) for x in input().split()]
listb = sorted(listb)
g = int(input())
listg = [int(x) for x in input().split()]
listg = sorted(listg)
count = 0
for i in range(len(listb)):
	if listb[i] - 1 in listg:
		count += 1
		listg.remove(listb[i] - 1)
	elif listb[i] in listg:
		count += 1
		listg.remove(listb[i])
	elif listb[i] + 1 in listg:
		count += 1
		listg.remove(listb[i] + 1)
print(count)


from collections import deque
from math import ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
n = ii()
a = li()
m = ii()
b = li()
a.sort()
b.sort()
c = 0
for i in range(n):
	x = a[i]
	for j in range(m):
		y = abs(x - b[j])
		if y <= 1:
			b.remove(b[j])
			c += 1
			m -= 1
			break
print(c)


n = int(input())
li1 = [int(x) for x in input().split()]
m = int(input())
li2 = [int(x) for x in input().split()]
li1.sort()
li2.sort()
if n < m:
	count = 0
	for i in range(n):
		for j in range(m):
			if li2[j] != 0 and abs(li1[i] - li2[j]) <= 1:
				li2[j] = 0
				count = count + 1
				break
	print(count)
else:
	count = 0
	for i in range(m):
		for j in range(n):
			if li1[j] != 0 and abs(li1[j] - li2[i]) <= 1:
				li1[j] = 0
				count = count + 1
				break
	print(count)


n = int(input())
pairs = 0
boy_skill = list(map(int, input().split()))
m = int(input())
girl_skill = list(map(int, input().split()))
boys = {}
for boy in boy_skill:
	boys[boy] = boys.get(boy, 0) + 1
for g_s in sorted(girl_skill):
	if boys.get(g_s - 1, 0) != 0:
		boys[g_s - 1] -= 1
		pairs += 1
	elif boys.get(g_s, 0) != 0:
		boys[g_s] -= 1
		pairs += 1
	elif boys.get(g_s + 1, 0) != 0:
		boys[g_s + 1] -= 1
		pairs += 1
print(pairs)


n = int(input())
a = [int(w) for w in input().split()]
m = int(input())
b = [int(e) for e in input().split()]
x = sorted(a)
y = sorted(b)
i = 0
j = 0
ans = 0
while i < n and j < m:
	if abs(x[i] - y[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif x[i] < y[j]:
		i += 1
	else:
		j += 1
print(ans)


n = int(input())
boy = [int(boy) for boy in input().split()]
m = int(input())
girl = [int(girl) for girl in input().split()]
res = 0
boy.sort()
girl.sort()
for i in range(n):
	for j in range(m):
		if abs(boy[i] - girl[j]) <= 1:
			res += 1
			girl[j] = -1
			break
print(res)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
j = 0
if a[-1] > b[-1]:
	i = n - 1
	while i != -1:
		if a[i] + 1 in b:
			j += 1
			m -= 1
			b.remove(a[i] + 1)
		elif a[i] in b[:m]:
			j += 1
			b.remove(a[i])
		elif a[i] - 1 in b:
			j += 1
			b.remove(a[i] - 1)
		i -= 1
else:
	i = m - 1
	while i != -1:
		if b[i] + 1 in a:
			j += 1
			a.remove(b[i] + 1)
		elif b[i] in a:
			j += 1
			a.remove(b[i])
		elif b[i] - 1 in a:
			j += 1
			a.remove(b[i] - 1)
		i -= 1
print(j)


import copy
n = int(input())
s = input()
s = s.split()
m = [int(s[i]) for i in range(n)]
u = int(input())
s = input()
s = s.split()
f = [int(s[i]) for i in range(u)]
f = sorted(f)
m = sorted(m)
c = 0
j = 0
if f[j] == m[0]:
	c = 1
	f.pop(0)
	m.pop(0)
if len(f) != 0:
	for i in range(len(m)):
		j = 0
		while m[i] > f[j] + 1:
			j = j + 1
			if j > len(f) - 1:
				break
		if j > len(f) - 1:
			break
		if f[j] == m[i] or m[i] == f[j] - 1 or m[i] - 1 == f[j]:
			c = c + 1
			f.pop(j)
		if len(f) == 0:
			break
print(c)


boys = int(input())
bskill = [int(x) for x in input().split()]
girls = int(input())
gskill = [int(x) for x in input().split()]
bskill.sort()
gskill.sort()
b = 0
g = 0
pairs = 0
while b < len(bskill) and g < len(gskill):
	if abs(bskill[b] - gskill[g]) <= 1:
		pairs += 1
		b += 1
		g += 1
	elif bskill[b] > gskill[g]:
		g += 1
	else:
		b += 1
print(pairs)


n = int(input())
na = list(map(int, input().split()))
m = int(input())
ma = list(map(int, input().split()))
count = 0
j = 0
na.sort()
ma.sort()
if len(na) > len(ma):
	(na, ma) = (ma, na)
i = 0
while i < len(na) and j < len(ma):
	if abs(na[i] - ma[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif na[i] > ma[j]:
		j += 1
	elif na[i] < ma[j]:
		i += 1
print(count)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a.sort()
b.sort()
flag = []
for i in range(m):
	flag.append(1)
for i in range(n):
	for j in range(m):
		if flag[j] == 1 and (b[j] == a[i] or b[j] == a[i] - 1 or b[j] == a[i] + 1):
			flag[j] = 0
			break
print(flag.count(0))


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
a.reverse()
b.sort()
l = 0
for i in range(m - 1, -1, -1):
	for j in range(2, -1, -1):
		if b[i] - 1 + j in a:
			l += 1
			a.pop(a.index(b[i] - 1 + j))
			break
print(l)


size1 = int(input())
list1 = sorted([int(x) for x in input().split()])
list1.reverse()
size2 = int(input())
list2 = sorted([int(x) for x in input().split()])
list2.reverse()
pairs = 0
while min(size1, size2) > 0:
	x1 = list1[0]
	x2 = list2[0]
	if max(x1 - x2, x2 - x1) < 2:
		pairs += 1
		list1.pop(0)
		list2.pop(0)
		size1 -= 1
		size2 -= 1
	elif x1 >= x2:
		list1.pop(0)
		size1 -= 1
	else:
		list2.pop(0)
		size2 -= 1
print(pairs)


import sys
num_boys = int(sys.stdin.readline().strip())
boys_skills = list(map(int, sys.stdin.readline().split()))
boys_skills.sort()
num_girls = int(sys.stdin.readline().strip())
girls_skills = list(map(int, sys.stdin.readline().split()))
girls_skills.sort()
boy_i = 0
girl_j = 0
pairs = 0
while boy_i < num_boys and girl_j < num_girls:
	if abs(boys_skills[boy_i] - girls_skills[girl_j]) <= 1:
		boy_i += 1
		girl_j += 1
		pairs += 1
	elif boys_skills[boy_i] < girls_skills[girl_j]:
		boy_i += 1
	else:
		girl_j += 1
print(pairs)


na = int(input())
a = list(map(int, input().split()))
nb = int(input())
b = list(map(int, input().split()))
(i, count) = (0, 0)
a.sort()
b.sort()
while i < len(a):
	k = 0
	while k < len(b):
		if a[i] - b[k] in [-1, 0, 1]:
			b.pop(k)
			count += 1
			break
		k += 1
	i += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
K = 0
for i in range(len(a)):
	for j in range(len(b)):
		if a[i] != 0 and b[j] != 0 and (abs(a[i] - b[j]) < 2):
			K += 1
			a[i] = 0
			b[j] = 0
			break
print(K)


n_boys = int(input())
boys_skills = sorted(list(map(int, input().split())))
n_girls = int(input())
girls_skills = sorted(list(map(int, input().split())))
increase = lambda x: x + 1

def no_while(ls_1, ls_2, i=0, j=0, result=0):
	return (i == len(ls_1) or j == len(ls_2)) and str(result) or (abs(ls_1[i] - ls_2[j]) <= 1 and no_while(ls_1, ls_2, *list(map(increase, [i, j, result])))) or (ls_1[i] < ls_2[j] and no_while(ls_1, ls_2, increase(i), j, result)) or no_while(ls_1, ls_2, i, increase(j), result)
print(no_while(boys_skills, girls_skills))


no_of_boys = int(input())
boys = list(map(int, input().split()))
boys.sort()
no_of_girls = int(input())
girls = list(map(int, input().split()))
girls.sort()
idx = {}
cnt = 0
if no_of_girls > no_of_boys:
	for i in range(no_of_girls):
		for j in range(no_of_boys):
			if not idx:
				if abs(boys[j] - girls[i]) <= 1:
					idx[j] = i
					cnt += 1
					break
			else:
				flag = True
				for (n, m) in idx.items():
					if n == j or m == i:
						flag = False
						break
				if flag:
					if abs(boys[j] - girls[i]) <= 1:
						idx[j] = i
						cnt += 1
						break
else:
	for i in range(no_of_boys):
		for j in range(no_of_girls):
			if not idx:
				if abs(boys[i] - girls[j]) <= 1:
					idx[j] = i
					cnt += 1
					break
			else:
				flag = True
				for (n, m) in idx.items():
					if n == j or m == i:
						flag = False
						break
				if flag:
					if abs(boys[i] - girls[j]) <= 1:
						idx[j] = i
						cnt += 1
						break
print(cnt)


from collections import deque
n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]

def parse(n, m, boys, girls):
	boys = deque(sorted(boys))
	girls = deque(sorted(girls))
	indexes = []
	count = 0
	if n >= m:
		for boy in boys:
			for girl in girls:
				if girl in [i for i in range(boy - 1, boy + 2)]:
					girls.remove(girl)
					count += 1
					break
	else:
		for girl in girls:
			for boy in boys:
				if boy in [i for i in range(girl - 1, girl + 2)]:
					boys.remove(boy)
					count += 1
					break
	return count
print(parse(n, m, boys, girls))


n = int(input())
list_a = str(input()).split()
list_a = [int(it) for it in list_a]
m = int(input())
list_b = str(input()).split()
list_b = [int(it) for it in list_b]
list_a.sort()
list_b.sort()
value = 0
ptr_a = 0
ptr_b = 0
while True:
	if abs(list_a[ptr_a] - list_b[ptr_b]) <= 1:
		value += 1
		ptr_a += 1
		ptr_b += 1
	elif list_a[ptr_a] < list_b[ptr_b]:
		ptr_a += 1
	else:
		ptr_b += 1
	if ptr_a == n or ptr_b == m:
		break
print(value)


m = int(input())
s = sorted(list(map(int, input().split())))
n = int(input())
t = sorted(list(map(int, input().split())))
k = 0
if len(s) > len(t):
	(s, t) = (t, s)
for i in range(len(s)):
	if t.count(s[i] - 1) != 0:
		k = k + 1
		t.remove(s[i] - 1)
	elif t.count(s[i]) != 0:
		k = k + 1
		t.remove(s[i])
	elif t.count(s[i] + 1) != 0:
		k = k + 1
		t.remove(s[i] + 1)
print(k)


input()
hombres = input().split(' ')
input()
mujeres = input().split(' ')
hombres = [int(hom) for hom in hombres]
mujeres = [int(muj) for muj in mujeres]
hombres.sort()
mujeres.sort()
emparejados = 0
if len(hombres) <= len(mujeres):
	for h in hombres:
		for m in mujeres:
			if int(h) == int(m) + 1 or int(h) == int(m) or int(h) == int(m) - 1:
				emparejados += 1
				mujeres.remove(m)
				break
else:
	for m in mujeres:
		for h in hombres:
			if int(m) == int(h) + 1 or int(m) == int(h) or int(m) == int(h) - 1:
				emparejados += 1
				hombres.remove(h)
				break
print(emparejados)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
La = sorted(a)
Lb = sorted(b)
result = 0
for i in range(len(La)):
	for k in range(len(Lb)):
		if La[i] + 1 == Lb[k] or La[i] - 1 == Lb[k] or La[i] == Lb[k]:
			result += 1
			Lb.pop(k)
			break
print(result)


input()
a = [int(x) for x in input().split()]
input()
b = [int(x) for x in input().split()]
a.sort()
b.sort()
p = s = 0
for i in range(len(a)):
	t = p
	while t < len(b):
		if -1 <= a[i] - b[t] <= 1:
			s += 1
			p = t + 1
			break
		t += 1
print(s)


n = int(input())
boySkills = [int(x) for x in input().split()]
m = int(input())
girlSkills = [int(x) for x in input().split()]
boySkills.sort(reverse=True)
girlSkills.sort(reverse=True)
ans = 0
while len(boySkills) != 0 and len(girlSkills) != 0:
	if abs(boySkills[0] - girlSkills[0]) <= 1:
		ans += 1
		del boySkills[0]
		del girlSkills[0]
	elif boySkills[0] > girlSkills[0]:
		del boySkills[0]
	else:
		del girlSkills[0]
print(ans)


def fun(n, ln, m, lm):
	ln = sorted(ln)
	lm = sorted(lm)
	len_n = len(ln)
	len_m = len(lm)
	i = 0
	j = 0
	count = 0
	while i < len_n and j < len_m:
		val_n = ln[i]
		val_m = lm[j]
		if abs(val_m - val_n) <= 1:
			count += 1
			i += 1
			j += 1
		elif val_m < val_n:
			j += 1
		else:
			i += 1
	print(count)
T = 1
for _ in range(T):
	n = int(input())
	ln = list(map(int, input().split()))
	m = int(input())
	lm = list(map(int, input().split()))
	fun(n, ln, m, lm)


n = int(input())
n_list = sorted(list(map(int, input().split())))
m = int(input())
m_list = sorted(list(map(int, input().split())))
k = 0
for i in range(n):
	for j in range(m):
		if abs(n_list[i] - m_list[j]) <= 1:
			m_list[j] = 1000
			k += 1
			break
print(k)


from sys import stdin

def solve(n_boys, n_girls, boys_map, girls_map):
	boys_list = []
	girls_list = []
	counter = 0
	for i in boys_map:
		boys_list.append(i)
	for i in girls_map:
		girls_list.append(i)
	boys_list.sort()
	girls_list.sort()
	boy = boys_list.pop(0)
	girl = girls_list.pop(0)
	while True:
		if (boy - girl) ** 2 <= 1:
			counter += 1
			if len(boys_list) > 0 and len(girls_list) > 0:
				boy = boys_list.pop(0)
				girl = girls_list.pop(0)
			else:
				return counter
		elif boy > girl and len(girls_list) > 0:
			girl = girls_list.pop(0)
		elif boy < girl and len(boys_list) > 0:
			boy = boys_list.pop(0)
		else:
			return counter
question = stdin.readlines()
while len(question) > 1:
	n_boys = int(question.pop(0))
	boys_list = map(int, question.pop(0).split(' '))
	n_girls = int(question.pop(0))
	girls_list = map(int, question.pop(0).split(' '))
	print(solve(n_boys, n_girls, boys_list, girls_list))


a = int(input())
b = list(map(int, input().strip(' ').split(' ')))
c = int(input())
d = list(map(int, input().strip(' ').split(' ')))
b.sort()
d.sort()
count = 0
for i in range(0, a):
	for j in range(0, c):
		if abs(b[i] - d[j]) <= 1 and d[j] != -2:
			d[j] = -2
			count += 1
			break
print(count)


bn = int(input())
boyskill = list(map(int, input().split()))
boyskill.sort(reverse=True)
gn = int(input())
girlskill = list(map(int, input().split()))
girlskill.sort(reverse=True)
dic = {}
pairg = []
pairb = []
for i in range(gn):
	for j in range(bn):
		if abs(girlskill[i] - boyskill[j]) == 0:
			if i not in pairg and j not in pairb:
				dic[i] = j
				pairg.append(i)
				pairb.append(j)
for i in range(gn):
	for j in range(bn):
		if abs(girlskill[i] - boyskill[j]) == 1:
			if i not in pairg and j not in pairb:
				dic[i] = j
				pairg.append(i)
				pairb.append(j)
maxx = len(dic)
dic = {}
pairg = []
pairb = []
for i in range(gn):
	for j in range(bn):
		if abs(girlskill[i] - boyskill[j]) <= 1:
			if i not in pairg and j not in pairb:
				dic[i] = j
				pairg.append(i)
				pairb.append(j)
maxxx = len(dic)
print(max(maxx, maxxx))


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
b = list(map(int, input().split()))
b.sort()
counter = 0
for i in range(n):
	j = 0
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			counter += 1
			b.pop(j)
			m -= 1
			break
print(counter)


n = int(input())
l = list(map(int, input().split()))
m = int(input())
l1 = list(map(int, input().split()))
l.sort()
l1.sort()
ans = 0
while len(l1) > 0 and len(l) > 0:
	if abs(l[0] - l1[0]) < 2:
		ans += 1
		l.pop(0)
		l1.pop(0)
	elif l[0] < l1[0]:
		l.pop(0)
	else:
		l1.pop(0)
print(ans)


import sys
import math
n = input()
a = list(map(int, input().split()))
m = input()
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
for x in a:
	for y in range(x - 1, x + 2):
		if y in b:
			i = b.index(y)
			if i != -1:
				b.pop(i)
				ans += 1
				break
print(ans)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
c = 0
for i in range(len(b)):
	for j in range(len(g)):
		if b[i] == g[j] or abs(b[i] - g[j]) == 1:
			c += 1
			g.remove(g[j])
			break
print(c)


n = int(input())
s1 = input().split()
for i in range(len(s1)):
	s1[i] = int(s1[i])
m = int(input())
s2 = input().split()
for i in range(len(s2)):
	s2[i] = int(s2[i])
s1 = sorted(s1)
s2 = sorted(s2)
l = 0
for i in range(len(s1)):
	for j in range(len(s2)):
		if abs(s1[i] - s2[j]) <= 1:
			l = l + 1
			s2.remove(s2[j])
			break
print(l)


n = int(input())
b = input().split()
bskill = [int(i) for i in b]
m = int(input())
g = input().split()
gskill = [int(i) for i in g]
bskill.sort()
gskill.sort()
count = 0
i = 0
while i < len(bskill):
	s = bskill[i]
	k = {s - 1, s, s + 1}
	j = 0
	while j < len(gskill):
		if gskill[j] in k:
			count += 1
			del bskill[i]
			del gskill[j]
			break
		else:
			j += 1
	else:
		i += 1
print(count)


n1 = int(input())
n = list(map(int, input().split(' ')))
m1 = int(input())
m = list(map(int, input().split(' ')))
n.sort()
m.sort()
a = 0
(i, j) = (0, 0)
while i <= n1 - 1 and j <= m1 - 1:
	if abs(n[i] - m[j]) <= 1:
		a = a + 1
		i = i + 1
		j = j + 1
	elif n[i] < m[j]:
		i = i + 1
	else:
		j = j + 1
print(a)


n = int(input())
c = list(map(int, input().split()))
m = int(input())
d = list(map(int, input().split()))
c.sort()
d.sort()
cnt = 0
for k in range(n):
	for l in range(m):
		if c[k] - d[l] == 1 or c[k] - d[l] == 0 or c[k] - d[l] == -1:
			cnt += 1
			d[l] = 150
			break
print(cnt)


import math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	m = int(input())
	l1 = list(map(int, input().split()))
	cnt = 0
	l.sort()
	l1.sort()
	for i in range(n):
		for j in range(m):
			if abs(l[i] - l1[j]) <= 1:
				l1[j] = 1000
				cnt += 1
				break
	print(cnt)
t = 1
for i in range(t):
	solve()


nBoys = int(input())
boySkill = [int(x) for x in input().split()]
nGirls = int(input())
girlSkill = [int(x) for x in input().split()]
boySkill.sort()
girlSkill.sort()
count = 0
for i in boySkill:
	for e in girlSkill:
		if e >= i - 1 and e <= i + 1:
			count += 1
			girlSkill.remove(e)
			break
print(count)


n = input()
_list_1 = sorted(list(map(lambda x: [int(x), 0], input().split())), key=lambda x: x[0])
m = input()
_list_2 = sorted(list(map(lambda x: [int(x), 0], input().split())), key=lambda x: x[0])
_min = min(_list_1, _list_2, key=lambda x: len(x))
_max = _list_2 if _min == _list_1 else _list_1
count = 0
for _id in range(len(_min)):
	(i, _c) = _min[_id]
	for idx in range(len(_max)):
		(j, _count) = _max[idx]
		if abs(i - j) <= 1 and (not _count):
			_max[idx][1] = 1
			count += 1
			break
print(count)


def BerSU(b, g):
	count = 0
	i = 0
	b.sort()
	g.sort()
	for x in b:
		while i < len(g):
			if abs(x - g[i]) < 2:
				count += 1
				i += 1
				break
			elif x - g[i] < 0:
				break
			else:
				i += 1
	print(count)
input()
b = [int(x) for x in input().split()]
input()
BerSU(b, [int(x) for x in input().split()])


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [int(x) for x in input().split()]
M = int(input())
B = [int(x) for x in input().split()]
A.sort()
B.sort()
dp = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
for i in range(1, M + 1):
	for j in range(1, N + 1):
		if abs(B[i - 1] - A[j - 1]) <= 1:
			dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1])
		else:
			dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
print(dp[M][N])


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
ln = sorted(il())
m = ii()
np = 0
lm = sorted(il())
(i, j) = (0, 0)
while i < n and j < m:
	if abs(ln[i] - lm[j]) <= 1:
		np += 1
		i += 1
		j += 1
	elif ln[i] > lm[j]:
		j += 1
	else:
		i += 1
print(np)


n = int(input())
a = input().split(' ')
m = int(input())
b = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
a.sort()
for j in range(m):
	b[j] = int(b[j])
b.sort()
l = 0
d = 0
for k in range(n):
	for j in range(l, m):
		if b[j] < a[k] - 1:
			l = j + 1
		elif b[j] >= a[k] - 1 and b[j] <= a[k] + 1:
			l = j + 1
			d += 1
			break
		else:
			break
	if j == m:
		break
print(d)


n1 = int(input())
num1 = input()
n2 = int(input())
num2 = input()
a = []
b = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr1 = get_the_data(0, num1, a)
arr2 = get_the_data(0, num2, b)
check1 = [False] * len(arr1)
arr1.sort()
check2 = [False] * len(arr2)
arr2.sort()
teams = 0
for i in range(n1):
	for j in range(n2):
		if check2[j] == False and check1[i] == False:
			if abs(arr2[j] - arr1[i]) == 1 or arr2[j] - arr1[i] == 0:
				check2[j] = True
				check1[i] = True
				teams += 1
print(teams)


n = int(input())
a = list(map(int, input().rstrip().split()))
m = int(input())
b = list(map(int, input().rstrip().split()))
a.sort()
b.sort()
k = 0
for _ in range(len(a)):
	for i in range(len(b)):
		if abs(a[_] - b[i]) <= 1:
			b[i] = 10101010
			k += 1
			break
print(k)


def mergeSort(cols):
	if len(cols) >= 2:
		middle = len(cols) // 2
		left = cols[:middle]
		right = cols[middle:]
		mergeSort(left)
		mergeSort(right)
		(left_index, right_index, col_index) = (0, 0, 0)
		while left_index < len(left) and right_index < len(right):
			if left[left_index] < right[right_index]:
				cols[col_index] = left[left_index]
				left_index += 1
			else:
				cols[col_index] = right[right_index]
				right_index += 1
			col_index += 1
		while left_index < len(left):
			cols[col_index] = left[left_index]
			left_index += 1
			col_index += 1
		while right_index < len(right):
			cols[col_index] = right[right_index]
			right_index += 1
			col_index += 1
	return cols

def main():
	input()
	boys = mergeSort([int(x) for x in input().replace('\n', '').split(' ')])
	input()
	girls = mergeSort([int(x) for x in input().replace('\n', '').split(' ')])
	(b, g, total) = (0, 0, 0)
	while b < len(boys) and g < len(girls):
		if boys[b] - girls[g] < 2:
			if boys[b] - girls[g] > -2:
				b += 1
				g += 1
				total += 1
			else:
				b += 1
		else:
			g += 1
	print(total)
main()


input()
bs = list(map(int, input().split()))
input()
gs = list(map(int, input().split()))
b = [0] * 102
for x in bs:
	b[x] += 1
g = [0] * 102
for x in gs:
	g[x] += 1
c = 0
p = 1
while p < 101:
	if b[p] == 0 and g[p] == 0:
		p += 1
		continue
	if b[p] != 0 and g[p] != 0:
		mi = min(g[p], b[p])
		b[p] -= mi
		g[p] -= mi
		c += mi
		continue
	if b[p] == 0:
		mi = min(g[p], b[p + 1])
		g[p] -= mi
		b[p + 1] -= mi
		g[p] = 0
		c += mi
		p += 1
		continue
	if g[p] == 0:
		mi = min(g[p + 1], b[p])
		g[p + 1] -= mi
		b[p] -= mi
		b[p] = 0
		c += mi
		p += 1
		continue
print(c)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = []
for i in range(200):
	d.append([0] * 200)
n = I()
a = L()
m = I()
b = L()
a.sort()
b.sort()
for i in range(n):
	for j in range(m):
		d[i][j] = d[i - 1][j - 1]
		if abs(a[i] - b[j]) < 2:
			d[i][j] += 1
		d[i][j] = max(d[i][j], d[i - 1][j], d[i][j - 1])
print(d[n - 1][m - 1])


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
result = 0
a.sort()
b.sort()
for i in a:
	for j in b:
		if abs(i - j) == 0 or abs(i - j) == 1:
			result += 1
			b.remove(j)
			break
print(result)


n = int(input())
arr = [int(i) for i in input().split()]
m = int(input())
arr_2 = [int(i) for i in input().split()]
counter = 0
while True:
	if len(arr) == 0 or len(arr_2) == 0:
		break
	mx_1 = max(arr)
	mx_2 = max(arr_2)
	if mx_2 + 1 == mx_1 or mx_2 - 1 == mx_1 or mx_2 == mx_1 or (mx_2 == mx_1 + 1) or (mx_2 == mx_1 - 1):
		counter += 1
		arr.remove(mx_1)
		arr_2.remove(mx_2)
	elif mx_1 > mx_2:
		arr.remove(mx_1)
	else:
		arr_2.remove(mx_2)
print(counter)


tam_b = int(input())
entrada = input()
b = [int(x) for x in entrada.split(' ')]
tam_g = int(input())
entrada = input()
g = [int(x) for x in entrada.split(' ')]
b.sort()
g.sort()
auxb = 0
auxg = 0
pares = 0
while auxb < tam_b and auxg < tam_g:
	if abs(int(b[auxb]) - int(g[auxg])) <= 1:
		auxb += 1
		auxg += 1
		pares += 1
	elif int(b[auxb]) < int(g[auxg]):
		auxb += 1
	else:
		auxg += 1
print(pares)


n = int(input())
l1 = sorted(map(int, input().split()))
m = int(input())
l2 = sorted(map(int, input().split()))
(i, j) = (0, 0)
ans = 0
while i < n and j < m:
	if abs(l1[i] - l2[j]) <= 1:
		ans += 1
		i += 1
		j += 1
	elif l1[i] > l2[j]:
		j += 1
	else:
		i += 1
print(ans)


b = int(input())
blist = list(map(int, input().split()))
g = int(input())
glist = list(map(int, input().split()))
count = 0
blist.sort()
glist.sort()
for i in range(b):
	for j in range(len(glist)):
		if abs(blist[i] - glist[j]) < 2:
			glist.remove(glist[j])
			count = count + 1
			break
print(count)


from collections import defaultdict
n = int(input())
count = 0
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort(reverse=True)
d = defaultdict(int)
for i in girls:
	d[i] += 1
for i in boys:
	if d[i + 1]:
		count += 1
		d[i + 1] -= 1
	elif d[i]:
		count += 1
		d[i] -= 1
	elif d[i - 1]:
		count += 1
		d[i - 1] -= 1
print(count)


mensAm = int(input())
mens = list(map(int, input().split()))
girlsAm = int(input())
girls = list(map(int, input().split()))
mens.sort()
girls.sort()
t = 0
was = [False] * girlsAm
for i in range(mensAm):
	for g in range(girlsAm):
		if abs(girls[g] - mens[i]) <= 1 and (not was[g]):
			t += 1
			was[g] = True
			break
print(t)


boy = int(input())
boylist = list(map(int, input().split()))
girl = int(input())
girllist = list(map(int, input().split()))
girllist.sort()
boylist.sort()
if boy > girl:
	(girllist, boylist) = (boylist, girllist)
count = 0
pair = 0
while count <= min(boy, girl) - 1:
	if boylist[count] - 1 in girllist:
		girllist.remove(boylist[count] - 1)
		pair += 1
	elif boylist[count] in girllist:
		girllist.remove(boylist[count])
		pair += 1
	elif boylist[count] + 1 in girllist:
		girllist.remove(boylist[count] + 1)
		pair += 1
	count += 1
print(pair)


b = int(input())
b_skills = [int(i) for i in input().strip().split()]
g = int(input())
g_skills = [int(i) for i in input().strip().split()]
b_skills.sort()
g_skills.sort()
i = 0
j = 0
count = 0
while i < len(b_skills) and j < len(g_skills):
	if 0 <= abs(b_skills[i] - g_skills[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif b_skills[i] > g_skills[j] + 1:
		j += 1
	elif g_skills[j] > b_skills[i] + 1:
		i += 1
print(count)


m = int(input())
ml = list(map(int, input().split()))
n = int(input())
nl = list(map(int, input().split()))
cunt = 0
ml.sort(reverse=True)
nl.sort(reverse=True)
for i in range(m):
	for j in range(len(nl)):
		if abs(ml[i] - nl[j]) < 2:
			cunt += 1
			nl.pop(j)
			break
print(cunt)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort(reverse=True)
ans = 0
kids = a + b
j = n + m - 1
for i in range(n):
	while j > n - 1:
		if abs(kids[i] - kids[j]) > 1:
			if kids[i] < kids[j]:
				break
			j -= 1
		else:
			j -= 1
			ans += 1
			break
print(ans)


boys = int(input())
l_boys = input().split(' ')
girls = int(input())
l_girls = input().split(' ')
l_girls = [int(x) for x in l_girls]
l_boys = [int(x) for x in l_boys]
l_boys = sorted(l_boys)
l_girls = sorted(l_girls)
suma = 0
for i in range(boys):
	for j in range(girls):
		if abs(l_boys[i] - l_girls[j]) <= 1:
			l_girls[j] = 100000
			suma += 1
			break
print(suma)


a = int(input())
boys = sorted(map(int, input().split()))
b = int(input())
girls = sorted(map(int, input().split()))
res = 0
i = j = 0
for i in range(0, a):
	for j in range(0, b):
		if abs(boys[i] - girls[j]) <= 1:
			res += 1
			girls[j] = 1000
			break
print(res)


a = []
b = []
pairs = 0
x = input()
a = [int(x) for x in input().split()]
y = input()
b = [int(x) for x in input().split()]
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			pairs += 1
			b.remove(b[j])
			break
print(pairs)


n = int(input())
b = [int(x) for x in input().split()]
m = int(input())
g = [int(x) for x in input().split()]
boys = [0] * 110
girls = [0] * 110
for i in b:
	boys[i] += 1
for i in g:
	girls[i] += 1
ans = 0
for i in range(1, 101):
	for j in range(i - 1, i + 2):
		minus = min(boys[i], girls[j])
		boys[i] -= minus
		girls[j] -= minus
		ans += minus
print(ans)


men_count = int(input())
men_skills = sorted([int(i) for i in input().split()])
women_count = int(input())
women_skills = sorted([int(i) for i in input().split()])
women_skills_mark = [True] * women_count
pairs_count = 0
for i in range(men_count):
	for j in range(women_count):
		if women_skills_mark[j] and -1 <= men_skills[i] - women_skills[j] <= 1:
			pairs_count += 1
			women_skills_mark[j] = False
			break
print(pairs_count)


a = 1
a += 1

def quicksort(array):
	less = []
	equal = []
	greater = []
	if len(array) > 1:
		pivot = array[0]
		for x in array:
			if x < pivot:
				less.append(x)
			if x == pivot:
				equal.append(x)
			if x > pivot:
				greater.append(x)
		return quicksort(less) + equal + quicksort(greater)
	else:
		return array

def str_to_int_array(lista):
	list = lista
	for i in range(0, len(list)):
		list[i] = int(list[i])
	return list

def contar_parejas(h, m):
	new_h = quicksort(h)
	new_m = quicksort(m)
	contador_parejas = 0
	i_h = 0
	i_m = 0
	while i_m < len(new_m) and i_h < len(new_h):
		hombre = new_h[i_h]
		mujer = new_m[i_m]
		if hombre >= mujer:
			if hombre - mujer == 0 or hombre - mujer == 1:
				contador_parejas += 1
				i_h += 1
				i_m += 1
			else:
				i_m += 1
		elif mujer - hombre == 0 or mujer - hombre == 1:
			contador_parejas += 1
			i_h += 1
			i_m += 1
		else:
			i_h += 1
	return contador_parejas
cantidad_H = input()
hombres = str_to_int_array(input().split(' '))
cantidad_M = input()
mujeres = str_to_int_array(input().split(' '))
print('{}'.format(contar_parejas(hombres, mujeres)), end='')


def init():
	b = int(input())
	b_skill = list(map(lambda x: int(x), input().split(' ')))
	g = int(input())
	g_skill = list(map(lambda x: int(x), input().split(' ')))
	b_skill.sort()
	g_skill.sort()
	i = j = pairs = 0
	while i < b and j < g:
		if g_skill[j] - 1 <= b_skill[i] <= g_skill[j] + 1:
			pairs += 1
			i += 1
			j += 1
		elif b_skill[i] < g_skill[j]:
			i += 1
		else:
			j += 1
	print(pairs)
init()


from math import *
from collections import *
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
i = 0
j = 0
prev = 0
ct = 0
a.sort()
b.sort()
while i < n:
	j = prev
	while j < m:
		if abs(a[i] - b[j]) <= 1:
			ct += 1
			prev = j + 1
			break
		j += 1
	i += 1
print(ct)


a = int(input())
b = list(map(int, input().split()))
b.sort()
c = int(input())
d = list(map(int, input().split()))
d.sort()
(i, j) = (0, 0)
k = 0
while i < a and j < c:
	if abs(b[i] - d[j]) <= 1:
		i = i + 1
		j = j + 1
		k = k + 1
	elif b[i] < d[j]:
		i = i + 1
	elif b[i] > d[j]:
		j = j + 1
print(k)


import math
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
c = 0
a.sort()
b.sort()
for i in range(n):
	for j in range(m):
		if a[i] != -1 and b[j] != -1 and (math.fabs(a[i] - b[j]) <= 1):
			c += 1
			a[i] = b[j] = -1
			break
print(c)


from math import inf
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1:
			ans += 1
			b[j] = inf
			break
print(ans)


import math

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	b = [int(x) for x in input().split()]
	return (n, m, b)

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
(m, b) = na()
a = sorted(a)
b = sorted(b)
sets = []
for i in range(n):
	sets.append([])
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) < 2:
			sets[i].append((b[j], j))
k = 0
f = False
used = []
usedm = []
ss = 0
while not f and k != n and (k != m):
	f = True
	for i in range(n):
		if len(sets[i]) != 0:
			for j in sets[i]:
				if j[1] not in used and i not in usedm:
					used.append(j[1])
					usedm.append(i)
					k += 1
					f = False
					sets[i].remove(j)
					for _ in range(n):
						if j in sets[_]:
							sets[_].remove(j)
	ss += 1
print(k)


inp = lambda : map(int, input().rstrip().split())
n = int(input())
b = sorted(list(inp()))
m = int(input())
g = sorted(list(inp()))
r = 0
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			r += 1
			g[j] = 1000
			break
print(r)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())
sys.setrecursionlimit(10000)

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		nb = I()
		b = list(In())
		ng = I()
		g = list(In())
		(i, j) = (0, 0)
		b.sort()
		g.sort()
		ans = 0
		took = [False] * (ng + 1)
		for i in range(nb):
			for j in range(ng):
				if abs(b[i] - g[j]) <= 1 and took[j] == False:
					took[j] = True
					ans += 1
					break
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
Ma = 100000000000
for _ in range(1):
	main()


p = lambda : [int(x) for x in input().split()]
(n, a, m, b) = (int(input()), sorted(p()), int(input()), sorted(p()))
(i, j) = (0, 0)
for row in a:
	if row - 1 in b:
		i += 1
		b.pop(b.index(row - 1))
	elif row in b:
		i += 1
		b.pop(b.index(row))
	elif row + 1 in b:
		i += 1
		b.pop(b.index(row + 1))
print(i)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
m = int(input())
bj = list(map(int, input().split()))
bj.sort()
i = 0
j = 0
kol = 0
while i < n and j < m:
	if abs(ai[i] - bj[j]) <= 1:
		i += 1
		j += 1
		kol += 1
	elif ai[i] > bj[j]:
		j += 1
	else:
		i += 1
print(kol)


n = int(input())
list1 = list(map(int, input().split()))
m = int(input())
list2 = list(map(int, input().split()))
count = 0
list1 = sorted(list1)
list2 = sorted(list2)
for k in range(n):
	for l in range(m):
		if abs(list1[k] - list2[l]) <= 1:
			count += 1
			list1[k] = -100
			list2[l] = -200
print(count)


boy = int(input())
blst = list(map(int, input().split()))
girl = int(input())
glst = list(map(int, input().split()))
blst = sorted(blst)
glst = sorted(glst)
c = 0
while blst and glst:
	if abs(blst[0] - glst[0]) <= 1:
		blst.pop(0)
		glst.pop(0)
		c += 1
	elif blst[0] > glst[0]:
		glst.pop(0)
	else:
		blst.pop(0)
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
(i, j) = (0, 0)
c = 0
dif = [-1, 0, 1]
while True:
	if i >= n or j >= m:
		break
	if a[i] - b[j] in dif:
		i += 1
		j += 1
		c += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(c)


boys_n = int(input())
boys = list(map(int, input().split()))
girls_n = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
count = 0
for boy in boys:
	for girl in girls:
		if abs(boy - girl) <= 1:
			count += 1
			girls.remove(girl)
			break
print(count)


import sys
n = int(input())
alist = sorted(list(map(int, sys.stdin.readline().split())))
m = int(input())
blist = sorted(list(map(int, sys.stdin.readline().split())))
ans = 0
crt_a = 0
crt_b = 0
for _ in range(n + m):
	if crt_a >= n or crt_b >= m:
		break
	elif abs(alist[crt_a] - blist[crt_b]) <= 1:
		ans += 1
		crt_a += 1
		crt_b += 1
	elif alist[crt_a] < blist[crt_b]:
		crt_a += 1
	else:
		crt_b += 1
print(ans)


def is_pair(x, y):
	return abs(x - y) <= 1
n = int(input())
a = [int(_) for _ in input().split(' ')]
m = int(input())
b = [int(_) for _ in input().split(' ')]
a.sort(reverse=True)
b.sort(reverse=True)
i = 0
j = 0
pairs = 0
while i < n and j < m:
	while j < m and b[j] >= a[i] - 1 and (not is_pair(a[i], b[j])):
		j += 1
	if j < m and is_pair(a[i], b[j]):
		pairs += 1
		i += 1
		j += 1
	elif j < m:
		i += 1
print(pairs)


a = int(input())
s = input()
r = int(input())
e = input()
w = []
q = []
w = s.split(' ')
q = e.split(' ')
for i in range(a):
	w[i] = int(w[i])
for i in range(r):
	q[i] = int(q[i])
w.sort()
d = 0
q.sort()
for i in w:
	for j in q:
		if i + 1 == j or j + 1 == i or j == i:
			d += 1
			q.remove(j)
			break
print(d)


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l1 = szz()
m = int(z())
l2 = szz()
c = 0
for i in range(n):
	for j in range(m):
		if abs(l2[j] - l1[i]) <= 1:
			l2[j] = 32985793475937598
			c += 1
			break
print(c)


n = int(input())
a = sorted([int(i) for i in input().split()])
m = int(input())
b = sorted([int(i) for i in input().split()])
if len(a) >= len(b):
	(s, l) = (b, a)
else:
	(s, l) = (a, b)
(pointer, pair) = (0, 0)
for i in range(len(s)):
	for j in range(pointer, len(l)):
		if abs(s[i] - l[j]) <= 1:
			pointer = j + 1
			pair += 1
			break
		if l[j] > s[i]:
			pointer = j
			break
print(pair)


b = int(input())
bl = list(map(int, input().split()))
bl.sort()
g = int(input())
gl = list(map(int, input().split()))
gl.sort()
count = 0
blcopy = bl
for bskill in blcopy:
	for gskill in gl:
		if abs(gskill - bskill) < 2:
			gl.remove(gskill)
			count = count + 1
			break
print(count)


def merge(arr1, arr2):
	n = len(arr1) + len(arr2)
	ans = []
	while True:
		if len(ans) == n:
			return ans
		elif len(arr2) >= 1 and len(arr1) >= 1:
			if arr1[0] > arr2[0]:
				ans.append(arr2[0])
				arr2.pop(0)
			else:
				ans.append(arr1[0])
				arr1.pop(0)
		else:
			for i in arr1:
				ans.append(i)
			for j in arr2:
				ans.append(j)

def mergeSort(arr):
	if len(arr) <= 1:
		return arr
	elif len(arr) == 2:
		if arr[1] < arr[0]:
			(arr[0], arr[1]) = (arr[1], arr[0])
		return arr
	else:
		return merge(mergeSort(arr[0:len(arr) // 2 + 1]), mergeSort(arr[len(arr) // 2 + 1:]))
n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys = mergeSort(boys)
girls = mergeSort(girls)
count = 0
while True:
	if abs(boys[0] - girls[0]) <= 1:
		count += 1
		boys.pop(0)
		girls.pop(0)
	elif boys[0] > girls[0]:
		girls.pop(0)
	else:
		boys.pop(0)
	if len(boys) == 0 or len(girls) == 0:
		break
print(count)


m = int(input())
m_list = sorted(list(map(int, input().split())))
f = int(input())
f_list = sorted(list(map(int, input().split())))
counter = 0
m_pointer = 0
f_pointer = 0
while m_pointer < m and f_pointer < f:
	if m_list[m_pointer] == f_list[f_pointer] or abs(m_list[m_pointer] - f_list[f_pointer]) == 1:
		counter += 1
		m_pointer += 1
		f_pointer += 1
	elif m_list[m_pointer] < f_list[f_pointer]:
		m_pointer += 1
	else:
		f_pointer += 1
print(counter)


b = int(input())
lisb = list(map(int, input().split()))
g = int(input())
lisg = list(map(int, input().split()))
res = 0
lisb.sort()
lisg.sort()
r = min(len(lisb), len(lisg))
for i in range(b):
	for j in range(g):
		if abs(lisb[i] - lisg[j]) <= 1:
			res += 1
			lisg[j] = 1000
			break
print(res)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
p1 = p2 = count = 0
while p1 < n and p2 < m:
	if abs(a[p1] - b[p2]) < 2:
		(p1, p2, count) = (p1 + 1, p2 + 1, count + 1)
	elif a[p1] < b[p2]:
		p1 += 1
	else:
		p2 += 1
print(count)


n_boys = int(input())
b_skills = input().split(' ')
n_girls = int(input())
g_skills = input().split(' ')
for i in range(n_boys):
	b_skills[i] = int(b_skills[i])
for i in range(n_girls):
	g_skills[i] = int(g_skills[i])
b_skills.sort()
g_skills.sort()
contador_parejas = 0
while len(b_skills) != 0 and len(g_skills) != 0:
	boy = b_skills[0]
	girl = g_skills[0]
	if abs(boy - girl) <= 1:
		contador_parejas += 1
		b_skills.pop(0)
		g_skills.pop(0)
	elif boy > girl:
		g_skills.pop(0)
	else:
		b_skills.pop(0)
print(contador_parejas)


boys = int(input())
listboys = list(map(int, input().split()))
girls = int(input())
listgirls = list(map(int, input().split()))
listboys.sort()
listgirls.sort()
count = 0
for i in range(boys):
	for j in range(girls):
		if abs(listboys[i] - listgirls[j]) <= 1:
			count += 1
			listgirls[j] = 100000
			break
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
res = 0
a.sort()
b.sort()
for i in range(n):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			res += 1
			b.remove(b[j])
			break
print(res)


def berSU(m, a, n, b):
	a.sort()
	b.sort()
	s = 0
	k = 0
	for i in range(m):
		for j in range(k, n):
			if abs(a[i] - b[j]) <= 1:
				s += 1
				k = j + 1
				break
	return s
m = int(input())
a = list(map(int, input().split()))
n = int(input())
b = list(map(int, input().split()))
print(berSU(m, a, n, b))


def main():
	n = int(input())
	boys = [int(x) for x in input().split()]
	m = int(input())
	girls = [int(x) for x in input().split()]
	boys.sort()
	girls.sort()
	count = 0
	for i in range(len(boys)):
		for j in range(len(girls)):
			if abs(boys[i] - girls[j]) <= 1:
				count += 1
				girls[j] = 1000
				break
	print(count)
main()


n = int(input())
L1 = list(map(int, input().strip().split()))
m = int(input())
L2 = list(map(int, input().strip().split()))
L1.sort()
L2.sort()
k = 0
for i in range(n):
	for j in range(m):
		if abs(L1[i] - L2[j]) <= 1:
			L2[j] = 1000
			k += 1
			break
print(k)


from sys import stdin
n = int(stdin.readline())
boys = sorted([int(x) for x in stdin.readline().split()])
m = int(stdin.readline())
girls = sorted([int(x) for x in stdin.readline().split()])
ans = 0
(pb, pg) = (0, 0)
while pb < n and pg < m:
	if abs(boys[pb] - girls[pg]) < 2:
		ans += 1
		pb += 1
		pg += 1
	elif boys[pb] <= girls[pg]:
		pb += 1
	else:
		pg += 1
print(ans)


import sys
n = int(sys.stdin.readline())
boys_list = list(map(int, sys.stdin.readline().strip().split(' ')))
boys_list.sort()
m = int(sys.stdin.readline())
girls_list = list(map(int, sys.stdin.readline().strip().split(' ')))
girls_list.sort()
i = 0
j = 0
matches = 0
while i < n and j < m:
	b = boys_list[i]
	g = girls_list[j]
	if b < g - 1:
		i += 1
	elif g < b - 1:
		j += 1
	else:
		matches += 1
		i += 1
		j += 1
print(matches)


def dance(n, b, m, g):
	b = sorted(b)
	g = sorted(g)
	count = 0
	for i in range(len(b)):
		j = 0
		while j < len(g):
			if abs(b[i] - g[j]) <= 1:
				del g[j]
				count += 1
				break
			j += 1
	return count
n = int(input())
b = [int(i) for i in input().split()]
m = int(input())
g = [int(i) for i in input().split()]
print(dance(n, b, m, g))


import sys
data = sys.stdin.read().strip()
data = data.split('\n')
boys = data[1].split(' ')
girls = data[3].split(' ')
for (i, item) in enumerate(boys):
	boys[i] = int(item)
for (i, item) in enumerate(girls):
	girls[i] = int(item)
boys.sort()
girls.sort()
b = len(boys)
g = len(girls)
bPoint = 0
gPoint = 0
count = 0
while bPoint < b and gPoint < g:
	if boys[bPoint] == girls[gPoint] or boys[bPoint] == girls[gPoint] + 1 or boys[bPoint] == girls[gPoint] - 1:
		bPoint += 1
		gPoint += 1
		count += 1
	elif boys[bPoint] > girls[gPoint]:
		gPoint += 1
	else:
		bPoint += 1
print(count)


n = int(input())
A = [int(x) for x in input().split()]
m = int(input())
B = [int(x) for x in input().split()]
A.sort()
B.sort()
count = 0
for i in range(n):
	for j in range(m):
		if A[i] == B[j] or A[i] == B[j] + 1 or A[i] + 1 == B[j]:
			A[i] = -1
			B[j] = -1
			count += 1
			break
print(count)


def getInput():
	s = []
	for i in input().split():
		s.append(int(i))
	s.sort()
	return s

def binarySearch(l, a, lower, upper):
	if lower == upper:
		if l[upper] == a:
			return upper
		else:
			return -1
	middle = (lower + upper) // 2
	if a <= l[middle]:
		return binarySearch(l, a, lower, middle)
	else:
		return binarySearch(l, a, middle + 1, upper)

def pair1(ms, fs):
	pair = 0
	for m in ms:
		for i in range(3):
			if fs == []:
				break
			flag = binarySearch(fs, m + i - 1, 0, len(fs) - 1)
			if flag != -1:
				fs.pop(flag)
				pair += 1
				break
	return pair

def main():
	input()
	ms = getInput()
	input()
	fs = getInput()
	print(pair1(ms, fs))
main()


n = int(input())
boys = [int(s) for s in input().rstrip().split(' ')]
m = int(input())
girls = [int(s) for s in input().rstrip().split(' ')]
boys.sort()
girls.sort()
p = 0
i = 0
j = 0
while i < len(boys) and j < len(girls):
	b = boys[i]
	g = girls[j]
	if b in [g - 1, g, g + 1]:
		p += 1
		i += 1
		j += 1
	elif b < g:
		i += 1
	else:
		j += 1
print(p)


n = int(input())
c = ind = z = 0
p = q = 1
rahat = []
girls = list(map(int, input().split()))
m = int(input())
boys = list(map(int, input().split()))
girls.sort()
boys.sort()
for i in range(0, len(girls), p):
	for j in range(z, len(boys), q):
		if abs(boys[j] - girls[i]) <= 1:
			c += 1
			ind = j
			z = ind + 1
			break
print(c)


count = 0
first_stack = int(input())
lens_firsts_bars = input().split()
lens_firsts_bars = sorted(list(map(int, lens_firsts_bars)))
second_stack = int(input())
lens_seconds_bars = input().split()
lens_seconds_bars = sorted(list(map(int, lens_seconds_bars)))
i = 0
n = len(lens_seconds_bars)
for first_bar in lens_firsts_bars:
	while i < n:
		if first_bar < lens_seconds_bars[i] - 1:
			break
		if abs(first_bar - lens_seconds_bars[i]) <= 1:
			count += 1
			i += 1
			break
		i += 1
print(count)


b = int(input())
lst1 = list(map(int, input().split()))
g = int(input())
lst2 = list(map(int, input().split()))
lst1.sort()
lst2.sort()
i = j = count = 0
while i < b and j < g:
	t = lst1[i] - lst2[j]
	if t == -1 or t == 0 or t == 1:
		i += 1
		j += 1
		count += 1
	elif t < -1:
		i += 1
	else:
		j += 1
print(count)


import sys
count = 0
n = int(sys.stdin.readline())
l1 = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
l2 = list(map(int, sys.stdin.readline().split()))
l1.sort()
l2.sort()
for i in range(n):
	for j in range(m):
		if abs(l1[i] - l2[j]) <= 1:
			l1[i] = -1
			l2[j] = -3
			count += 1
print(count)


from sys import stdin
n = int(input())
nn = list(map(int, stdin.readline().split()))
m = int(input())
mm = list(map(int, stdin.readline().split()))
nn = sorted(nn)
mm = sorted(mm)
(i, j, k) = (0, 0, 0)
while i < n and j < m:
	if abs(nn[i] - mm[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif nn[i] < mm[j]:
		i += 1
	else:
		j += 1
print(k)


input()
guys = sorted(map(int, input().split()))
input()
girls = sorted(map(int, input().split()))
pairs = 0
while guys and girls:
	d = guys[-1] - girls[-1]
	if abs(d) <= 1:
		pairs += 1
		guys.pop()
		girls.pop()
	elif d > 0:
		guys.pop()
	else:
		girls.pop()
print(pairs)


n = int(input())
A = [int(x) for x in input().split()]
m = int(input())
B = [int(x) for x in input().split()]
A.sort()
B.sort()
s = 0
for i in range(n):
	if A[i] - 1 in B:
		s += 1
		B.remove(A[i] - 1)
	elif A[i] in B:
		s += 1
		B.remove(A[i])
	elif A[i] + 1 in B:
		s += 1
		B.remove(A[i] + 1)
print(s)


na = int(input())
a = [int(i) for i in input().split()]
nb = int(input())
b = [int(i) for i in input().split()]
a.sort()
b.sort()
dp = [[0 for _ in range(nb + 1)] for _ in range(na + 1)]
for i in range(na - 1, -1, -1):
	for j in range(nb - 1, -1, -1):
		c = 0
		if abs(a[i] - b[j]) <= 1:
			c = max(c, 1 + dp[i + 1][j + 1])
		c = max(c, dp[i + 1][j])
		c = max(c, dp[i][j + 1])
		dp[i][j] = c
print(dp[0][0])


b = int(input())
l = list(map(int, input().split()))
g = int(input())
s = list(map(int, input().split()))
l.sort()
s.sort()
(i, j, c) = (0, 0, 0)
while i < b and j < g:
	if abs(l[i] - s[j]) <= 1:
		i += 1
		j += 1
		c = c + 1
	elif l[i] > s[j]:
		j += 1
	elif l[i] < s[j]:
		i += 1
print(c)


n = int(input())
a = [i for i in list(map(int, input().split()))]
m = int(input())
b = [i for i in list(map(int, input().split()))]
a.sort()
b.sort()
c = [a, b]
count = 0
for i in c[0]:
	f = 0
	for j in c[1]:
		if abs(i - j) <= 1 and f == 0:
			f += 1
			count += 1
			c[1].remove(j)
print(count)


m = int(input())
man = list(map(int, input().split()))
g = int(input())
girl = list(map(int, input().split()))
man.sort()
girl.sort()
c = 0
for mm in man:
	for i in range(len(girl)):
		if abs(mm - girl[i]) <= 1:
			c += 1
			girl.pop(i)
			break
print(c)


import sys
n1 = int(input())
l1 = [int(x) for x in input().split()]
n2 = int(input())
l2 = [int(x) for x in input().split()]
i = j = res = 0
l1.sort()
l2.sort()
while i < n1 and j < n2:
	if abs(l1[i] - l2[j]) <= 1:
		res += 1
		i += 1
		j += 1
	elif l1[i] < l2[j]:
		i += 1
	else:
		j += 1
print(res)


boys = int(input())
boys_skills = list(map(int, input().split()))[:boys]
boys_skills.sort()
girls = int(input())
girls_skills = list(map(int, input().split()))[:girls]
girls_skills.sort()
count = 0
for i in range(boys):
	for j in range(girls):
		if abs(boys_skills[i] - girls_skills[j]) <= 1:
			girls_skills[j] = -10
			count += 1
			break
print(count)


nb = int(input())
b = [int(i) for i in input().split()]
ng = int(input())
g = [int(i) for i in input().split()]
b.sort()
g.sort()
count = 0
temp = 0
if nb < ng:
	while 1:
		for i in range(nb):
			for j in range(ng):
				if b[i] - g[j] == 0 or b[i] - g[j] == 1 or b[i] - g[j] == -1:
					count += 1
					if len(b) != 0 and i < len(b):
						b.pop(i)
					if len(g) != 0 and j < len(g):
						g.pop(j)
					i = 0
					j = 0
					nb -= 1
					ng -= 1
					temp = 0
					break
				else:
					temp += 1
			if i == 0 and j == 0:
				break
		if temp == nb * ng:
			break
elif ng <= nb:
	while 1:
		for i in range(ng):
			for j in range(nb):
				if b[j] - g[i] == 0 or b[j] - g[i] == 1 or b[j] - g[i] == -1:
					count += 1
					if len(b) != 0 and j < len(b):
						b.pop(j)
					if len(g) != 0 and i < len(g):
						g.pop(i)
					i = 0
					j = 0
					nb -= 1
					ng -= 1
					temp = 0
					break
				else:
					temp += 1
			if i == 0 and j == 0:
				break
		if temp == nb * ng:
			break
print(count)


class CodeforcesTask489BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.a = []
		self.m = 0
		self.b = []

	def read_input(self):
		self.n = int(input())
		self.a = [int(x) for x in input().split(' ')]
		self.m = int(input())
		self.b = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.a.sort()
		self.b.sort()
		pairs = 0
		for x in range(self.n):
			for y in range(self.m):
				if abs(self.a[x] - self.b[y]) <= 1:
					pairs += 1
					self.b[y] = 1000
					break
		self.result = str(pairs)

	def get_result(self):
		return self.result
Solution = CodeforcesTask489BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


a = int(input())
b = sorted(list(map(int, input().split())))
c = int(input())
d = sorted(list(map(int, input().split())))
answer = 0
indd = 0
while len(b) != 0 and len(d) != 0:
	while abs(b[0] - d[0]) > 1:
		if b[0] < d[0]:
			del b[0]
			if len(b) == 0:
				break
		else:
			del d[0]
			if len(d) == 0:
				break
	if len(b) == 0 or len(d) == 0:
		break
	answer += 1
	del b[0]
	del d[0]
print(answer)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(j) for j in input().split()]
p = sorted(a)
q = sorted(b)
(i, j, k) = (0, 0, 0)
while i < n and j < m:
	if abs(p[i] - q[j]) < 2:
		i += 1
		k += 1
		j += 1
	elif p[i] < q[j]:
		i += 1
	else:
		j += 1
print(k)


N = int(input())
s = input().split(' ')
a = []
b = []
for i in s:
	a.append(int(i))
M = int(input())
s = input().split(' ')
for p in s:
	b.append(int(p))
a = sorted(a)
b = sorted(b)
i = 0
j = 0
ans = 0
if a[0] > b[M - 1] and abs(a[0] - b[M - 1]) > 1 or (b[0] > a[N - 1] and abs(b[0] - a[N - 1]) > 1):
	print(ans)
else:
	while i < N and j < M:
		if abs(a[i] - b[j]) <= 1:
			i = i + 1
			j = j + 1
			ans = ans + 1
		elif a[i] > b[j]:
			j = j + 1
		else:
			i = i + 1
	print(ans)


n = int(input())
s1 = input().split()
a1 = list(map(int, s1))
m = int(input())
s2 = input().split()
a2 = list(map(int, s2))
a1.sort()
a2.sort()
i = 0
j = 0
s = 0
k1 = a1[i]
k2 = a2[j]
while i < n and j < m:
	if k1 - k2 == 1 or k2 - k1 == 1 or k1 == k2:
		s = s + 1
		i = i + 1
		j = j + 1
		if i != n:
			k1 = a1[i]
		if j != m:
			k2 = a2[j]
	elif k1 > k2:
		j = j + 1
		if j != m:
			k2 = a2[j]
	elif k2 > k1:
		i = i + 1
		if i != n:
			k1 = a1[i]
print(s)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
bd = {}
gd = {}
for i in g:
	gd[i] = 0
for i in g:
	gd[i] += 1
b.sort()
ans = 0
for i in b:
	if i - 1 in gd and gd[i - 1]:
		ans += 1
		gd[i - 1] -= 1
	elif i in gd and gd[i]:
		ans += 1
		gd[i] -= 1
	elif i + 1 in gd and gd[i + 1]:
		ans += 1
		gd[i + 1] -= 1
print(ans)


boys = int(input())
boys_skills = list(map(int, input().split()))
girls = int(input())
girls_skills = list(map(int, input().split()))
count = 0
i = 0
j = 0
boys_skills = sorted(boys_skills)
girls_skills = sorted(girls_skills)
limit = len(boys_skills)
limi2 = len(girls_skills)
while i <= limit:
	j = 0
	limit2 = len(girls_skills)
	while j <= limit2:
		try:
			if abs(boys_skills[i] - girls_skills[j]) < 2:
				boys_skills.pop(i)
				girls_skills.pop(j)
				i = -1
				count += 1
				break
			else:
				j += 1
		except:
			break
	i += 1
	limit = len(boys_skills)
print(count)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
girls.sort()
boys.sort()
pairs = 0
if len(boys) <= len(girls):
	k = 0
	for i in range(n):
		for j in range(k, m):
			if abs(boys[i] - girls[j]) >= 0 and abs(boys[i] - girls[j]) <= 1:
				pairs += 1
				k = j + 1
				break
else:
	k = 0
	for i in range(m):
		for j in range(n):
			if abs(boys[j] - girls[i]) >= 0 and abs(boys[j] - girls[i]) <= 1:
				pairs += 1
				k = j + 1
				break
print(pairs)


x = int(input())
boys = [int(i) for i in input().split()]
boys.sort()
y = int(input())
girls = [int(i) for i in input().split()]
girls.sort()
i = j = res = 0
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		res += 1
		i += 1
		j += 1
	elif boys[i] > girls[j]:
		j += 1
	else:
		i += 1
print(res)


n = int(input())
l1 = map(int, input().split())
m = int(input())
l2 = map(int, input().split())
l1 = list(l1)
l2 = list(l2)
l1.sort()
l2.sort()
i1 = 0
i2 = 0
ans = 0
while True:
	if i1 == n or i2 == m:
		break
	if l1[i1] <= l2[i2]:
		if l1[i1] + 1 >= l2[i2]:
			ans += 1
			i1 += 1
			i2 += 1
		else:
			i1 += 1
	elif l2[i2] + 1 >= l1[i1]:
		ans += 1
		i1 += 1
		i2 += 1
	else:
		i2 += 1
print(ans)


n = int(input())
var1 = [int(x) for x in input().split()]
m = int(input())
var2 = [int(x) for x in input().split()]
var1 = sorted(var1)
var2 = sorted(var2)
index1 = 0
index2 = 0
cont = 0
while index1 < n and index2 < m:
	if var1[index1] + 1 == var2[index2] or var1[index1] == var2[index2] or var1[index1] == var2[index2] + 1:
		cont += 1
		index1 += 1
		index2 += 1
	elif var1[index1] < var2[index2]:
		index1 += 1
	else:
		index2 += 1
print(cont)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
i = j = c = 0
while i < n and j < m:
	if a[i] - b[j] == -1 or a[i] - b[j] == 0 or a[i] - b[j] == 1:
		c += 1
		i += 1
		j += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(c)


n = int(input())
b = map(int, input().split())
m = int(input())
g = map(int, input().split())
b = sorted(b)
g = sorted(g)
result = 0
for i in range(len(b)):
	for j in range(len(g)):
		if abs(b[i] - g[j]) <= 1:
			result = result + 1
			g[j] = 1001
			break
print(result)


n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(j) for j in input().split()]
k = 0
l = 0
a.sort()
b.sort()
for i in range(0, n):
	for j in range(l, m):
		if abs(a[i] - b[j]) < 2:
			k += 1
			l = j + 1
			break
print(k)


n = int(input())
boy = list(map(int, input().split()))
boy.sort()
m = int(input())
girl = list(map(int, input().split()))
girl.sort()
c = 0
if n < m:
	for i in boy:
		for j in range(m):
			if abs(i - girl[j]) <= 1 and girl[j] >= 1:
				c += 1
				girl[j] = 0
				break
	print(c)
else:
	for i in girl:
		for j in range(n):
			if abs(i - boy[j]) <= 1 and boy[j] >= 1:
				c += 1
				boy[j] = 0
				break
	print(c)


n = input()
li1 = sorted([int(x) for x in input().split()])
n2 = input()
li2 = sorted([int(x) for x in input().split()])
count = 0
for (i, num) in enumerate(li1):
	j = 0
	while j < len(li2):
		if abs(num - li2[j]) <= 1:
			count += 1
			del li2[j]
			break
		elif num + 1 < li2[j]:
			break
		j += 1
print(count)


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	p = 0
	for i in range(len(a)):
		for j in b:
			if math.fabs(a[i] - j) <= 1:
				b.remove(j)
				p = p + 1
				break
	print(p)
main()


bN = int(input())
bL = [int(xy) for xy in input().split()]
gN = int(input())
gL = [int(xx) for xx in input().split()]
bS = sorted(bL)
gS = sorted(gL)
notDone = True
ans = 0
while notDone:
	ansX = ans
	pair = False
	for i in range(len(bS)):
		for j in range(len(gS)):
			if abs(bS[i] - gS[j]) <= 1:
				ans += 1
				pair = True
				bS.remove(bS[i])
				gS.remove(gS[j])
				break
		if pair:
			break
	if ansX == ans:
		notDone = False
print(ans)


n = int(input())
ar = sorted(list(map(int, input().split())))
m = int(input())
pair = 0
ar1 = sorted(list(map(int, input().split())))
for i in ar:
	if i - 1 in ar1:
		ar1.remove(i - 1)
		pair += 1
	elif i in ar1:
		ar1.remove(i)
		pair += 1
	elif i + 1 in ar1:
		ar1.remove(i + 1)
		pair += 1
print(pair)


def bersu(b, arrayb, g, arrayg):
	arrayb.sort()
	arrayg.sort()
	if arrayb[0] > arrayg[-1] + 1:
		return 0
	elif arrayg[0] > arrayb[-1] + 1:
		return 0
	else:
		s = 0
		for x in arrayb:
			if x - 1 in arrayg:
				s += 1
				arrayg.remove(x - 1)
			elif x in arrayg:
				s += 1
				arrayg.remove(x)
			elif x + 1 in arrayg:
				s += 1
				arrayg.remove(x + 1)
			else:
				continue
		return s
b = int(input())
arrayb = list(map(int, input().split(' ')))
g = int(input())
arrayg = list(map(int, input().split(' ')))
print(bersu(b, arrayb, g, arrayg))


import sys
from collections import Counter
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
num_b = inp()
boys = inlt()
num_g = inp()
girls = inlt()

def get_max_match(boys, girls):
	boy_count = Counter(boys)
	res = 0
	girls.sort()
	for girl in girls:
		d1 = girl - 1
		d2 = girl
		d3 = girl + 1
		for d in [d1, d2, d3]:
			if d in boy_count:
				res += 1
				boy_count[d] -= 1
				if boy_count[d] == 0:
					del boy_count[d]
				break
	return res
print(get_max_match(boys, girls))


import sys
n = int(input())
a = [int(v) for v in sys.stdin.readline().split()]
m = int(input())
b = [int(v) for v in sys.stdin.readline().split()]
a.sort()
b.sort()
j = 0
k = 0
c = 0
while j < n and k < m:
	if abs(a[j] - b[k]) <= 1:
		c = c + 1
		j = j + 1
		k = k + 1
	elif a[j] > b[k]:
		k = k + 1
	else:
		j = j + 1
print(c)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
n = int(I1())
a = list(I())
m = int(I1())
b = list(I())
a.sort()
b.sort()
(i, j) = (0, 0)
p = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		p += 1
		i += 1
		j += 1
	elif a[i] > b[j]:
		j += 1
	else:
		i += 1
print(p)


input()
a = [int(x) for x in input().split()]
input()
b = [int(x) for x in input().split()]
a.sort()
b.sort()
x = 0
y = 0
count = 0
while x < len(a) and y < len(b):
	if abs(a[x] - b[y]) <= 1:
		count += 1
		x += 1
		y += 1
	elif a[x] > b[y]:
		y += 1
	else:
		x += 1
print(count)


def f(b, g):
	b.sort(reverse=True)
	g.sort(reverse=True)
	pairs = 0
	while len(g) > 0 and len(b) > 0:
		if b[-1] > g[-1]:
			if b[-1] - g[-1] == 1:
				b.pop()
				g.pop()
				pairs += 1
			else:
				g.pop()
		elif b[-1] < g[-1]:
			if g[-1] - b[-1] == 1:
				b.pop()
				g.pop()
				pairs += 1
			else:
				b.pop()
		else:
			b.pop()
			g.pop()
			pairs += 1
	return pairs
nb = int(input())
b = list(map(int, input().split()))
ng = int(input())
g = list(map(int, input().split()))
print(f(b, g))


def foo(n, m):
	c = 0
	n.sort()
	m.sort()
	for i in range(len(n)):
		for j in range(len(m)):
			if abs(n[i] - m[j]) <= 1:
				c += 1
				m[j] = 10000
				break
	return c
n = int(input())
a = input()
a = a.split(' ')
an = [int(i) for i in a]
m = int(input())
b = input()
b = b.split(' ')
bm = [int(i) for i in b]
print(foo(an, bm))


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n1 = inp(1)
b = inp()
n2 = inp(1)
g = inp()
b.sort()
g.sort()
pairs = 0
for i in range(n1):
	for j in range(n2):
		if abs(b[i] - g[j]) <= 1:
			g[j] = 100000000
			pairs += 1
			break
print(pairs)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
d = {}
j = 0
i = 0
f = 0
ans = 0
while i < n and j < m:
	f = 0
	if 0 <= abs(b[j] - a[i]) <= 1:
		j += 1
		ans += 1
	else:
		f = 0
		while j < m and b[j] + 1 < a[i]:
			f = 1
			j += 1
	if f == 0:
		i += 1
print(ans)


def input_int():
	return int(input())

def input_str():
	return str(input())
n = input_int()
boys = [int(x) for x in input().split()]
boys.sort()
m = input_int()
girls = [int(x) for x in input().split()]
girls.sort()
result = 0
i = 0
j = 0
while i < n and j < m:
	if abs(boys[i] - girls[j]) <= 1:
		i += 1
		j += 1
		result += 1
	elif boys[i] - girls[j] > 1:
		j += 1
	else:
		i += 1
print(result)


n = int(input())
arr = list(map(int, input().split()))
m = int(input())
arr1 = list(map(int, input().split()))
a = [0] * 101
b = [0] * 101
for i in arr:
	a[i] = arr.count(i)
for i in arr1:
	b[i] = arr1.count(i)
arr.sort()
arr1.sort()
k = min(n, m)
cnt = 0
if k == n:
	for i in arr:
		if i != 1 and i != 100:
			if b[i - 1] > 0:
				cnt += 1
				b[i - 1] -= 1
				continue
			if b[i] > 0:
				cnt += 1
				b[i] -= 1
				continue
			if b[i + 1] > 0:
				cnt += 1
				b[i + 1] -= 1
				continue
		elif i == 100:
			if b[i - 1] > 0:
				cnt += 1
				b[i - 1] -= 1
				continue
			if b[i] > 0:
				b[i] -= 1
				cnt += 1
				continue
		else:
			if b[i] > 0:
				b[i] -= 1
				cnt += 1
				continue
			if b[i + 1] > 0:
				cnt += 1
				b[i + 1] -= 1
				continue
else:
	for i in arr1:
		if i != 1 and i != 100:
			if a[i - 1] > 0:
				cnt += 1
				a[i - 1] -= 1
				continue
			if a[i] > 0:
				cnt += 1
				a[i] -= 1
				continue
			if a[i + 1] > 0:
				cnt += 1
				a[i + 1] -= 1
		elif i == 100:
			if a[i - 1] > 0:
				cnt += 1
				a[i - 1] -= 1
				continue
			if a[i] > 0:
				a[i] -= 1
				cnt += 1
				continue
		else:
			if a[i] > 0:
				a[i] -= 1
				cnt += 1
				continue
			if a[i + 1] > 0:
				cnt += 1
				a[i + 1] -= 1
				continue
print(cnt)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
(i, j) = (0, 0)
ans = 0
while i < n and j < m:
	if abs(a[i] - b[j]) < 2:
		ans += 1
		i += 1
		j += 1
	else:
		while a[i] > b[j] and a[i] - b[j] > 1:
			j += 1
			if j == m:
				break
		while j < m and a[i] < b[j] and (b[j] - a[i] > 1):
			i += 1
			if i == n:
				break
print(ans)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
girls_ = sorted(girls)[:]
boys.sort()
pairs = 0
for i in range(n):
	if boys[i] - 1 in girls_:
		girls_.remove(boys[i] - 1)
		pairs += 1
	elif boys[i] in girls_:
		girls_.remove(boys[i])
		pairs += 1
	elif boys[i] + 1 in girls_:
		girls_.remove(boys[i] + 1)
		pairs += 1
print(pairs)


b = int(input())
arr_b = list(map(int, input().split()))
g = int(input())
arr_g = list(map(int, input().split()))
arr_b.sort()
arr_g.sort()
ans = 0
for i in range(b):
	for j in range(g):
		if abs(arr_b[i] - arr_g[j]) <= 1:
			arr_g[j] = 10 ** 9
			arr_b[i] = 10 ** 9
			ans += 1
print(ans)


n = int(input())
b = list(map(int, input().split()))
k = int(input())
y = list(map(int, input().split()))
b.sort()
y.sort()
c = 0
for i in range(len(b)):
	for j in range(len(y)):
		if abs(b[i] - y[j]) <= 1:
			y[j] = 1000
			c += 1
			break
print(c)


n = int(input())
num1 = sorted([int(i) for i in input().split()])
k = int(input())
num2 = sorted([int(j) for j in input().split()])
count = 0
for i in range(len(num1)):
	for j in range(len(num2)):
		if abs(num1[i] - num2[j]) == 1 or abs(num1[i] - num2[j]) == 0:
			count += 1
			num1[i] = -3
			num2[j] = -3
print(count)


def solve(a, b):
	ans = 0
	while a and b:
		while abs(a[-1] - b[-1]) > 1:
			if b[-1] < a[-1]:
				b.pop()
			else:
				a.pop()
			if not (a and b):
				return ans
		if abs(a[-1] - b[-1]) <= 1:
			ans += 1
			b.pop()
			a.pop()
	return ans
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
m = int(input())
b = sorted([int(i) for i in input().split()], reverse=True)
print(solve(a, b))


nboys = int(input())
boys = list(map(int, input().split()))
boys.sort()
ngirls = int(input())
girls = list(map(int, input().split()))
girls.sort()
pares = 0
i = 0
j = 0
while i < ngirls and j < nboys:
	if abs(girls[i] - boys[j]) <= 1:
		pares += 1
		i += 1
		j += 1
	elif girls[i] > boys[j]:
		j += 1
	else:
		i += 1
print(pares)


def main():
	n = int(input())
	boys = input()
	m = int(input())
	girls = input()
	boys_list = [int(lt) for lt in boys.split(' ')]
	girls_list = [int(lt) for lt in girls.split(' ')]
	boys_list.sort()
	girls_list.sort()
	(p1, p2) = (0, 0)
	count = 0
	while p1 < len(boys_list) and p2 < len(girls_list):
		if abs(boys_list[p1] - girls_list[p2]) <= 1:
			p1 += 1
			p2 += 1
			count += 1
		elif boys_list[p1] < girls_list[p2]:
			p1 += 1
		elif boys_list[p1] >= girls_list[p2]:
			p2 += 1
	print(count)
main()


from typing import List, Tuple

def parse_input() -> Tuple[int, List[int], int, List[int]]:
	return (int(input()), [int(x) for x in input().split()], int(input()), [int(x) for x in input().split()])

def solve(n: int, a: List[int], m: int, b: List[int]) -> int:
	a.sort()
	b.sort()
	a_ptr = 0
	b_ptr = 0
	pairs = 0
	while a_ptr < n and b_ptr < m:
		d = abs(a[a_ptr] - b[b_ptr])
		if a[a_ptr] < b[b_ptr] and d > 1:
			a_ptr += 1
		elif b[b_ptr] < a[a_ptr] and d > 1:
			b_ptr += 1
		elif d <= 1:
			a_ptr += 1
			b_ptr += 1
			pairs += 1
	return pairs
(n, a, m, b) = parse_input()
print(solve(n, a, m, b))


def fun(a, b, n, m):
	a.sort()
	b.sort()
	c = 0
	w = 0
	for i in range(n):
		for j in range(w, len(b)):
			if abs(a[i] - b[j]) <= 1:
				c = c + 1
				w = 1 + j
				break
	return c
p = int(input())
f = list(map(int, input().split(' ')))
q = int(input())
g = list(map(int, input().split(' ')))
if p <= q:
	print(fun(f, g, p, q))
else:
	print(fun(g, f, q, p))


(n, a, m, b) = (int(input()), sorted(list(map(int, input().split()))), int(input()), sorted(list(map(int, input().split()))))
(i, j, c) = (0, 0, 0)
while i < n and j < m:
	if a[i] in range(b[j] - 1, b[j] + 2):
		c += 1
		j += 1
		i += 1
	elif a[i] < b[j]:
		i += 1
	elif a[i] > b[j]:
		j += 1
print(c)


n = int(input())
boy = [int(i) for i in input().split()]
m = int(input())
girl = [int(i) for i in input().split()]
boy = sorted(boy)
girl = sorted(girl)
count = 0
for i in range(len(boy)):
	j = 0
	while j < len(girl):
		if abs(boy[i] - girl[j]) <= 1:
			del girl[j]
			count += 1
			break
		j += 1
print(count)


def Insertion(Input):
	lista = Input
	for i in range(1, len(lista)):
		aux = int(lista[i])
		j = i
		while j > 0 and aux < int(lista[j - 1]):
			lista[j] = int(lista[j - 1])
			j -= 1
		lista[j] = int(aux)
	lista = [lista[i] for i in range(len(lista))]
	return lista
n = int(input())
nin_os_string = input()
nin_os_lista = nin_os_string.split(' ')
nin_os = [int(x) for x in nin_os_lista]
nin_os = Insertion(nin_os)
m = int(input())
nin_as_string = input()
nin_as_lista = nin_as_string.split(' ')
nin_as = [int(x) for x in nin_as_lista]
nin_as = Insertion(nin_as)

class Persona:

	def __init__(self, skill):
		self.skill = skill

class Baile:

	def __init__(self):
		self.nos = []
		self.nas = []
		self.personos = []
		self.personas = []

	def add_skill_os(self, value):
		self.nos.append(value)

	def add_skill_as(self, value):
		self.nas.append(value)

	def get_personas(self):
		nin_os = Insertion(self.nos)
		for v in nin_os:
			self.personos.append(Persona(v))
		nin_as = Insertion(self.nas)
		for v in nin_as:
			self.personas.append(Persona(v))

	def pairs(self):
		count = 0
		repetidos = list()
		if n < m:
			for i in range(len(self.personos)):
				for j in range(len(self.personas)):
					if self.personas[j] not in repetidos:
						if abs(self.personos[i].skill - self.personas[j].skill) <= 1:
							count += 1
							repetidos.append(self.personas[j])
							break
		else:
			for i in range(len(self.personas)):
				for j in range(len(self.personos)):
					if self.personos[j] not in repetidos:
						if abs(self.personas[i].skill - self.personos[j].skill) <= 1:
							count += 1
							repetidos.append(self.personos[j])
							break
		return count
b = Baile()
for o in nin_os:
	b.add_skill_os(o)
for a in nin_as:
	b.add_skill_as(a)
b.get_personas()
print(b.pairs())


q = int(input())
w = sorted(list(map(int, input().split())))
e = int(input())
r = sorted(list(map(int, input().split())))
t = 0
for i in w:
	for j in range(e):
		if abs(i - r[j]) <= 1:
			t += 1
			r[j] = -2
			break
print(t)


n = int(input(''))
boys = list(map(int, input('').split(' ')))
m = int(input(''))
girls = list(map(int, input('').split(' ')))
boys.sort()
girls.sort()
b = 0
g = 0
count = 0
while b < len(boys) and g < len(girls):
	if abs(boys[b] - girls[g]) <= 1:
		b += 1
		g += 1
		count += 1
	elif boys[b] < girls[g]:
		b += 1
	else:
		g += 1
print(count)


n = int(input())
boys = [int(i) for i in input().split()]
m = int(input())
girls = [int(i) for i in input().split()]
boys.sort()
girls.sort()
(i, j) = (0, 0)
(mini, maxi) = (min(n, m), max(n, m))
if len(boys) > len(girls):
	(boys, girls) = (girls, boys)
c = 0
while i < mini and j < maxi:
	if abs(boys[i] - girls[j]) <= 1:
		c += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(c)


n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
b = 0
g = 0
boy.sort()
girl.sort()
say = 0
while True:
	try:
		if abs(boy[b] - girl[g]) <= 1:
			say += 1
			b += 1
			g += 1
		elif boy[b] < girl[g]:
			b += 1
		else:
			g += 1
	except:
		break
print(say)


def solve():
	gidx = 0
	bidx = 0
	ans = 0
	while bidx < n and gidx < m:
		if abs(girls[gidx] - boys[bidx]) <= 1:
			ans += 1
			gidx += 1
			bidx += 1
		elif girls[gidx] > boys[bidx]:
			bidx += 1
		elif girls[gidx] < boys[bidx]:
			gidx += 1
	return ans
n = int(input())
boys = sorted(list(map(int, input().split())))
m = int(input())
girls = sorted(list(map(int, input().split())))
print(solve())


import sys
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)
readline = sys.stdin.readline

def process():
	n = int(readline())
	boys = list(map(int, readline().strip().split()))
	m = int(readline())
	girls = list(map(int, readline().strip().split()))
	visited_girls = [False] * m
	cnt = 0
	boys.sort()
	girls.sort()
	for i in range(n):
		for j in range(m):
			if abs(boys[i] - girls[j]) <= 1 and (not visited_girls[j]):
				cnt += 1
				visited_girls[j] = True
				break
	print(cnt)
process()


import sys

def solver(a, b):
	answer = 0
	ai = 0
	bi = 0
	while ai < len(a) and bi < len(b):
		if abs(a[ai] - b[bi]) <= 1:
			ai = ai + 1
			bi = bi + 1
			answer = answer + 1
		elif a[ai] > b[bi]:
			bi = bi + 1
		else:
			ai = ai + 1
	return answer

def main():
	lines = sys.stdin.readlines()
	a = list(map(int, lines[1].split()))
	aNew = sorted(a)
	b = list(map(int, lines[3].split()))
	bNew = sorted(b)
	print(solver(aNew, bNew))
main()


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
cnta = 0
cntb = 0
ans = 0
while cnta < n and cntb < m:
	if abs(a[cnta] - b[cntb]) <= 1:
		ans += 1
		cnta += 1
		cntb += 1
	elif a[cnta] > b[cntb]:
		cntb += 1
	else:
		cnta += 1
print(ans)


n = int(input())
b = input().split(' ')
boy = [int(i) for i in b]
m = int(input())
g = input().split(' ')
girl = [int(i) for i in g]
boy.sort()
girl.sort()
t = 0
i = j = 0
while i <= n - 1 and j <= m - 1:
	if abs(boy[i] - girl[j]) <= 1:
		t += 1
		i += 1
		j += 1
	elif boy[i] > girl[j] + 1:
		j += 1
	elif boy[i] < girl[j] - 1:
		i += 1
print(t)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
pairs_max = min(n, m)
pairs = 0
for boy in boys:
	for girl in girls:
		if abs(boy - girl) <= 1:
			pairs += 1
			girls.remove(girl)
			break
print(pairs_max if pairs >= pairs_max else pairs)


r = lambda : sorted(list(map(int, input().split())))
n = r()[0]
a = r()
m = r()[0]
b = r()
ini = 0
c = 0
for i in range(n):
	j = ini
	while j < m:
		if a[i] + 1 < b[j]:
			ini = j
			break
		elif abs(a[i] - b[j]) <= 1:
			ini = j + 1
			c += 1
			break
		j += 1
print(c)


t = 1
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	l.sort()
	l2.sort()
	ans = 0
	for k in range(n):
		for j in range(m):
			if abs(l[k] - l2[j]) <= 1:
				ans += 1
				l2[j] = float('inf')
				break
	print(ans)


n = int(input())
boy_skills = list(map(int, input().split()))
boy_skills.sort()
m = int(input())
girl_skills = list(map(int, input().split()))
girl_skills.sort()
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(boy_skills[i] - girl_skills[j]) < 2:
		count += 1
		i += 1
		j += 1
	elif boy_skills[i] < girl_skills[j]:
		i += 1
	else:
		j += 1
print(count)


n = int(input())
a = sorted(map(int, input().split()))
m = int(input())
b = sorted(map(int, input().split()))
pairs = j = 0
for i in range(n):
	if j == m:
		break
	while j < m and a[i] + 1 >= b[j]:
		if abs(a[i] - b[j]) <= 1:
			pairs += 1
			j += 1
			break
		else:
			j += 1
print(pairs)


n = int(input())
l1 = [int(x) for x in input().split()]
m = int(input())
l2 = [int(x) for x in input().split()]
l1.sort()
l2.sort()
c = 0
s = set()
for i in range(n):
	for j in range(m):
		if abs(l1[i] - l2[j]) <= 1 and j not in s:
			c += 1
			s.add(j)
			break
print(c)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
mx = max(max(a), max(b))
a_c = [0 for _ in range(mx)]
b_c = [0 for _ in range(mx)]
for e in a:
	a_c[e - 1] += 1
for e in b:
	b_c[e - 1] += 1
ans = 0
mn = min(a_c[0], b_c[0])
ans += mn
a_c[0] -= mn
b_c[0] -= mn
for i in range(1, mx):
	d_a_c = min(a_c[i], b_c[i - 1])
	ans += d_a_c
	a_c[i] -= d_a_c
	d_b_c = min(b_c[i], a_c[i - 1])
	ans += d_b_c
	b_c[i] -= d_b_c
	d_a_b = min(a_c[i], b_c[i])
	ans += d_a_b
	a_c[i] -= d_a_b
	b_c[i] -= d_a_b
print(ans)


n = int(input())
s = input().split()
m = int(input())
s1 = input().split()
lst = []
lst1 = []
c = 0
for i in s:
	lst.append(int(i))
for i in s1:
	lst1.append(int(i))
lst.sort()
lst1.sort()
for i in range(n):
	j = 0
	while j < m:
		if int(lst[i]) == int(lst1[j]) or int(lst[i]) - int(lst1[j]) == 1 or int(lst[i]) - int(lst1[j]) == -1:
			c += 1
			lst[i] = '102'
			lst1[j] = '102'
			break
		j += 1
print(c)


n = int(input())
m = map(int, input().split())
a = int(input())
b = map(int, input().split())
m = sorted(list(m))
b = sorted(list(b))
d = len(m)
f = len(b)
v = 0
if d > f:
	for i in range(f):
		if b[i] - 1 in m:
			v += 1
			m.remove(b[i] - 1)
		elif b[i] in m:
			v += 1
			m.remove(b[i])
		elif b[i] + 1 in m:
			v += 1
			m.remove(b[i] + 1)
		else:
			continue
else:
	for i in range(d):
		if m[i] - 1 in b:
			v += 1
			b.remove(m[i] - 1)
		elif m[i] in b:
			v += 1
			b.remove(m[i])
		elif m[i] + 1 in b:
			v += 1
			b.remove(m[i] + 1)
		else:
			continue
print(v)


n = int(input())
l_b = list(map(int, input().split()))
l_b.sort()
m = int(input())
l_g = list(map(int, input().split()))
l_g.sort()
b_i = 0
g_i = 0
t = 0
while b_i < len(l_b) and g_i < len(l_g):
	if abs(l_b[b_i] - l_g[g_i]) <= 1:
		t += 1
		b_i += 1
		g_i += 1
	elif l_b[b_i] < l_g[g_i]:
		b_i += 1
	else:
		g_i += 1
print(t)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
w = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if abs(a[i - 1] - b[j - 1]) <= 1:
			w[i][j] = w[i - 1][j - 1] + 1
		else:
			w[i][j] = max(w[i - 1][j], w[i][j - 1])
print(w[n][m])


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
d = 0
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if max(a[i], b[j]) - min(a[i], b[j]) <= 1:
			b[j] = 1000000000.0
			d += 1
			break
print(d)


n = int(input())
l = input()
l = sorted([int(i) for i in l.split()])
k = input()
t = input()
t = sorted([int(i) for i in t.split()])
b = 0
for i in range(int(n)):
	for j in range(int(k)):
		if abs(l[i] - t[j]) <= 1:
			t[j] = 1000
			b += 1
			break
print(b)


n = int(input())
a = iter(sorted([int(x) for x in input().split()]))
m = int(input())
b = iter(sorted([int(x) for x in input().split()]))
x_i = 1
y_i = 1
t = 0
try:
	while True:
		if x_i == 1:
			x = next(a)
		if y_i == 1:
			y = next(b)
		if y - x == 1 or x - y == 0 or x - y == 1:
			t += 1
			x_i = 1
			y_i = 1
		if x - y > 1:
			x_i = 0
			y_i = 1
		if y - x > 1:
			x_i = 1
			y_i = 0
except StopIteration:
	print(t)


nb = int(input())
boy = sorted(list(map(int, input().split())))
ng = int(input())
girl = {}
for i in range(max(boy) + 2):
	girl[i] = 0
g = map(int, input().split())
for i in g:
	if i not in girl:
		girl[i] = 1
	else:
		girl[i] += 1
count = 0
for i in boy:
	if girl[i - 1] > 0:
		count += 1
		girl[i - 1] = girl[i - 1] - 1
	elif girl[i] > 0:
		count += 1
		girl[i] = girl[i] - 1
	elif girl[i + 1] > 0:
		count += 1
		girl[i + 1] = girl[i + 1] - 1
print(count)


n_boys = int(input())
boy_p = list(map(int, input().split()))
n_girls = int(input())
girl_p = list(map(int, input().split()))
boy_p.sort()
girl_p.sort()
c = 0
pair = [False] * max(n_boys, n_girls)
for i in range(n_boys):
	for j in range(n_girls):
		if abs(boy_p[i] - girl_p[j]) < 2 and pair[j] == False:
			pair[j] = True
			c += 1
			break
print(c)


numBoys = int(input())
boys = sorted([int(x) for x in input().split()])
numGirls = int(input())
girls = sorted([int(x) for x in input().split()])
i = 0
j = 0
count = 0
while i < len(girls) and j < len(boys):
	if abs(girls[i] - boys[j]) <= 1:
		count += 1
		i = i + 1
		j = j + 1
	elif girls[i] < boys[j]:
		i = i + 1
	else:
		j = j + 1
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
if a[-1] + 1 < b[0] or a[0] > b[-1] + 1:
	print('0')
else:
	c = 0
	if n < m:
		d = a
		s = b
	else:
		d = b
		s = a
	for i in range(min(n, m)):
		if d[i] - 1 in s:
			c += 1
			s = s[:s.index(d[i] - 1)] + s[s.index(d[i] - 1) + 1:]
		elif d[i] in s:
			c += 1
			s = s[:s.index(d[i])] + s[s.index(d[i]) + 1:]
		elif d[i] + 1 in s:
			c += 1
			s = s[:s.index(d[i] + 1)] + s[s.index(d[i] + 1) + 1:]
	print(c)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
m = int(input())
b = input().split()
for i in range(m):
	b[i] = int(b[i])
a.sort()
b.sort()
num = 0
for i in range(n):
	try:
		index = b.index(a[i] - 1)
	except ValueError:
		index = -1
	if index != -1:
		num += 1
		b = b[:index] + b[index + 1:]
	else:
		try:
			index = b.index(a[i])
		except ValueError:
			index = -1
		if index != -1:
			num += 1
			b = b[:index] + b[index + 1:]
		else:
			try:
				index = b.index(a[i] + 1)
			except ValueError:
				index = -1
			if index != -1:
				num += 1
				b = b[:index] + b[index + 1:]
print(num)


n = int(input()) - 1
a = sorted(map(int, input().split()))
m = int(input()) - 1
b = sorted(map(int, input().split()))
cnt = 0
while n > -1 and m > -1:
	if a[n] > b[m] + 1:
		n -= 1
	elif b[m] > a[n] + 1:
		m -= 1
	else:
		n -= 1
		m -= 1
		cnt += 1
print(cnt)


import copy
import math
n_hombres = input()
skills_h = input()
skills_h = skills_h.split(' ')
n_mujeres = input()
skills_m = input()
skills_m = skills_m.split(' ')
skills_h = [int(i) for i in skills_h]
skills_m = [int(i) for i in skills_m]

def sort_list(lista):
	sorted_list = []
	lista_1 = lista
	lista_2 = copy.copy(lista)
	for i in range(0, len(lista_1)):
		min = math.inf
		for i in range(0, len(lista_2)):
			element = lista_2[i]
			if int(element) <= min:
				min = int(element)
		sorted_list.append(min)
		index = lista_2.index(min)
		lista_2.pop(index)
	return sorted_list

def greedy(list1, list2):
	list1 = sort_list(list1)
	list2 = sort_list(list2)
	big = None
	small = None
	max_list = []
	if len(list1) >= len(list2):
		big = list1
		small = list2
	else:
		big = list2
		small = list1
	max = 0
	pos = []
	for i in range(0, len(small)):
		for j in range(0, len(big)):
			element = small[i]
			element_2 = big[j]
			if (element_2 == element or element_2 + 1 == element or element_2 - 1 == element) and j not in pos:
				pos.append(j)
				max += 1
				break
	print(max)
greedy(skills_h, skills_m)


n = int(input())
nn = list(map(int, input().split()))
m = int(input())
mm = list(map(int, input().split()))
nn.sort()
mm.sort()
i = 0
j = 0
count = 0
while i < n and j < m:
	if abs(nn[i] - mm[j]) <= 1:
		count += 1
		i += 1
		j += 1
	elif nn[i] < mm[j]:
		i += 1
	else:
		j += 1
print(count)


c1 = [0] * 102
c2 = [0] * 102
_ = input()
for x in input().split():
	c1[int(x)] += 1
_ = input()
for x in input().split():
	c2[int(x)] += 1
ans = 0
for i in range(1, 101):
	x = min(c1[i], c2[i])
	ans += x
	c1[i] -= x
	c2[i] -= x
	x = min(c1[i + 1], c2[i])
	ans += x
	c1[i + 1] -= x
	c2[i] -= x
	x = min(c1[i], c2[i + 1])
	ans += x
	c1[i] -= x
	c2[i + 1] -= x
print(ans)


while True:
	try:

		def solution(nar, mar):
			i = j = 0
			team = 0
			n = len(nar)
			m = len(mar)
			if i < n and j < m:
				while j < m and i < n:
					if abs(nar[i] - mar[j]) <= 1:
						i += 1
						j += 1
						team += 1
					elif nar[i] > mar[j]:
						j += 1
					else:
						i += 1
			print(team)

		def read():
			n = int(input())
			nar = list(map(int, input().split()))
			nar.sort()
			m = int(input())
			mar = list(map(int, input().split()))
			mar.sort()
			solution(nar, mar)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


b = int(input())
boys = map(int, input().split())
boys = sorted(boys)
g = int(input())
girls = map(int, input().split())
girls = sorted(girls)
ans = 0
done = False
for bs in range(b):
	for gs in range(g):
		if abs(boys[bs] - girls[gs]) == 1 or boys[bs] == girls[gs]:
			boys[bs] = -101
			girls[gs] = -101
			done = True
			ans += 1
			break
	if done:
		done = False
print(ans)


n = int(input())
boys = sorted(map(int, input().split()))
m = int(input())
girls = sorted(map(int, input().split()))
res = 0
for x in boys:
	for (i, y) in enumerate(girls):
		if abs(x - y) <= 1:
			girls[i] = -1
			res += 1
			break
print(res)


a = int(input())
t = list(map(int, input().split()))
b = int(input())
d = list(map(int, input().split()))
h = 0
d.sort()
t.sort()
for k in range(a):
	p = 0
	for j in range(b):
		if p == 0:
			if d[j] != 'u':
				if abs(t[k] - d[j]) <= 1:
					h += 1
					d[j] = 'u'
					p += 1
		else:
			break
print(h)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
count = 0
a.sort()
b.sort()
for i in a:
	for j in range(m):
		if i - 1 == b[j] or i + 1 == b[j] or i == b[j]:
			count += 1
			b[j] = -2
			break
print(count)


n = int(input())
boys = list(map(int, input().strip().split()))
m = int(input())
girls = list(map(int, input().strip().split()))
dicti = {}
for i in boys:
	if i not in dicti:
		dicti[i] = [1, 0]
	else:
		dicti[i][0] += 1
girls.sort()
for i in girls:
	if i - 1 in dicti and dicti[i - 1][0] > 0:
		dicti[i - 1][1] += 1
		dicti[i - 1][0] -= 1
	elif i in dicti and dicti[i][0] > 0:
		dicti[i][1] += 1
		dicti[i][0] -= 1
	elif i + 1 in dicti and dicti[i + 1][0] > 0:
		dicti[i + 1][1] += 1
		dicti[i + 1][0] -= 1
sumi = 0
for i in dicti:
	sumi += dicti[i][1]
print(sumi)


def nice(a, b):
	if a <= b + 1 and a >= b - 1:
		return True
	return False

def solve(shorter, longer):
	i = 0
	j = 0
	pairs = 0
	while i < len(shorter) and j < len(longer):
		if shorter[i] <= longer[j] + 1 and shorter[i] >= longer[j] - 1:
			pairs += 1
			i += 1
			j += 1
		elif shorter[i] > longer[j]:
			j += 1
		else:
			i += 1
	return pairs
boysNum = int(input())
boys = sorted(list(map(int, input().split())))
girlsNum = int(input())
girls = sorted(list(map(int, input().split())))
if boysNum < girlsNum:
	print(solve(boys, girls))
else:
	print(solve(girls, boys))


n = int(input())
arr1 = sorted(list(map(int, input().split())))
n2 = int(input())
arr2 = sorted(list(map(int, input().split())))
pairs = 0
(i, j) = (0, 0)
while i < n and j < n2:
	if abs(arr1[i] - arr2[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif arr1[i] > arr2[j]:
		j += 1
	elif arr2[j] > arr1[i]:
		i += 1
print(pairs)


m = int(input())
valM = input().split(' ')
valM = list(map(int, valM))
f = int(input())
valF = input().split(' ')
valF = list(map(int, valF))
valM.sort()
valF.sort()
totalMatches = 0
for i in range(len(valM)):
	for j in range(len(valF)):
		a = valM[i] >= valF[j] - 1
		b = valM[i] <= valF[j] + 1
		if a and b:
			totalMatches += 1
			del valF[j]
			break
		elif valF[j] > valM[i] + 1:
			break
print(str(totalMatches))


n = int(input())
lista = list(map(int, input().split()))
visiteda = []
visitedb = []
count = 0
for i in range(n):
	visiteda.append(0)
m = int(input())
for i in range(m):
	visitedb.append(0)
listb = list(map(int, input().split()))
lista.sort()
listb.sort()
for i in range(n):
	for j in range(m):
		if abs(listb[j] - lista[i]) <= 1 and visiteda[i] == 0 and (visitedb[j] == 0):
			visitedb[j] = 1
			visiteda[i] = 1
			count = count + 1
			break
print(count)


n = int(input())
a = sorted([int(i) for i in input().split()])
m = int(input())
b = sorted([int(i) for i in input().split()])
k = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) <= 1 and b[j] != -1:
			k += 1
			b[j] = -1
			break
print(k)


b = int(input())
blist = list(map(int, input().strip().split()))
g = int(input())
glist = list(map(int, input().strip().split()))
res = 0
blist.sort()
glist.sort()
for a in range(0, b):
	for d in range(0, g):
		if glist[d] != None and abs(blist[a] - glist[d]) <= 1:
			glist[d] = None
			res += 1
			break
print(res)


n = int(input())
boys_skills = [int(x) for x in input().split()]
boys_skills.sort()
m = int(input())
girls_skills = [int(x) for x in input().split()]
girls_skills.sort()
i = 0
j = 0
count = 0
if n <= m:
	while i <= n - 1:
		if j > m - 1:
			break
		while j <= m - 1:
			if i > n - 1:
				break
			if abs(boys_skills[i] - girls_skills[j]) < 2:
				count = count + 1
				i = i + 1
				j = j + 1
			elif boys_skills[i] < girls_skills[j]:
				i = i + 1
			else:
				j = j + 1
elif m < n:
	while i <= m - 1:
		if j > n - 1:
			break
		while j <= n - 1:
			if i > m - 1:
				break
			if abs(girls_skills[i] - boys_skills[j]) < 2:
				count = count + 1
				i = i + 1
				j = j + 1
			elif girls_skills[i] < boys_skills[j]:
				i = i + 1
			else:
				j = j + 1
print(count)


from collections import Counter

def main():
	n = int(input())
	boys = sorted([int(c) for c in input().split()])
	m = int(input())
	girls = Counter([int(c) for c in input().split()])
	ans = 0
	for b in boys:
		for i in range(b - 1, b + 2):
			if girls[i] > 0:
				girls[i] -= 1
				ans += 1
				break
	print(ans)
main()


n = int(input())
a = [0] * 101
b = [0] * 101
for i in map(int, input().split()):
	a[i] += 1
m = int(input())
for i in map(int, input().split()):
	b[i] += 1
s = va = vb = 0
for i in range(1, 101):
	cva = va + a[i]
	cvb = vb + b[i]
	d = min(cva, cvb)
	s += d
	va = a[i] - max(d - va, 0)
	vb = b[i] - max(d - vb, 0)
print(s)


n = int(input())
Bi = list(map(int, input().split()))
Bi.sort()
n2 = int(input())
Gi = list(map(int, input().split()))
Gi.sort()
c = 0
B = []
G = []
for i in range(0, n):
	for j in range(0, n2):
		if abs(Bi[i] - Gi[j]) <= 1 and Bi[i] != -1 and (Gi[j] != -1):
			if Bi[i] not in B:
				B.append(Bi[i])
			if Gi[j] not in G:
				G.append(Gi[j])
			c += 1
			Bi[i] = -1
			Gi[j] = -1
			break
print(c)


ncnt = int(input())
n = [int(i) for i in input().split()]
n.sort()
mcnt = int(input())
m = [int(i) for i in input().split()]
m.sort()
matches = 0
for boy in n:
	for girl in m:
		if abs(boy - girl) <= 1:
			matches += 1
			m.remove(girl)
			break
print(matches)


ans = 0
n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
flag = True
l = 0
while l < n:
	for i in g:
		if b[l] == i or b[l] == i - 1 or b[l] == i + 1:
			g.remove(i)
			b.pop(l)
			n -= 1
			flag = False
			ans += 1
			break
	if flag:
		l += 1
	flag = True
print(ans)


n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]
boys.sort()
girls.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = 10000
			ans += 1
			break
print(ans)


nb = int(input())
b = sorted(map(int, input().split()))
ng = int(input())
g = sorted(map(int, input().split()))
p = 0
for i in range(nb):
	for j in range(ng):
		if -1 <= b[i] - g[j] <= 1:
			p += 1
			g[j] = -1
			break
print(p)


n = int(input())
b = list(map(int, input().split(' ')))
m = int(input())
g = list(map(int, input().split(' ')))
b.sort()
g.sort()
s = set()
c = 0
for i in range(0, n):
	for j in range(0, m):
		if j not in s:
			if abs(b[i] - g[j]) <= 1:
				c += 1
				s.add(j)
				break
print(c)


b = int(input())
bs = list(map(int, input().split()))
g = int(input())
gs = list(map(int, input().split()))
bs.sort()
gs.sort()
counter = 0
i = 0
j = 0
while i != len(bs) and bs and gs:
	if bs[i] == gs[j] or abs(bs[i] - gs[j]) == 1:
		counter += 1
		bs.pop(i)
		gs.pop(j)
		j = 0
	else:
		j += 1
	if j:
		if j == len(gs):
			j = 0
			i += 1
print(counter)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
b = sorted(list(map(int, input().split())))
memo = []
while len(memo) <= len(a):
	line = [0] * (1 + len(b))
	memo.append(line)
i = 1
while i <= len(a):
	j = 1
	while j <= len(b):
		if abs(a[i - 1] - b[j - 1]) <= 1:
			memo[i][j] = 1 + memo[i - 1][j - 1]
		else:
			memo[i][j] = max(memo[i - 1][j], memo[i][j - 1])
		j = j + 1
	i = i + 1
print(memo[n][m])


n_boys = int(input())
boys_array = [int(x) for x in input().strip().split()]
n_girls = int(input())
girls_array = [int(x) for x in input().strip().split()]
boys_array.sort()
girls_array.sort()
k = 0
i = 0
value = 0
while k < n_boys and i < n_girls:
	if abs(int(boys_array[k]) - int(girls_array[i])) <= 1:
		value += 1
		k += 1
		i += 1
	elif int(boys_array[k]) > int(girls_array[i]):
		i += 1
	elif int(boys_array[k]) < int(girls_array[i]):
		k += 1
print(value)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
n = stdint()
boys = list(stdarr())
m = stdint()
girls = list(stdarr())
total = []
for i in boys:
	total.append([i, 1, 0])
for i in girls:
	total.append([i, 2, 0])
total = sorted(total, key=lambda x: x[0])
i = 0
pairs = 0
while i < len(total):
	if total[i][2] == 1:
		i += 1
		continue
	done = False
	j = i + 1
	while j < len(total):
		if total[j][2] != 1:
			if total[i][1] != total[j][1]:
				if total[j][0] - total[i][0] <= 1:
					done = True
					pairs += 1
					total[j][2] = 1
					break
				else:
					j += 1
			else:
				j += 1
		else:
			j += 1
	if done:
		total[i][2] = 1
	i += 1
print(pairs)


n = int(input())
B = input().split()
B1 = []
for b in B:
	B1.append(int(b))
B1.sort()
m = int(input())
G = input().split()
G1 = []
for g in G:
	G1.append(int(g))
G1.sort()
count = 0
for b in B1:
	for g in G1:
		if abs(b - g) <= 1:
			count += 1
			G1.remove(g)
			break
print(count)


def main():
	n = int(input())
	b = list(map(int, input().split()))
	m = int(input())
	g = list(map(int, input().split()))
	g.sort()
	b.sort()
	count = 0
	for i in range(len(b)):
		for j in range(len(g)):
			if g[j] == -1:
				continue
			if abs(b[i] - g[j]) <= 1:
				count += 1
				g[j] = -1
				break
	print(count)
main()


input()
boys = list(map(int, input().split()))
input()
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
cnt = 0
for elem in boys:
	if elem - 1 in girls:
		cnt += 1
		girls.remove(elem - 1)
	elif elem in girls:
		cnt += 1
		girls.remove(elem)
	elif elem + 1 in girls:
		cnt += 1
		girls.remove(elem + 1)
print(cnt)


n = int(input())
arr1 = [int(i) for i in input().split()]
m = int(input())
arr2 = [int(i) for i in input().split()]
arr1.sort()
arr2.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(arr1[i] - arr2[j]) < 2:
			ans += 1
			arr1[i] = -10
			arr2[j] = -10
print(ans)


import sys

def main():
	sys.stdin.readline()
	lads = list(map(int, sys.stdin.readline().split()))
	sys.stdin.readline()
	lasses = list(map(int, sys.stdin.readline().split()))
	lads.sort()
	lasses.sort()
	pairs = 0
	chosen = []
	for i in min(lads, lasses):
		for (k, j) in enumerate(max(lads, lasses)):
			if abs(i - j) == 1 and k not in chosen or (i - j == 0 and k not in chosen):
				pairs += 1
				chosen.append(k)
				break
	sys.stdout.write(f'{pairs}')
main()


n = int(input())
li1 = [int(i) for i in input().split(' ')]
m = int(input())
li2 = [int(i) for i in input().split(' ')]
li = []
ll = []
c = 0
for i in range(105):
	li.append(0)
	ll.append(0)
for i in range(n):
	li[li1[i]] += 1
for i in range(m):
	ll[li2[i]] += 1
for i in range(101):
	if i - 1 >= 0:
		y = min(li[i], ll[i - 1])
		ll[i - 1] -= y
		li[i] -= y
		c += y
	z = min(li[i], ll[i])
	li[i] -= z
	ll[i] -= z
	c += z
	x = min(li[i], ll[i + 1])
	li[i] -= x
	ll[i + 1] -= x
	c += x
print(c)


isDebug = False
n = int(input())
sn = [int(x) for x in input().split()]
m = int(input())
sm = [int(x) for x in input().split()]
bm = [False] * m
sn = sorted(sn)
sm = sorted(sm)
t = 0
for i in range(0, n):
	for j in range(0, m):
		if bm[j]:
			continue
		d = abs(sn[i] - sm[j])
		if d <= 1:
			t = t + 1
			bm[j] = True
			break
print(t)


__author__ = 'Bian'
boyNum = int(input())
boy = [int(x) for x in input().split()]
girlNum = int(input())
girl = [int(x) for x in input().split()]
pair = 0
boy.sort()
girl.sort()
for i in range(boyNum):
	for j in range(girlNum):
		if girl[j] - boy[i] > 1:
			break
		elif abs(girl[j] - boy[i]) <= 1:
			pair += 1
			girl[j] = -1
			break
print(pair)


b = int(input())
ba = list(map(int, input().split()))
g = int(input())
ga = list(map(int, input().split()))
ba.sort()
ga.sort()
(i, j, count1) = (0, 0, 0)
while i < b and j < g:
	if abs(ba[i] - ga[j]) <= 1:
		i = i + 1
		j = j + 1
		count1 = count1 + 1
	elif ba[i] > ga[j]:
		j = j + 1
	elif ba[i] < ga[j]:
		i = i + 1
print(count1)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
if m < n:
	r = m
	c = 0
else:
	r = n
	c = 1
p = 0
for i in range(r):
	if c == 0:
		for j in b:
			d = g[i] - j
			if d == 1 or d == 0 or d == -1:
				p += 1
				b.remove(j)
				break
	if c == 1:
		for k in g:
			d = b[i] - k
			if d == 1 or d == 0 or d == -1:
				p += 1
				g.remove(k)
				break
print(p)


def f(a, b):
	k = 0
	for i in a:
		if i + 1 in b:
			b.remove(i + 1)
			k += 1
		elif i in b:
			b.remove(i)
			k += 1
		elif i - 1 in b:
			b.remove(i - 1)
			k += 1
	return k
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
if n >= m:
	print(f(b, a))
else:
	print(f(a, b))


t = int(input())
s = [int(x) for x in input().split()]
t1 = int(input())
s1 = [int(x) for x in input().split()]
s.sort(reverse=True)
s1.sort(reverse=True)
c = 0
for i in s:
	for h in s1:
		if abs(i - h) <= 1:
			c += 1
			s1.remove(h)
			break
print(c)


n = int(input())
a = list((int(x) for x in input().split()))
m = int(input())
b = list((int(x) for x in input().split()))
a.sort()
b.sort()
ans = 0
c = a[:]
for i in c:
	if i - 1 in b:
		ans += 1
		a.remove(i)
		b.remove(i - 1)
	elif i in b:
		ans += 1
		a.remove(i)
		b.remove(i)
	elif i + 1 in b:
		ans += 1
		a.remove(i)
		b.remove(i + 1)
print(ans)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
b = inlist()
m = inp()
g = inlist()
p = 0
b = sorted(b)
g = sorted(g)
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			b[i] = -5
			g[j] = -10
			p += 1
			break
print(p)


from collections import Counter
b = int(input())
bb = sorted(list(map(int, input().split())))
g = int(input())
gg = dict(Counter(list(map(int, input().split()))))
k = 0
for _ in bb:
	if _ - 1 in gg and gg[_ - 1] > 0:
		k += 1
		gg[_ - 1] -= 1
	elif _ in gg and gg[_] > 0:
		k += 1
		gg[_] -= 1
	elif _ + 1 in gg and gg[_ + 1] > 0:
		k += 1
		gg[_ + 1] -= 1
print(k)


numberOfBoys = int(input())
boys = list(map(int, input().split()))
numberOfGirls = int(input())
girls = list(map(int, input().split()))
count = 0
boys = sorted(boys)
girls = sorted(girls)
for i in range(numberOfBoys):
	for j in range(numberOfGirls):
		if girls[j] + 1 == boys[i] or boys[i] + 1 == girls[j] or (boys[i] == girls[j] and boys[i] != -1 and (girls[j] != -1)):
			(boys[i], girls[j]) = (-1, -1)
			count += 1
			break
print(count)


from sys import stdin, stdout
import bisect as bs
for _ in range(1):
	la = int(stdin.readline())
	a = sorted(map(int, stdin.readline().split()))
	lb = int(stdin.readline())
	b = sorted(map(int, stdin.readline().split()))
	ans = 0
	for v in a:
		for i in range(lb):
			if b[i] in {v, v - 1, v + 1}:
				ans += 1
				b[i] = -1
				break
	print(ans)


n = int(input())
l_b = list(map(int, input().split()))
l_b.sort()
m = int(input())
l_g = list(map(int, input().split()))
l_g.sort()
c = 0
if n < m:
	for i in l_b:
		for j in range(m):
			if abs(i - l_g[j]) <= 1:
				l_g[j] = 0
				c += 1
				break
else:
	for i in l_g:
		for j in range(n):
			if abs(i - l_b[j]) <= 1:
				l_b[j] = 0
				c += 1
				break
print(c)


import sys
from math import sqrt

def write_to_stdout(res):
	sys.stdout.write('%d\n' % res)

def read_input():
	n = input().rstrip().split()[0]
	men_scores = input().rstrip().split()
	m = input().rstrip().split()[0]
	women_scores = input().rstrip().split()
	return ([int(i) for i in men_scores], [int(i) for i in women_scores])

def get_answer(men_scores, women_scores):
	men_scores = sorted(men_scores)
	women_scores = sorted(women_scores)
	(men_idx, women_idx) = (0, 0)
	count = 0
	while men_idx < len(men_scores) and women_idx < len(women_scores):
		men_score = men_scores[men_idx]
		women_score = women_scores[women_idx]
		if abs(men_score - women_score) <= 1:
			men_idx += 1
			women_idx += 1
			count += 1
		if men_score - women_score >= 2:
			women_idx += 1
		if women_score - men_score >= 2:
			men_idx += 1
	return count

def main():
	(men_scores, women_scores) = read_input()
	answer = get_answer(men_scores, women_scores)
	write_to_stdout(answer)
main()


import math
n = int(input())
a = sorted(list(map(int, input().split())))
k = int(input())
b = sorted(list(map(int, input().split())))
dp = [[0] * n] * k
ans = 0
for i in range(n):
	for j in range(k):
		if abs(a[i] - b[j]) <= 1:
			ans += 1
			b[j] = 1000
			break
print(ans)


b = int(input())
boys = [int(a) for a in input().split()]
g = int(input())
girls = [int(a) for a in input().split()]
boys.sort()
girls.sort()
total = 0
for index in range(b):
	for index2 in range(g):
		if abs(boys[index] - girls[index2]) <= 1:
			girls[index2] = 1000
			total += 1
			break
print(total)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
b = [int(i) for i in input().split()]
b.sort()
ans = 0
for i in range(n):
	for j in range(m):
		if a[i] == b[j]:
			ans += 1
			b[j] = -15
			a[i] = -20
			break
		elif a[i] == b[j] - 1:
			ans += 1
			b[j] = -15
			a[i] = -20
			break
		elif a[i] - 1 == b[j]:
			ans += 1
			a[i] = -20
			b[j] = -15
			break
print(ans)


n1 = int(input())
b = list(map(int, input().split(' ')))
n2 = int(input())
g = list(map(int, input().split(' ')))
g.sort()
b.sort()
count = 0
for i in range(n1):
	for j in range(n2):
		if abs(b[i] - g[j]) < 2:
			g[j] = 100000
			count = count + 1
			break
print(count)


input()
boy = sorted(list(map(int, input().split())))
input()
girl = sorted(list(map(int, input().split())))
count = 0
for skill in girl:
	pan = 0
	for num in range(skill - 1, skill + 2):
		for i in range(len(boy)):
			if boy[i] == num:
				boy = boy[i + 1:]
				count += 1
				pan = 1
				break
		if pan == 1:
			break
print(count)


guys = int(input())
guysk = list(map(int, input().split()))
gals = int(input())
galsk = list(map(int, input().split()))
bb = []
gg = []
for i in range(len(guysk)):
	bb.append(0)
for j in range(len(galsk)):
	gg.append(0)
count = 0
for i in range(guys):
	for j in range(guys):
		if guysk[i] < guysk[j] and i > j:
			t = guysk[i]
			guysk[i] = guysk[j]
			guysk[j] = t
for i in range(gals):
	for j in range(gals):
		if galsk[i] < galsk[j] and i > j:
			t = galsk[i]
			galsk[i] = galsk[j]
			galsk[j] = t
for i in range(len(guysk)):
	for j in range(len(galsk)):
		if abs(guysk[i] - galsk[j]) <= 1 and gg[j] == 0 and (bb[i] == 0):
			count += 1
			gg[j] = -1
			bb[i] = -1
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
k = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) == 0 or abs(a[i] - b[j]) == 1:
			k += 1
			b[j] = -1
			break
print(k)


import collections

class AdjacencyList:

	def __init__(self, undirected=False):
		self.undirected = undirected
		self.vertices = set([])
		self.adjacency = {}

	def add_vertex(self, label):
		self.vertices.add(label)

	def _add_edge(self, v, u):
		try:
			self.adjacency[v].add(u)
		except KeyError:
			self.adjacency[v] = {u}

	def add_edge(self, v, u):
		self._add_edge(v, u)
		if self.undirected:
			self._add_edge(u, v)

	def delete_edge(self, v, u):
		self.adjacency[v].remove(u)
		if self.undirected:
			self.adjacency[u].remove(v)

	def delete_vertex(self, v):
		self.adjacency.pop(v)
		self.vertices.remove(v)
		for neighbors in self.adjacency.values():
			if v in neighbors:
				neighbors.remove(v)

	def is_vertex(self, v):
		return v in self.vertices

	def is_edge(self, v, u):
		return u in self.children(v)

	def children(self, v):
		return self.adjacency.get(v, set([]))

	def parents(self, v):
		return set([key for (key, value) in self.adjacency.items() if v in value])

	def out_degree(self, v):
		return len(self.children(v))

	def in_degree(self, v):
		return len(self.parents(v))

def dfs(G, v):
	stack = [v]
	visited = set([])
	while stack:
		u = stack.pop()
		print(u)
		visited.add(u)
		children = G.children(u)
		for w in children:
			if w not in visited:
				stack.append(w)

def bfs(G, v):
	visited = set([])
	queue = collections.deque([v])
	while queue:
		for i in range(len(queue)):
			element = queue.popleft()
			visited.add(element)
			print(element, depth)
			for x in G.children(element):
				if x not in visited:
					queue.append(x)
from sys import stdin

def read_lines(sep=' ', input_type=None):
	_lines = stdin.readlines()
	cast = input_type is not None
	lines = []
	for line in _lines:
		line = line[:-1].split(sep)
		if cast:
			line = [input_type(x) for x in line]
		lines.append(line)
	return lines

def main2():
	lines = read_lines(input_type=int)
	(n, m) = lines[0]
	graph = AdjacencyList(undirected=True)
	vertices = list(range(1, n + 1))
	edges = [(v1, v2) for (v1, v2) in lines[1:]]
	for v in vertices:
		graph.add_vertex(v)
	for e in edges:
		graph.add_edge(*e)

	def dfs2(G):
		removes = []
		visited = set([])
		for v in G.vertices:
			if v not in visited:
				stack = [v]
				while stack:
					u = stack.pop()
					if G.in_degree(u) == 1:
						removes.append(u)
					visited.add(u)
					children = G.children(u)
					for w in children:
						if w not in visited:
							stack.append(w)
		if removes:
			for v_remove in removes:
				G.delete_vertex(v_remove)
			return True
		else:
			return False
	count = 0
	while dfs2(graph):
		count += 1
	print(count)

def main():
	lines = read_lines(input_type=int)
	(s1, s2) = (lines[1], lines[3])
	s1 = sorted(s1)
	s2 = sorted(s2)
	npairs = 0
	while s1 and s2:
		(a, b) = (s1[-1], s2[-1])
		d = a - b
		if abs(d) <= 1:
			npairs += 1
			s1.pop()
			s2.pop()
		elif d > 0:
			s1.pop()
		else:
			s2.pop()
	print(npairs)
main()


n = int(input())
l = list(map(int, input().split()))
m = int(input())
d = list(map(int, input().split()))
l.sort()
d.sort()
c = 0
for i in l:
	for j in range(m):
		if abs(i - d[j]) <= 1:
			c = c + 1
			d[j] = -369
			break
print(c)


n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
boy.sort()
girl.sort()
girls = set(girl)
boys = set(boy)
dicb = {}
dicg = {}
for x in boys:
	dicb[x] = boy.count(x)
for i in range(0, max(max(girl), max(boy)) + 2):
	if i not in boys:
		dicb[i] = 0
for x in girls:
	dicg[x] = girl.count(x)
for i in range(0, max(max(girl), max(boy)) + 2):
	if i not in girls:
		dicg[i] = 0
num = 0
for i in range(1, max(girl) + 1):
	if dicg[i] != 0:
		if dicg[i] > dicb[i - 1] + dicb[i] + dicb[i + 1]:
			num += dicb[i - 1] + dicb[i] + dicb[i + 1]
			dicb[i - 1] = 0
			dicb[i] = 0
			dicb[i + 1] = 0
		else:
			num += dicg[i]
			dicb[i + 1] = min(dicb[i + 1], dicb[i - 1] + dicb[i] + dicb[i + 1] - dicg[i])
			dicb[i] = min(dicb[i], max(0, dicb[i - 1] + dicb[i] - dicg[i]))
			dicb[i - 1] = max(dicb[i - 1] - dicg[i], 0)
print(num)


def bersu_ball(b, boys, g, girls):
	d = []
	for i in girls:
		d.append([i - 1, i, i + 1])
	cnt = 0
	for i in boys:
		for j in range(g):
			if i in d[j]:
				cnt += 1
				d[j] = [0, 0, 0]
				break
	return cnt
b = int(input())
boys = sorted(list(map(int, input().split())))
g = int(input())
girls = sorted(list(map(int, input().split())))
print(bersu_ball(b, boys, g, girls))


arr = []
arr1 = []
n = int(input())
arr = sorted(map(int, input().split()))
m = int(input())
arr1 = sorted(map(int, input().split()))
c = 0
t = m
if n < m:
	for i in range(n):
		for j in range(t):
			if abs(arr[i] - arr1[j]) <= 1:
				c += 1
				arr1.pop(j)
				t -= 1
				break
else:
	for i in range(m):
		for j in range(n):
			if abs(arr[j] - arr1[i]) <= 1:
				c += 1
				arr.pop(j)
				n -= 1
				break
print(c)


def maxpair(b, g, n, m):
	i = 0
	j = 0
	b = sorted(b)
	g = sorted(g)
	count = 0
	while i < n and j < m:
		if abs(b[i] - g[j]) <= 1:
			count = count + 1
			i = i + 1
			j = j + 1
		elif b[i] > g[j]:
			j = j + 1
		elif b[i] < g[j]:
			i = i + 1
	return count
n = int(input())
b = list(map(int, list(input().split())))
m = int(input())
g = list(map(int, list(input().split())))
print(maxpair(b, g, n, m))


x = int(input())
a = list(map(int, input().split()))
y = int(input())
b = list(map(int, input().split()))
count = 0
ar = sorted(a)
br = sorted(b)
for i in range(x):
	for j in range(y):
		if abs(ar[i] - br[j]) <= 1 and ar[i] != 0 and (br[j] != 0):
			count += 1
			ar[i] = 0
			br[j] = 0
print(count)


N = int(input())
A = list(map(int, input().split()))
A.sort()
M = int(input())
B = list(map(int, input().split()))
B.sort()
count = 0
i = 0
j = 0
while i < N and j < M:
	if abs(A[i] - B[j]) <= 1:
		i += 1
		j += 1
		count += 1
	elif A[i] > B[j]:
		j += 1
	else:
		i += 1
print(count)


input()
boys = sorted([int(i) for i in input().split()])
input()
girls = sorted([int(i) for i in input().split()])
pairsNum = 0
(i, j) = (0, 0)
while i < len(boys) and j < len(girls):
	if abs(boys[i] - girls[j]) <= 1:
		pairsNum += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	elif girls[j] < boys[i]:
		j += 1
	else:
		break
print(pairsNum)


__author__ = 'valeriy.shevchuk'
input()
b = sorted(list(map(int, input().split())))
input()
g = sorted(list(map(int, input().split())))
c = 0
while b and g:
	bb = b[0]
	gg = g[0]
	if abs(bb - gg) <= 1:
		c += 1
		b.pop(0)
		g.pop(0)
	else:
		b.pop(0) if bb < gg else g.pop(0)
print(c)


n = int(input())
ai = sorted(list(map(int, input().split())))
m = int(input())
bi = sorted(list(map(int, input().split())))
i = 0
j = 0
ni = 0
while i < n and j < m:
	if ai[i] < bi[j] - 1:
		while i < n and ai[i] < bi[j] - 1:
			i += 1
	elif ai[i] - 1 > bi[j]:
		while j < m and ai[i] - 1 > bi[j]:
			j += 1
	if i < n and j < m and (ai[i] == bi[j] or ai[i] - 1 == bi[j] or ai[i] == bi[j] - 1):
		ni += 1
		i += 1
		j += 1
print(ni)


b = [0] * 102
g = [0] * 102
m = [0] * 102
input()
for i in map(int, input().split(' ')):
	b[i] += 1
input()
for i in map(int, input().split(' ')):
	g[i] += 1
for i in range(1, 101):
	p = min(b[i - 1], g[i])
	b[i - 1] -= p
	g[i] -= p
	m[i] += p
	p = min(b[i], g[i])
	b[i] -= p
	g[i] -= p
	m[i] += p
	p = min(b[i + 1], g[i])
	b[i] -= p
	g[i] -= p
	m[i] += p
print(sum(m))


dp = [[None] * 100 for _ in range(100)]

def recurse(i, j):
	if i == n or j == m:
		return 0
	if dp[i][j] is not None:
		return dp[i][j]
	dp[i][j] = 0
	if abs(a[i] - b[j]) <= 1:
		dp[i][j] = max(dp[i][j], recurse(i + 1, j + 1) + 1)
	dp[i][j] = max(dp[i][j], recurse(i + 1, j), recurse(i, j + 1))
	return dp[i][j]
n = int(input())
a = sorted(map(int, input().split()))
m = int(input())
b = sorted(map(int, input().split()))
print(recurse(0, 0))


nm = int(input())
mls = sorted([int(x) for x in input().split()])
nw = int(input())
wls = sorted([int(x) for x in input().split()])
mi = wi = 0
tot = 0
while mi < nm and wi < nw:
	if abs(mls[mi] - wls[wi]) <= 1:
		tot += 1
		wi += 1
		mi += 1
	elif mls[mi] > wls[wi]:
		wi += 1
	else:
		mi += 1
print(tot)


n = int(input())
list = [int(z) for z in input().split()]
m = int(input())
list1 = [int(k) for k in input().split()]
list = sorted(list)
list1 = sorted(list1)
count = 0
for index in range(len(list)):
	for index1 in range(len(list1)):
		if list[index] - 1 == list1[index1] or list[index] + 1 == list1[index1] or list[index] == list1[index1]:
			list1.pop(index1)
			count = count + 1
			break
print(count)


num_boys = int(input())
boys = [int(x) for x in input().split(' ')]
boys.sort()
num_girls = int(input())
girls = [int(x) for x in input().split(' ')]
girls.sort()
count_pairs = 0
boy_pointer = 0
girl_pointer = 0
while girl_pointer < num_girls and boy_pointer < num_boys:
	if abs(boys[boy_pointer] - girls[girl_pointer]) <= 1:
		count_pairs += 1
		boy_pointer += 1
		girl_pointer += 1
	elif boys[boy_pointer] > girls[girl_pointer]:
		girl_pointer += 1
	else:
		boy_pointer += 1
print(count_pairs)


n = int(input())
skillman = [int(n) for n in input().split()]
m = int(input())
skillgirls = [int(m) for m in input().split()]
skillman.sort()
skillgirls.sort()
res = 0
for i in range(n):
	for j in range(m):
		if abs(skillman[i] - skillgirls[j]) <= 1:
			skillgirls[j] = 1000
			res += 1
			break
print(res)


a = int(input())
al = list(map(int, input().split()))
b = int(input())
bl = list(map(int, input().split()))
al.sort()
bl.sort()
cnt = 0
for i in range(a):
	j = 0
	while j < len(bl):
		if abs(al[i] - bl[j]) <= 1:
			bl.pop(j)
			cnt += 1
			break
		if bl[j] > al[i] + 1:
			break
		j += 1
print(cnt)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	res = 0
	for i in range(n):
		for j in range(m):
			if abs(a[i] - b[j]) <= 1:
				res += 1
				b[j] = 100000
				break
	print(res)
main()


b = int(input())
boys = input().split()
g = int(input())
girls = input().split()
boys = [int(i) for i in boys]
girls = [int(i) for i in girls]
boys.sort()
count = 0
for i in range(b):
	test = boys[i]
	if test - 1 in girls:
		girls.remove(test - 1)
		count += 1
	elif test in girls:
		girls.remove(test)
		count += 1
	elif test + 1 in girls:
		girls.remove(test + 1)
		count += 1
print(count)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
m = int(input())
b = input().split()
for i in range(m):
	b[i] = int(b[i])
a.sort()
b.sort()
answ = 0
used = []
for i in range(m):
	used.append(False)
for i in range(n):
	check = True
	for j in range(m):
		if check and abs(a[i] - b[j]) <= 1 and (not used[j]):
			check = False
			answ += 1
			used[j] = True
print(answ)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
x = 0
for i in range(n):
	for j in range(m):
		if abs(a[i] - b[j]) < 2:
			x += 1
			b[j] = -9999
			break
print(x)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
(i1, i2, ans) = (0, 0, 0)
while i1 < n and i2 < m:
	if abs(boys[i1] - girls[i2]) <= 1:
		ans += 1
		i1 += 1
		i2 += 1
	elif boys[i1] > girls[i2]:
		i2 += 1
	else:
		i1 += 1
print(ans)


boycount = int(input())
boyskill = list(map(int, input().split()))
girlcount = int(input())
girlskill = list(map(int, input().split()))
match = 0
if boycount > girlcount:
	for _ in range(boycount):
		if max(boyskill) + 1 in girlskill:
			match += 1
			girlskill.remove(max(boyskill) + 1)
			boyskill.remove(max(boyskill))
		elif max(boyskill) in girlskill:
			match += 1
			girlskill.remove(max(boyskill))
			boyskill.remove(max(boyskill))
		elif max(boyskill) - 1 in girlskill:
			match += 1
			girlskill.remove(max(boyskill) - 1)
			boyskill.remove(max(boyskill))
		else:
			boyskill.remove(max(boyskill))
		if not boyskill:
			break
		if not girlskill:
			break
else:
	for _ in range(girlcount):
		if max(boyskill) + 1 in girlskill:
			match += 1
			girlskill.remove(max(boyskill) + 1)
			boyskill.remove(max(boyskill))
		elif max(boyskill) in girlskill:
			match += 1
			girlskill.remove(max(boyskill))
			boyskill.remove(max(boyskill))
		elif max(boyskill) - 1 in girlskill:
			match += 1
			girlskill.remove(max(boyskill) - 1)
			boyskill.remove(max(boyskill))
		else:
			boyskill.remove(max(boyskill))
		if not boyskill:
			break
		if not girlskill:
			break
print(match)


def dif(n, m):
	return max(n, m) - min(n, m)
n = int(input())
l = [int(x) for x in input().split()]
m = int(input())
s = [int(x) for x in input().split()]
l.sort()
s.sort()
v = list(range(m))
a = 0
for i in range(n):
	for j in v:
		if dif(l[i], s[j]) < 2:
			a += 1
			v.pop(v.index(j))
			break
print(a)


n = int(input())
b = sorted([int(i) for i in input().split()])
m = int(input())
g = sorted([int(i) for i in input().split()])
res = 0
for i in range(len(b)):
	for j in range(len(g)):
		if abs(b[i] - g[j]) <= 1:
			res += 1
			g[j] = 99999
			break
print(res)


males = int(input())
males_ability = [int(m) for m in input().split()]
females = int(input())
females_ability = [int(m) for m in input().split()]
males_ability.sort()
females_ability.sort()
pairs = 0
for x in males_ability:
	for y in females_ability:
		if y in range(x - 1, x + 2):
			females_ability.remove(y)
			pairs += 1
			break
print(pairs)


boys = int(input())
boys_input = input().split()
boys_skills = []
for skill in boys_input:
	boys_skills.append(int(skill))
girls = int(input())
girls_input = input().split()
girls_skills = []
for skill_ in girls_input:
	girls_skills.append(int(skill_))
boys_skills = sorted(boys_skills)
girls_skills = sorted(girls_skills)
pairs = 0
for boy in range(boys):
	for girl in range(girls):
		if abs(boys_skills[boy] - girls_skills[girl]) < 2:
			girls_skills[girl] = 10000
			pairs += 1
			break
print(pairs)


a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
i = min(len(b), len(d))
(x, y) = (0, 0)
z = 0
while z <= i and b != [] and (d != []):
	x = int(min(b))
	y = int(min(d))
	if x <= y:
		if y - x < 2:
			b.pop(b.index(x))
			d.pop(d.index(y))
			z += 1
		else:
			b.pop(b.index(x))
	elif x - y < 2:
		b.pop(b.index(x))
		d.pop(d.index(y))
		z += 1
	else:
		d.pop(d.index(y))
print(z)


b = int(input())
bo = list(map(int, input().split()))
g = int(input())
gi = list(map(int, input().split()))
bo.sort()
gi.sort()
i = 0
j = 0
cnt = 0
while i < b and j < g:
	if abs(bo[i] - gi[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
	elif bo[i] > gi[j]:
		j += 1
	else:
		i += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
bb = [0] * 102
a.sort()
b.sort()
for i in b:
	bb[i] += 1
ans = 0
for i in range(n):
	if bb[a[i] - 1] > 0:
		bb[a[i] - 1] -= 1
		ans += 1
	elif bb[a[i]] > 0:
		bb[a[i]] -= 1
		ans += 1
	elif bb[a[i] + 1] > 0:
		bb[a[i] + 1] -= 1
		ans += 1
print(ans)


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
c = 0
vis = [0 for i in range(m)]
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1 and vis[j] == 0:
			c = c + 1
			vis[j] = 1
			break
print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for _ in range(1):
	nb = int(input())
	a = list(map(int, input().split()))
	ng = int(input())
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	(j, cnt) = (0, 0)
	for i in range(nb):
		if j == ng:
			break
		while a[i] + 1 >= b[j]:
			if abs(a[i] - b[j]) <= 1:
				cnt += 1
				j += 1
				break
			else:
				j += 1
			if j == ng:
				break
	print(cnt)


import sys
n = int(input())
boyarr = list(map(int, input().split()))
m = int(input())
girlarr = list(map(int, input().split()))
boyarr.sort()
girlarr.sort()
l1 = 0
l2 = 0
count = 0
for j in range(n + m):
	if l1 >= n:
		break
	elif l2 >= m:
		break
	if int(abs(boyarr[l1] - girlarr[l2])) < 2:
		l1 += 1
		l2 += 1
		count += 1
	elif l2 + 1 < m and boyarr[l1] > girlarr[l2]:
		l2 += 1
	elif l1 + 1 < n and boyarr[l1] < girlarr[l2]:
		l1 += 1
print(count)


def dp(brr, grr, b, g):
	brr.sort()
	grr.sort()
	ans = 0
	for i in range(b):
		for j in range(g):
			if abs(brr[i] - grr[j]) == 1 or abs(brr[i] - grr[j]) == 0:
				grr[j] = 1000
				ans += 1
				break
	return ans
b = int(input())
brr = list(map(int, input().split()))
g = int(input())
grr = list(map(int, input().split()))
print(dp(brr, grr, b, g))


from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
a = dict(Counter(ls))
m = int(input())
ls = list(map(int, input().split()))
b = dict(Counter(ls))
count = {}
for (k, v) in a.items():
	try:
		count[k] = [k, a[k], b[k]]
	except:
		count[k] = [k, a[k], 0]
for (k, v) in b.items():
	try:
		count[k] += []
	except:
		count[k] = [k, 0, b[k]]
ls = sorted(list(count.values()), key=lambda x: x[0])
cnt = 0
for i in range(len(ls) - 1):
	m = min(ls[i][1], ls[i][2])
	ls[i][1] -= m
	ls[i][2] -= m
	cnt += m
	if ls[i + 1][0] == ls[i][0] + 1:
		m = min(ls[i + 1][1], ls[i][2])
		ls[i + 1][1] -= m
		ls[i][2] -= m
		cnt += m
		m = min(ls[i][1], ls[i + 1][2])
		ls[i][1] -= m
		ls[i + 1][2] -= m
		cnt += m
m = min(ls[-1][1], ls[-1][2])
ls[-1][1] -= m
ls[-1][2] -= m
cnt += m
print(cnt)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
count = 0
for i in boys:
	cur = 0
	for j in girls:
		if j == i - 1:
			girls[cur] = -1
			count += 1
			cur += 1
			break
		elif j == i:
			girls[cur] = -1
			count += 1
			cur += 1
			break
		elif j == i + 1:
			girls[cur] = -1
			count += 1
			cur += 1
			break
		cur += 1
print(count)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(n,) = mp()
a = sorted(mp())
(m,) = mp()
b = mp()
count = 0
for i in range(n):
	for j in range(a[i] - 1, a[i] + 2):
		if j in b:
			count += 1
			b.remove(j)
			break
cout(str(count))


import math
input()
lista_hombres = list(input().split())
for i in range(len(lista_hombres)):
	lista_hombres[i] = int(lista_hombres[i])
input()
lista_mujeres = list(input().split())
for i in range(len(lista_mujeres)):
	lista_mujeres[i] = int(lista_mujeres[i])
lista_hombres.sort()
lista_mujeres.sort()
parejas = 0
for i in range(len(lista_hombres)):
	for j in range(len(lista_mujeres)):
		if abs(lista_hombres[i] - lista_mujeres[j]) <= 1:
			parejas += 1
			lista_hombres[i] = math.inf
			lista_mujeres[j] = math.inf
print(parejas)


n1 = input()
l1 = list(map(int, input().split()))
n2 = input()
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
if len(l1) > len(l2):
	min = l2
	nmin = l1
else:
	min = l1
	nmin = l2
count = 0
for i in min:
	if i - 1 in nmin:
		count = count + 1
		nmin.remove(i - 1)
	elif i in nmin:
		count = count + 1
		nmin.remove(i)
	elif i + 1 in nmin:
		count = count + 1
		nmin.remove(i + 1)
print(count)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
pairs = 0
(i_a, i_b) = (0, 0)
while i_a < len(a) and i_b < len(b):
	if a[i_a] < b[i_b] - 1:
		i_a += 1
	elif a[i_a] > b[i_b] + 1:
		i_b += 1
	else:
		pairs += 1
		i_a += 1
		i_b += 1
print(pairs)


b = int(input())
lb = sorted([int(x) for x in input().split()])
g = int(input())
lg = sorted([int(x) for x in input().split()])
cont = 0
for boi in lb:
	try:
		lg[lg.index(boi - 1)] = -2
		cont += 1
	except:
		try:
			lg[lg.index(boi)] = -2
			cont += 1
		except:
			try:
				lg[lg.index(boi + 1)] = -2
				cont += 1
			except:
				pass
print(cont)


n = int(input())
L1 = [int(x) for x in input().split()]
m = int(input())
L2 = [int(x) for x in input().split()]
num = 0
L1.sort()
L2.sort()
for i in range(len(L1)):
	for j in range(len(L2)):
		if abs(L1[i] - L2[j]) <= 1:
			num = num + 1
			L1[i] = L2[j] = 200
			break
print(num)


nofboys = int(input())
boy_list = input()
nofgirls = int(input())
girl_list = input()
boy_list = boy_list.split(' ')
girl_list = girl_list.split(' ')
for i in range(len(boy_list)):
	boy_list[i] = int(boy_list[i])
for i in range(len(girl_list)):
	girl_list[i] = int(girl_list[i])
boy_list.sort()
girl_list.sort()
count = 0
i = j = 0
while i != len(boy_list) and j != len(girl_list):
	if boy_list[i] - girl_list[j] == 0 or boy_list[i] - girl_list[j] == 1 or boy_list[i] - girl_list[j] == -1:
		count += 1
		i += 1
		j += 1
	elif boy_list[i] > girl_list[j]:
		j += 1
	elif boy_list[i] < girl_list[j]:
		i += 1
print(count)


def solve():
	boys = int(input())
	boys_skill = sorted([int(x) for x in input().split()])
	girls = int(input())
	girls_skill = sorted([int(x) for x in input().split()])
	count = 0
	for i in range(len(boys_skill)):
		for j in range(len(girls_skill)):
			if abs(boys_skill[i] - girls_skill[j]) <= 1:
				count += 1
				girls_skill[j] = -999999
				boys_skill[i] = 99999
	print(count)
solve()


def quick_sort(a):
	if len(a) <= 1:
		return a
	mid = len(a) // 2
	L = []
	R = []
	M = []
	for num in a:
		if num < a[mid]:
			L.append(num)
		elif num > a[mid]:
			R.append(num)
		else:
			M.append(num)
	return quick_sort(L) + M + quick_sort(R)
n = int(input())
a = []
b = []
a += [int(i) for i in input().split()]
k = int(input())
b += [int(i) for i in input().split()]
a = quick_sort(a)
b = quick_sort(b)
a.reverse()
b.reverse()
ans = 0
while len(a) > 0 and len(b) > 0:
	if abs(b[0] - a[0]) <= 1:
		ans += 1
		b.remove(b[0])
		a.remove(a[0])
	elif b[0] > a[0]:
		b.remove(b[0])
	elif a[0] > b[0]:
		a.remove(a[0])
print(ans)


b = int(input())
x = [int(x) for x in input().split()]
x.sort()
g = int(input())
y = [int(y) for y in input().split()]
y.sort()
cnt = 0
for i in range(b):
	for j in range(g):
		if abs(x[i] - y[j]) <= 1:
			y[j] = 1000
			cnt += 1
			break
print(cnt)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
bp = 0
gp = 0
c = 0
while bp < n and gp < m:
	if abs(boys[bp] - girls[gp]) <= 1:
		c += 1
		bp += 1
		gp += 1
	elif boys[bp] > girls[gp]:
		gp += 1
	elif boys[bp] < girls[gp]:
		bp += 1
print(c)


a = int(input())
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
b = int(input())
b = input().split()
for i in range(len(b)):
	b[i] = int(b[i])
a.sort()
b.sort()
s = 0
for i in range(len(a)):
	try:
		l = b.index(a[i] - 1)
		s += 1
		del b[l]
	except:
		try:
			l1 = b.index(a[i])
			s += 1
			del b[l1]
		except:
			try:
				l2 = b.index(a[i] + 1)
				s += 1
				del b[l2]
			except:
				lll = 1
print(s)


n = input()
char_man = input().split(' ')
m = input()
char_woman = input().split(' ')
man = [int(e) for e in char_man]
woman = [int(e) for e in char_woman]
man.sort()
woman.sort()
counter = 0
while len(man) > 0 and len(woman) > 0:
	diff = man[0] - woman[0]
	if abs(diff) <= 1:
		counter += 1
		man.pop(0)
		woman.pop(0)
	elif diff < -1:
		man.pop(0)
	elif diff > 1:
		woman.pop(0)
print(counter)


from collections import deque, Counter
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
_ = read_int()
a = read_int_array()
_ = read_int()
b = read_int_array()
(a, b) = (a, b) if len(a) < len(b) else (b, a)
n = len(a)
m = len(b)
a.sort()
b.sort()
i = 0
j = 0
pairs = 0
while i < n and j < m:
	if abs(a[i] - b[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif a[i] < b[j]:
		i += 1
	else:
		j += 1
print(pairs)


a = int(input(''))
t = list(map(int, input('').split()))
b = int(input(''))
f = list(map(int, input('').split()))

def check_availability(element, collection: iter):
	return element in collection
t.sort()
stevec = 0
for i in range(len(t)):
	mozni1 = t[i] - 1
	mozni2 = t[i]
	mozni3 = t[i] + 1
	if check_availability(mozni1, f):
		f.remove(mozni1)
		stevec += 1
	elif check_availability(mozni2, f):
		f.remove(mozni2)
		stevec += 1
	elif check_availability(mozni3, f):
		f.remove(mozni3)
		stevec += 1
	if len(f) == 0:
		break
print(stevec)


n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
pairs = 0
(i, j) = (0, 0)
while i < n and j < m:
	if boys[i] == girls[j] or boys[i] == girls[j] - 1 or boys[i] == girls[j] + 1:
		pairs += 1
		i += 1
		j += 1
	elif boys[i] < girls[j]:
		i += 1
	else:
		j += 1
print(pairs)


import random

def solve(boy, girl):
	boy.sort(reverse=True)
	girl.sort(reverse=True)
	pairs = 0
	b = boy.pop()
	g = girl.pop()
	while b != None and g != None:
		if abs(b - g) <= 1:
			pairs += 1
			try:
				b = boy.pop()
				g = girl.pop()
			except:
				break
		elif b > g:
			try:
				g = girl.pop()
			except:
				g = None
		elif g > b:
			try:
				b = boy.pop()
			except:
				b = None
	return pairs

def fast_pair(b, g, count):
	if len(b) == 0 or len(g) == 0:
		return count

def solve_naive(boySkill, girlSkill):
	boySkill.sort()
	girlSkill.sort()
	return pair_up(boySkill, girlSkill, 0)

def pair_up(boySkill, girlSkill, count):
	if len(boySkill) == 0 or len(girlSkill) == 0:
		return count
	total = []
	for i in range(len(boySkill)):
		for j in range(len(girlSkill)):
			if abs(boySkill[i] - girlSkill[j]) <= 1:
				total.append(pair_up(boySkill[:i] + boySkill[i + 1:], girlSkill[:j] + girlSkill[j + 1:], count + 1))
			else:
				break
	if len(total) == 0:
		return count
	return max(total)
input()
boySkill = list(map(int, input().split(' ')))
input()
girlSkill = list(map(int, input().split(' ')))
print(solve(boySkill, girlSkill))


n = int(input())
ar = [int(i) for i in input().split()]
m = int(input())
a = [int(i) for i in input().split()]
ar = sorted(ar)
a = sorted(a)
d = 0
i = 0
j = 0
while i < n and j < m:
	if ar[i] == a[j] or abs(ar[i] - a[j]) == 1:
		i = i + 1
		j = j + 1
		d = d + 1
	elif ar[i] < a[j]:
		i = i + 1
	else:
		j = j + 1
print(d)


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
s = 0
a.sort()
b.sort()
for i in range(len(a)):
	for j in range(len(b)):
		if abs(a[i] - b[j]) <= 1:
			s += 1
			b[j] = 10000
			break
print(s)


n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(y) for y in input().split()]
boys.sort()
girls.sort()
cont = 0
b = 0
g = 0
while True:
	if abs(boys[b] - girls[g]) <= 1:
		cont += 1
		b += 1
		g += 1
	elif boys[b] > girls[g]:
		g += 1
	else:
		b += 1
	if b == n or g == m:
		break
print(cont)


n = int(input())
liboy = sorted([int(x) for x in input().split()])
m = int(input())
ligirl = sorted([int(x) for x in input().split()])
ncount = 0
for num in range(n):
	for unm in range(m):
		if abs(liboy[num] - ligirl[unm]) <= 1:
			ncount += 1
			ligirl[unm] = -1
			break
print(ncount)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
for i in a:
	for j in b:
		if abs(i - j) < 2:
			b.remove(j)
			ans += 1
			break
print(ans)


n = int(input())
list1 = [int(x) for x in input().split()]
m = int(input())
list2 = [int(x) for x in input().split()]
list1.sort()
list2.sort()
counter = 0
for i in list1:
	for j in list2:
		if abs(i - j) == 1 or i - j == 0:
			counter += 1
			list2.remove(j)
			break
print(counter)


n1 = int(input())
arr1 = list(map(int, input().split()))
n2 = int(input())
arr2 = list(map(int, input().split()))
arr1.sort()
arr2.sort()
for j in arr1:
	if arr2.count(j - 1) > 0:
		arr2.remove(j - 1)
	elif arr2.count(j) > 0:
		arr2.remove(j)
	elif arr2.count(j + 1) > 0:
		arr2.remove(j + 1)
print(n2 - len(arr2))


input()
a = list(map(int, input().split()))
a.sort()
input()
b = list(map(int, input().split()))
b.sort()
i = j = 0
c = 0
while i < len(a) and j < len(b):
	if a[i] <= b[j]:
		if abs(a[i] - b[j]) <= 1:
			c += 1
			i += 1
			j += 1
		else:
			i += 1
	elif abs(a[i] - b[j]) <= 1:
		c += 1
		i += 1
		j += 1
	else:
		j += 1
print(c)


num_of_boys = int(input())
boy_list = sorted(list(map(int, input().split())))
num_of_girls = int(input())
girl_list = sorted(list(map(int, input().split())))
ans = 0
while len(boy_list) > 0 and len(girl_list) > 0:
	if abs(boy_list[0] - girl_list[0]) <= 1:
		ans += 1
		boy_list = boy_list[1:]
		girl_list = girl_list[1:]
	elif boy_list[0] > girl_list[0]:
		girl_list = girl_list[1:]
	else:
		boy_list = boy_list[1:]
print(ans)


n = int(input())
boys = [int(x) for x in input().split(' ')]
m = int(input())
girls = [int(x) for x in input().split(' ')]
boys.sort()
girls.sort()
pairs = 0
i_b = 0
i_g = 0
while i_g < m and i_b < n:
	if i_b >= n:
		break
	talent = girls[i_g]
	i_b_new = -1
	if talent - 1 in boys:
		i_b_new = boys.index(talent - 1)
	elif talent in boys:
		i_b_new = boys.index(talent)
	elif talent + 1 in boys:
		i_b_new = boys.index(talent + 1)
	if i_b_new != -1:
		if i_b <= i_b_new:
			pairs += 1
			i_b = i_b_new + 1
		elif boys[i_b] - talent <= 1:
			pairs += 1
			i_b = i_b + 1
	i_g += 1
print(pairs)


from collections import deque
n = int(input())
l1 = sorted(list(map(int, input().split())))
m = int(input())
l2 = sorted(list(map(int, input().split())))
d = deque()
d2 = deque()
cnt = 0
for i in range(n):
	for j in range(m):
		if abs(l1[i] - l2[j]) <= 1:
			if len(d) == 0:
				cnt += 1
				d.append(l2[j])
				d2.append(j)
				break
			elif l2[j] in d and j in d2:
				continue
			else:
				cnt += 1
				d.append(l2[j])
				d2.append(j)
				break
print(cnt)


def single():
	return int(input())

def multiple():
	return list(map(int, input().split()))
import heapq
pairs = 0
n = single()
boys = multiple()
m = single()
girls = multiple()
heapq.heapify(boys)
heapq.heapify(girls)
(fb, fg) = (1, 1)
while boys and girls:
	if fb:
		b = heapq.heappop(boys)
	if fg:
		g = heapq.heappop(girls)
	if b == g:
		pairs += 1
		(fb, fg) = (1, 1)
	elif b < g:
		while boys and g - b > 1:
			b = heapq.heappop(boys)
		(fg, fb) = (1, 0)
		if abs(b - g) <= 1:
			pairs += 1
			(fb, fg) = (1, 1)
	else:
		while girls and b - g > 1:
			g = heapq.heappop(girls)
		(fb, fg) = (1, 0)
		if abs(b - g) <= 1:
			pairs += 1
			(fb, fg) = (1, 1)
print(pairs)


input()
b = list(map(int, input().strip().split()))
input()
g = list(map(int, input().strip().split()))
b.sort()
g.sort()
c = 0
for i in b:
	if i - 1 in g:
		g.remove(i - 1)
		c += 1
	elif i in g:
		g.remove(i)
		c += 1
	elif i + 1 in g:
		g.remove(i + 1)
		c += 1
print(c)


import sys
sys = sys.stdin.readline
L = lambda : list(map(int, input().split()))
n = int(input())
ln = L()
m = int(input())
lm = L()
ln.sort()
lm.sort()
c = 0
for i in range(n):
	for j in range(len(lm)):
		if abs(ln[i] - lm[j]) <= 1:
			c += 1
			lm.pop(j)
			break
print(c)


n = int(input())
boy_arr = list(map(int, input().split()))
m = int(input())
girl_arr = list(map(int, input().split()))
boy_arr.sort()
girl_arr.sort()
boy_ptr = 0
girl_ptr = 0
cnt = 0
while boy_ptr < n and girl_ptr < m:
	boy_port = boy_arr[boy_ptr]
	girl_port = girl_arr[girl_ptr]
	if boy_port > girl_port + 1:
		girl_ptr += 1
	elif girl_port > boy_port + 1:
		boy_ptr += 1
	else:
		cnt += 1
		boy_ptr += 1
		girl_ptr += 1
print(cnt)


a = int(input())
a = list(map(int, input().split()))
b = int(input())
b = list(map(int, input().split()))
a = sorted(a)
b = reversed(sorted(b))
x = [0] * 200
for t in a:
	x[t] += 1
ans = 0
for t in b:
	if x[t + 1]:
		ans += 1
		x[t + 1] -= 1
		continue
	if x[t]:
		ans += 1
		x[t] -= 1
		continue
	if x[t - 1]:
		ans += 1
		x[t - 1] -= 1
		continue
print(ans)


def handleInput():
	n = int(input())
	men = input()
	men = men.split(' ')
	m = int(input())
	women = input()
	women = women.split(' ')
	for j in range(m):
		women[j] = int(women[j])
	for i in range(n):
		men[i] = int(men[i])
	return [n, men, m, women]

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def ball(arr1, arr2, n, m):
	mergeSort(arr1)
	mergeSort(arr2)
	pairs = []
	largo1 = n
	largo2 = m
	if largo1 < largo2:
		for i in range(largo1):
			chec = check(arr1[i], arr2, 0, pairs)
			if not chec:
				j = 1
				returned = False
				while j <= len(arr2) - 1 and (not returned):
					returned = check(arr1[i], arr2, j, pairs)
					j += 1
	else:
		for i in range(largo2):
			chec = check(arr2[i], arr1, 0, pairs)
			if not chec:
				j = 1
				returned = False
				while j <= len(arr1) - 1 and (not returned):
					returned = check(arr2[i], arr1, j, pairs)
					j += 1
	return pairs

def check(e, a, j, pairs):
	if abs(e - a[j]) <= 1:
		pairs.append([e, a[j]])
		a.pop(j)
		return True
	elif e - a[0] < 0:
		return True
	else:
		return False
inp = handleInput()
b = ball(inp[1], inp[3], inp[0], inp[2])
print(len(b))


len1 = int(input())
list1 = sorted(list(map(int, input().split())))
len2 = int(input())
list2 = sorted(list(map(int, input().split())))
Count = 0
black_list = []
for i in list1:
	for (j2, j) in enumerate(list2):
		if (i == j or i - 1 == j or i + 1 == j) and j2 not in black_list:
			black_list.append(j2)
			Count += 1
			break
else:
	print(Count)


cant = int(input())
h1 = input()
cant2 = int(input())
h2 = input()
hombres = []
for i in h1.split(' '):
	hombres.append(int(i))
mujeres = []
for i in h2.split(' '):
	mujeres.append(int(i))
hombres = sorted(hombres)
mujeres = sorted(mujeres)
parejas = 0
while len(hombres) != 0 and len(mujeres) != 0:
	if hombres[0] - mujeres[0] in [-1, 0, 1]:
		hombres.pop(0)
		mujeres.pop(0)
		parejas += 1
	elif hombres[0] - mujeres[0] < -1:
		hombres.pop(0)
	else:
		mujeres.pop(0)
print(parejas)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
c = 0
a.sort()
b.sort()
for i in range(n):
	for j in range(m):
		if a[i] - b[j] <= 1 and a[i] - b[j] >= -1:
			c += 1
			b.remove(b[j])
			b.append(500)
			break
print(c)


n = int(input())
x = list(map(int, input().split()))
m = int(input())
y = list(map(int, input().split()))
x.sort()
y.sort()
p = 0
if n == min(n, m):
	for i in range(len(x)):
		if x[i] == 1:
			if 1 in y:
				y.remove(1)
				p += 1
			elif 2 in y:
				y.remove(2)
				p += 1
		elif x[i] - 1 in y:
			y.remove(x[i] - 1)
			p += 1
		elif x[i] in y:
			y.remove(x[i])
			p += 1
		elif x[i] + 1 in y:
			y.remove(x[i] + 1)
			p += 1
elif m == min(n, m):
	for i in range(len(y)):
		if y[i] == 1:
			if 1 in x:
				x.remove(1)
				p += 1
			elif 2 in x:
				x.remove(2)
				p += 1
		elif y[i] - 1 in x:
			x.remove(y[i] - 1)
			p += 1
		elif y[i] in x:
			x.remove(y[i])
			p += 1
		elif y[i] + 1 in x:
			x.remove(y[i] + 1)
			p += 1
print(p)


n = int(input())
ns = sorted([int(i) for i in input().split()])
m = int(input())
ms = sorted([int(i) for i in input().split()])
count = 0
for i in range(n):
	for j in range(m):
		if abs(ns[i] - ms[j]) <= 1:
			count += 1
			ns[i] = 1000
			ms[j] = 10000
print(count)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = [0] * 102
for i in mints():
	a[i] += 1
m = mint()
b = [0] * 102
for i in mints():
	b[i] += 1
r = 0
for i in range(101):
	while a[i] > 0:
		if i > 0 and b[i - 1] > 0:
			j = i - 1
		elif b[i] > 0:
			j = i
		elif b[i + 1] > 0:
			j = i + 1
		else:
			break
		z = min(a[i], b[j])
		a[i] -= z
		b[j] -= z
		r += z
print(r)


B = int(input())
b = sorted(list(map(int, input().split())))
G = int(input())
g = sorted(list(map(int, input().split())))
d = 0
for i in b:
	for j in g:
		if abs(i - j) == 1 or i - j == 0:
			d += 1
			g.remove(j)
			break
print(d)


input()
g = list(map(int, input().split(' ')))
input()
b = list(map(int, input().split(' ')))
g.sort()
b.sort()
p1 = 0
p2 = 0
result = 0
while True:
	if p1 >= len(g):
		break
	if p2 >= len(b):
		break
	if abs(g[p1] - b[p2]) <= 1:
		result += 1
		p1 += 1
		p2 += 1
	elif g[p1] > b[p2]:
		p2 += 1
	elif g[p1] < b[p2]:
		p1 += 1
print(result)


n = int(input())
b = sorted(map(int, input().split()))
m = int(input())
g = sorted(map(int, input().split()))
(i, j, cnt) = (0, 0, 0)
while i < n and j < m:
	if abs(b[i] - g[j]) <= 1:
		cnt += 1
		i += 1
		j += 1
		continue
	if b[i] > g[j]:
		j += 1
	else:
		i += 1
print(cnt)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = int(input())
b = [int(x) for x in input().split()]
b.sort()
l = 0
for i in range(n):
	for j in range(m):
		if a[i] != 0 and b[j] != 0 and (abs(a[i] - b[j]) <= 1):
			l += 1
			a[i] = 0
			b[j] = 0
print(l)


n = int(input())
nn = list(map(int, input().split()))
m = int(input())
mm = list(map(int, input().split()))
nn = sorted(nn)
mm = sorted(mm)
(i, j, k) = (0, 0, 0)
while i < n and j < m:
	if abs(nn[i] - mm[j]) < 2:
		k += 1
		i += 1
		j += 1
	elif nn[i] < mm[j]:
		i += 1
	else:
		j += 1
print(k)


n = int(input())
x = list(sorted(map(int, input().split())))
m = int(input())
y = list(sorted(map(int, input().split())))
count = 0
if n < m:
	for i in range(n):
		for j in range(m):
			if abs(x[i] - y[j]) <= 1:
				count += 1
				y[j] = 1000
				break
else:
	for i in range(m):
		for j in range(n):
			if abs(x[j] - y[i]) <= 1:
				count += 1
				x[j] = 1000
				break
print(count)


input()
Boys = sorted([int(_) for _ in input().split()])
input()
Girls = sorted([int(_) for _ in input().split()])
(C, i, j) = (0, 0, 0)
if set(Boys) == set(Girls) and len(Boys) == len(Girls):
	print(len(Boys))
else:
	while i < len(Boys):
		if len(Boys) == 0 or len(Girls) == 0:
			break
		itheBoys = Boys[i]
		while j < len(Girls):
			itheGirls = Girls[j]
			if itheBoys + 1 == itheGirls or itheBoys - 1 == itheGirls or itheBoys == itheGirls:
				Boys[i] = -1
				Girls[j] = -1
				break
			j += 1
			if len(Boys) == 0 or len(Girls) == 0:
				break
		j = 0
		i += 1
	print(Boys.count(-1))


boys = int(input())
skill_boy = list(map(int, input().split()))
girls = int(input())
skill_girl = list(map(int, input().split()))
sort_boy = sorted(skill_boy)
sort_girl = sorted(skill_girl)
sum = 0
for i in range(len(sort_boy)):
	for j in range(len(sort_girl)):
		if abs(sort_boy[i] - sort_girl[j]) < 2:
			sum += 1
			sort_girl.remove(sort_girl[j])
			break
print(sum)


import sys

def main():
	n = int(input())
	a = list(map(int, sys.stdin.readline().split()))
	m = int(input())
	b = list(map(int, sys.stdin.readline().split()))
	a.sort()
	b.sort()
	i = j = 0
	s = 0
	while i < n and j < m:
		if a[i] < b[j]:
			if b[j] - a[i] <= 1:
				s += 1
				i += 1
				j += 1
			else:
				i += 1
		elif a[i] - b[j] <= 1:
			s += 1
			i += 1
			j += 1
		else:
			j += 1
	print(s)
main()


m = int(input().strip())
a = list(map(int, input().strip().split()))
a.sort()
n = int(input().strip())
b = list(map(int, input().strip().split()))
b.sort()
ans = j = 0
for (i, val) in enumerate(a):
	while j < n and b[j] < val - 1:
		j += 1
	if j < n and val - 1 <= b[j] <= val + 1:
		ans += 1
		j += 1
print(ans)


import math
n = int(input())
input_s = list([int(x) for x in input().split()])
input_s.sort()
m = int(input())
input_l = list([int(x) for x in input().split()])
input_l.sort()
s = 0
l = 0
result = 0
while s < len(input_s) and l < len(input_l):
	if abs(input_s[s] - input_l[l]) <= 1:
		l += 1
		s += 1
		result += 1
	elif input_s[s] > input_l[l]:
		l += 1
	else:
		s += 1
print(result)


count = 0
n1 = int(input())
a = list(map(int, input().strip().split()))
a.sort()
n2 = int(input())
b = list(map(int, input().strip().split()))
b.sort()
for k in range(0, n1):
	for l in range(0, n2):
		if a[k] == b[l]:
			count = count + 1
			a[k] = -5
			b[l] = -10
			break
		elif abs(a[k] - b[l]) == 1:
			count = count + 1
			a[k] = -5
			b[l] = -10
			break
print(count)


def main():
	b = input()
	boys = input().split()
	boylist = []
	for i in range(len(boys)):
		boylist.append(int(boys[i]))
	boylist.sort()
	g = input()
	girls = input().split()
	girllist = []
	for i in range(len(girls)):
		girllist.append(int(girls[i]))
	girllist.sort()
	output = 0
	i = 0
	j = 0
	while i < len(boylist) and j < len(girllist):
		if abs(boylist[i] - girllist[j]) <= 1:
			output += 1
			i += 1
			j += 1
		elif boylist[i] - girllist[j] < -1:
			i += 1
		elif boylist[i] - girllist[j] > 1:
			j += 1
	print(output)
main()


n = int(input())
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
m = int(input())
aa = input().split()
for i in range(len(aa)):
	aa[i] = int(aa[i])
a.sort()
aa.sort()
t = 0
tg = -1
for i in range(len(a)):
	for j in range(tg + 1, len(aa)):
		if abs(a[i] - aa[j]) < 2:
			tg = j
			t += 1
			break
print(t)


def dic(arr):
	d = {}
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	return d

def solve(n1, a, n2, b):
	d1 = dic(b)
	count = 0
	a.sort()
	for i in a:
		if i - 1 in d1:
			if d1[i - 1] > 0:
				count += 1
				d1[i - 1] -= 1
				continue
		if i in d1:
			if d1[i] > 0:
				count += 1
				d1[i] -= 1
				continue
		if i + 1 in d1:
			if d1[i + 1] > 0:
				count += 1
				d1[i + 1] -= 1
	return count
n1 = int(input())
a = [int(x) for x in input().split()]
n2 = int(input())
b = [int(x) for x in input().split()]
print(solve(n1, a, n2, b))


n = int(input())
guys = list(map(int, input().split(' ')))
m = int(input())
gals = list(map(int, input().split(' ')))
guys.sort()
gals.sort()
count = 0
for i in range(n):
	for j in range(m):
		if abs(guys[i] - gals[j]) <= 1:
			gals[j] = float('inf')
			count += 1
			break
print(count)


input()
b = sorted(map(int, input().split()))
input()
g = sorted(map(int, input().split()))
cnt = 0
while b and g:
	if b[-1] > g[-1] + 1:
		b.pop()
	elif g[-1] > b[-1] + 1:
		g.pop()
	else:
		b.pop()
		g.pop()
		cnt += 1
print(cnt)


input()
b = sorted([int(x) for x in input().split()])
input()
g = sorted([int(x) for x in input().split()])
n = 0
i = 0
for x in b:
	while i < len(g) and x - g[i] > 1:
		i += 1
	if i < len(g) and abs(x - g[i]) <= 1:
		n += 1
		i += 1
print(n)


n = int(input())
boy = list(map(int, input().split()))
m = int(input())
girl = list(map(int, input().split()))
girl.sort()
count = 0
for i in range(m):
	g = girl[i]
	if len(boy) > 0:
		if g - 1 in boy:
			boy.remove(g - 1)
			count += 1
		elif g in boy:
			boy.remove(g)
			count += 1
		elif g + 1 in boy:
			count += 1
			boy.remove(g + 1)
	else:
		break
print(count)


n = int(input())
narr = list(map(int, input().split()))
narr.sort()
m = int(input())
marr = list(map(int, input().split()))
marr.sort()
res = 0
for i in range(n):
	for j in range(m):
		if narr[i] > 0 and marr[j] > 0:
			if abs(narr[i] - marr[j]) == 0 or abs(narr[i] - marr[j]) == 1:
				(narr[i], marr[j]) = (-narr[i], -marr[j])
				res += 1
				break
print(res)


n = int(input())
B = list(map(int, input().split()))
m = int(input())
G = list(map(int, input().split()))
c = 0
for i in sorted(B):
	if i - 1 in G:
		G.remove(i - 1)
		c += 1
	elif i in G:
		G.remove(i)
		c += 1
	elif i + 1 in G:
		G.remove(i + 1)
		c += 1
print(c)


def most(x, y):
	k = x
	if k > y:
		k = y
	return k
nb = input()
nb = int(nb)
sb = input()
sb = sb.split()
for i in range(nb):
	sb[i] = int(sb[i])
ng = input()
ng = int(ng)
sg = input()
sg = sg.split()
for i in range(ng):
	sg[i] = int(sg[i])
sb.sort()
sg.sort()
c = 0
b = 0
g = 0
x = most(len(sb), len(sg))
while 1:
	diff = sb[b] - sg[g]
	if abs(diff) <= 1:
		c += 1
		b += 1
		g += 1
	elif diff > 0:
		g += 1
	elif diff < 0:
		b += 1
	if b == len(sb) or g == len(sg):
		break
print(c)


n = int(input())
k = sorted(list(map(int, input().split())))
m = int(input())
l = sorted(list(map(int, input().split())))
c = 0
for x in k:
	if x - 1 in l:
		c += 1
		l.remove(x - 1)
	elif x in l:
		c += 1
		l.remove(x)
	elif x + 1 in l:
		c += 1
		l.remove(x + 1)
	if len(l) == 0:
		break
print(c)


boys = []
girls = []
n_boys = int(input())
boy_skills = input().split(' ')
for b in boy_skills:
	boys.append(int(b))
n_girls = int(input())
girl_skills = input().split(' ')
for g in girl_skills:
	girls.append(int(g))
sorted_boys = sorted(boys)
sorted_girls = sorted(girls)
result = 0
for i in range(n_boys):
	for j in range(n_girls):
		if int(abs(sorted_boys[i] - sorted_girls[j])) <= 1:
			sorted_girls[j] = 10000
			result += 1
			break
print(result)


n = int(input())
b = [int(i) for i in input().split()]
b.sort()
m = int(input())
g = [int(i) for i in input().split()]
g.sort()
pairs = 0
i = 0
j = 0
while i < len(b) and j < len(g):
	if abs(b[i] - g[j]) <= 1:
		pairs += 1
		i += 1
		j += 1
	elif b[i] > g[j]:
		j += 1
	else:
		i += 1
print(pairs)


n = int(input())
l1 = [int(x) for x in input().split()]
m = int(input())
l2 = [int(x) for x in input().split()]
l1.sort()
l2.sort()
c = 0
for i in l1:
	if i - 1 in l2:
		del l2[l2.index(i - 1)]
		c += 1
	elif i in l2:
		del l2[l2.index(i)]
		c += 1
	elif i + 1 in l2:
		del l2[l2.index(i + 1)]
		c += 1
print(c)


n = int(input())
aline = input().split(' ')
m = int(input())
bline = input().split(' ')
a = [int(i) for i in aline]
b = [int(i) for i in bline]
sorted_a = sorted(a)
sorted_b = sorted(b)

def count_match(sorteda, i, sortedb, count):
	if i == len(sorteda) or len(sortedb) == 0:
		return count
	elif sorteda[i] - 1 in sortedb:
		sortedb.remove(sorteda[i] - 1)
		return count_match(sorteda, i + 1, sortedb, count + 1)
	elif sorteda[i] in sortedb:
		sortedb.remove(sorteda[i])
		return count_match(sorteda, i + 1, sortedb, count + 1)
	elif sorteda[i] + 1 in sortedb:
		sortedb.remove(sorteda[i] + 1)
		return count_match(sorteda, i + 1, sortedb, count + 1)
	else:
		return count_match(sorteda, i + 1, sortedb, count)
count = count_match(sorted_a, 0, sorted_b, 0)
print(count)


from collections import Counter
input()
boys = [int(i) for i in input().split(' ')]
input()
girls = [int(i) for i in input().split(' ')]
girls.sort()
pairs = Counter(boys)
count = 0
for i in girls:
	if pairs.get(i - 1):
		pairs.subtract([i - 1])
		count = count + 1
	elif pairs.get(i):
		pairs.subtract([i])
		count = count + 1
	elif pairs.get(i + 1):
		pairs.subtract([i + 1])
		count = count + 1
print(count)


x = int(input())
emon1 = input().split()
emon = []
y = int(input())
mishu1 = input().split()
mishu = []
for i in emon1:
	c = int(i)
	emon.append(c)
for i in mishu1:
	c = int(i)
	mishu.append(c)
emon.sort()
mishu.sort()
a = 0
for i in emon:
	for l in mishu:
		if i - 1 == l or i + 1 == l or i == l:
			a = a + 1
			mishu.remove(l)
			break
print(a)


input()
b = list(map(int, input().split(' ')))
input()
m = list(map(int, input().split(' ')))
b.sort()
m.sort()
i = 0
j = 0
match = 0
while i < len(b) and j < len(m):
	if abs(b[i] - m[j]) <= 1:
		i += 1
		j += 1
		match += 1
		continue
	if b[i] > m[j]:
		j += 1
		continue
	i += 1
print(match)


inp = input()
chars = inp.split()
n = int(chars[0])
inp = input()
chars = inp.split()
a = []
for i in range(n):
	a.append(int(chars[i]))
inp = input()
chars = inp.split()
m = int(chars[0])
inp = input()
chars = inp.split()
b = []
for i in range(m):
	b.append(int(chars[i]))
boys = sorted(a)
girls = sorted(b)
pairs = 0
for i in range(n):
	for j in range(m):
		if abs(boys[i] - girls[j]) <= 1:
			girls[j] = 1000
			pairs = pairs + 1
			break
print(pairs)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l1 = szzz()
m = int(z())
l2 = szzz()
ans = 0
for i in range(n):
	for j in range(m):
		if abs(l1[i] - l2[j]) <= 1:
			ans += 1
			l2[j] = 1000
			break
print(ans)


len_b = int(input())
boys = sorted([int(x) for x in input().split()])
len_g = int(input())
girls = sorted([int(x) for x in input().split()])
count_b = 0
count_g = 0
pairs = 0
while count_b < len_b and count_g < len_g:
	if abs(boys[count_b] - girls[count_g]) <= 1:
		pairs += 1
		count_b += 1
		count_g += 1
	elif girls[count_g] > boys[count_b]:
		count_b += 1
	else:
		count_g += 1
print(pairs)


k = int(input())
a = list(map(int, input().split()))
q = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
c = 0
for i in a:
	for j in b:
		if abs(i - j) <= 1:
			c += 1
			b.remove(j)
			break
print(c)


n = int(input())
b = sorted(list(map(int, input().split())))
m = int(input())
g = sorted(list(map(int, input().split())))
arr = [list() for i in range(n)]
ans = 0
for i in range(n):
	for j in range(m):
		if abs(b[i] - g[j]) <= 1:
			arr[i].append(j)
seen = [0] * 101
ans = 0
for i in range(n):
	for each in arr[i]:
		if not seen[each]:
			ans += 1
			seen[each] = 1
			break
print(ans)


n = int(input())
l = list(map(int, input().split()))
n1 = int(input())
l1 = list(map(int, input().split()))
d = {l1[i]: 0 for i in range(n1)}
for i in range(len(l1)):
	d[l1[i]] = d[l1[i]] + 1
l.sort()
t = 0
for i in range(n):
	if l[i] - 1 in d and d[l[i] - 1]:
		d[l[i] - 1] = d[l[i] - 1] - 1
		t = t + 1
	elif l[i] in d and d[l[i]]:
		d[l[i]] = d[l[i]] - 1
		t = t + 1
	elif l[i] + 1 in d and d[l[i] + 1]:
		d[l[i] + 1] = d[l[i] + 1] - 1
		t = t + 1
print(t)


from sys import stdin, stdout
n = int(stdin.readline())
boys = list(map(int, stdin.readline().split()))
m = int(stdin.readline())
girls = list(map(int, stdin.readline().split()))
(boys, girls) = (sorted(boys), sorted(girls))
c = 0
(l, r) = (0, 0)
while l < n and r < m:
	if abs(boys[l] - girls[r]) <= 1:
		c += 1
		(l, r) = (l + 1, r + 1)
	elif boys[l] > girls[r]:
		r += 1
	else:
		l += 1
stdout.write('{}\n'.format(c))


def init(data, d_type):
	res = []
	for d in data:
		res.append([int(d), d_type, False])
	return res

def find_count(dancers):
	dancers.sort(key=lambda x: x[0])
	length = len(dancers)
	count = 0
	for d in range(length - 1):
		if not dancers[d][2]:
			index = d + 1
			while index < length and abs(dancers[d][0] - dancers[index][0]) <= 1:
				if not dancers[index][2] and dancers[d][1] ^ dancers[index][1]:
					dancers[index][2] = True
					count += 1
					break
				index += 1
	return count
input()
data = input()
data = data.split(' ')
dancers = init(data, True)
input()
data = input()
data = data.split(' ')
dancers += init(data, False)
print(find_count(dancers))