#include #include #include #include #include #include namespace atcoder { namespace internal { #ifndef _MSC_VER template using is_signed_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using is_unsigned_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using make_unsigned_int128 = typename std::conditional::value, __uint128_t, unsigned __int128>; template using is_integral = typename std::conditional::value || is_signed_int128::value || is_unsigned_int128::value, std::true_type, std::false_type>::type; template using is_signed_int = typename std::conditional<(is_integral::value && std::is_signed::value) || is_signed_int128::value, std::true_type, std::false_type>::type; template using is_unsigned_int = typename std::conditional<(is_integral::value && std::is_unsigned::value) || is_unsigned_int128::value, std::true_type, std::false_type>::type; template using to_unsigned = typename std::conditional< is_signed_int128::value, make_unsigned_int128, typename std::conditional::value, std::make_unsigned, std::common_type>::type>::type; #else template using is_integral = typename std::is_integral; template using is_signed_int = typename std::conditional::value && std::is_signed::value, std::true_type, std::false_type>::type; template using is_unsigned_int = typename std::conditional::value && std::is_unsigned::value, std::true_type, std::false_type>::type; template using to_unsigned = typename std::conditional::value, std::make_unsigned, std::common_type>::type; #endif template using is_signed_int_t = std::enable_if_t::value>; template using is_unsigned_int_t = std::enable_if_t::value>; template using to_unsigned_t = typename to_unsigned::type; } // namespace internal } // namespace atcoder namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template struct fenwick_tree { using U = internal::to_unsigned_t; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder #define rep(i,n) for(int i=0; i<(int)(n); i++) using namespace std; using namespace atcoder; using LL = long long; const int Max_N = 1e5; const int Max_A = 1e9; int main(){ int N; cin >> N; assert(1 <= N and N <= Max_N); vector a(N), b(N); rep(i,N) cin >> a[i]; rep(i,N) assert(1 <= a[i] and a[i] <= Max_A); rep(i,N) cin >> b[i]; rep(i,N) assert(1 <= b[i] and b[i] <= Max_A); vector c(2 * N); rep(i,N) c[i] = a[i]; rep(i,N) c[N + i] = b[i]; sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); sort(a.begin(), a.end()); rep(i,N) a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin(); rep(i,N) b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin(); fenwick_tree ft(2 * N); LL ans = 0; rep(i,N){ ft.add(b[i], 1); ans += ft.sum(0, a[i]); } cout << ans << endl; return 0; }