题目描述
Problem Description
Silvia is currently at Milano Centrale station, where she notices that there are many platforms. She finds the number of platforms excessive, so she intends to count how many are truly necessary.
Silvia also observes an interesting fact about the station: the departure and arrival schedules repeat every two days, and the schedules ensure that all \( n \) trains arrive at the station on one day and depart on another. Note that in this manner, no train will leave before all trains have arrived.
The platforms at the station are long enough to accommodate all \( n \) trains in a single line. However, if train \( x \) enters a platform first, followed by train \( y \), then train \( x \) cannot leave the platform before train \( y \).
Silvia wants to know the minimum number of platforms required so that all trains can stop without any train being unable to depart due to a train in front of it not having left.
Input Format
The first line contains an integer \( n \) \((1 \le n \le 2 \cdot 10^5)\), representing the number of trains.
The second line contains \( n \) integers \( a_i \) \((1 \le a_i \le n, \forall i \neq j, a_i \neq a_j)\), indicating that the \( i \)-th train arrives at the station on the first day as the \( a_i \)-th train. The sequence \((a_i)\) is a permutation.
The third line contains \( n \) integers \( b_i \) \((1 \le b_i \le n, \forall i \neq j, b_i \neq b_j)\), indicating that the \( i \)-th train departs from the station on the second day as the \( b_i \)-th train. The sequence \((b_i)\) is a permutation.
Output Format
Output a single integer, representing the minimum number of platforms required.
Sample Input and Output
Sample Input #1
5
3 5 2 4 1
3 2 5 1 4
Sample Output #1
2
Sample Input #2
5
3 1 2 5 4
4 2 3 1 5
Sample Output #2
4
Sample Input #3
3
3 2 1
1 2 3
Sample Output #3
1
Notes/Hints
Sample Explanation 2

The diagram above shows a possible train scheduling scenario for Sample #2. The label \((i:a_i/b_i)\) on a train indicates that the \( i \)-th train arrives at the station on the first day as the \( a_i \)-th train and departs on the second day as the \( b_i \)-th train. Train \((2:1/2)\) cannot leave the station earlier than train \((4:5/1)\).
Sample Explanation 3
All trains can be arranged on the same platform without any issues.
Subtasks
| Subtask | Additional Constraints | Score |
|---|---|---|
| 1 | \( n \le 10 \) | 21 |
| 2 | Minimum required platforms is either 1 or 2 | 18 |
| 3 | \( n \le 1,000 \) | 31 |
| 4 | No additional constraints | 40 |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分