QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#10651. Two cakes

统计

Bajtazar's confectionery has received two urgent cake orders. As is well known, cakes have layers. The confectionery offers $n$ different types of layers, and each cake produced contains exactly one layer of each type. A cake order specifies the order in which the layers must be stacked.

Bajtazar employs $n$ pastry chefs; the $i$-th chef (for $1 \le i \le n$) can prepare a layer of type $i$. A chef takes one minute to prepare their layer (and can only work on one cake at a time during this period). Layers for each cake must be stacked one after another. Work on the cakes can proceed in parallel. What is the minimum time required to produce the two ordered cakes?

Input

The first line of input contains a single integer $n$ ($1 \le n \le 1\,000\,000$). The second and third lines contain descriptions of the first and second orders, respectively. Each of these descriptions is a sequence of $n$ distinct integers from $1$ to $n$, specifying the types of successive layers of the given cake, starting from the layer placed at the top of the cake.

Output

The first and only line of output should contain a single integer - the minimum number of minutes required to produce the ordered cakes.

Examples

Input 1

3
1 2 3
3 2 1

Output 1

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.