#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const long long int mod = 1000000007;
const int N = 3e5, M = N;
vector<int> g[N];
int a[N];
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long int)result * base) % mod;
    base = ((long long int)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
void ipgraph(int m) {
  int u, v;
  while (m--) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
void dfs(int u, int par) {
  for (int v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
}
long long int mod1(string num, long long int a1) {
  long long int res = 0;
  for (int i = 0; i < num.length(); i++)
    res = (res * 10 + (int)num[i] - '0') % a1;
  return res;
}
vector<pair<int, int> > pos, negs;
int mergepos(int l, int m, int r) {
  int ls = m - l + 1;
  int rs = r - m;
  vector<pair<int, int> > lss(ls + 1), rss(rs + 1);
  lss[ls] = {-1, -1};
  rss[rs] = {-1, -1};
  for (int i = l; i <= m; i++) lss[i - l] = pos[i];
  for (int i = m + 1; i <= r; i++) rss[i - m - 1] = pos[i];
  long long int runsum[ls + 1];
  runsum[0] = 0;
  for (int i = 0; i < ls; i++) runsum[i + 1] = runsum[i] + lss[i].first;
  int i = 0, j = 0, diffs = 0;
  for (int k = l; k <= r; k++) {
    if (lss[i].second > rss[j].second) {
      pos[k] = lss[i];
      i++;
    } else if (lss[i].second <= rss[j].second) {
      if (i != ls) diffs += rss[j].first * (ls - i) - (runsum[ls] - runsum[i]);
      pos[k] = rss[j];
      j++;
    }
  }
  return diffs;
}
int mergeneg(int l, int m, int r) {
  int ls = m - l + 1;
  int rs = r - m;
  vector<pair<int, int> > lss(ls + 1), rss(rs + 1);
  lss[ls] = {1, 1};
  rss[rs] = {1, 1};
  for (int i = l; i <= m; i++) lss[i - l] = negs[i];
  for (int i = m + 1; i <= r; i++) rss[i - m - 1] = negs[i];
  long long int runsum[rs + 1];
  runsum[0] = 0;
  for (int i = 0; i < rs; i++) runsum[i + 1] = runsum[i] + rss[i].first;
  int i = 0, j = 0, diffs = 0;
  for (int k = l; k <= r; k++) {
    if (lss[i].second > rss[j].second) {
      negs[k] = rss[i];
      j++;
    } else if (lss[i].second <= rss[j].second) {
      if (j != rs) diffs += (runsum[rs] - runsum[j]) - lss[i].first * (rs - j);
      negs[k] = lss[i];
      i++;
    }
  }
  return diffs;
}
int mergesort2(int l, int r) {
  int mid = (l + r) / 2;
  if (l < r) {
    int lcount = mergesort2(l, mid);
    int rcount = mergesort2(mid + 1, r);
    int cross = mergeneg(l, mid, r);
    return lcount + rcount + cross;
  } else
    return 0;
}
int mergesort1(int l, int r) {
  int mid = (l + r) / 2;
  if (l < r) {
    int lcount = mergesort1(l, mid);
    int rcount = mergesort1(mid + 1, r);
    int cross = mergepos(l, mid, r);
    return lcount + rcount + cross;
  } else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int velo[n];
  int i;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> velo[i];
  for (i = 0; i < n; i++) {
    if (velo[i] >= 0)
      pos.push_back({a[i], velo[i]});
    else
      negs.push_back({a[i], velo[i]});
  }
  int x = pos.size();
  int y = negs.size();
  sort(pos.begin(), pos.end());
  sort(negs.begin(), negs.end());
  int diff = 0;
  if (x > 0 && y > 0) {
    x--;
    y--;
    int runsum[y];
    runsum[0] = negs[0].first;
    for (i = 1; i <= y; i++) runsum[i] = runsum[i - 1] + negs[i].first;
    for (i = 0; i < n; i++) {
      if (x >= 0 && y >= 0 && pos[x].first >= negs[y].first) {
        diff += pos[x].first * (y + 1) - runsum[y];
        x--;
      } else if (x >= 0 && y >= 0 && pos[x].first < negs[y].first)
        y--;
      else
        break;
    }
  }
  x = pos.size();
  y = negs.size();
  int diff1 = mergesort1(0, x - 1);
  int diff2 = mergesort2(0, y - 1);
  cout << diff + diff1 + diff2 << endl;
  return 0;
}
