Maximize MEX
Time limit1sMemory limit1024 MB
Given a multiset of N integers below N, repeatedly replace any chosen subset with its mex until one element remains. Find the largest possible final value.
Statement
A multiset of integers is given.
Initially, consists of elements .
Repeat the following operation as many times as you want until has exactly one element.
- Choose a non-empty subset of . Remove from , then insert into the smallest non-negative integer that does not appear in .
After performing the operations appropriately, find the maximum possible value of the single element left in .
Input
The first line contains an integer .
The second line contains the sequence of integers, separated by spaces.
Output
Print the maximum possible value of the element remaining in when the operations are performed appropriately.