#include "partition.h"
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
std::vector<int> solve(std::vector<int> A)
{
    vector<int>ans;
    vector<int>other;
    /*vector<pair<int,int>>v;
    for(int i=0;i<A.size();i++)
    {
        v.push_back({A[i],i});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i+=2)
    {
        ans.push_back(v[i].second);
        other.push_back(v[i+1].second);
    }*/

    map<int,int>cnt;
    map<int,bool>marked;
    for(int i=0;i<A.size();i++)
    {
        cnt[A[i]]++;
    }

    for(auto [key,val]:cnt)
    {
        if(val%2==0)marked[key]=1;
    }

    vector<int>left;
    for(int i=0;i<A.size();i++)
    {
        if(marked[A[i]]==1)
        {
            if(cnt[A[i]]%2==0)ans.push_back(i);
            else other.push_back(i);
            cnt[A[i]]--;
        }
        else left.push_back(i);
    }

    n=left.size();
    if(n%2==0){
    for(int i=1;i<n/2;i++)
    {
        ans.push_back(left[i-1]);
    }
    ans.push_back(left[n-1]);
    for(int i=n/2;i<n;i++)
    {
        other.push_back(left[i-1]);
    }}
    else
    {
        for(int i=1;i<=n/2;i++)
        {
            ans.push_back(left[i-1]);
        }
        ans.push_back(left[n-1]);
        for(int i=n/2+1;i<n;i++)
        {
            other.push_back(left[i-1]);
        }
    }


    for(int x:other)ans.push_back(x);
    return ans;
}
