#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x[100010 * 2], v[100010 * 2];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (x[i] < x[j]) {
        if (v[i] > v[j])
          continue;
        else
          ans += x[j] - x[i];
      } else if (x[i] > x[j]) {
        if (v[j] > v[i])
          continue;
        else
          ans += x[i] - x[j];
      } else
        continue;
    }
  }
  printf("%d", ans);
  return 0;
}
