P6820 [PA 2012 Finals] Two Cakes
Description
You have two permutations of $1 \sim n$. You use your left hand and right hand to write the two permutations from left to right, respectively. Each hand needs $1$ unit of time to write one number, and the two hands can work at the same time. If your two hands are not allowed to write the same number at the same time, what is the minimum time needed to finish writing both permutations?
Input Format
The first line contains a positive integer $n$.
The next line contains $n$ integers, forming a permutation of $1 \sim n$.
The next line contains $n$ integers, forming another permutation of $1 \sim n$.
Output Format
Output a single integer, the minimum time.
Explanation/Hint
**Sample Explanation**
In the first unit of time: the left hand writes $1$, and the right hand writes $3$.
In the second unit of time: the left hand writes $2$.
In the third unit of time: the right hand writes $2$.
In the fourth unit of time: the left hand writes $3$, and the right hand writes $1$.
**Constraints**
For $100\%$ of the testdata, $1 \le n \le 10^6$.
Translated by ChatGPT 5