#include <bits/stdc++.h>
using namespace std;
const int maxp = 22;
const long double EPS = 1e-18;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 1;
template <typename T>
struct SEGTREE {
  struct node {
    T val;
    T cnt;
    node() : val(0), cnt(0) {}
    node(T _val) : val(_val), cnt(1) {}
  };
  vector<node> seg;
  int N;
  void init(int n) {
    N = n;
    seg.assign(4 * n, node());
  }
  node merge(node x, node y) {
    node res;
    res.val = x.val + y.val;
    res.cnt = x.cnt + y.cnt;
    return res;
  }
  void build(int s, int e, int idx, T arr[]) {
    if (s == e) {
      seg[idx] = node(arr[s]);
      return;
    }
    int mid = (s + e) / 2;
    build(s, mid, idx * 2, arr);
    build(mid + 1, e, idx * 2 + 1, arr);
    seg[idx] = merge(seg[idx * 2], seg[idx * 2 + 1]);
  }
  void build(T arr[]) { build(1, N, 1, arr); }
  void update(int s, int e, int idx, int k, T val) {
    if (s == e && s == k) {
      seg[idx].val += val;
      if (val > 0)
        seg[idx].cnt++;
      else
        seg[idx].cnt--;
      return;
    }
    if (s > k || e < k) return;
    int mid = (s + e) / 2;
    update(s, mid, idx * 2, k, val);
    update(mid + 1, e, idx * 2 + 1, k, val);
    seg[idx] = merge(seg[idx * 2], seg[idx * 2 + 1]);
  }
  void update(int k, T val) { update(1, N, 1, k, val); }
  node query(int s, int e, int idx, int qs, int qe) {
    if (qs <= s && e <= qe) return seg[idx];
    if (s > qe || e < qs) return node();
    int mid = (s + e) / 2;
    return merge(query(s, mid, idx * 2, qs, qe),
                 query(mid + 1, e, idx * 2 + 1, qs, qe));
  }
  pair<int, int> query(int l, int r) {
    node ans = query(1, N, 1, l, r);
    return {ans.val, ans.cnt};
  }
};
template <typename T>
vector<int> compress(vector<T> in) {
  vector<T> arr = in;
  sort(arr.begin(), arr.end());
  arr.erase(unique(arr.begin(), arr.end()), arr.end());
  for (int &x : in)
    x = int(lower_bound(arr.begin(), arr.end(), x) - arr.begin());
  return in;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  pair<long long, long long> arr[n];
  int i;
  vector<int> a(n);
  for (i = 0; i < n; i++) cin >> arr[i].first;
  for (i = 0; i < n; i++) cin >> a[i];
  a = compress<int>(a);
  for (i = 0; i < n; i++) arr[i].second = a[i];
  sort(arr, arr + n);
  long long ans = 0;
  SEGTREE<long long> seg;
  seg.init(n);
  for (i = 0; i < n; i++) seg.update(arr[i].second + 1, arr[i].first);
  for (i = 0; i < n; i++) {
    seg.update(arr[i].second + 1, -arr[i].first);
    pair<int, int> temp = seg.query(arr[i].second + 1, n);
    ans += temp.first - arr[i].first * temp.second;
  }
  cout << ans;
}
