Wrong answer although the whole program logic seems to be working : <p>This is my solution to the problem <a href="http://codeforces.com/contest/129/problem/A" rel="nofollow noreferrer">Codeforces-D2A-129 Cookies</a>. The program outputs a wrong answer at testcase 11, which is: </p>

<p>82 </p>

<p>43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15</p>

<p>My program: </p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;algorithm&gt; // for count() and sort()
#include &lt;vector&gt;
using namespace std;

// function prototype
void erase_duplicates(vector&lt;int&gt; &amp;, int, int);

int main()
{
    int num; // number of bags of cookies
    int total = 0; // total number of cookies
    int ways = 0; // number of ways Olga can take a bag of cookies
    int duplicates = 0; // number of duplicates of an element
    scanf("%i", &amp;num); // getting number of bags of cookies

    vector&lt;int&gt; cookies(num); // number of cookies in the ith bag
    // getting number of cookies in each bag
    for(int i = 0; i &lt; num; i++)
        scanf("%i", &amp;cookies[i]);

    for(int j = 0; j &lt; num; j++) // calculating total number of cookies
        total += cookies[j];

    // sorting the input
    sort(cookies.begin(), cookies.end());

    for(int k = 0; k &lt; cookies.size(); k++)
    {
        if((total - cookies[k]) % 2 == 0)
        {
            // adding number of duplicates of the current element to the number of ways
            duplicates = count(cookies.begin(), cookies.end(), cookies[k]);
            ways += duplicates;
            // erasing the duplicates of that element
            erase_duplicates(cookies, cookies[k], k);
        }
    }
    //printing the possible number of ways
    printf("%i", ways);
    return 0;
}

// This function erases the duplicates of the element passed as the second argument.
// Parameters are: vector of integers, element, index of the element.
void erase_duplicates(vector&lt;int&gt; &amp;cookies, int value, int k){
    for(int i = k; i &lt; cookies.size(); i++){
        if(cookies[i] == value) // if it is a duplicate, remove it.
            cookies.erase(cookies.begin() + i);
    }
}
</code></pre>

<p>What's wrong with my code?</p>
