#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int arr[200000];
  long long int v[200000];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> arr[i];
  for (int i = 0; i < N; i++) cin >> v[i];
  long long int answer = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      long long int dist = arr[j] - arr[i];
      long long int speed = v[j] - v[i];
      if (dist == 0 || dist * speed < 0) continue;
      if (speed == 0) {
        answer += abs(dist);
        continue;
      }
      if (dist < 0 && arr[i] < arr[j]) {
        answer += abs(dist);
        continue;
      }
      if (dist > 0 && arr[i] < arr[j]) {
        answer += abs(dist);
        continue;
      }
    }
  }
  cout << answer << '\n';
  return 0;
}
