#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int n2 = n;
  queue<int> q;
  set<int> inc, dec, cte;
  map<int, int> mp;
  while (n--) {
    int x;
    cin >> x;
    q.push(x);
  }
  while (n2--) {
    int x;
    cin >> x;
    int y = q.front();
    mp[y] = x;
    if (x > 0)
      inc.insert(y);
    else if (x < 0)
      dec.insert(y);
    else
      cte.insert(y);
    q.pop();
  }
  long long sum = 0;
  set<int>::iterator it, it2;
  for (it = inc.begin(); it != inc.end(); it++) {
    int a = *it;
    for (it2 = it; it2 != inc.end(); it2++) {
      if (it2 == it) continue;
      int b = *it2;
      if (mp[a] <= mp[b]) sum += (long long)(b - a);
    }
  }
  for (it = dec.begin(); it != dec.end(); it++) {
    int a = *it;
    for (it2 = it; it2 != dec.end(); it2++) {
      if (it2 == it) continue;
      int b = *it2;
      if (mp[a] <= mp[b]) sum += (long long)(b - a);
    }
  }
  for (it = cte.begin(); it != cte.end(); it++) {
    int a = *it;
    for (it2 = it; it2 != cte.end(); it2++) {
      int b = *it2;
      sum += (long long)(b - a);
    }
  }
  for (it = inc.begin(); it != inc.end(); it++) {
    int a = *it;
    for (it2 = dec.begin(); it2 != dec.find(a); it2++) {
      int b = *it2;
      sum += (long long)(a - b);
    }
    for (it2 = cte.begin(); it2 != cte.find(a); it2++) {
      int b = *it2;
      sum += (long long)(a - b);
    }
  }
  for (it = dec.begin(); it != dec.end(); it++) {
    int a = *it;
    for (it2 = cte.find(a); it2 != cte.end(); it2++) {
      int b = *it2;
      sum += (long long)(b - a);
    }
  }
  cout << sum << endl;
  return 0;
}
