#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  solve();
  return 0;
}
inline long long max(long long a, int b) { return max(a, (long long)b); }
inline long long max(int a, long long b) { return max((long long)a, b); }
inline long long min(long long a, int b) { return min(a, (long long)b); }
inline long long min(int a, long long b) { return min((long long)a, b); }
template <class T>
vector<T> iarr(long long n) {
  vector<T> a;
  while (n--) {
    T _v;
    cin >> _v, a.push_back(_v);
  }
  return a;
}
template <class T>
vector<vector<T>> imat(long long n, long long m) {
  vector<vector<T>> ma(n, vector<T>(m));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> ma[i][j];
  return ma;
}
template <class T = long long, long long D = 1>
struct matrix : public vector<matrix<T, D - 1>> {
  matrix(long long sz, matrix<T, D - 1> dim)
      : vector<matrix<T, D - 1>>(sz, dim) {}
  matrix() : vector<matrix<T, D - 1>>() {}
};
template <class T>
struct matrix<T, 1> : public vector<T> {
  matrix(long long sz, T v) : vector<T>(sz, v) {}
  matrix() : vector<T>() {}
  matrix(const initializer_list<T> &init) : vector<T>(init) {}
};
template <class T>
struct matrix_allocator {
  matrix_allocator(T v) : v(v) {}
  T v;
  template <typename N, typename... Ns>
  matrix<T, sizeof...(Ns) + 1> alloc(N cardinality, Ns... dims) {
    return matrix<T, sizeof...(Ns) + 1>(cardinality, alloc(dims...));
  }
  template <typename N>
  matrix<T, 1> alloc(N cardinality) {
    return matrix<T, 1>(cardinality, v);
  }
};
template <class V, typename... Ns>
static matrix<V, sizeof...(Ns)> mat(V v, Ns... dims) {
  return matrix_allocator<V>(v).alloc(dims...);
}
long long N = 1e5;
struct bit {
  bit(long long n = 0) { a = mat(0ULL, n + 1); }
  long long get(long long i) {
    long long s = 0;
    for (; i > 0; i -= i & -i) s += a[i];
    return s;
  }
  void add(long long i, long long v) {
    for (; i < a.size(); i += i & -i) a[i] += v;
  }
  matrix<unsigned long long, 1> a;
};
void solve() {
  long long n;
  cin >> n;
  auto x = iarr<long long>(n);
  auto v = iarr<long long>(n);
  matrix<pair<long long, long long>, 1> p;
  auto suf_tot = mat(0ULL, n + 1);
  auto suf_neg = mat(0ULL, n + 1);
  auto suf_num_neg = 0;
  auto ans = 0ULL;
  for (long long i = 0; i < n; i++) {
    p.push_back(make_pair(x[i], v[i] + (v[i] < 0 ? -1 : 1)));
  }
  sort(p.begin(), p.end());
  map<long long, long long> vc;
  long long idx = 1;
  sort(v.begin(), v.end());
  for (auto &o : v) {
    long long t = o + (o < 0 ? -1 : 1);
    if (!vc.count(t)) {
      vc[t] = idx++;
    } else {
    }
  }
  bit pre_neg(idx);
  bit pre_num_neg(idx);
  bit pre_pos(idx);
  bit pre_num_pos(idx);
  for (long long i = n - 1; i >= 0; i--) {
    auto xi = p[i].first;
    auto vi = p[i].second;
    auto step = suf_tot[i + 1] - (n - i - 1) * xi;
    if (vi > 0) {
      step = step - (suf_neg[i + 1] - suf_num_neg * xi);
      step =
          step - (pre_pos.get(vc[vi] - 1) - pre_num_pos.get(vc[vi] - 1) * xi);
    } else {
      step = step - ((pre_neg.get(idx) - pre_neg.get(vc[vi])) -
                     (pre_num_neg.get(idx) - pre_num_neg.get(vc[vi])) * xi);
    }
    suf_tot[i] = suf_tot[i + 1] + xi;
    suf_neg[i] = suf_neg[i + 1] + (vi < 0 ? xi : 0);
    suf_num_neg += (vi < 0 ? 1 : 0);
    if (vi < 0) {
      pre_neg.add(vc[vi], xi);
      pre_num_neg.add(vc[vi], 1);
    } else {
      pre_pos.add(vc[vi], xi);
      pre_num_pos.add(vc[vi], 1);
    }
    ans += step;
  }
  cout << ans << "\n";
}
