logo AlgoBeat OnlineJudge
登录 注册

#214572. [2019 KAIST RUN Fall] Maximizer

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Maximizer has two permutations and . Both have length and consists of from to .

Maximizer wants to maximize the sum of differences of each element, . But he can only swap two adjacent elements in . Precisely, he can only swap and for some from to . He can swap as many times as he wants.

What is the minimum number of swaps required for maximizing the difference sum?

输入格式

The first line contains an integer . ()

The second line contains integers ().

The third line contains integers ().

Each of and is a permutation. In other words, it is consisted of distinct integers from to .

输出格式

Print an integer, the minimum number of swaps required for maximizing the difference sum.

样例

样例输入 1

3
1 2 3
1 2 3

样例输出 1

2

样例输入 2

4
3 4 1 2
3 2 4 1

样例输出 2

3