#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n, {0, 0});
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[i].first = x;
  }
  for (long long i = 0; i < n; i++) {
    long long v;
    cin >> v;
    a[i].second = v;
  }
  sort(a.begin(), a.end());
  vector<long long> x, dp(n, 0);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (i > 0) {
      long long v = upper_bound(x.begin(), x.end(), a[i].second) - x.begin();
      dp[i] = dp[i - 1] + (i * (a[i].first - a[i - 1].first));
      ans += dp[v] + (v * (a[i].first - a[v].first));
      x.push_back(a[i].second);
    } else {
      x.push_back(a[i].second);
    }
  }
  cout << ans;
}
