#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};
vector<pair<long long int, long long int> > vec;
int n;
int tree[(int)(2 * 1e5 + 1)], tree2[(int)(2 * 1e5 + 1)];
void atualiza(int x, int v) {
  for (; x <= n; x += (x & -x)) tree[x] += v;
}
void atualiza2(int x, int v) {
  for (; x <= n; x += (x & -x)) tree2[x] += v;
}
long long int sum(long long int x) {
  int s = 0;
  for (; x > 0; x -= (x & -x)) s += tree[x];
  return s;
}
long long int sum2(int x) {
  int s = 0;
  for (; x > 0; x -= (x & -x)) s += tree2[x];
  return s;
}
void compress() {
  vector<int> aux2;
  for (int i = 1; i <= n; i++) aux2.push_back(vec[i].second);
  sort(aux2.begin(), aux2.end());
  for (int j = 1; j <= n; j++) {
    auto i = vec[j];
    vec[j].second =
        lower_bound(aux2.begin(), aux2.end(), i.second) - aux2.begin();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<int> aux;
  vec.push_back({0, 0});
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    vec.push_back({a, 1});
  }
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    vec[i].second = a;
  }
  sort(vec.begin() + 1, vec.end());
  compress();
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (sum2(i - 1) * vec[i].first - sum(i - 1));
    atualiza(vec[i].second + 1, vec[i].first);
    atualiza2(vec[i].second + 1, 1);
  }
  cout << ans << "\n";
  return 0;
}
