Hide

Problem I
Imperfection

Mei has an array A of N integers. Currently, Mei considers the array to be imperfect. For Mei, an array is perfect if and only if its maximum element is also the majority element. An element is considered the majority element if and only if the number of times it appears is strictly greater than the total number of occurrences of all other elements. Formally, an array V is perfect if and only if count(Vi=max(V))>|V|count(Vi=max(V)).

Mei wants to delete some elements from A to make the array perfect. The deletion cost for the i-th element of A is Bi, and the total deletion cost is the sum of the individual costs.

Can you help Mei find the minimum cost to delete elements such that the resulting array is perfect?

Input

The first line of input contains one integer N (1N3×105), the number of elements in array A.

The second line of the input contains N integers Ai (1Ai3×105), the elements of A.

The third line of the input contains N integers Bi (1Bi3×105), the deletion cost of Ai.

Output

Output one line containing one integer denoting the minimum cost.

Sample Input 1 Sample Output 1
4
5 3 3 3
3 2 2 2
3
Sample Input 2 Sample Output 2
15
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
8 6 4 7 5 1 3 4 9 8 5 4 1 2 2
34
Hide

Please log in to submit a solution to this problem

Log in