import java.util.*; public class Main { static int[] dp; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); HashMap> all = new HashMap<>(); for (int i = 0; i < n; i++) { Team t = new Team(i, sc.nextInt(), sc.nextInt(), sc.nextInt()); if (!all.containsKey(t.univ)) { all.put(t.univ, new PriorityQueue<>()); } all.get(t.univ).add(t); } PriorityQueue queue = new PriorityQueue<>(); for (PriorityQueue tmp : all.values()) { int idx = 0; while (tmp.size() > 0) { Team t = tmp.poll(); t.rank = idx; idx++; queue.add(t); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(queue.poll().idx).append("\n"); } System.out.print(sb); } static int dfw(int x) { if (x < 10) { return x; } if (dp[x] != -1) { return dp[x]; } int prev = x % 10; x /= 10; int next = 0; while (x > 0) { int cur = x % 10; x /= 10; next *= 10; next += (prev + cur) % 10 + (prev + cur) / 10; prev = cur; } dp[x] = dfw(next); return dp[x]; } static class Team implements Comparable { int idx; int score; int penalty; int univ; int rank; public Team(int idx, int score, int penalty, int univ) { this.idx = idx; this.score = score; this.penalty = penalty; this.univ = univ; } public int compareTo(Team another) { if (score == another.score) { if (rank == another.rank) { return penalty - another.penalty; } else { return rank - another.rank; } } else { return another.score - score; } } } }