#include <bits/stdc++.h>
using namespace std;
int N;
int get(vector<int> &tree, int pos) {
  int ret = 0;
  while (pos) {
    ret += tree[pos];
    pos -= (pos & -pos);
  }
  return ret;
}
void update(vector<int> &tree, int pos, int diff) {
  while (pos < tree.size()) {
    tree[pos] += diff;
    pos += (pos & -pos);
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> N;
  vector<pair<int, int>> p(N);
  for (int i = 0; i < N; ++i) cin >> p[i].first;
  for (int i = 0; i < N; ++i) cin >> p[i].second;
  sort(p.begin(), p.end());
  vector<int> v;
  for (int i = 0; i < N; ++i) v.push_back(p[i].second);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  vector<int> cnt(v.size() + 1), sum(v.size() + 1);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int pos = lower_bound(v.begin(), v.end(), p[i].second) - v.begin();
    ++pos;
    ans += (get(cnt, pos) * p[i].first - get(sum, pos));
    update(cnt, pos, 1);
    update(sum, pos, p[i].first);
  }
  cout << ans << '\n';
  return 0;
}
