import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class prog { public static void main(String[] args) throws java.lang.Exception { BufferedReader bi = new BufferedReader(new InputStreamReader(System.in)); String line = null; List teams = new ArrayList(); Map teamMap = new HashMap(); while ((line = bi.readLine()) != null) { String[] data = line.split(" "); Integer goals1 = Integer.parseInt(data[2]); Integer goals2 = Integer.parseInt(data[3]); Team t1; Team t2; if(teamMap.containsKey(data[0])){ t1 = teamMap.get(data[0]); } else { t1 = new Team(); t1.name = data[0]; teamMap.put(data[0], t1); teams.add(t1); } if(teamMap.containsKey(data[1])){ t2 = teamMap.get(data[1]); } else { t2 = new Team(); t2.name = data[1]; teamMap.put(data[1], t2); teams.add(t2); } t1.goals += goals1; t2.goals += goals1; if(goals1 == goals2){ t1.points += 1; t2.points += 1; } else if(goals1 > goals2){ t1.points += 3; } else { t2.points += 3; } } Collections.sort(teams); for (int i = 0; i < teams.size(); i++) { System.out.println(teams.get(i).name); } bi.close(); } public static class Team implements Comparable{ String name; Integer goals = 0; Integer points = 0; public int compareTo(Team o) { if(o.points != points){ return o.points.compareTo(points); } if(o.goals != goals){ return o.points.compareTo(goals); } return name.compareTo(o.name); } } }