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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   vi         = vector<int>;
using   pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

void run() {
	int n, k;
	cin >> n >> k;

	vi seq(n);
	each(e, seq) cin >> e;

	auto answer = [&](vi ends) {
		ends.erase(remove_if(all(ends), [&](int i) { return i < 0 || i >= n-1; }), ends.end());
		int pos = 0, splits = k-sz(ends)-1;
		cout << "TAK\n";
		each(e, ends) {
			while (pos < e && splits > 0) {
				cout << ++pos << ' ';
				splits--;
			}
			cout << e+1 << ' ';
			pos = e+1;
		}
		while (splits > 0) {
			cout << ++pos << ' ';
			splits--;
		}
		cout << '\n';
	};

	bool increasing = 1;

	rep(i, 1, n) if (seq[i-1] >= seq[i]) {
		if (k >= 4) {
			answer({i-2, i-1, i});
			return;
		}
		increasing = 0;
		break;
	}

	if (increasing) {
		cout << "NIE\n";
		return;
	}

	if (k == 2) {
		vi prefMin(n+1, INT_MAX), sufMax(n+1, INT_MIN);
		rep(i, 0, n) prefMin[i+1] = min(prefMin[i], seq[i]);
		for (int i = n-1; i >= 0; i--) sufMax[i] = max(sufMax[i+1], seq[i]);
		rep(i, 1, n) {
			if (prefMin[i] >= sufMax[i]) {
				answer({i-1});
				return;
			}
		}
	} else {
		assert(k == 3);
		int vMin = *min_element(all(seq)), vMax = *max_element(all(seq));
		rep(i, 1, n) {
			if (seq[i] == vMin) {
				answer({i-1, i});
				return;
			}
		}
		rep(i, 0, n-1) {
			if (seq[i] == vMax) {
				answer({i-1, i});
				return;
			}
		}
	}

	cout << "NIE\n";
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(10);
	run();
	cout << flush; _Exit(0);
}