#P6820. [PA 2012 Finals] Two Cakes

[PA 2012 Finals] Two Cakes

Problem Description

You have two permutations of 1n1 \sim n. You use your left hand and right hand to write the two permutations from left to right, respectively. Each hand needs 11 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 nn.

The next line contains nn integers, forming a permutation of 1n1 \sim n.

The next line contains nn integers, forming another permutation of 1n1 \sim n.

Output Format

Output a single integer, the minimum time.

3
1 2 3
3 2 1
4

Hint

Sample Explanation

In the first unit of time: the left hand writes 11, and the right hand writes 33.

In the second unit of time: the left hand writes 22.

In the third unit of time: the right hand writes 22.

In the fourth unit of time: the left hand writes 33, and the right hand writes 11.

Constraints

For 100%100\% of the testdata, 1n1061 \le n \le 10^6.

Translated by ChatGPT 5