#d2740. 最长公共子序列

最长公共子序列

Longest Common Subsequence

Problem Description

You are given two permutations P1P_1 and P2P_2 of the numbers 11 to nn. Find the length of their longest common subsequence.

Input Format

The first line contains a positive integer nn.

Each of the next two lines contains nn integers — a permutation of the natural numbers 1,2,…,n1, 2, \dots, n.

Output Format

Output one number: the length of the longest common subsequence.

Sample Input

5
3 2 1 4 5
2 1 3 4 5

Sample Output

4

Constraints

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