#d11202. 最大连边数量

最大连边数量

Maximum Number of Edges

Problem Description

You are given two permutations AA and BB, each of length nn. All elements are in the range 11 to nn.

You may draw an edge between A[i]A[i] and B[j]B[j] if and only if ∣A[i]−B[j]∣≤4|A[i] - B[j]| \le 4.

Find the maximum number of edges that can be drawn such that no two edges intersect (cross each other).

For example, in the sample, if a1a_1 is connected to b2b_2 and a2a_2 is connected to b1b_1, then these two edges intersect.

It is guaranteed that both AA and BB are permutations.

Input Format

The first line contains an integer nn.

The next nn lines each contain one number aia_i.

The next nn lines each contain one number bib_i.

Sample Input

6
1 
2 
3 
4 
5 
6
6 
5 
4 
3 
2 
1

Sample Output

5

Constraints

1≤n≤1051 \le n \le 10^5