#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second < b.second;
}
int main() {
  int n;
  cin >> n;
  int x[n];
  vector<pair<int, int> > v(n);
  int id = 0;
  for (auto &u : v) {
    cin >> u.first;
    x[id] = u.first;
    id += 1;
  }
  for (auto &u : v) cin >> u.second;
  sort(x, x + n);
  sort(v.begin(), v.end(), cmp);
  int ans = 0;
  map<int, int> m1;
  for (int i = 0; i < n; i++) {
    ans = ans + (x[i] * (2 * i + 1 - n));
    m1[x[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    ans = ans - (v[i].first * (m1[v[i].first] - i));
  }
  cout << ans << endl;
}
