All problems

Problem 477

Reduce Array Size to Half

Medium · 20 pts · Array, Hash Table, Greedy, Sorting

Problem

Choose a set of values and remove every occurrence of those values from the array. Find the smallest number of values you need to choose so that at least half of the array's elements are removed. Greedily, remove the most frequent values first: sort the frequencies in descending order and add them up until you reach half of N.

Input

First line: N. Second line: N integers.

Output

Print the minimum number of values to choose.

Constraints

1 <= N <= 100000; 1 <= A[i] <= 100000

Example input

10
3 3 3 3 5 5 5 2 2 7

Example output

2

Explanation

In 3 3 3 3 5 5 5 2 2 7 (10 elements), removing all 3s and 5s removes 7 elements, at least half. Any single value removes at most 4, so the answer is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Bag of Tokens Next: Single Number II