import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n=Integer.valueOf(input.nextLine());
String name[]=new String[n];
for(int i=0;i<n;i++)
{
name[i]=input.nextLine();
}
String grade[]=new String[n];
for(int i=0;i<n;i++)
{
grade[i]=name[i].substring(name[i].length()-2,name[i].length());
}
Arrays.sort(grade);
for(int i=0;i<n;i++)
{
if(name[i].contains(grade[n-1]))System.out.println(name[i]);
}
for(int i=0;i<n;i++)
{
if(name[i].contains(grade[n-2]))System.out.println(name[i]);
}
}
}
컴파일 정상적으로 되고 잘 작동하는데 WA떠서 봐주셨으면 좋겠습니다