#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
vector<pair<long long int, long long int> > v;
long long int solve(long long int i, long long int j) {
  if (v[i].first == v[j].first) return 0;
  if (v[i].second > v[j].second and v[i].second > 0 and v[j].second > 0)
    return 0;
  if (v[i].second > v[j].second and v[i].second < 0 and v[j].second < 0)
    return 0;
  if (v[i].second > 0 and v[j].second < 0) return 0;
  if (v[i].second == 0) {
    if (v[j].second < 0) return 0;
  }
  if (v[j].second == 0) {
    if (v[i].second > 0) return 0;
  }
  return abs(v[i].first - v[j].first);
}
long long int n;
long long int bit[300009] = {0};
void update(long long int num) {
  while (num <= 300009) {
    bit[num] += 1;
    num += (num & -num);
  }
}
long long int query(long long int num) {
  long long int ans = 0;
  while (num > 0) {
    ans += bit[num];
    num -= (num & -num);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long int speed[n + 2];
  map<long long int, long long int> mp;
  long long int pos[n + 2];
  for (long long int i = 1; i < n + 1; i++) cin >> pos[i];
  for (long long int i = 1; i < n + 1; i++) cin >> speed[i];
  sort(speed + 1, speed + n + 1);
  long long int cnt = 1;
  for (auto it : speed) {
    if (mp.find(it) != mp.end()) continue;
    mp.insert({it, cnt++});
  }
  for (long long int i = 1; i < n + 1; i++) v.push_back({pos[i], mp[speed[i]]});
  sort((v).begin(), (v).end());
  long long int ans = 0;
  long long int sum = v[0].first;
  for (long long int i = 1; i < n; i++) {
    ans += (v[i].first * i) - sum;
    sum += v[i].first;
  }
  for (long long int i = n - 1; i >= 0; i--) {
    long long int haha = query(v[i].second - 1);
    ans -= haha;
    update(v[i].second);
  }
  cout << ans << endl;
}
