#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  int n;
  cin >> n;
  vector<long int> x(n);
  vector<long int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int d = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (v[j] < 0 && v[i] > 0) {
        if (x[i] < x[j])
          d += 0;
        else
          d += abs(x[j] - x[i]);
      } else if (v[j] < 0 && v[i] > 0) {
        if (x[i] > x[j])
          d += 0;
        else
          d += abs(x[j] - x[i]);
      } else {
        if ((v[j] > v[i] && x[j] > x[i]) || v[j] == v[i]) {
          d += abs(x[j] - x[i]);
        }
      }
    }
  }
  cout << d;
}
