#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define x first
#define v second

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

template <class T>
struct SegTree {
  T f(T a, T b) { return a + b; }
  vector<T> s; int n;
  SegTree(int n) : s(2*n, T()), n(n) {}
  void update(int pos, T val) {
    for (s[pos += n] = val; pos /= 2;) {
      s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
    }
  }
  T query(int b, int e) {
    e++;
    T ra = T(), rb = T();
    for (b += n, e += n; b < e; b /= 2, e /= 2) {
      if (b % 2) { ra = f(ra, s[b++]); }
      if (e % 2) { rb = f(s[--e], rb); }
    }
    return f(ra, rb);
  }
};

using T = pair<int, ll>;
T operator+(const T& a, const T& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}

int n;
vector<pll> A;

int main() {
  cin >> n;
  A.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i].x;
  }
  for (int i = 0; i < n; i++) {
    cin >> A[i].v;
  }
  sort(A.begin(), A.end(), [](pll x, pll y) { return x.x < y.x; });
  map<int, int> mp;
  int c = 0;
  for (auto a : A) {
    mp[a.x] = c++;
  }
  sort(A.begin(), A.end(), [](pll x, pll y) { return x.v < y.v; });
  // count pairs x_i < x and v_i <= v
  ll sum = 0;
  SegTree<T> seg(n);
  for (pll pt : A) {
    T q = seg.query(0, mp[pt.x]);
    ll add = (mp[pt.x] + 1) * (q.first) - q.second;
    sum += add;
    assert((seg.query(mp[pt.x], mp[pt.x]) == T(0, 0)));
    seg.update(mp[pt.x], T(1, pt.x));
  }
  cout << sum << endl;
  return 0;
}
