#include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long #define rep(i,m,n) for(ll i = m;i < n;i++) #define UE(N) N.erase(unique(N.begin(), N.end()), N.end()); #define Sort(n) sort(n.begin(), n.end()) template< typename T > struct BinaryIndexedTree { vector< T > data; BinaryIndexedTree(int sz) { data.assign(++sz, 0); } T sum(int k) { T ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } void add(int k, T x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; int main() { ll N, res = 0; cin >> N; vector A(N), B(N), comp; map mp; multiset st; rep(i, 0, N) cin >> A[i]; rep(i, 0, N) cin >> B[i]; rep(i, 0, N) comp.push_back(A[i]); rep(i, 0, N) comp.push_back(B[i]); Sort(comp); UE(comp); rep(i, 0, comp.size()) mp[comp[i]] = i + 1; rep(i, 0, N) A[i] = mp[A[i]]; rep(i, 0, N) B[i] = mp[B[i]]; Sort(A); BinaryIndexedTree rs(comp.size() + 10); st.insert(0); rep(i, 0, N) { rs.add(B[i], 1); st.insert(B[i]); auto itr = st.lower_bound(A[i]); itr--; //[1,*itr]の個数が答え res += rs.sum(*itr); } cout << res << endl; }