cswork / OAOpen practice workspace

AmazonOA #120

Count Failed Executions

Estimated MediumJudge-ready

Topics (AI-labelled)HashingPrefix & Ranges

Both arrays are permutations of 1..n, giving the prescribed order and the actual execution order respectively. When a process runs, it fails if any process prescribed before it has not run yet. A process that has already run but failed no longer counts as not yet run, so failures do not propagate.

Input

The first line contains n (1..200000), followed by two lines: the prescribed permutation and the actual permutation.

Output

Output a single integer answer.

Example 1

Input:

6
4 2 3 5 1 6
2 3 5 1 6 4

Output:

5

Example 2

Input:

3
3 2 1
3 2 1

Output:

0

Example 3

Input:

5
2 3 5 1 4
5 2 3 4 1

Output:

2

Example notes

Example 1: 4 runs last, so the other five processes all miss the prerequisite 4; the answer is 5. Example 2: the orders match, so the answer is 0. Example 3: when 5 runs, 2 and 3 are missing, and when 4 runs, 1 is missing; only these two fail, so the answer is 2.

Editorial

Loading solution…