407961: GYM102951 C LCS on Permutations

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. LCS on Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given two permutations $$$a$$$ and $$$b$$$ of length $$$N$$$ ($$$1 \leq N \leq 10^5$$$). Determine the length of their longest common subsequence.

Input

Line 1: The single integer $$$N$$$

Line 2: $$$N$$$ space separated integers $$$a_1 \dots a_N$$$ ($$$1 \leq a_i \leq N$$$ and $$$a_i \neq a_j$$$ for all $$$1 \leq i < j \leq N$$$)

Line 3: $$$N$$$ space separated integers $$$b_1 \dots b_N$$$ ($$$1 \leq b_i \leq N$$$ and $$$b_i \neq b_j$$$ for all $$$1 \leq i < j \leq N$$$)

Output

A single integer: the answer to the above problem

ExampleInput
5
3 2 1 4 5
1 2 3 4 5
Output
3
Note

One possible longest common subsequence would be $$$3, 4, 5$$$.

加入题单

上一题 下一题 算法标签: