import java.io.BufferedReader; import java.io.IOException; 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 { static class Team implements Comparable{ private String name; private int goals; int points; public Team(String name, int goals, int points) { this.name = name; this.goals = goals; this.points = points; } @Override public int compareTo(Team o) { if (this.points > o.points) { return -1; } if (this.points < o.points) { return 1; } if (this.goals > o.goals) { return -1; } if (this.goals < o.goals) { return 1; } return name.compareTo(o.name); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Team team = (Team) o; if (goals != team.goals) return false; if (points != team.points) return false; if (name != null ? !name.equals(team.name) : team.name != null) return false; return true; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + goals; result = 31 * result + points; return result; } public void setGoals(int goals) { this.goals = goals; } public void setPoints(int points) { this.points = points; } public int getPoints() { return points; } public int getGoals() { return goals; } public String getName() { return name; } @Override public String toString() { return "Team{" + "name='" + name + '\'' + ", goals=" + goals + ", points=" + points + '}'; } } static int getPoints(int i1, int i2) { if (i1 > i2) { return 3; } if (i1 == i2) { return 1; } return 0; } static void update(Team t,int gMe, int gOther) { t.setGoals(t.getGoals() + gMe); t.setPoints(t.getPoints() + getPoints(gMe, gOther)); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Map teams = new HashMap(); for (int iiii = 0; iiii < 6; iiii++) { String line = br.readLine(); String [] split = line.split(" "); String n = split[0]; String n2 = split[1]; String g1 = split[2]; String g2 = split[3]; int gg1 = Integer.parseInt(g1); int gg2 = Integer.parseInt(g2); Team team = teams.get(n); if (team == null) { teams.put(n, new Team(n, gg1, getPoints(gg1, gg2))); } else { update(team, gg1, gg2); } Team team2 = teams.get(n2); if (team2 == null) { teams.put(n2, new Team(n2, gg2, getPoints(gg2, gg1))); } else { update(team2, gg2, gg1); } } List list = new ArrayList(teams.values()); Collections.sort(list); for (Team team : list) { System.out.println(team.getName()); // System.out.println(team.getName()); } } }