#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
const int INFTY = 1e7;
class FenwickTree2D {
 private:
  map<pair<long long, long long>, long long> m;

 public:
  FenwickTree2D() { m.clear(); }
  void update(int r, int c, long long delta) {
    int maxi = 2e8 + 5;
    for (int r_ = r; r_ < (int)maxi; r_ = r_ + (r_ & -r_)) {
      for (int c_ = c; c_ < (int)maxi; c_ = c_ + (c_ & -c_)) {
        m[make_pair(r_, c_)] += delta;
      }
    }
  }
  long long sum(int r, int c) {
    long long second = 0;
    for (int r_ = r; r_ > 0; r_ = r_ - (r_ & (-r_))) {
      for (int c_ = c; c_ > 0; c_ = c_ - (c_ & (-c_))) {
        auto it = m.find(make_pair(r_, c_));
        if (it != m.end()) {
          second += it->second;
        }
      }
    }
    return second;
  }
  long long rangeQuery(int r1, int c1, int r2, int c2) {
    return (sum(r2, c2) - sum(r1 - 1, c2) - sum(r2, c1 - 1) +
            sum(r1 - 1, c1 - 1));
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> x(n), v(n);
  for (int i = 0; i < (n); i++) cin >> x[i];
  set<long long> second;
  unordered_map<long long, long long> mapper;
  for (int i = 0; i < (n); i++) cin >> v[i], second.insert(v[i]);
  long long to = 2;
  for (const auto& v : second) mapper[v] = to++;
  long long ans = 0;
  FenwickTree2D ft;
  FenwickTree2D counter;
  for (int i = 0; i < n; i++) {
    long long q1 = ft.rangeQuery(x[i] + 1, mapper[v[i]] + 1, 2e8 + 1, 2e8 + 1);
    long long count1 =
        counter.rangeQuery(x[i] + 1, mapper[v[i]] + 1, 2e8 + 1, 2e8 + 1);
    long long q2 = ft.rangeQuery(0, 0, x[i] - 1, mapper[v[i]] - 1);
    long long count2 = counter.rangeQuery(0, 0, x[i] - 1, mapper[v[i]] - 1);
    long long q3 = ft.rangeQuery(0, mapper[v[i]], 2e8 + 1, mapper[v[i]]);
    long long count3 =
        counter.rangeQuery(0, mapper[v[i]], 2e8 + 1, mapper[v[i]]);
    ft.update(x[i], mapper[v[i]], x[i]);
    counter.update(x[i], mapper[v[i]], 1);
    long long delta = abs(1ll * count1 * x[i] - q1) +
                      abs(1ll * count2 * x[i] - q2) +
                      abs(1ll * count3 * x[i] - q3);
    ans += delta;
  }
  cout << ans << endl;
}
