#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long maxn = 4e5 + 13;
const long long INF = 1e18;
const long long B = 257;
long long v[maxn];
long long x[maxn];
struct Point {
  long long x, v;
};
bool comp(Point A, Point B) { return A.v < B.v; }
long long f(long long v, vector<Point>& a) {
  long long l = -1, r = a.size();
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (a[m].v <= v)
      l = m;
    else
      r = m;
  }
  return l + 1;
}
long long g(long long v, vector<Point>& a) {
  long long l = -1, r = a.size();
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (a[m].v >= v)
      r = m;
    else
      l = m;
  }
  return a.size() - r;
}
long long val(vector<Point>& plsL, vector<Point>& plsR) {
  if (plsL.empty() || plsR.empty()) return 0;
  long long sum1 = 0, sum2 = 0;
  for (long long i = 0; i < plsL.size(); ++i)
    sum1 += plsL[i].x * g(plsL[i].v, plsR);
  for (long long i = 0; i < plsR.size(); ++i)
    sum2 += plsR[i].x * f(plsR[i].v, plsL);
  return sum2 - sum1;
}
long long getsum(long long l, long long r, vector<Point>& P) {
  if (l == r) return 0;
  long long m = (l + r) >> 1;
  long long s1 = getsum(l, m, P);
  long long s2 = getsum(m + 1, r, P);
  long long res = 0;
  vector<Point> mnsL, plsL, mnsR, plsR;
  for (long long i = l; i <= m; ++i) {
    if (P[i].v >= 0)
      plsL.push_back(P[i]);
    else
      mnsL.push_back(P[i]);
  }
  for (long long i = m + 1; i <= r; ++i) {
    if (P[i].v >= 0)
      plsR.push_back(P[i]);
    else
      mnsR.push_back(P[i]);
  }
  sort(mnsL.begin(), mnsL.end(), comp);
  sort(mnsR.begin(), mnsR.end(), comp);
  sort(plsL.begin(), plsL.end(), comp);
  sort(plsR.begin(), plsR.end(), comp);
  long long sum1 = 0, sum2 = 0;
  for (long long i = 0; i < plsR.size(); ++i) sum1 += plsR[i].x;
  for (long long i = 0; i < mnsL.size(); ++i) sum2 += mnsL[i].x;
  res += sum1 * mnsL.size() - sum2 * plsR.size();
  res += val(plsL, plsR);
  for (long long i = 0; i < mnsL.size(); ++i) mnsL[i].v *= -1;
  for (long long i = 0; i < mnsR.size(); ++i) mnsR[i].v *= -1;
  res += val(mnsL, mnsR);
  return s1 + s2 + res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> x[i];
  for (long long i = 1; i <= n; ++i) cin >> v[i];
  vector<Point> P;
  for (long long i = 1; i <= n; ++i) P.push_back({x[i], v[i]});
  sort(P.begin(), P.end(), [](Point A, Point B) { return A.x < B.x; });
  cout << getsum(0, n - 1, P) << " ";
  return 0;
}
