#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {
  cout << x << "\n";
}
template <typename T>
inline void printvec(T x) {
  for (auto a : x) cout << a << ' ';
  cout << '\n';
}
struct custom {
  bool operator()(
      const pair<long long int, pair<long long int, long long int> > &p1,
      const pair<long long int, pair<long long int, long long int> > &p2)
      const {
    return p1.second.second < p2.second.second;
  }
};
long long int get_pow(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
const long long int N = 2e5 + 7, inf = 4e18;
class segTree {
 public:
  long long int tree[5 * N];
  long long int siz;
  void init(int n) { siz = n; }
  inline long long int _merge(long long int a, long long int b) {
    return a + b;
  }
  void _update(int node, int lx, int rx, int idx, long long int val) {
    if (lx == rx && lx == idx) {
      tree[node] = val;
      return;
    }
    int mid = (lx + rx) / 2;
    if (lx <= idx && idx <= mid)
      _update(2 * node + 1, lx, mid, idx, val);
    else
      _update(2 * node + 2, mid + 1, rx, idx, val);
    tree[node] = _merge(tree[2 * node + 1], tree[2 * node + 2]);
  }
  void update(int i, long long int val) { _update(0, 0, siz - 1, i, val); }
  long long int _query(int node, int lx, int rx, int req_l, int req_r) {
    if (req_r < lx || rx < req_l) {
      return 0;
    }
    if (req_l <= lx && rx <= req_r) {
      return tree[node];
    }
    int mid = (lx + rx) / 2;
    long long int p1 = _query(2 * node + 1, lx, mid, req_l, req_r);
    long long int p2 = _query(2 * node + 2, mid + 1, rx, req_l, req_r);
    return _merge(p1, p2);
  }
  long long int query(int req_l, int req_r) {
    return _query(0, 0, siz - 1, req_l, req_r);
  }
};
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  return a.first < b.first;
}
void solve() {
  long long int n;
  cin >> n;
  std::vector<pair<long long int, long long int> > v(n), d(n);
  for (long long int i = (long long int)0; i < (long long int)(n); i++) {
    cin >> v[i].first;
    d[i].second = v[i].first;
  }
  for (long long int i = (long long int)0; i < (long long int)(n); i++) {
    cin >> v[i].second;
    d[i].first = v[i].second;
  }
  sort(v.begin(), v.end(), cmp);
  sort(d.begin(), d.end(), cmp);
  map<int, int> mp;
  segTree fen, cnt;
  fen.init(n);
  cnt.init(n);
  for (long long int i = (long long int)0; i < (long long int)(n); i++) {
    mp[d[i].second] = i;
    fen.update(i, d[i].second);
    cnt.update(i, 1);
  }
  long long int ans = 0;
  for (long long int i = (long long int)0; i < (long long int)(n); i++) {
    int p = mp[v[i].first];
    long long int q = fen.query(p, n - 1) - v[i].first;
    long long int c = cnt.query(p, n - 1) - 1;
    ans += q - c * v[i].first;
    fen.update(p, 0);
    cnt.update(p, 0);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  clock_t z = clock();
  for (long long int tes = (long long int)0; tes < (long long int)(test);
       tes++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
