#P10225. [COCI 2023/2024 #3] Milano C.le
[COCI 2023/2024 #3] Milano C.le
Background
Translated from COCI 2023/2024 Contest #3 T3 “Milano C.le”.
Problem Description
Silvia is currently at Milano Centrale station, and she notices that the station has many platforms. She thinks there are too many platforms, so she decides to count how many platforms are actually needed.
Silvia also notices an interesting fact about this station: the departure and arrival timetable repeats every two days, and the timetable satisfies that all trains arrive at the station on one day and leave on the other day. Note that in this way, no train will leave before all trains have arrived.
The platforms are long enough so that all trains can line up on the same platform as a single queue. However, if train enters a platform before train enters the same platform, then train cannot leave before train leaves the platform.
Silvia wants to know the minimum number of platforms needed to park all trains, under the condition that no train becomes unable to leave because a train in front of it has not left yet.
Input Format
The first line contains an integer , denoting the number of trains.
The second line contains integers , where the -th train arrives at the station as the -th arrival on the first day. The sequence is a permutation.
The third line contains integers , where the -th train leaves the station as the -th departure on the second day. The sequence is a permutation.
Output Format
Output one integer in one line, denoting the minimum number of platforms needed.
5
3 5 2 4 1
3 2 5 1 4
2
5
3 1 2 5 4
4 2 3 1 5
4
3
3 2 1
1 2 3
1
Hint
Sample Explanation 2

The figure above shows one possible train arrangement on the platforms for Sample 2. The label on a train means that the -th train arrives as the -th arrival on the first day and then leaves as the -th departure on the second day. Train cannot leave the platform earlier than train .
Sample Explanation 3
All trains can line up on a single platform without any issues.
Subtasks
| Subtask | Additional Constraints | Score |
|---|---|---|
| The minimum number of required platforms is either or | ||
| No additional constraints |
Translated by ChatGPT 5