package yukicoder; import java.util.*; public class Q433 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int[] S = new int[N]; int[] P = new int[N]; String[] U = new String[N]; for (int i = 0; i < N; ++i) { S[i] = sc.nextInt(); P[i] = sc.nextInt(); U[i] = sc.next(); } Integer[] ord = new Integer[N]; for (int i = 0; i < N; ++i) { ord[i] = i; } Arrays.sort(ord, new Comparator() { @Override public int compare(Integer o1, Integer o2) { if (S[o1] != S[o2]) { return -Integer.compare(S[o1], S[o2]); } else { return Integer.compare(P[o1], P[o2]); } } }); int[] C = new int[N]; HashMap map = new HashMap<>(); for (int i = 0; i < N; ++i) { if (!map.containsKey(U[ord[i]])) { map.put(U[ord[i]], 0); } else { C[ord[i]] = map.get(U[ord[i]]) + 1; map.put(U[ord[i]], map.get(U[ord[i]]) + 1); } } Arrays.sort(ord, new Comparator() { @Override public int compare(Integer o1, Integer o2) { if (S[o1] != S[o2]) { return -Integer.compare(S[o1], S[o2]); } else if (C[o1] != C[o2]) { return Integer.compare(C[o1], C[o2]); } else if (P[o1] != P[o2]) { return Integer.compare(P[o1], P[o2]); } else { throw new AssertionError(); } } }); for(int i=0;i