def solution(n, lost, reserve):
more = []
lost = lost[::-1]; reserve=reserve[::-1]
reserve, lost = list(set(reserve)-set(lost)), list(set(lost)-set(reserve))
for i in reserve:
if i in lost:
lost.remove(i)
elif i+1 in lost:
if i-1 in lost:
more.append(i)
else:
lost.remove(i+1)
elif i-1 in lost:
lost.remove(i-1)
for i in more:
if i-1 in lost:
lost.remove(i-1)
elif i+1 in lost:
lost.remove(i+1)
answer = n - (len(lost))
return answer