#include "partition.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> solve(std::vector<int> a) {
    vector<pair<int,int>>v(a.size());
    int n = v.size();
    for ( int i = 0 ; i < n ; ++ i ) v[i]=make_pair(a[i],i);
    sort(v.begin(),v.end());
    int i = n - 1 ;
    vector<int>r;
    vector<bool>fr(n+1,0);
    while ( i >= 2 ){
    if ( v[i].first == v[i-1].first * v[i-2].first ){
    r.push_back(v[i-1].second);
    r.push_back(v[i-2].second);
    fr[v[i-1].second]=1;
    fr[v[i-2].second]=1;
    i -= 3 ;
    }
    else {
    r.push_back(v[i].second);
    fr[v[i].second]=1;
    --i;
    }
    }
    for ( int j = 0 ; j < n ; ++ j ) if ( !fr[j] ) r.push_back(j);
    return r ;
}

