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