// 2024 IUSB Programming Competition // Round 2 Problem 1 // Sort Dates // Solution by Liguo Yu import java.util.Scanner; public class round2_p1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int size = input.nextInt(); String[] day = new String[size]; String[] month = new String[size]; int[] year = new int[size]; for(int i=0; i< size; i++) { day[i] = input.next(); month[i] = input.next(); year[i] = input.nextInt(); } for (int i = 0; i < size-1; i++) { int min_idx = i; for (int j = i+1; j < size; j++) { if (year[j] < year[min_idx]) { min_idx = j; } else if (year[j] == year[min_idx]) { if (compareMonth(month[j], month[min_idx]) < 0) { min_idx = j; } else if (compareMonth(month[j], month[min_idx]) == 0) { if (day[j].compareTo(day[min_idx]) < 0) { min_idx = j; } } } } int temp1 = year[min_idx]; year[min_idx] = year[i]; year[i] = temp1; String temp2 = month[min_idx]; month[min_idx] = month[i]; month[i] = temp2; String temp3 = day[min_idx]; day[min_idx] = day[i]; day[i] = temp3; } for(int i=0; i< size; i++) { System.out.println(day[i] + " " + month[i] + " " + year[i]); } } public static int compareMonth(String m1, String m2) { int n1 = Month2number(m1); int n2 = Month2number(m2); if(n1 < n2) return -1; else if (n1 == n2) return 0; else return 1; } public static int Month2number(String m) { int n = 0; if(m.equals("Jan")) n = 1; else if(m.equals("Feb")) n = 2; else if(m.equals("Mar")) n = 3; else if(m.equals("Apr")) n = 4; else if(m.equals("May")) n = 5; else if(m.equals("Jun")) n = 6; else if(m.equals("Jul")) n = 7; else if(m.equals("Aug")) n = 8; else if(m.equals("Sep")) n = 9; else if(m.equals("Oct")) n = 10; else if(m.equals("Nov")) n = 11; else if(m.equals("Dec")) n = 12; return n; } }