#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int x[200005];
vector<pair<long long int, long long int> > cord;
map<long long int, long long int> vel_freq, vel_map;
long long int num[3 * 200005], xcnt[3 * 200005];
int get_cnt(long long int node, long long int l, long long int r,
            long long int start, long long int end) {
  if (start > r || end < l) return 0;
  if (start >= l && end <= r) {
    return num[node];
  }
  long long int mid = (start + end) / 2;
  long long int left = 0, right = 0;
  if (r >= start && r <= mid)
    left = get_cnt(2 * node, l, r, start, mid);
  else
    right = get_cnt(2 * node + 1, l, r, (mid + 1), end);
  return left + right;
}
void add_vel(long long int node, long long int start, int end,
             long long int idx) {
  if (start == end) {
    num[node]++;
    return;
  }
  long long int mid = (start + end) / 2;
  if (idx >= start && idx <= mid) {
    add_vel(2 * node, start, mid, idx);
  } else
    add_vel(2 * node + 1, mid + 1, end, idx);
  num[node] = num[2 * node] + num[2 * node + 1];
}
void add_x(long long int node, long long int start, long long int end,
           long long int idx, long long int val) {
  if (start == end) {
    xcnt[node] += val;
    return;
  }
  long long int mid = (start + end) / 2;
  if (idx >= start && idx <= mid)
    add_x(2 * node, start, mid, idx, val);
  else
    add_x(2 * node + 1, mid + 1, end, idx, val);
  xcnt[node] = xcnt[2 * node] + xcnt[2 * node + 1];
}
long long int get_x_sum(long long int node, long long int start,
                        long long int end, long long int l, long long int r) {
  if (start > r || end < l) return 0;
  if (start >= l && end <= r) {
    return xcnt[node];
  }
  long long int mid = (start + end) / 2, left = 0, right = 0;
  if (r >= start && r <= mid)
    left = get_x_sum(2 * node, start, (start + end) / 2, l, r);
  else
    right = get_x_sum(2 * node + 1, (start + end) / 2 + 1, end, l, r);
  return left + right;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) {
    long long int cur_vel;
    cin >> cur_vel;
    cord.push_back({x[i], cur_vel});
    vel_freq[cur_vel]++;
  }
  long long int k = 0;
  sort(cord.begin(), cord.end());
  for (auto it = vel_freq.begin(); it != vel_freq.end(); it++) {
    vel_map[it->first] = k;
    k++;
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    long long int cur_cnt =
        cord[i].first * (get_cnt(1, 0, vel_map[cord[i].second], 0, k - 1));
    long long int sum = get_x_sum(1, 0, k - 1, 0, vel_map[cord[i].second]);
    add_vel(1, 0, k - 1, vel_map[cord[i].second]);
    add_x(1, 0, k - 1, vel_map[cord[i].second], cord[i].first);
    ans += cur_cnt - sum;
  }
  cout << ans;
}
