#include <iostream>
#include <cstring>
using namespace std;
const int MAX_SIZE = 20;
const int MAX_STUDENTS = 30;
struct Elev {
double medie;
char nume[MAX_SIZE + 1];
};
void sortare(int n, Elev elevi[]) {
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int changed = 0;
if (elevi[i].medie > elevi[j].medie) {
int medie = elevi[j].medie;
elevi[j].medie = elevi[i].medie;
elevi[i].medie = medie;
changed = 1;
}
if ((changed && elevi[i].medie < elevi[j].medie) || (elevi[i].medie == elevi[j].medie && strcmp(elevi[i].nume, elevi[j].nume) > 0)) {
char aux[MAX_SIZE + 1];
strcpy(aux, elevi[j].nume);
strcpy(elevi[j].nume, elevi[i].nume);
strcpy(elevi[i].nume, aux);
}
}
}
}
int main() {
Elev elevi[MAX_STUDENTS];
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> elevi[i].medie;
cin.getline(elevi[i].nume, MAX_SIZE + 1);
}
sortare(n, elevi);
for (int i = 0; i < n; ++i) {
cout << elevi[i].medie << ' ' << elevi[i].nume << '\n';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhfU0laRSA9IDIwOwpjb25zdCBpbnQgTUFYX1NUVURFTlRTID0gMzA7CgpzdHJ1Y3QgRWxldiB7CiAgZG91YmxlIG1lZGllOwogIGNoYXIgbnVtZVtNQVhfU0laRSArIDFdOwp9OwoKdm9pZCBzb3J0YXJlKGludCBuLCBFbGV2IGVsZXZpW10pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDE7ICsraSkgIHsKICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCBuOyArK2opIHsKICAgICAgICAgICAgaW50IGNoYW5nZWQgPSAwOwogICAgICAgICAgICBpZiAoZWxldmlbaV0ubWVkaWUgPiBlbGV2aVtqXS5tZWRpZSkgewogICAgICAgICAgICAgICAgaW50IG1lZGllID0gZWxldmlbal0ubWVkaWU7CiAgICAgICAgICAgICAgICBlbGV2aVtqXS5tZWRpZSA9IGVsZXZpW2ldLm1lZGllOwogICAgICAgICAgICAgICAgZWxldmlbaV0ubWVkaWUgPSBtZWRpZTsKICAgICAgICAgICAgICAgIGNoYW5nZWQgPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICgoY2hhbmdlZCAmJiBlbGV2aVtpXS5tZWRpZSA8IGVsZXZpW2pdLm1lZGllKSB8fCAoZWxldmlbaV0ubWVkaWUgPT0gZWxldmlbal0ubWVkaWUgJiYgc3RyY21wKGVsZXZpW2ldLm51bWUsIGVsZXZpW2pdLm51bWUpID4gMCkpIHsKICAgICAgICAgICAgICAgIGNoYXIgYXV4W01BWF9TSVpFICsgMV07CiAgICAgICAgICAgICAgICBzdHJjcHkoYXV4LCBlbGV2aVtqXS5udW1lKTsKICAgICAgICAgICAgICAgIHN0cmNweShlbGV2aVtqXS5udW1lLCBlbGV2aVtpXS5udW1lKTsKICAgICAgICAgICAgICAgIHN0cmNweShlbGV2aVtpXS5udW1lLCBhdXgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpIHsKCUVsZXYgZWxldmlbTUFYX1NUVURFTlRTXTsKCWludCBuOwoJY2luID4+IG47Cglmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewoJCWNpbiA+PiBlbGV2aVtpXS5tZWRpZTsKCQljaW4uZ2V0bGluZShlbGV2aVtpXS5udW1lLCBNQVhfU0laRSArIDEpOwoJfQoJc29ydGFyZShuLCBlbGV2aSk7Cglmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewoJCWNvdXQgPDwgZWxldmlbaV0ubWVkaWUgPDwgJyAnIDw8IGVsZXZpW2ldLm51bWUgPDwgJ1xuJzsKCX0KCXJldHVybiAwOwp9