#include "bits/stdc++.h" #define REP(i,n,N) for(ll i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll inf=1e18; ll N, K; int main(){ while(cin>>N>>K){ pair, ll> A[100010]; ll S[100010], P[100010], U[100010]; map m; map>> last; REP(i,0,N){ cin>>S[i]>>P[i]>>U[i]; U[i]--; m[U[i]]++; last[P[i]].push_back({-S[i],i}); } REP(i,0,N){ A[i] = {{-S[i],m[U[i]]},P[i]}; } sort(A,A+N); REP(i,0,K){ REP(j,0,last[A[i].second].size()) { if(last[A[i].second][j].first == A[i].first.first){ p(last[A[i].second][j].second); break; } } } } return 0; }