QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#6580. The Construction

الإحصائيات

Byteasar would like to construct a racetrack in Byteotia. He competes with Bytemon, who would prefer building a ski jump, in gathering the funds necessary for the construction. Both projects are expensive, so Byteasar and Bytemon try to persuade The King of Byteotia for a donation.

The king must now choose one of the two options: either to provide funding for the racetrack or for the ski jump. For this purpose he would seek advice of the Chief Adviser, who is the head of the hierarchy of king's counsellors. Each counsellor is either an expert and provides his own recommendation, or leads a team of counsellors. Such a team leader recommends a decision, which is taken in accordance with the opinion of the majority of the members of his team. Fortunately, the number of counsellors in each team is odd. Therefore, the final decision depends only on the experts (i.e. counsellors not leading any of the teams). Each counsellor, with an exception of the Chief Adviser, has exactly one superior above him.

Byteasar and Bytemon are not waiting idly. They try to convince the experts to their case. It is not a simple task---persuading one expert takes exactly one day. When the expert is convinced there is no possibility he will change his opinion. It may happen that some of the experts at the very beginning already have a definite opinion that will not be changed.

Every day at dawn Byteasar selects one undecided expert and visits him in order to convince him. Bytemon does not like to get up so early, and so he selects an expert whom he wants to convince a bit later (and thus he loses a chance to convince the expert who already is busy, being persuaded by Byteasar). Rivals operate until all the experts would have a definite opinion. Byteasar and Bytemon know the hierarchy of the king's counsellors. Can Byteasar plan his lobbying activities in such a way that the Chief Advisor recommends the construction of the race track, regardless of how Bytemon would proceed?

Input

The first line of input contains one integer $n$ ($2 \leq n \leq 1000$), denoting the number of counsellors. The counsellors are numbered from $1$ do $n$. The counsellor numbered $1$ is the Chief Advisor. In the $i$-th of $n$ following lines there is a description of the $i$-th counsellor. It starts with an integer $c_i$ ($-2 \leq c_i \leq n$). If $c_i \leq 0$, the described counsellor is an expert (and his description consists only of number $c_i$). Values of $-2$, $-1$ and $0$ indicate that he is, respectively, in favour of building the racetrack, in favour of building the ski jump, or undecided. When $c_i \geq 1$, the number $c_i$ is odd, indicating that the advisor $i$ leads a team of counsellors consisting of $c_i$ members. Team member numbers are sequentially given in the following part of the line. Each counsellor with a number greater than $1$ belongs to exactly one team.

Output

If Byteasar cannot convince the experts that the Chief Advisor recommends the construction of the racetrack, your program should print one output line containing the word NIE (Polish for no). Otherwise, your program should produce two lines. The first one should contain the word TAK (Polish for yes), followed by the integer $d$, which states in how many ways Byteasar can choose an expert to be convinced on the first day, in order to be certain that when making optimal decisions in the following days, a favourable recommendation of the Chief Adviser would be obtained. The second line should contain a sequence of $d$ numbers of these very experts, in the increasing order. If, at the beginning, all the experts have definite opinions (and the recommendation of the Chief Adviser is beneficial to Byteasar), the program should print $d = 0$.

Example

Input

4
3 2 3 4
-2
0
-1

Output

TAK 1
3