#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> &a, pair<long long, long long> &b) {
  return a.first < b.first;
}
int main() {
  int n;
  cin >> n;
  long long x[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long tt;
    cin >> tt;
    v.push_back(tt);
  }
  sort(v.begin(), v.end());
  vector<pair<long long, long long>> xv;
  for (int i = 0; i < n; i++) {
    xv.push_back(make_pair(x[i], v[i]));
  }
  sort(xv.begin(), xv.end(), cmp);
  long long cont = 0;
  for (long long i = 0; i < n; i++) {
    cont += ((i * xv[i].first) - ((n - i - 1) * xv[i].first));
    long long vv;
    long long vv2 = lower_bound(v.begin(), v.end(), xv[i].second) - v.begin();
    if (upper_bound(v.begin(), v.end(), xv[i].second) == v.end())
      vv = n - 1;
    else
      vv = upper_bound(v.begin(), v.end(), xv[i].second) - v.begin() - 1;
    if (vv2 > i) cont += ((vv2 - i) * xv[i].first);
    if (vv < i) cont += ((vv - i) * xv[i].first);
  }
  cout << cont << endl;
}
