Football Paradoxes
After the Brazilian national team won the World Cup in football, they were defeated by the Italian team. The Italian team then lost to the Bulgarian team, who subsequently lost to Luxembourg. Does this mean Luxembourg is stronger than Brazil?
Such paradoxes are common because victory in a match does not follow the property of transitivity. This means that the scenario described above does not necessarily imply that Luxembourg would win against Brazil. This concept intrigued Petya, prompting him to analyze the results of all the matches he knows. He aims to find the longest sequence of games with the following property: the winner of any match in this sequence (except the last one) must lose in the next match. Importantly, the chronological order of the games must be maintained, meaning each subsequent match in the sequence must occur after the previous one. Petya is not concerned whether the sequence of games ends with the same team it starts with. What matters most to him is the number of games in the sequence.
Input
The input file contains a chronologically sorted list of games, meaning each game occurs later than the previous one. The first line of the input file contains an integer n - the number of games played (0 < n ≤ 10000). Each of the following n lines provides a description of one game. Each game is represented by a seven-character string. The first three characters are the identifier of the winning team, the fourth character is a dash, and characters five to seven are the identifier of the losing team. Each team identifier is exactly three letters long and consists only of uppercase Latin letters. The total number of different team identifiers in the input file does not exceed 200.
Output
In the first line of the output file, print the maximum number of matches in the desired sequence. In the second line, print the sequence of teams, starting with the team that won the last match of the sequence and ending with the team that lost the first match. If there are multiple options for the longest sequences, print any one of them.