#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, v;
  int s = 0;
  vector<int> pos, vit;
  scanf("%d", &t);
  int tst = t;
  for (int i = 0; i < t; i++) {
    scanf("%d", &x);
    pos.push_back(x);
  }
  for (int i = 0; i < t; i++) {
    scanf("%d", &v);
    vit.push_back(v);
  }
  for (int i = 0; i < (tst - 1); i++) {
    for (int j = i + 1; j < tst; j++) {
      if ((vit[i] <= vit[j] && pos[i] < pos[j]) ||
          (vit[j] <= vit[i] && pos[j] < pos[i]))
        s += abs(pos[j] - pos[i]);
    }
  }
  cout << s << endl;
  return 0;
}
