1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 99;
const int INF = 1e9 + 99;
int n,k;
int t[MAXN];

void solve2(){
	vector<int> pmin(n+2, INF);
	vector<int> pmax(n+2, -1);
	pmin[0] = t[0];
	pmax[n-1] = t[n-1];
	for(int i = 1; i < n; i++)
		pmin[i] = min(pmin[i - 1], t[i]);
	for(int i = n - 2; i >= 0; i--)
		pmax[i] = max(pmax[i + 1], t[i]);

	for(int i = 0; i < n - 1; i++){
		if(pmin[i] >= pmax[i + 1]){
			cout << "TAK\n" << i + 1 << "\n";
			return;
		}
	}
	cout << "NIE\n";
}

void solve3(){
	vector<int> pmin(n+2, INF);
	vector<int> pmax(n+2, -1);
	pmin[0] = t[0];
	pmax[n-1] = t[n-1];
	for(int i = 1; i < n; i++)
		pmin[i] = min(pmin[i - 1], t[i]);
	for(int i = n - 2; i >= 0; i--)
		pmax[i] = max(pmax[i + 1], t[i]);

	for(int i = 1; i < n - 1; i++){
		if(pmin[i - 1] >= t[i] ||  t[i] >= pmax[i + 1]){
			cout << "TAK\n" << i << " " << i + 1 << "\n";
			return;
		}
	}
	cout << "NIE\n";
}

void solve4(){
	for(int i = 0; i < n - 1; i++){
		if(t[i] >= t[i + 1]){
			cout << "TAK\n";
			for(int j = 1; j <= k - 4; j++){
				cout << j << " ";
			}
			if(i + 3 <= k - 2)
				cout << k - 2 << " " << k - 1 << " " << k;
			else{
				cout << i << " " << i + 1 << " " << i + 2;
			}
			cout << "\n";
			return ;
		}
	}
	cout << "NIE\n";
}

int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> t[i];
	if(k == 2)
		solve2();
	if(k == 3)
		solve3();
	if(k > 3)
		solve4();
}