#include <bits/stdc++.h>
#include "partition.h"

using namespace std;

const int MAXN = 3e7;

//vector<int> a;
int f[MAXN + 1];
int f2[MAXN + 1];
int fi[MAXN + 1];

/*void bkt( int k ) {
    int cateA, cateB, diff;
    long long sumA, sumB;
    if( k == n ) {
        i = sumA = sumB = cateA = cateB = 0;
        while( i < n && sumA < s2 )
            sumA += v[ind[i++]], cateA++;
        while( i < n )
            sumB += v[ind[i++]], cateB++;

        diff = abs( cateA - cateB );
        if( diff < mini ) {
            mini = diff;
            for( i = 0; i < n; i++ )
                perm[i] = ind[i];
        }
    } else {
        for( i = 0; i < n; i++ ) {
            if( !f[i] ) {
                f[i] = 1;
                ind[k] = i;
                bkt( k + 1 );
                f[i] = 0;
            }
        }
    }
}*/

/*void bkt( int k ) {
    int i;
    if( k == n ) {
        long long sumA;
        int cateA, cateB, diff;
        cateA = cateB = diff = 0;
        sumA = 0;
        i = 0;
        while( i < n && sumA < s2 ) {
            sumA += a[v[i]];
            cateA++;
            i++;
        }
        while( i < n ) {
            cateB++;
            i++;
        }
        diff = abs( cateA - cateB );
        if( diff < mini ) {
            mini = diff;
            for( i = 0; i < n; i++ )
                perm[i] = v[i];
        }
        //for( i = 0; i < n; i++ )
        //    cout << v[i] << ' ';
        //cout << '\n';
    } else {
        for( i = 0; i < n; i++ )
            if( !f[i] ) {
                f[i] = 1;
                v[k] = i;
                bkt( k + 1 );
                f[i] = 0;
            }
    }
}*/

std::vector<int> solve(std::vector<int> v) {
    //int i, n, diff, cateA, cateB, mini;
    //long long sumA, sumB, s, s2;
    int i, n;
    n = v.size();
    for( i = 0; i < n; i++ )
        f[v[i]]++;

    vector<int> rez;
    for( i = 0; i < n; i++ ) {
        f2[v[i]]++;
        if( f2[v[i]] <= f[v[i]] / 2 ) {
            rez.push_back( i );
            fi[i] = 1;
        }
    }
    for( i = 0; i < n; i++ )
        if( !fi[i] )
            rez.push_back( i );
    return rez;
}
