#include using namespace std; int main() { int n; cin >> n; vector a(n), b(n), c; for (int i = 0; i < n; i++) { cin >> a.at(i); c.push_back(a.at(i)); } for (int i = 0; i < n; i++) { cin >> b.at(i); c.push_back(b.at(i)); } 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.at(i) = lower_bound(c.begin(), c.end(), a.at(i)) - c.begin() + 1; b.at(i) = lower_bound(c.begin(), c.end(), b.at(i)) - c.begin() + 1; } vector t(2 * n + 1); int64_t ans = 0; for (int i = 0; i < n; i++) { int idx = b.at(i); while (idx <= 2 * n) { t.at(idx)++; idx += idx & -idx; } idx = a.at(i) - 1; while (idx) { ans += t.at(idx); idx -= idx & -idx; } } cout << ans << endl; }