import java.util.*;
import java.io.*;
/**
 * Write a description of class p2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class p2
{
    
    public static void main(String args[]) throws Exception
    {
        //ArrayList<
        
        final String in = "DATA2.txt";
        final String out = "OUT2.txt";
        List<HighScoreRecord> highscoreRecords = new ArrayList<HighScoreRecord>();
        PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(out)));
        Scanner infile = new Scanner (new File(in));
        HighScoreRecord temp;
        int score = 0;
        String name = " ";
        
        
        while(infile.hasNextLine()) //repeat while not end of file
        {
            highscoreRecords.clear();
            for (int x = 0; x < 5; x++)
            {
                score = infile.nextInt();
                name = infile.nextLine();
                
                if (highscoreRecords.size() == 0)
                {
                    highscoreRecords.add(new HighScoreRecord(score, name));
                }
                else
                {
                    for (int y = 0; y <= highscoreRecords.size()-1; y++)
                    {
                        if (score > highscoreRecords.get(y).getScore() && y==highscoreRecords.size()-1)
                        {
                            highscoreRecords.add(new HighScoreRecord(score, name));
                            y=9999;
                        }
                        else if (score == highscoreRecords.get(y).getScore() && y==highscoreRecords.size()-1)
                        {
                            highscoreRecords.add(y, new HighScoreRecord(score, name));
                            y=9999;
                        }
                        else if (score > highscoreRecords.get(y).getScore() && score < highscoreRecords.get(y+1).getScore())
                        {
                            highscoreRecords.add(y+1, new HighScoreRecord(score, name));
                            y=9999;
                        }
                        else if (score == highscoreRecords.get(y).getScore())
                        {
                            highscoreRecords.add(y, new HighScoreRecord(score, name));
                            y=9999;
                        }
                    }
                }
            }
            
            for (int x = highscoreRecords.size()-1; x >= 0; x--)
            {
                outfile.println(highscoreRecords.get(x));
            }
                
        }
        
        outfile.close();
        
        
        
    }
    
    public static class HighScoreRecord
    {
        String name;
        int score;
        public HighScoreRecord(int score, String name)
        {
            this.name = name;
            this.score = score;
        }
        
        public String toString()
        {
            return this.name.trim();
        }
        
        public int getScore()
        {
            return this.score;
        }
        
        public String getName()
        {
            return this.name;
        }
        
        
        
    }
}

