#include<bits/stdc++.h>usingnamespacestd;#define ff first#define ss secondtypedefpair<int,int>PII;constintN=100010;constintmod=1e8-3;intn;PIIa[N],b[N];intc[N],tr[N];inlineintlowbit(intx){returnx&-x;}inlinevoidadd(intx,intk){for(inti=x;i<=n;i+=lowbit(i))tr[i]=(tr[i]+k)%mod;}inlineintsum(intx){intres=0;for(inti=x;i;i-=lowbit(i))res=(res+tr[i])%mod;returnres;}intmain(){cin>>n;for(inti=1;i<=n;i++)cin>>a[i].ff;for(inti=1;i<=n;i++)cin>>b[i].ff;for(inti=1;i<=n;i++)a[i].ss=b[i].ss=i;sort(a+1,a+n+1);sort(b+1,b+n+1);for(inti=1;i<=n;i++)c[a[i].ss]=b[i].ss;intres=0;for(inti=1;i<=n;i++){res=(res+sum(n)-sum(c[i]))%mod;add(c[i],1);}cout<<res<<'\n';return0;}