#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 4;
int n, nef[maxn];
pair<int, int> a[maxn];
long long fen[maxn];
void _accepted_by_one_hit_() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long get(int u) {
  long long res = 0;
  for (int i = u; i >= 1; i -= i & (-i)) res += fen[i];
  return res;
}
int count(int u) {
  int res = 0;
  for (int i = u; i >= 1; i -= i & (-i)) res += nef[i];
  return res;
}
void update(int x, int val) {
  for (int i = x; i < maxn; i += i & (-i)) fen[i] += val;
  for (int i = x; i < maxn; i += i & (-i)) nef[i]++;
}
int main() {
  _accepted_by_one_hit_();
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i].first;
  for (int i = 1; i <= n; ++i) cin >> a[i].second;
  vector<int> v;
  for (int i = 1; i <= n; ++i) v.push_back(a[i].second);
  unique(v.begin(), v.end());
  map<int, int> p;
  for (int i = 0; i < v.size(); ++i) p[v[i]] = i + 1;
  for (int i = 1; i <= n; ++i) a[i].second = p[a[i].second];
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += -get(a[i].second) + 1LL * count(a[i].second) * a[i].first;
    update(a[i].second, a[i].first);
  }
  cout << ans;
}
