#include <bits/stdc++.h>
#include <map>
using namespace std;
int main ()
{
multimap<double,string> mymultimap;
multimap<double,string>::iterator it;
int n;
double costoT=0.0, costo;
string nombre;
cin >> n;
while(n>0){
cin >> nombre >> costo;
costoT+=costo;
mymultimap.insert ( pair<double,string>(costo,nombre) );
n--;
}
int i=1;
for (it=mymultimap.end(), it--; it!=mymultimap.begin(); it--){
cout << i << " | " << (*it).second << " | " << (*it).first << '\n';
i++;
}
cout << i << " | " << (*it).second << " | " << (*it).first << '\n';
cout << '\n' << costoT;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxtYXA+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluICgpCnsKICBtdWx0aW1hcDxkb3VibGUsc3RyaW5nPiBteW11bHRpbWFwOwogIG11bHRpbWFwPGRvdWJsZSxzdHJpbmc+OjppdGVyYXRvciBpdDsKICBpbnQgbjsKICBkb3VibGUgY29zdG9UPTAuMCwgY29zdG87CiAgc3RyaW5nIG5vbWJyZTsKICBjaW4gPj4gbjsKICB3aGlsZShuPjApewogIAljaW4gPj4gbm9tYnJlID4+IGNvc3RvOwogIAljb3N0b1QrPWNvc3RvOwogIAlteW11bHRpbWFwLmluc2VydCAoIHBhaXI8ZG91YmxlLHN0cmluZz4oY29zdG8sbm9tYnJlKSApOwogIAluLS07CiAgfQogIGludCBpPTE7CiAgZm9yIChpdD1teW11bHRpbWFwLmVuZCgpLCBpdC0tOyBpdCE9bXltdWx0aW1hcC5iZWdpbigpOyBpdC0tKXsKICAJY291dCA8PCBpIDw8ICIgfCAiIDw8ICgqaXQpLnNlY29uZCA8PCAiIHwgIiA8PCAoKml0KS5maXJzdCA8PCAnXG4nOwogICAgaSsrOwogIH0KICBjb3V0IDw8IGkgPDwgIiB8ICIgPDwgKCppdCkuc2Vjb25kIDw8ICIgfCAiIDw8ICgqaXQpLmZpcnN0IDw8ICdcbic7CiAgY291dCA8PCAnXG4nIDw8IGNvc3RvVDsKICByZXR1cm4gMDsKfQ==