#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, X[N];
int l_cnt, r_cnt;
pair<int, int> L[N], R[N];
vector<int> nums;
int cnt[N];
long long sum[N];
int tt, q[N];
long long dis;
int get_pos(int p) {
  int l = 1, r = r_cnt;
  while (l < r) {
    int mid = l + r >> 1;
    if (R[mid].first > p)
      r = mid;
    else
      l = mid + 1;
  }
  if (R[l].first <= p) l = -1;
  return l;
}
void get_differ() {
  for (int i = r_cnt; i; i--) sum[i] = sum[i + 1] + R[i].first;
  for (int i = 1; i <= l_cnt; i++) {
    int pos = get_pos(L[i].first);
    if (pos == -1) continue;
    dis += sum[pos] - 1ll * (r_cnt - pos + 1) * L[i].first;
  }
  return;
}
int get_idx(int x) {
  return lower_bound(nums.begin(), nums.end(), x) - nums.begin() + 1;
}
int lowbit(int x) { return x & -x; }
void add(int pos, int c) {
  for (int i = pos; i <= nums.size(); i += lowbit(i)) {
    sum[i] += c;
    cnt[i]++;
  }
  return;
}
long long get_sum(int pos) {
  long long s = 0;
  for (int i = pos; i; i -= lowbit(i)) s += sum[i];
  return s;
}
int get_cnt(int pos) {
  int c = 0;
  for (int i = pos; i; i -= lowbit(i)) c += cnt[i];
  return c;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", X + i);
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    if (!v) {
      L[++l_cnt] = {X[i], v};
      R[++r_cnt] = {X[i], v};
    } else if (v > 0)
      R[++r_cnt] = {X[i], v};
    else
      L[++l_cnt] = {X[i], v};
    nums.push_back(v);
  }
  sort(L + 1, L + l_cnt + 1);
  sort(R + 1, R + r_cnt + 1);
  get_differ();
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
  memset(sum, 0, sizeof sum);
  for (int i = 1; i <= l_cnt; i++) {
    int pos = get_idx(L[i].second), c = get_cnt(pos);
    dis += 1ll * c * L[i].first - get_sum(pos);
    add(pos, L[i].first);
  }
  memset(sum, 0, sizeof sum);
  memset(cnt, 0, sizeof cnt);
  for (int i = r_cnt; i; i--) {
    int pos = get_idx(R[i].second), c = get_cnt(nums.size()) - get_cnt(pos - 1);
    dis += get_sum(nums.size()) - get_sum(pos - 1) - 1ll * c * R[i].first;
    add(pos, R[i].first);
  }
  printf("%lld\n", dis);
  return 0;
}
