//#include #include //#include using namespace std; //using namespace atcoder; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef pair p; const int INF = 1e9; const double eps = 1e-7; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; const long double pi = 4 * atan(1); #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout< struct Compress { vector xs; Compress(const vector &vs) : xs(vs) { sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); } int compress(const T &x) { return lower_bound(xs.begin(), xs.end(), x) - xs.begin(); } T decompress(int i) { return xs[i]; } }; //1-indexだから0にaddすると死んじゃうよ struct fenwick_tree { typedef int T; T n; vector bit; T b = 1; // 各要素の初期値は 0 fenwick_tree(T num) : bit(num + 1, 0) { n = num; } // a_i += w void add(T i, T w) { for (T x = i; x <= n; x += x & -x) { bit[x] += w; } } ll get(T i) { ll s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } // [1, i] の和を計算. T sum(T i) { T ret = 0; for (T x = i; x > 0; x -= x & -x) { ret += bit[x]; } return ret; } // [left+1, right] の和を計算. T sum(T left, T right) { return sum(right) - sum(left); } int get_index(ll x) { //something like lower_bound(all(sum), a). O(logn) x--; while (b * 2 <= n) b *= 2; int r = b; int res = 0; while (r > 0) { if ((r | res) <= n) { int rv = bit[r | res]; if (x >= rv) { x -= rv; res += r; } } r >>= 1; } return res + 1; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n; vector a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; vector all; rep(i, n) all.push_back(a[i]); rep(i, n) all.push_back(b[i]); Compress c(all); sort(ALL(a)); rep(i, n) { a[i] = c.compress(a[i]); a[i]++; } rep(i, n) { b[i] = c.compress(b[i]); b[i]++; } ll ans=0; fenwick_tree ft(200001); rep(i,n){ ft.add(b[i], 1); ans += ft.sum(a[i]-1); //cout<