#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
map<int, int> g;
map<int, int> invG;
int tree[4][maxn];
int sum(int k, int t) {
  int res = 0;
  for (int i = k; i >= 1; i -= i & -i) res += tree[t][i];
  return res;
}
void add(int k, int v, int t) {
  for (int i = k; i < maxn; i += i & -i) tree[t][i] += v;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < 4; j++) tree[j][i] = 0;
  int n;
  cin >> n;
  priority_queue<pair<int, pair<int, int>>> pq;
  vector<int> xs;
  vector<int> vs;
  set<int> distinct;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    xs.push_back(x);
    distinct.emplace(x);
  }
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    vs.push_back(v);
  }
  vector<int> vec(distinct.begin(), distinct.end());
  for (int i = 0; i < n; i++) {
    g[vec[i]] = i + 1;
    invG[i + 1] = vec[i];
  }
  for (int i = 0; i < n; i++) {
    int dir = 0;
    if (vs[i] < 0) dir = 1;
    pq.emplace(abs(vs[i]), make_pair(g[xs[i]], dir));
  }
  int res = 0;
  while (!pq.empty()) {
    pair<int, pair<int, int>> p = pq.top();
    pq.pop();
    int x = p.second.first;
    int dir = p.second.second;
    int sumRight = sum(maxn - 1, 0) - sum(x, 0);
    sumRight -= x * (sum(maxn - 1, 0 + 2) - sum(x, 0 + 2));
    int sumLeft = sum(x, 1);
    sumLeft -= x * sum(x, 1 + 2);
    res += abs(sumRight) + abs(sumLeft);
    add(x, invG[x], dir);
    add(x, 1, dir + 2);
  }
  cout << res << '\n';
}
