#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) {
    return a>b;
}
vector<int> solve(vector<int> A) {
    map<int, int> mp;
    vector<int> a, b, ans;
    mp.clear();
    a.clear();
    b.clear();
    ans.clear();
    bool used[A.size()+2];
    for (int i=0;i<A.size();i++) used[i]=false;
    set<int> s;
    s.clear();
    for (int i=0;i<A.size();i++) {
        mp[A[i]]++;
        s.insert(A[i]);
    }

    for (auto i:s) {
        if (mp[i]%2==1) {
            mp[i]--;
        }
    }
    for (int i=0;i<A.size();i++) {
        if (mp[A[i]]==0) continue;
        if (mp[A[i]]%2==0) {
            a.push_back(i);
            mp[A[i]]--;
            used[i]=true;
        }else {
            b.push_back(i);
            mp[A[i]]--;
            used[i]=true;
        }

    }
    int mx_ind=0;
    int mx=0;
    for (int i=0;i<A.size();i++) {
        if (!used[i]) {
            if (A[i]>mx) {
                mx=A[i];
                mx_ind=i;
            }
        }
    }
    used[mx_ind]=true;
    
    for (int i=0;i<a.size();i++) {
        ans.push_back(a[i]);
       // cout<<a[i]<<" ";
    }
    //cout<<endl;
    ans.push_back(mx_ind);
    for (int i=0;i<A.size();i++) if (!used[i]) ans.push_back(i);
   // cout<<mx_ind<<endl;
    for (int i=0;i<b.size();i++) {
        ans.push_back(b[i]);
        //cout<<b[i]<<" ";
    }
    return ans;
}