#include <bits/stdc++.h>
using namespace std;
const long long int N = 300009;
const long long int mod = 1000000007;
long long int n;
vector<pair<long long int, long long int>> v;
const long long int inf = 0;
struct Node {
  Node *l = 0, *r = 0;
  long long int lo, hi, mset = inf, madd = 0, val = 0;
  Node(long long int lo, long long int hi) : lo(lo), hi(hi) {}
  Node(vector<long long int> &v, long long int lo, long long int hi)
      : lo(lo), hi(hi) {
    if (lo + 1 < hi) {
      long long int mid = lo + (hi - lo) / 2;
      l = new Node(v, lo, mid);
      r = new Node(v, mid, hi);
      val = (l->val + r->val);
    } else
      val = v[lo];
  }
  long long int query(long long int L, long long int R) {
    if (R <= lo || hi <= L) return 0;
    if (L <= lo && hi <= R) return val;
    push();
    return (l->query(L, R) + r->query(L, R));
  }
  void set(long long int L, long long int R, long long int x) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R)
      mset = x, val = x * (hi - lo), madd = 0;
    else {
      push(), l->set(L, R, x), r->set(L, R, x);
      val = (l->val + r->val);
    }
  }
  void add(long long int L, long long int R, long long int x) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R) {
      if (mset != inf)
        mset += x;
      else
        madd += x;
      val += x * (hi - lo);
    } else {
      push(), l->add(L, R, x), r->add(L, R, x);
      val = (l->val + r->val);
    }
  }
  void push() {
    if (!l) {
      long long int mid = lo + (hi - lo) / 2;
      l = new Node(lo, mid);
      r = new Node(mid, hi);
    }
    if (mset != inf)
      l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf;
    else if (madd)
      l->add(lo, hi, madd), r->add(lo, hi, madd), madd = 0;
  }
};
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(cin.failbit);
  ;
  pre();
  cin >> n;
  v.resize(n);
  for (long long int i = 0; i < (n); ++i) {
    cin >> v[i].first;
  }
  for (long long int i = 0; i < (n); ++i) {
    cin >> v[i].second;
  }
  sort(v.begin(), v.end());
  long long int negi = 0, posi = 0, ans = 0;
  Node *neg = new Node(-1, 1e9);
  Node *pos = new Node(-1, 1e9);
  Node *neg_num = new Node(-1, 1e9);
  Node *pos_num = new Node(-1, 1e9);
  long long int sumnegi = 0;
  long long int sumposi = 0;
  for (long long int i = 0; i < (n); ++i) {
    if (v[i].second >= 0) {
      long long int add = pos->query(-1, (v[i].second) + 1);
      long long int num = pos_num->query(-1, (v[i].second) + 1);
      ans += (num * v[i].first - (add));
      pos->add((v[i].second), (v[i].second) + 1, v[i].first);
      pos_num->add((v[i].second), (v[i].second) + 1, 1);
      ans += ((negi * v[i].first) - sumnegi);
    } else {
      v[i].second = (-v[i].second);
      long long int add = neg->query(v[i].second + 1, 1e9);
      long long int num = neg_num->query(v[i].second + 1, 1e9);
      ans += (num * v[i].first - (add));
      neg->add(v[i].second, v[i].second + 1, v[i].first);
      neg_num->add(v[i].second, v[i].second + 1, 1);
      negi += 1;
      sumnegi += v[i].first;
    }
  }
  cout << ans << "\n";
  return 0;
}
