In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
In the time of Louis XIII and his powerful minister cardinal Richelieu in the Full Barrel Inn musketeers had consumed their meal and were drinking wine. Wine had not run short and therefore the musketeers were eager to quarrel, a drunken brawl broke out, in which each musketeer insulted all the others.
A duel was inevitable. But who should fight who and in what order? They decided (for the first time since the brawl they had done something together) that they would stay in a circle and draw lots in order. A drawn musketeer fought against his neighbor to the right. A looser "quit the game" and to be more precise his corpse was taken away by servants. The next musketeer who stood beside the looser became the neighbor of a winner.
After years, when historians read memories of the winner they realized that a final result depended in a crucial extent on the order of duels. They noticed that a fence practice had indicated, who against who could win a duel. It appeared that (in mathematical language) the relation "A beats B" was not transitive! It could happen that the musketeer A fought better than B, B better than C and C better than A. Of course, among three of them the first duel influenced the final result. If A and B fight as the first, C wins eventually. But if B and C fight as the first, A wins finally. Historians fascinated by their discovery decided to verify which musketeers could survive. The fate of France and the whole civilized Europe indeed depended on that!
persons with consecutive numbers from to are placed on a circle. They fight duels. In the first round one of these persons (e.g. with the number ) fights against its neighbor to the right, i.e. against the person numbered (or, if , against the person numbered ). A looser quits the game, and the circle is tighten so that the next person in order becomes a winner's neighbor. We are given the table with possible duels results, in the form of a matrix. If then the person with the number always wins with the person . If the person looses with . We can say that the person may win the game if there exists such a series of drawings, that wins the final duel.
Write a program which:
In the first line of the standard input an integer which satisfies the inequality is written. In each of the following lines appears one word consisting of digits 0 or 1. A digit on -th position in -th line denote . Of course , for . We assume that , for each .
In the first line of the standard output there should be written - the number of persons, who may win the game. In the following lines numbers of these persons should be written in ascending order, one number in each line.
For the input data:
7 1111101 0101100 0111111 0001101 0000101 1101111 0100001
the correct result is:
3 1 3 6
The order of duels: 1-2, 1-3, 5-6, 7-1, 4-6, 6-1 gives a final victory to the person numbered 6. You can also check that only two persons more (1 and 3) may win the game.
Task author: Wojciech Guzicki.