#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  pair<int, int> arr[n];
  long long int counter = 0;
  pair<long long int, int> arrr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first;
  }
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].second;
  }
  sort(arr, arr + n);
  for (int i = n - 2; i >= 0; --i) {
    for (int j = i + 1; j < n; ++j) {
      if (arr[i].second > arr[j].second) {
        arrr[i].first +=
            arrr[j].first + abs(arr[i].first - arr[j].first) * (arrr[j].second);
        arrr[i].second += arrr[j].second + 1;
        break;
      }
      arrr[i].first += abs(arr[i].first - arr[j].first);
      arrr[i].second++;
    }
    counter += arrr[i].first;
  }
  cout << counter << '\n';
  return 0;
}
