#include<iostream>
#include<string>
using namespace std;
const int N = 100010;
struct student{
string id, name;
int grade;
bool operator!=(const student &s) const{
return id != s.id;
}
}s[N];
int n, c;
int cmp(student &a, student &b, int c){
if(c == 2 && a.name != b.name) return a.name < b.name;
if(c == 3 && a.grade != b.grade) return a.grade < b.grade;
return a.id < b.id;
}
void quick_sort(int l, int r, int c){
if(l >= r) return;
int i = l - 1, j = r + 1;
student x = s[l + r >> 1];
while(i < j){
do i ++; while(cmp(s[i], x, c));
do j --; while(!cmp(s[j], x, c) && s[j] != x);
if(i < j) swap(s[i], s[j]);
}
quick_sort(l, j, c);
quick_sort(j + 1, r, c);
}
int main(){
cin >> n >> c;
for(int i = 0; i < n; i ++){
string id, name;
int grade;
cin >> id >> name >> grade;
s[i] = {id, name, grade};
}
quick_sort(0, n - 1, c);
for(int i = 0; i < n; i ++)
cout << s[i].id << ‘ ‘ << s[i].name << ‘ ‘ << s[i].grade << endl;
return 0;
}
1028 List Sorting (25 分)