408779: GYM103316 F Airship Merger

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

Description

F. Airship Mergertime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Cabbage Corp recently bought two airship routes that were being flown with the exact same set of stations. Wanting to cut costs, Cabbage Corp decides that the two routes can be replaced by one route that service some subset of the stations in the same order that appears in both routes. Still wanting some customer satisfaction, however, they still want to maximize the number of stops kept in this new route. Can you help them find the maximum length of the route they can keep?

Input

First line contains $$$1 \leq N \leq 5 \cdot 10^5$$$, the number of stations serviced. The next two lines each contain $$$N$$$ integers $$$0 \leq a_i < N$$$, $$$a_i \neq a_j \forall i \neq j$$$ representing the order of stations serviced by each.

Output

Print one integer that corresponds to the length of the longest route common to both routes.

ExamplesInput
5
0 1 2 3 4
4 1 2 3 0
Output
3
Input
5
4 1 0 3 2
2 0 4 3 1
Output
2

加入题单

上一题 下一题 算法标签: