P3497 [POI 2010] KOL-Railway
Description
A railroad siding consists of two (dead-end) sidetracks 1 and 2.
The siding is entered by track A, and left by track B (see figure below).
There are  cars on track A, numbered from  to .
They are arranged in such a way that they enter the siding in the order .
The cars are to be transferred to the siding, so that they leave it by track B in the order .
Each car is to be transferred once from track A to one of the sidetracks 1 or 2, and later (possibly after some transfers of the remaining cars) once from that sidetrack to the track B.
The sidetracks are long enough to store even the longest trains, so there is no need to worry about their capacity.
Input Format
The first line of the standard input holds one integer  () that denotes the number of cars for transfer.
The second line stores the numbers  that are a permutation of  (i.e., each  belongs to , and all these numbers are unique), separated by single spaces.
Output Format
The first line of the standard output should contain the word TAK (yes in Polish) if there is a way of transferring the cars so that they enter track B in the order , or the word NIE (no in Polish) if it is impossible.
If the answer is TAK, the second line should give, separated by single spaces, the numbers of sidetracks (1 or 2) to which successive cars  are moved in a correct transfer.
If there are several ways of making the transfer, choose one arbitrarily.
Explanation/Hint
对于 $100\%$ 的数据,有 $n \le 1 \times 10^5$。