#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct SegmentTree{ using F=function; int sz; vector seg; const F f; const Monoid gen; SegmentTree(int n,const F f,const Monoid &gen):f(f),gen(gen){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,const Monoid &x){ k+=sz; seg[k]=x; while(k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } // [a,b) Monoid query(int a,int b){ Monoid L=gen,R=gen; for(a+=sz,b+=sz;a>=1,b>>=1){ if(a&1) L=f(L,seg[a++]); if(b&1) R=f(seg[--b],R); } return f(L,R); } Monoid operator[](const int &k)const { return seg[k+sz]; } }; ll f(ll a,ll b){return a+b;} signed main(){ int n;cin>>n; vector a(n),b(n),c; for(auto &x:a){ cin>>x;c.push_back(x); } for(auto &x:b){ cin>>x;c.push_back(x); } sort(ALL(c)); c.erase(unique(ALL(c)),end(c)); for(auto &x:a){ x=lower_bound(ALL(c),x)-begin(c); } for(auto &x:b){ x=lower_bound(ALL(c),x)-begin(c); } SegmentTree seg(2*n+10,f,0); seg.build(); sort(ALL(a)); ll res=0; rep(i,n){ seg.update(b[i],seg[b[i]]+1); res+=seg.query(0,a[i]); } cout<