408779: GYM103316 F Airship Merger
Description
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?
InputFirst 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.
OutputPrint one integer that corresponds to the length of the longest route common to both routes.
ExamplesInput5 0 1 2 3 4 4 1 2 3 0Output
3Input
5 4 1 0 3 2 2 0 4 3 1Output
2