Problem A
Foosball Dynasty
Balaji and his coworkers like to play Foosball on their
lunch break. Foosball is a game typically played by
![\includegraphics[width=0.5\textwidth ]{foos4}](/problems/foosball/file/statement/en/img-0001.png)
The remaining players wait in line for their turn to play. On each point, the players on the scoring team switch positions (e.g., if White scores the point, then the White Offense player becomes the White Defense player, and vice versa). The Offense player of the team that lost the point becomes the Defense player of the same team, while the Defense player of the team that lost the point goes to the back of the line and waits for their next chance to play. The person at the front of the line becomes the new Offense player of the team that lost the point.
Based on these rules, a team that continues scoring
consecutive points gets to keep playing together (swapping
positions with each other after each point) until the other
team breaks the streak. Each such streak of points creates a
dynasty for the winning team. Dynasties can be
short-lived (a single point) or long-lived, but they are always
broken when the opposing team scores a point. The “winners” of
this variation of foosball are the players that can create the
longest dynasty.
Input
Input begins with a line containing an integer
Output
Display the team that has achieved the longest dynasty. If more than one team ties for the record, then display each of these teams in chronological order of when the record was set, one team per line. When displaying a team, names should be displayed in the order in which the players arrived at the table for that team. Note that it is possible for the same team to appear more than once in the output, potentially with the player names in a different order.
Sample Input 1 | Sample Output 1 |
---|---|
6 Balaji David Alex Scott Andrew Ravi WWBWBBWBW |
Balaji Alex Andrew David |
Sample Input 2 | Sample Output 2 |
---|---|
6 Amy Jinu Kasey Sarah Sheetal Julia BBBBB |
Jinu Sarah |