#include <bits/stdc++.h>
using namespace std;
template <class T>
struct fen {
  vector<T> fenwick;
  int size;
  fen(int sz) {
    size = sz;
    fenwick.resize(size);
    for (int i = 0; i < size; i++) fenwick[i] = 0;
  }
  fen(vector<T> arr) {
    size = arr.size();
    fenwick.resize(size);
    for (int i = 0; i < size; i++) fenwick[i](0);
    for (int i = 0; i < size; i++) update(i, arr[i]);
  }
  void add(int index, T add) {
    for (int k = index; k < size; k |= (~k & -~k)) {
      fenwick[k] = fenwick[k] + add;
    }
  }
  void update(int index, T nval) {
    add(index, nval - rangeQuery(index, index));
  }
  T query(int to) {
    if (to < 0) return 0;
    T sum = 0;
    for (int curr = to + 1; curr > 0; curr ^= (curr & -curr)) {
      sum = sum + fenwick[curr - 1];
    }
    return sum;
  }
  T rangeQuery(int from, int to) {
    if (from > to) return 0;
    if (!from) return query(to);
    return query(to) - query(from - 1);
  }
  void print() {
    for (int i = 0; i < size; i++) cout << query(i) << " ";
    cout << endl;
  }
};
const int sz = 2e5;
int n;
pair<int, int> xv[sz];
vector<pair<pair<int, int>, int>> pos, neg;
int ppos[sz], npos[sz];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> xv[i].first;
  for (int i = 0; i < n; i++) cin >> xv[i].second;
  sort(xv, xv + n);
  for (int i = 0; i < n; i++) {
    if (xv[i].second >= 0)
      pos.push_back({{xv[i].second, xv[i].first}, i});
    else
      neg.push_back({{-xv[i].second, xv[i].first}, i});
  }
  sort(pos.begin(), pos.end());
  sort(neg.rbegin(), neg.rend());
  int pamt = pos.size(), namt = neg.size();
  for (int i = 0; i < pamt; i++) ppos[pos[i].second] = i;
  for (int i = 0; i < namt; i++) npos[neg[i].second] = i;
  fen<int> fp(n), fpcnt(n), fn(n), fncnt(n);
  long long poscnt = 0, negcnt = 0, tot = 0, negsum = 0;
  for (int i = 0; i < n; i++) {
    if (xv[i].second >= 0) {
      int rk = ppos[i];
      long long bamt = fpcnt.query(rk - 1);
      tot += bamt * xv[i].first - fp.query(rk - 1);
      fp.update(rk, xv[i].first);
      fpcnt.update(rk, 1);
      tot += negcnt * xv[i].first - negsum;
    } else {
      int rk = npos[i];
      long long bamt = fncnt.query(rk - 1);
      tot += bamt * xv[i].first - fn.query(rk - 1);
      fn.update(rk, xv[i].first);
      fncnt.update(rk, 1);
      negsum += xv[i].first;
      negcnt++;
    }
  }
  cout << tot;
  return 0;
}
