cho.sh
Notes
Loading...

Parliamentary Election

Time limit

2s

Memory limit

128 MB

Problem

Dasom has a machine that can tell in advance which candidate each person will vote for. Once a person has decided on a candidate, that person will definitely vote for that candidate in the election.

There are N candidates in Hyeongtaek District, and Dasom is candidate number 1. After reading the residents' intentions, Dasom wants to bribe people who do not plan to vote for her so that their votes change to her. A bribed person will definitely vote for Dasom. A candidate is elected only when that candidate's vote count is strictly greater than the vote count of every other candidate.

For example, if candidate 1 has 5 votes, candidate 2 has 7 votes, and candidate 3 has 7 votes, Dasom can be elected by bribing one person who planned to vote for candidate 2 and one person who planned to vote for candidate 3.

Find the minimum number of people Dasom must bribe in order to be elected.

Input

The first line contains the number of candidates N. The next N lines contain, in order from candidate 1 to candidate N, the number of people who plan to vote for each candidate.

N is a positive integer no greater than 50, and each vote count is a positive integer no greater than 100.

Output

Output one line containing the minimum number of people Dasom must bribe.