public class Main { public static void main(String[] ar) { Scanner cin = new Scanner(System.in); int a = cin.nextInt(); List<Double> ts = new ArrayList<>(); List<Double> ty = new ArrayList<>(); for (int j = 0; j < a; j++) { String sex = cin.next(); double ma; double me; if (sex.equals("male")) { ma = cin.nextDouble(); ts.add(ma); } else { me = cin.nextDouble(); ty.add(me); } } ts.sort(new C2()); ty.sort(new C1()); for (double s : ts) { String st = String.format("%.2f", s); System.out.print(st); System.out.print(" "); } for (double s : ty) { String st = String.format("%.2f", s); System.out.print(st); System.out.print(" "); } } }
class C1 implements Comparator<Double> { @Override public int compare(Double o1, Double o2) { return o2.compareTo(o1); } }
class C2 implements Comparator<Double> { @Override public int compare(Double o1, Double o2) { return o1.compareTo(o2); } }