import collections import heapq def read_data(): N, K = map(int, input().split()) db = [collections.defaultdict(list) for _ in range(11)] for teamID in range(N): s, p, u = map(int, input().split()) db[s][u].append((-p, teamID)) return N, K, db def solve(N, K, db): ans = [] counter = [0] * (10**5 + 1) for dbs in db[::-1]: if not dbs: continue result = solve_core(dbs, counter) ans.extend(result) if len(ans) >= K: return ans[:K] def solve_core(dbs, counter): ans = [] que = [] for univID, lst in dbs.items(): lst.sort() p = -lst[-1][0] teamID = lst[-1][1] que.append((counter[univID], p, teamID, univID)) counter[univID] += 1 del lst[-1] heapq.heapify(que) while que: counts, p, teamID, univID = que[0] ans.append(teamID) lst = dbs[univID] if lst: p, teamID = lst[-1] heapq.heapreplace(que, (counts + 1, p, teamID, univID)) del dbs[univID][-1] counter[univID] += 1 else: heapq.heappop(que) return ans N, K, db = read_data() ans = solve(N, K, db) for univ_key in ans: print(univ_key)