#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int n;
struct Point {
  int x, v;
  bool operator<(const Point& b) const { return x < b.x; }
} p[N];
pair<long long, int> tr[N];
int cnt;
int V[N];
void add(int x, long long v) {
  for (int i = x; i <= n; i += i & (-i)) tr[i].first += v, tr[i].second++;
}
pair<long long, int> sum(int x) {
  pair<long long, int> res;
  for (int i = x; i; i -= i & (-i))
    res.first += tr[i].first, res.second += tr[i].second;
  return res;
}
long long solve(int ok) {
  for (int i = 1; i <= n; ++i) tr[i] = {0, 0};
  long long X = 1e8 + 8;
  long long num = 0;
  long long tem = 0;
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i].v == 0) continue;
    if (p[i].v * ok > 0) {
      res += tem - num * (X - p[i].x);
    } else {
      ++num;
      tem += X - p[i].x;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i].v * ok <= 0) continue;
    V[++cnt] = p[i].v;
  }
  sort(V + 1, V + 1 + cnt);
  cnt = unique(V + 1, V + 1 + cnt) - V - 1;
  for (int i = 1; i <= n; ++i) {
    if (p[i].v * ok <= 0) continue;
    int pl = lower_bound(V + 1, V + 1 + cnt, p[i].v) - V;
    pair<long long, int> tem = sum(pl);
    res += tem.first - tem.second * (X - p[i].x);
    add(pl, X - p[i].x);
  }
  return res;
}
long long solve0() {
  int num = 0;
  long long X = 1e8 + 9;
  long long res = 0;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i].v) continue;
    res += sum - num * (X - p[i].x);
    sum += X - p[i].x;
    ++num;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i].x);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i].v);
  }
  sort(p + 1, p + 1 + n);
  long long ans = 0;
  ans += solve(1);
  ans += solve(-1);
  ans += solve0();
  printf("%lld", ans);
}
