#Lutece1583. 曜酱的心意

曜酱的心意

Migrated from Lutece 1583 曜酱的心意

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

ChikaChika说希望和我一起做学园偶像的时候,我真的很开心。——WatanabeYouWatanabe\,You

曜是千歌的青梅竹马,但是AqoursAqours成立以后,千歌似乎总是与梨子在一起,而把曜冷落了。
为了让千歌知晓自己的心意,曜酱决定做一件大事!
她决定把一个给定的1n1\sim n的排列{a1,a2,,an}\{a_1,a_2,{\ldots},a_n\}1ain1{\leq}a_i{\leq}n,且aia_i各不相同),
用最少的交换次数,变换成另一个1n1\sim n的排列{b1,b2,,bn}\{b_1,b_2,{\ldots},b_n\}。并且,每次只交换相邻的两个元素。
也许这样做了以后,千歌能更多地注意自己吧。曜这样想。

Input

第一行是一个整数nn
第二行是一个长度为nn1n1\sim n的排列aa
第三行是另一个长度为nn1n1\sim n的排列bb

Output

输出一行,一个整数,表示最少的交换次数。

Samples

4
2 3 1 4
3 2 1 4
1
3
3 2 1
1 2 3
3

Note

1n1000001{\leq}n{\leq}100000

Resources

17暑假前集训-数据结构专题 By AutSky_JadeK - NOIP2014 提高组 火柴排队