A regional sports federation is finalizing the fixture list for its upcoming season. There are n clubs signed up, listed in the order they registered. League rules require that every club hosts every other club exactly once at its own home ground over the season — so a match where club X hosts club Y is a distinct fixture from the match where club Y hosts club X, and every ordered pair of different clubs must appear as exactly one fixture.
Produce the complete fixture list, grouped by host club in registration order; within each host's block, list its fixtures against every other club in that club's registration order (skipping the host itself).
The first line contains one integer n, the number of clubs. The second line contains n space-separated club names (each a non-empty string of at most 20 letters and/or digits, no two clubs sharing the same name), listed in registration order.
Print n*(n-1) lines. For host index i from 1 to n (in registration order) and guest index j from 1 to n with j != i (in registration order), print a line "hostName guestName".
Example 1
Input
2 Falcons Wolves
Expected
Falcons Wolves Wolves Falcons
Explanation
There are 2 clubs. Falcons must host Wolves once, and Wolves must host Falcons once, giving exactly 2*(2-1)=2 fixtures: 'Falcons Wolves' (Falcons hosting) followed by 'Wolves Falcons' (Wolves hosting).
Example 2
Input
3 Red Blue Green
Expected
Red Blue Red Green Blue Red Blue Green Green Red Green Blue
Explanation
There are 3 clubs, so 3*2=6 fixtures. Red hosts Blue and Green in that order ('Red Blue', 'Red Green'), then Blue hosts Red and Green ('Blue Red', 'Blue Green'), then Green hosts Red and Blue ('Green Red', 'Green Blue').
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →