#include using namespace std; template class Fenwick { private: vector dat; int n; public: Fenwick(int _n) : dat(_n + 1), n(_n) {} // sum of [1, i] T sum(int i) { T s = 0; while(i > 0) s += dat[i], i -= i & -i; return s; } // sum of [l, r] T sum(int l, int r) { return l > r ? 0 : sum(r) - sum(l - 1); } void add(int i, T x) { while(i <= n) dat[i] += x, i += i & -i; } }; const int m = 5e5; int main() { int n; cin >> n; vector a(n), b(n); vector c; for(auto &e : a) { cin >> e; c.push_back(e); } for(auto &e : b) { cin >> e; c.push_back(e); } sort(a.begin(), a.end()); sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); for(int i = 0; i < n; ++i) { a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin() + 2; } for(int i = 0; i < n; ++i) { b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin() + 2; } long long ans = 0; Fenwick f(m); for(int i = 0; i < n; ++i) { f.add(b[i], 1); ans += f.sum(a[i] - 1); } cout << ans << '\n'; return 0; }