#include using namespace std; template struct binary_indexed_tree{ int N; vector BIT; binary_indexed_tree(int n){ N = 1; while (N < n){ N *= 2; } BIT = vector(N + 1, 0); } void add(int i, T x){ i++; while (i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i){ T ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } }; int main(){ int N; cin >> N; vector a(N); for (int i = 0; i < N; i++){ cin >> a[i]; } sort(a.begin(), a.end()); vector b(N); for (int i = 0; i < N; i++){ cin >> b[i]; } vector x; for (int i = 0; i < N; i++){ x.push_back(a[i]); x.push_back(b[i]); } sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); int cnt = x.size(); map mp; for (int i = 0; i < cnt; i++){ mp[x[i]] = i; } for (int i = 0; i < N; i++){ a[i] = mp[a[i]]; b[i] = mp[b[i]]; } long long ans = 0; binary_indexed_tree BIT(cnt); for (int i = 0; i < N; i++){ BIT.add(b[i], 1); ans += BIT.sum(a[i]); } cout << ans << endl; }