#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5, mny = -1e9;
vector<vector<pair<int, pair<int, int> > > > seg(4 * N);
long long n, ans;
pair<int, int> p[N];
vector<pair<int, pair<int, int> > > merge(
    vector<pair<int, pair<int, int> > > l,
    vector<pair<int, pair<int, int> > > r) {
  vector<pair<int, pair<int, int> > > ans;
  merge(l.begin(), l.end(), r.begin(), r.end(), back_inserter(ans));
  sort(ans.begin(), ans.end());
  for (int i = 1; i < ans.size(); i++)
    ans[i].second.second += ans[i - 1].second.second;
  return ans;
}
pair<long long, long long> merge(pair<long long, long long> p1,
                                 pair<long long, long long> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
pair<long long, long long> get_ans(vector<pair<int, pair<int, int> > > node,
                                   int val) {
  if (!node.size()) return {0, 0};
  pair<long long, long long> ans;
  auto idx = lower_bound(node.begin(), node.end(),
                         make_pair(val, make_pair(mny, mny))) -
             node.begin();
  ans.second = node.size() - idx;
  if (!ans.second) return {0, 0};
  ans.first = (idx) ? node.back().second.second - node[idx - 1].second.second
                    : node.back().second.second;
  return ans;
}
void build(int s, int e, int idx) {
  if (s == e) {
    seg[idx].push_back({p[s].second, {p[s].first, p[s].first}});
    return;
  }
  int mid = (s + e) / 2;
  build(s, mid, 2 * idx + 1);
  build(mid + 1, e, 2 * idx + 2);
  seg[idx] = merge(seg[2 * idx + 1], seg[2 * idx + 2]);
}
pair<long long, long long> qry(int l, int r, int s, int e, int idx, int val) {
  if (s > r || l > e) return make_pair(0ll, 0ll);
  if (s >= l && e <= r) return get_ans(seg[idx], val);
  int mid = (s + e) / 2;
  return merge(qry(l, r, s, mid, 2 * idx + 1, val),
               qry(l, r, mid + 1, e, 2 * idx + 2, val));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i].first;
  for (int i = 0; i < n; i++) cin >> p[i].second;
  sort(p, p + n);
  build(0, n - 1, 0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    pair<long long, long long> res =
        qry(i + 1, n - 1, 0, n - 1, 0, p[i].second);
    ans += res.first - p[i].first * res.second;
  }
  cout << ans << '\n';
  return 0;
}
