All problems

Problem 988

Rabbits in Forest

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

Problem

Some rabbits in a forest were asked how many other rabbits have the same colour as them, and their answers are listed. Find the minimum possible number of rabbits in the forest. Rabbits answering x can share a colour group of size x + 1, so if c rabbits answered x, they need at least ceil(c / (x + 1)) groups, each of x + 1 rabbits. Add this up over the different answers.

Input

The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].

Output

Print the minimum number of rabbits in the forest.

Constraints

1 <= N <= 1000; 0 <= A[i] < 1000

Example input

3
1 1 2

Example output

5

Explanation

For answers 1 1 2, the two rabbits saying 1 can be one colour pair. The rabbit saying 2 belongs to a group of 3, two of whom were not asked. That makes 2 + 3 = 5 rabbits.

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

Previous: Minimize Maximum Pair Sum in Array Next: Flipping an Image