5
1000000000 1000000000 1000000000 1000000000 1000000000
100000 100000 100000 100000 100000
 10
14 31 50 67 42 44 86 82 35 63
76 17 26 44 60 54 50 73 71 70
 10
4 4 1 2 2 2 5 4 1 5
28 81 36 44 2 40 39 43 36 33
 10
69564153 558821634 273092444 121621442 354953668 157021146 918149509 902159900 772175415 945981912
29 26 22 78 90 35 24 75 52 53
 1
743365444
98
 5
298137706 371378543 159326899 423775489 643749813
1 90 76 23 14
 5
2 52 60 67 26
51 96 75 41 88
 2
8 4
57 28
 5
12 4 19 18 19
15467 14873 66248 58962 90842
 1
380100964
63923
 2
3 2
55839 83916
 2
1000000000 1000000000
100000 100000
 2
5 3
96 59
 1
4
85648
 2
84 18
96 92
 5
4 2 4 3 3
8 9 34 54 14
 1
23
29532
 2
759394108 613490963
19556 57005
 1
1000000000
100000
 2
624526990 51492804
74 4
 1
1
72
 1
5
16
 2
86 67
77701 9079
 2
7 6
2374 9808
 5
487208130 193137490 653652531 77955217 628457798
37995 12724 66478 45619 87697
 1
204
74562
 5
82 90 21 10 3
37195 83314 87379 83209 32491
 5
3 10 9 5 8
12157 40766 83283 22455 29741
 10
1 4 2 3 5 1 3 5 4 2
95757 10134 79392 48220 34450 34587 61472 88154 76492 38800
 5
8 2 3 10 1
2 37 19 73 60
 1
3
31
 10
2 2 2 6 4 4 10 2 2 8
18 13 94 43 72 62 23 47 94 41
 10
97 75 68 98 56 44 68 24 40 18
75753 53146 17573 59200 87853 73083 67536 45475 70260 99681
 40
19 20 8 13 13 17 1 14 15 20 14 17 2 9 9 10 19 16 6 12 9 7 20 5 12 6 4 4 12 5 4 11 8 1 2 8 11 19 18 4
52258 5648 46847 9200 63940 79328 64407 54479 1788 60107 8234 64215 15419 84411 50307 78075 92548 17867 43456 7970 1390 99373 97297 90662 82950 678 79356 51351 2794 82477 16508 19254 81295 9711 72350 11578 21595 69230 82626 25134
 10
400625724 498124775 960958038 697226708 233136478 292118728 33139194 339478293 914271877 828083523
9789 90524 51162 97707 59267 60261 43260 60358 64419 44097
 10
2 5 1 9 1 2 7 8 1 10
38888 43309 35602 62895 51161 96523 20607 20309 21976 21231
 10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
 5
1 5 1 2 1
49027 92184 18591 86401 84238
 1
1
40825

1000000
 0
 593
 0
 0
 0
 0
 0
 66248
 0
 0
 100000
 0
 0
 0
 44
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 779373
 0
 0
 630
 17573
 6113465
 0
 255574
 4500000
 153827
 0

#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a < b) return b;
  return a;
}
void solve() {
  long long a, b, n, p;
  cin >> n;
  unordered_map<long long, int> umap;
  vector<long long> v, t;
  vector<pair<long long, long long> > vec;
  set<long long> s;
  for (int i = 0; i < n; i++) {
    long long te;
    cin >> te;
    v.push_back(te);
  }
  for (int i = 0; i < n; i++) {
    long long te;
    cin >> te;
    t.push_back(te);
  }
  for (int i = 0; i < n; i++) {
    vec.push_back(make_pair(t[i], v[i]));
  }
  sort(v.begin(), v.end());
  long long g = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > g) {
      g = v[i];
      s.insert(g);
    } else {
      g++;
      s.insert(g);
    }
  }
  sort(vec.begin(), vec.end());
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    auto e = s.lower_bound(vec[i].second);
    ans += vec[i].first * (*e - vec[i].second);
    s.erase(e);
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
