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: interview

Starter code:

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

n = int(input())
boys = [int(x) for x in input().split()]
m = int(input())
girls = [int(x) for x in input().split()]

# we sort the lads
boys.sort()
girls.sort()

count = 0
last_girl = -1

for boy in boys:
    # try to find a match, if we find, we increment the namber
    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())
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)


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))



n = int(input())
a = [int(s) for s in input().split()]
m = int(input())
b = [int(s) for s in input().split()]

a.sort()
b.sort()

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)


    



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)


__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)

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)


__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)

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)





#!/usr/bin/env python

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())



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)

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
# print(str(graph).replace('], [','],\n[')[1:].replace('True','1').replace('False','-'))
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())
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)       


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)



from sys import stdin

lines = list([_f for _f in stdin.read().split('\n') if _f])

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))


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)
    
def __starting_point():
    main()


__starting_point()

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 = 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)

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)


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)




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 = 0, 0
ans = 0
while i < n and j < m:
	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)


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())  # ���������� ���������
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
    else:
        if a[pos1] > b[pos2]:  # ������ ������� �� �������� ���������
            pos2 += 1
        else:
            pos1 += 1
            
print(k)