[POI2010] KOL-Railway

题目描述

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 ![](http://main.edu.pl/images/OI17/kol-en-tex.1.png) cars on track A, numbered from ![](http://main.edu.pl/images/OI17/kol-en-tex.2.png) to ![](http://main.edu.pl/images/OI17/kol-en-tex.3.png). They are arranged in such a way that they enter the siding in the order ![](http://main.edu.pl/images/OI17/kol-en-tex.4.png). The cars are to be transferred to the siding, so that they leave it by track B in the order ![](http://main.edu.pl/images/OI17/kol-en-tex.5.png). 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. 数据范围10W的双栈排序..双栈排序是啥呢?给你一个序列和两个栈,每次你可以把序列头入到两个栈的任意一个,或者把两个栈的任意一个弹出到最终序列,最后要求最终序列是有序的,求一种字典序最小的入栈方案

输入输出格式

输入格式


The first line of the standard input holds one integer ![](http://main.edu.pl/images/OI17/kol-en-tex.6.png) (![](http://main.edu.pl/images/OI17/kol-en-tex.7.png)) that denotes the number of cars for transfer. The second line stores the numbers ![](http://main.edu.pl/images/OI17/kol-en-tex.8.png) that are a permutation of ![](http://main.edu.pl/images/OI17/kol-en-tex.9.png) (i.e., each ![](http://main.edu.pl/images/OI17/kol-en-tex.10.png) belongs to ![](http://main.edu.pl/images/OI17/kol-en-tex.11.png), and all these numbers are unique), separated by single spaces.

输出格式


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 ![](http://main.edu.pl/images/OI17/kol-en-tex.12.png), 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 ![](http://main.edu.pl/images/OI17/kol-en-tex.13.png) are moved in a correct transfer. If there are several ways of making the transfer, choose one arbitrarily.

输入输出样例

输入样例 #1

4
1 3 4 2

输出样例 #1

TAK
1 1 2 1

说明

$n \le 10^5$