<p>There is a forest with an unknown number of rabbits. We asked n rabbits <strong>&quot;How many rabbits have the same color as you?&quot;</strong> and collected the answers in an integer array <code>answers</code> where <code>answers[i]</code> is the answer of the <code>i<sup>th</sup></code> rabbit.</p>

<p>Given the array <code>answers</code>, return <em>the minimum number of rabbits that could be in the forest</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> answers = [1,1,2]
<strong>Output:</strong> 5
<strong>Explanation:</strong>
The two rabbits that answered &quot;1&quot; could both be the same color, say red.
The rabbit that answered &quot;2&quot; can&#39;t be red or the answers would be inconsistent.
Say the rabbit that answered &quot;2&quot; was blue.
Then there should be 2 other blue rabbits in the forest that didn&#39;t answer into the array.
The smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn&#39;t.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> answers = [10,10,10]
<strong>Output:</strong> 11
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= answers.length &lt;= 1000</code></li>
	<li><code>0 &lt;= answers[i] &lt; 1000</code></li>
</ul>

class Solution {
public:
    int numRabbits(vector<int>& answers) {
        
        unordered_map< int , int > mp;


        for(int i=0; i< answers.size(); i++){

              mp[answers[i]]++;
        }
        int Rabbit =0;
      //  pair <int, int > p;
        while(mp.size() > 0){
          auto p = mp.begin();
          int colour = p->first;
          int freq = p->second;
          if(colour ==0) {
             Rabbit = Rabbit + (freq*(colour +1)) ;
              mp.erase(colour);
          }
          else if(freq <= colour +1){
            Rabbit = Rabbit + colour +1;
            mp.erase(colour);
          }
          else{
            Rabbit = Rabbit + colour +1;
             mp[colour] = freq - ( colour + 1 ) ;

          }
        
        }

        return Rabbit;
    }
};
12000