## Algorithm

C. Arthur and Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

In total the table Arthur bought has n legs, the length of the i-th leg is li.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.

A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

Input

The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

Output

Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

Examples
input
Copy
`21 53 2`
output
Copy
`2`
input
Copy
`32 4 41 1 1`
output
Copy
`0`
input
Copy
`62 2 1 1 3 34 3 5 5 2 1`
output
Copy
`8`

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 1;
int n, cs[N][201];
pair<int, int> all[N];
set<int> st;
map<int, pair<int, int> > mp;

int work(int val) {
int ret = 0;

int s = mp[val].first, e = mp[val].second;

for(int i = 0; i < 201; ++i)
ret += i * (cs[n - 1][i] - cs[e][i]);

int mxr = e - s + 1;
int otr = s;

if(mxr == otr) {
for(int i = 0; i < 201; ++i)
if(cs[s - 1][i] != 0) {
ret += i;
break;
}
} else if(mxr < otr) {
int need = otr - mxr + 1;
for(int i = 0; need > 0 && i < 201; ++i) {
if(cs[s - 1][i] >= need) {
ret += i * need;
break;
}
else {
need -= cs[s - 1][i];
ret += i * cs[s - 1][i];
}
}
}

return ret;
}

int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d", &all[i].first);
st.insert(all[i].first);
}
for(int i = 0; i < n; ++i)
scanf("%d", &all[i].second);
sort(all, all + n);

if(n == 1) {
puts("0");
return 0;
}

for(int i = 0; i < n; ++i) {
if(mp.count(all[i].first))
mp[all[i].first].second = i;
else {
mp[all[i].first].first = i;
mp[all[i].first].second = i;
}
}

++cs[0][all[0].second];
for(int i = 1; i < n; ++i) {
for(int j = 0; j < 201; ++j)
cs[i][j] = cs[i - 1][j];
++cs[i][all[i].second];
}

int res = 2e9;
for(set<int>::iterator it = st.begin(); it != st.end(); ++it)
res = min(res, work(*it));

printf("%d\n", res);

return 0;
}``````
Copy The Code &

Input

cmd
2
1 5
3 2

Output

cmd
2