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

using namespace  std;

const int maxn=1e5+10;
const int mod=1e9+7;


std::vector<int> solve(std::vector<int> A)
{
    int n=A.size();
    bool ok2=1;
    vector<int>ans;
    if (ok2==1) {///Sub 2 and 3
        vector<pair<int,int>>eks;
        vector<int>d;
        vector<int>m;
        for (int i=0;i<n;i++) {
            int j=i-1;
            while (j+1<n && A[j+1]==A[i]) {
                j++;
            }
            int cnt=j-i+1;
            if (cnt%2==1) {
                eks.push_back({A[i],i+cnt-1});
                cnt--;
            }
            for (int idx=0;idx<cnt;idx++) {
                if (idx%2==0)
                ans.push_back(i+idx);
                if (idx%2==1)
                m.push_back(i+idx);
            }
            i=j;
        }
        sort(eks.begin(),eks.end());
        for (int idx=0;idx<eks.size()/2;idx++) {
            ans.push_back(eks[idx].second);
        }
        ans.push_back(eks.back().second);
        for (int idx=eks.size()/2;idx<eks.size()-1;idx++) {
            ans.push_back(eks[idx].second);
        }
        for (auto x:m) {
            ans.push_back(x);
        }
        return ans;
    }
}
