#include <bits/stdc++.h>
using namespace std;
const long long mx = 2 * 1e5 + 5;
const long long mod = 1e9 + 7;
pair<long long, long long> arr[mx * 4];
void update(int node, int left, int right, int pos, int val) {
  if (left == right) {
    arr[node].first++;
    arr[node].second += val;
    return;
  }
  int mid = (left + right) / 2;
  if (pos <= mid) {
    update(node * 2, left, mid, pos, val);
  } else {
    update(node * 2 + 1, mid + 1, right, pos, val);
  }
  arr[node].first = arr[node * 2].first + arr[node * 2 + 1].first;
  arr[node].second = arr[node * 2].second + arr[node * 2 + 1].second;
  return;
}
pair<long, long> sum(pair<long long, long long> a,
                     pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
pair<long long, long long> query(int node, int left, int right, int l, int r) {
  if (right < l || left > r) {
    return {0, 0};
  }
  if (right <= r && left >= l) {
    return {arr[node].first, arr[node].second};
  }
  int mid = (left + right) / 2;
  return sum(query(node * 2, left, mid, l, r),
             query(node * 2 + 1, mid + 1, right, l, r));
}
int main() {
  int n;
  cin >> n;
  pair<int, int> p[n];
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i].second;
    mp[p[i].second] = i;
  }
  int cur = 0;
  for (auto& i : mp) {
    i.second = cur;
    cur++;
  }
  for (int i = 0; i < n; i++) {
    p[i].second = mp[p[i].second];
  }
  sort(p, p + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int myv = p[i].second;
    int myx = p[i].first;
    pair<int, int> cnt = query(1, 0, n, 0, myv);
    ans += myx * cnt.first;
    ans -= cnt.second;
    update(1, 0, n, myv, myx);
  }
  update(1, 0, n, 0, 5);
  pair<int, int> cnt = query(1, 0, n - 1, 0, 0);
  cout << ans;
}
