#include "bits/stdc++.h" using namespace std; //#include "atcoder/all" //using namespace atcoder; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; // a^b long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^-1 long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // a^x ≡ b (mod. m) となる最小の正の整数 x を求める long long modlog(long long a, long long b, int m) { a %= m, b %= m; // calc sqrt{M} long long lo = -1, hi = m; while (hi - lo > 1) { long long mid = (lo + hi) / 2; if (mid * mid >= m) hi = mid; else lo = mid; } long long sqrtM = hi; // {a^0, a^1, a^2, ..., a^sqrt(m)} map apow; long long amari = 1; for (long long r = 0; r < sqrtM; ++r) { if (!apow.count(amari)) apow[amari] = r; (amari *= a) %= m; } // check each A^p long long A = modpow(modinv(a, m), sqrtM, m); amari = b; for (long long q = 0; q < sqrtM; ++q) { if (apow.count(amari)) { long long res = q * sqrtM + apow[amari]; if (res > 0) return res; } (amari *= A) %= m; } // no solutions return -1; } template< typename T > struct Compress { vector< T > xs; Compress() = default; Compress(const vector< T > &vs) { add(vs); } Compress(const initializer_list< vector< T > > &vs) { for(auto &p : vs) add(p); } void add(const vector< T > &vs) { copy(begin(vs), end(vs), back_inserter(xs)); } void add(const T &x) { xs.emplace_back(x); } void build() { sort(begin(xs), end(xs)); xs.erase(unique(begin(xs), end(xs)), end(xs)); } vector< int > get(const vector< T > &vs) const { vector< int > ret; transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) { return lower_bound(begin(xs), end(xs), x) - begin(xs); }); return ret; } int get(const T &x) const { return lower_bound(begin(xs), end(xs), x) - begin(xs); } const T &operator[](int k) const { return xs[k]; } }; template struct SegmentTree{ using F = function; int n; F f; T ti; vector dat; SegmentTree(){} SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){ if(a>=b) return ti; T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template int find(int st,C &check,T &acc,int k,int l,int r){ if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?k-n:-1; } int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l&&!check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template int find(int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } //アウトの条件を渡す }; signed main(){ int N; cin >> N; vector a(N), b(N); cin >> a >> b; sort(ALL(a)); Compress c(a); c.add(b); c.build(); SegmentTree seg([](int a, int b) {return a + b;}, 0ll); seg.build(vector(c.xs.size())); int ans = 0; REP(i, b.size()) { int idx = c.get(b[i]); seg.set_val(idx, seg.query(idx, idx + 1) + 1); ans += seg.query(0, c.get(a[i])); } out(ans); }