#C352. Frisbee Tournament Scheduler

    ID: 46956 Type: Default 1000ms 256MiB

Frisbee Tournament Scheduler

Frisbee Tournament Scheduler

You are given n teams participating in a frisbee tournament. Every pair of teams must play exactly one match against each other. However, in one round, a team can play at most one match. Your task is to schedule all the matches in a minimal number of rounds such that in each round, no team plays more than once.

Details:

  • Generate all possible pairs of teams.
  • In each round, select as many matches as possible such that no team appears twice.
  • Continue until all matches are scheduled.

The output should first contain the total number of rounds, followed by the matches in each round. Matches within a round are printed one per line in the format TeamA TeamB and rounds are separated by a blank line.

Note: If there are multiple valid schedules, any one is acceptable.

inputFormat

The input is read from standard input. The first line contains an integer n representing the number of teams. Each of the following n lines contains a string representing the name of a team.

outputFormat

The output should be printed to standard output. The first line contains the number of rounds. For each round, each match is printed on a new line in the format TeamA TeamB. Rounds are separated by a blank line.

## sample
4
TeamA
TeamB
TeamC
TeamD
3

TeamA TeamB TeamC TeamD

TeamA TeamC TeamB TeamD

TeamA TeamD TeamB TeamC

</p>