아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Milano C.le

시간 제한1초메모리 제한1024 MB

요약
열차가 한 순열 순서로 도착하고 다른 순열 순서로 떠날 때, 각 승강장이 스택이므로 필요한 최소 승강장 수를 구한다.
난이도

보통10점 중 6점

유형
스택, 그리디, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 : a_ia\_i/b_ib\_i' denote that the ii-th train will arrive a_ia\_i-th at the station on the first day, and leave the station b_ib\_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⋅1051 ≤ n ≤ 2 \cdot 10^5), the number of trains.

The second line contains nn integers a_ia\_i, (1≤a_i≤n1 ≤ a\_i ≤ n, a_i≠a_ja\_i \ne a\_j for all i≠ji \ne j), which denote that the ii-th train arrives at the station as the a_ia\_i-th train on the first day. The sequence (a_i)(a\_i) is a permutation.

The third line contains nn integers b_ib\_i, (1≤b_i≤n1 ≤ b\_i ≤ n, b_i≠b_jb\_i \ne b\_j for all i≠ji \ne j), which denote that the ii-th train leaves the station as the b_ib\_i-th train on the second day. The sequence (b_i)(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.

예제3

  1. 예제 1

    입력
    5
    3 5 2 4 1
    3 2 5 1 4
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5
    3 1 2 5 4
    4 2 3 1 5
    
    예상 출력
    4
    
  3. 예제 3

    입력
    3
    3 2 1
    1 2 3
    
    예상 출력
    1