QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#10651. Dwa torty

统计

Cukiernia Bajtazara 收到了两个紧急的蛋糕订单。众所周知,蛋糕有多层结构。该蛋糕店提供 $n$ 种不同类型的蛋糕层,并且每个制作出的蛋糕都恰好包含每种类型的一个蛋糕层。每个蛋糕订单都规定了蛋糕层的排列顺序。

Bajtazar 雇佣了 $n$ 名糕点师;第 $i$ 位糕点师($1 \le i \le n$)能够制作第 $i$ 种类型的蛋糕层。每位糕点师在一分钟内可以完成一层(且这段时间内只能为一个蛋糕工作)。每个蛋糕的蛋糕层必须依次铺设。两个蛋糕可以并行制作。请问完成这两个订单最少需要多少分钟?

输入格式

输入的第一行包含一个整数 $n$($1 \le n \le 1,000,000$)。第二行和第三行分别描述第一个和第二个蛋糕订单。每个订单描述为 $n$ 个两两不同的整数,范围从 1 到 $n$,表示该蛋糕各层类型的排列顺序,从蛋糕最上层开始。

输出格式

输出的唯一一行应包含一个整数——完成两个订单所需的最小分钟数。

样例

输入

3
1 2 3
3 2 1

输出

4
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.