#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename tuple<long long, long long, long long> >
struct SegmentTree {
  using F = function<tuple<long long, long long, long long>(
      tuple<long long, long long, long long>,
      tuple<long long, long long, long long>)>;
  long long n;
  F f;
  tuple<long long, long long, long long> ti;
  vector<tuple<long long, long long, long long> > dat;
  SegmentTree(){};
  SegmentTree(F f, tuple<long long, long long, long long> ti) : f(f), ti(ti) {}
  void init(long long n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  void build(const vector<tuple<long long, long long, long long> > &v) {
    long long n_ = v.size();
    init(n_);
    for (long long i = 0; i < n_; i++) dat[n + i] = v[i];
    for (long long i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  void update(long long k, tuple<long long, long long, long long> x) {
    dat[k += n] = x;
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  void add(long long k, tuple<long long, long long, long long> x) {
    dat[k += n] += x;
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  tuple<long long, long long, long long> query(long long a, long long b) {
    tuple<long long, long long, long long> vl = ti, vr = ti;
    for (long long l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
  template <typename C>
  long long lower_find(long long a, long long b, C &check,
                       tuple<long long, long long, long long> x,
                       long long k = 1, long long l = 0, long long r = -1) {
    if (r < 0) r = n;
    if (!check(f(x, dat[k])) || r <= a || b <= l) return -1;
    if (r - l == 1) return l;
    long long xl = lower_find(a, b, check, x, (k << 1), l, (l + r) / 2);
    if (xl >= 0) return xl;
    x = f(x, dat[(k << 1)]);
    return lower_find(a, b, check, x, (k << 1) | 1, (l + r) / 2, r);
  }
  template <typename C>
  long long lower_find(long long a, long long b, C &check) {
    tuple<long long, long long, long long> x = ti;
    return lower_find(a, b, check, x);
  }
  template <typename C>
  long long upper_find(long long a, long long b, C &check,
                       tuple<long long, long long, long long> x,
                       long long k = 2, long long l = 0, long long r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return -1;
    if (r - l == 1) return l;
    if (check(f(x, dat[k]))) {
      long long xr =
          upper_find(a, b, check, f(x, dat[k]), ((k + 1) << 1), (l + r) / 2, r);
      if (xr >= 0) return xr;
    }
    return upper_find(a, b, check, x, (k << 1), l, (l + r) / 2);
  }
  template <typename C>
  long long upper_find(long long a, long long b, C &check) {
    tuple<long long, long long, long long> x = ti;
    return upper_find(a, b, check, x);
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (long long i = (0); i < ((n)); ++i) cin >> a[i].first;
  for (long long i = (0); i < ((n)); ++i) cin >> a[i].second;
  sort(a.begin(), a.end());
  vector<long long> d(n);
  for (long long i = (0); i < ((n)); ++i) d[i] = a[i].first, a[i].first = i;
  long long ans = 0, tmp = d[n - 1];
  for (long long i = ((n - 1) - 1); i >= (0); --i)
    ans += tmp - d[i] * (n - 1 - i), tmp += d[i];
  auto comp = [](pair<long long, long long> x, pair<long long, long long> y) {
    return x.second < y.second;
  };
  sort(a.begin(), a.end(), comp);
  auto f = [](pair<long long, long long> x, pair<long long, long long> y) {
    return pair<long long, long long>(x.first + y.first, x.second + y.second);
  };
  SegmentTree<pair<long long, long long> > L(f,
                                             pair<long long, long long>(0, 0)),
      R(f, pair<long long, long long>(0, 0));
  L.build(
      vector<pair<long long, long long> >(n, pair<long long, long long>(0, 0)));
  R.build(
      vector<pair<long long, long long> >(n, pair<long long, long long>(0, 0)));
  long long now = (1LL << 60), id = n - 1;
  for (long long i = ((n)-1); i >= (0); --i) {
    pair<long long, long long> l = L.query(0, a[i].first);
    ans -= d[a[i].first] * l.second - l.first;
    if (now != a[i].second) {
      while (id >= i) {
        L.update(a[id].first, pair<long long, long long>(d[a[id].first], 1));
        id--;
      }
      now = a[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}
