import java.util.Date;
import java.util.TreeMap;
import java.util.Random;

public class Scheduler {
    // first two should be read from a file and not hardcoded
    public final static int TEAMS = 21;
    public final static String[] NAMES = { "SUN", "BOU", "MIN", "REA", "LAW", "LEX", "ALA", "TUL", "MOT", "NAS", "BAY", "CAL", "ROM", "PLE", "ANA", "NAZ", "ANC", "TEM", "DAV", "LAK", "DAK" };
    public final static int GAMES = 82;

    int totalGames;
    int homeMatrix[][];
    int awayMatrix[][];
    int maxGamesPerTeam;
    TreeMap<Float, Game> map = new TreeMap<Float, Game>();
    Random rnd = new Random(new Date().getTime()) ;


    public class Game {
	int home;
	int away;
	boolean scheduled = false;

	public Game(int home, int away) {
	    this.home = home;
	    this.away = away;
	}
    }

    public static void main(String args[]) {
	new Scheduler().createSchedule();
    }

    public boolean validateGame(int home, int away) {
	// teams have faced each other too many times
	if (homeMatrix[home][away] + homeMatrix[away][home] == maxGamesPerTeam)
	    return false;

	return true;
    }

    public int homeTotal(int home) {
	int total = 0;
	for (int i = 0; i < TEAMS; i++) {
	    total += homeMatrix[home][i];
	}
	return total;
    }

    public int awayTotal(int away) {
	int total = 0;
	for (int i = 0; i < TEAMS; i++) {
	    total += awayMatrix[away][i];
	}
	return total;
    }

    public boolean allScheduled() {
	for (Game game : map.values())
	    if (!game.scheduled)
		return false;
	return true;
    }

    public void createSchedule() {
	homeMatrix = new int[TEAMS][TEAMS];
	awayMatrix = new int[TEAMS][TEAMS];
	totalGames = TEAMS * GAMES / 2;

	// create balanced schedule
	int gamesPerTeam = GAMES / (TEAMS - 1);
	if (gamesPerTeam % 2 == 1)
	    gamesPerTeam--;
	for (int i = 0; i < TEAMS; i++) {
	    for (int j = 0; j < TEAMS; j++) {
		if (i == j)
		    continue;
		for (int k = 0; k < gamesPerTeam / 2; k++) {
		    Game game = new Game(i, j);
		    map.put(rnd.nextFloat(), game);
		    homeMatrix[i][j]++;
		    awayMatrix[j][i]++;
		}
	    }
	}

	// add unbalanced schedule
	while (map.size() < totalGames) {
	    int home = rnd.nextInt(TEAMS);
	    if (homeTotal(home) == GAMES / 2)
		continue;
	    int away = rnd.nextInt(TEAMS);
	    if (home == away || awayTotal(away) == GAMES / 2)
		continue;
	    if (!validateGame(home, away))
		continue;
	    Game game = new Game(home, away);
	    map.put(rnd.nextFloat(), game);
	    homeMatrix[home][away]++;
	    awayMatrix[away][home]++;
	}

	// assign games to day
	int day = 0;
	while (!allScheduled()) {
	    int mask = 0;
	    for (Game game : map.values()) {
		int homeBit = 1<<game.home;
		int awayBit = 1<<game.away;
		if (game.scheduled || ((mask & homeBit) != 0) || ((mask & awayBit) != 0))
		    continue;
		mask |= homeBit | awayBit;
		game.scheduled = true;
		System.out.println((day + 1) + "," + NAMES[game.home] + "," + NAMES[game.away]);
	    }
	    day++;
	}
    }
}