PivotOJ

Milano C.le

시간 제한: 1000ms메모리 제한: 1024MB출처: COCI 2023-2024BOJ 31271

문제

Silvia is at the Milano Centrale railway station and she noticed that the station has a lot of platforms. She thought that there are too many of them, so she decided to check how many of them are actually needed.

Silvia also noticed an interesting fact that holds at this station: the schedule of arrivals and departures repeats every two days, and additionally, the schedule is such that all nn trains arrive at the station on one day, and leave the station on the other day. Note that in this way no train will leave before all trains have arrived.

The platforms at the station are long enough so that all nn trains can be lined up one after another on the same platform. However, if train xx enters the platform first, and then train yy, then train xx cannot leave the platform before train yy.

The illustration shows a possible train schedule on the platforms in the second sample test.

The labels on the train 'ii : aia_i/bib_i' denote that the ii-th train will arrive aia_i-th at the station on the first day, and leave the station bib_i-th on the second day.

The train (22 : 11/22) cannot leave the platform before the train (44 : 55/11).

Silvia is interested in what is the minimum number of platforms needed so that all trains can be lined up on the platforms, without the possibility that a train cannot leave the platform because there is a train in front of it that has not yet left.

입력

The first line contains an integer nn (1 ≤ n ≤ 2 \cdot 10^5), the number of trains.

The second line contains nn integers aia_i, (1 ≤ a_i ≤ n, aiaja_i \ne a_j for all iji \ne j), which denote that the ii-th train arrives at the station as the aia_i-th train on the first day. The sequence (ai)(a_i) is a permutation.

The third line contains nn integers bib_i, (1 ≤ b_i ≤ n, bibjb_i \ne b_j for all iji \ne j), which denote that the ii-th train leaves the station as the bib_i-th train on the second day. The sequence (bi)(b_i) is a permutation.

출력

In the first and only line you should output the minimum number of platforms needed.

힌트

Clarification of the second example: Take a look at the illustration in the statement.

Clarification of the third example: All the trains can be lined up on the same platform without any problems.

예제

예제 1

입력
5
3 5 2 4 1
3 2 5 1 4
출력
2

예제 2

입력
5
3 1 2 5 4
4 2 3 1 5
출력
4

예제 3

입력
3
3 2 1
1 2 3
출력
1
코드를 제출하려면 로그인하세요.