#include <bits/stdc++.h>
#include "festival.h"
#define pb push_back
#define fi first
#define se second
#define ll long long
using namespace std;
const ll MAX=1e17;
vector<pair<ll,ll>> t1,t2,t3,t4;
vector<int> max_coupons(int A, vector<int> P, vector<int> T) {
ll n=P.size(), a=A;
for(ll i=0; i<n; i++){
if(T[i]==1) t1.pb({P[i],i});
if(T[i]==2) t2.pb({P[i],i});
if(T[i]==3) t3.pb({P[i],i});
if(T[i]==4) t4.pb({P[i],i});
}
sort(t1.begin(),t1.end());
sort(t2.begin(),t2.end());
sort(t3.begin(),t3.end());
sort(t4.begin(),t4.end());
vector<int> atb;
for(ll i=0; i<t4.size(); i++) atb.pb(t4[i].se);
for(ll i=0; i<t3.size(); i++) atb.pb(t3[i].se);
for(ll i=0; i<t2.size(); i++) atb.pb(t2[i].se);
for(ll i=0; i<t1.size(); i++) atb.pb(t1[i].se);
return atb;
}