406790: GYM102556 F Riana and Fiber Chatroom
Description
Riana recently made a Fiber account! Fiber is an all-new healthy, fibrous chatroom system that obviously does not collect any data about you or your chats. Because Fiber is a Weast Korean service, its users follow an unusual lingustic tradition of Confucian respect based on age; essentially, rules on who uses informal language to refer to other people and who uses formal language to refer to their chatroom mates, within each Fiber chatroom.
A Fiber user must use informal language (talk informally) to a user of the same age or younger. A user must use formal language (talk formally) to older users. Age in Weast Korea is determined by year: users born in the same year are considered to be the same age, regardless of birthday. A user born on a date whose year is greater than the year of the birthdate of another user is considered to be younger. Similarly, A user born in a year less than that of another user is considered to be older.
The members of Girl's Generation. How would they talk to each other in their Fiber chatroom?
This sounds simple enough, except there is one other thing to consider. Users born on or before February 28 of a certain year are considered to be "fast year", and are considered to be the same age to users born in the immediately previous year, as well as those users born on the same year. Also, if two users in a Fiber chatroom has a common user who are considered to be the same age, then these two users are also the same age.
Refer to the sample cases and the notes section for an example of the rules above.
Riana is not very accustomed to this whole "talking formally" thing, so when she joins a chatroom with $$$N$$$ users already in it, she wants to bring some more users so that everyone in the chatroom (including the users that she brought in) can talk informally to each other. More formally, for every pair of users in the chatroom (including the new users), both users should talk to each other informally. Fortunately, Riana is sociable enough to bring along an arbitrary number of users, each with arbitrary birthdays to the chatroom. But she wants to bring the least number of users necessary to accomplish the task. Given that Riana's registered birthday in Fiber is $$$B$$$, help her accomplish this.
Please note that Riana's sometimes uses different birthdays to register in Fiber!
InputThe first line of input contains the integer $$$1 \leq N \leq 100000$$$, the number of people who are already in the Fiber chatroom that Riana wants to join. The second line of input contains Riana's birthday $$$B$$$ in the YYYY-MM-DD format or the YYYYY-MM-DD format. The next $$$N$$$ lines of input contains the birthdays of the people in the Fiber chatroom in the YYYY-MM-DD format or the YYYYY-MM-DD format. It is guaranteed that all of the given birthdays are valid dates. There will be no dates corresponding to leap days. Also, it is guaranteed that the year of each date will be at least $$$1000$$$ and no more than $$$99999$$$.
OutputThe first line of output should contain the number of people $$$p$$$ that Riana needs to bring along. Then, for each of the next $$$p$$$ lines, print the birthdates of the people she should add to the Fiber chatroom. Print all of them using the YYYY-MM-DD format, if the year of the birthdate is less than 10000, and YYYYY-MM-DD format otherwise. If there are multiple possible answers, print any one of them. If Riana does not need to bring users, then print $$$0$$$. If Riana cannot accomplish her task, then output $$$-1$$$.
ExamplesInput4 1999-09-13 1999-08-01 1999-05-15 1999-12-05 2000-05-30Output
1 2000-02-10Input
2 1999-07-25 1999-03-05 1996-09-03Output
3 1999-01-28 1998-01-03 1997-01-13Note
For the first sample case, Riana's Birthday $$$B$$$ is on September 13, 1999.
Tiffany, who was born on August 1, 1999, is the same age as Sunny, who was born on May 15, 1999, as well as Yuri, who was born on December 5, 1999. Tiffany is also older than Seohyun, born on May 30, 2000. This means that Seohyun, in turn, is younger than Tiffany, or any of the people born on 1999. Now, Riana brings in Sooyoung, who was born on February 10, 2000. Sooyoung is considered to be the same age as Seohyun, because they were born on the same year. Sooyoung is also considered to be the same age as Yuri, for example, because Sooyoung is considered to be "fast year". Now, because Yuri and Seohyun are both considered to be the same age as Sooyoung, Yuri and Seohyun are considered the same age too. It can be shown that, by adding Sooyoung to the chat, everyone will now talk to each other informally.
For the second sample case, Riana's Birthday $$$B$$$ is on July 25, 1999.
Joy, born on September 3, 1996, is older than both Riana, and Yeri, born on March 5, 1999. Riana and Yeri are of the same age. To make sure that Riana and Yeri should talk informally to Joy, Riana will bring three people. Let us label these three people as A, B, and C, as shown in the sample output. Riana and Yeri are considered the same age as A. A is also considered the same age as B. Therefore, Riana and Yeri are considered the same age as B. In this way, it can be shown that, when Riana adds A, B, and C to the chatroom, everyone will talk to each other informally.