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 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 trains can be lined up one after another on the same platform. However, if train enters the platform first, and then train , then train cannot leave the platform before train .
The illustration shows a possible train schedule on the platforms in the second sample test.
The labels on the train i : a_i/b_i
denote that the -th train will arrive -th at the station on the first day,
and leave the station -th on the second day.
The train (2 : 1/2)
cannot leave the platform before the train (4 : 5/1)
.
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.
Input Specification
The first line contains an integer , the number of trains.
The second line contains integers , , which denotes that the -th train arrives at the station as the -th train on the first day. The sequence is a permutation of the first positive integers.
The third line contains integers , , which denotes that the -th train leaves the station as the -th train on the second day. The sequence is a permutation of the first positive integers.
Output Specification
In the first and only line you should output the minimum number of platforms needed.
Scoring
Subtask | Points | Constraints |
---|---|---|
1 | 21 | |
2 | 18 | The minimum number of platforms needed will be either or . |
3 | 31 | |
4 | 40 | No additional constraints. |
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
Explanation for Sample 2
Take a look at the illustration in the statement.
Sample Input 3
3
3 2 1
1 2 3
Sample Output 3
1
Explanation for Sample 3
All the trains can be lined up on the same platform without any problems.
Comments