1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cstring>
5 #define mod 99999997
6 #define N 1000010
7 using namespace std;
8 struct node{
9 int x,cnt;
10 }a[N],b[N];
11 long long ans,c[N],aa[N],n;
12 void megre_sort(int l,int r)
13 {
14 if(l>=r) return;
15 int mid=(l+r)/2;
16 megre_sort(l,mid);megre_sort(mid+1,r);
17 int i=l,k=l,j=mid+1;
18 while(i<=mid&&j<=r)
19 {
20 if(aa[i]>aa[j])
21 {
22 ans=(ans+(mid-i+1)%mod)%mod,
23 c[k++]=aa[j++];
24 }
25 else{
26 c[k++]=aa[i++];
27 }
28 }
29 while(i<=mid) c[k++]=aa[i++];
30 while(j<=r) c[k++]=aa[j++];
31 for(int i=l;i<=r;i++) aa[i]=c[i];
32 }
33 bool cmp(node a,node b)
34 {
35 return a.x<b.x;
36 }
37 int main()
38 {
39 scanf("%d",&n);
40 for(int i=1;i<=n;i++)
41 {
42 scanf("%d",&a[i].x);
43 a[i].cnt=i;
44 }
45 for(int i=1;i<=n;i++)
46 {
47 scanf("%d",&b[i].x);
48 b[i].cnt=i;
49 }
50 sort(a+1,a+1+n,cmp);
51 sort(b+1,b+1+n,cmp);
52 for(int i=1;i<=n;i++)
53 aa[a[i].cnt]=b[i].cnt;
54 megre_sort(1,n);
55 printf("%lld\n",ans);
56 return 0;
57 }