#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[200000 + 10];
int vs[200000 + 10];
int n;
pair<int, long long> add_(pair<int, long long> a, pair<int, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
pair<int, long long int> init(vector<pair<int, long long>> &a,
                              vector<pair<int, long long>> &tree, int node,
                              int start, int end) {
  if (start == end) {
    return tree[node] = a[start];
  } else {
    return tree[node] =
               add_(init(a, tree, node * 2, start, (start + end) / 2),
                    init(a, tree, node * 2 + 1, (start + end) / 2 + 1, end));
  }
}
void update(vector<pair<int, long long>> &tree, int node, int start, int end,
            int index, long long diff) {
  if (index < start || index > end) return;
  tree[node].first++;
  tree[node].second += diff;
  if (start != end) {
    update(tree, node * 2, start, (start + end) / 2, index, diff);
    update(tree, node * 2 + 1, (start + end) / 2 + 1, end, index, diff);
  }
}
pair<int, long long> sum(vector<pair<int, long long>> &tree, int node,
                         int start, int end, int left, int right) {
  if (left > end || right < start) {
    return {0, 0};
  }
  if (left <= start && end <= right) {
    return tree[node];
  }
  return add_(sum(tree, node * 2, start, (start + end) / 2, left, right),
              sum(tree, node * 2 + 1, (start + end) / 2 + 1, end, left, right));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &d[i].first);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i].second);
    vs[i] = d[i].second;
  }
  sort(vs, vs + n);
  for (int i = 0; i < n; i++) {
    d[i].second = lower_bound(vs, vs + n, d[i].second) - vs;
  }
  sort(d, d + n);
  int h = (int)ceil(log2(n));
  int tree_size = (1 << (h + 1));
  vector<pair<int, long long>> tree(tree_size);
  vector<pair<int, long long>> a(tree_size);
  init(a, tree, 1, 0, n - 1);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    auto sum_d = sum(tree, 1, 0, n - 1, 0, d[i].second);
    res += d[i].first * sum_d.first;
    res -= sum_d.second;
    update(tree, 1, 0, n - 1, d[i].second, d[i].first);
  }
  cout << res;
  return 0;
}
