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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x)
#else
#define debug(...) {}
#endif

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int n, k;
	cin >> n >> k;
	vector t(n, 0);
	REP (i, n)
		cin >> t[i];
	bool ok = false;
	REP (i, n - 1)
		if (t[i] >= t[i + 1])
			ok = true;

	auto good = [&](vector<int> odp) {
		if (ssize(odp) != k - 1)
			return false;
		int last = 1, val = -1;
		odp.emplace_back(n);
		REP (i, k) {
			int nx = int(1e9 + 7);
			debug(last, odp[i]);
			FOR (j, last - 1, odp[i] - 1) {
				if (t[j] > val) {
					nx = min(nx, t[j]);
				}
			}
			if (nx == int(1e9 + 7))
				return true;
			val = nx;
			last = odp[i] + 1;
		}
		return false;
	};

	auto brute = [&]() {
		vector<int> tt;
		bool okk = false;
		function<void(int)> rek = [&](int x) {
			if (okk)
				return;
			if (x == n) {
				debug(tt);
				if (good(tt)) {
					okk = true;
					debug(tt);
				}
				return;
			}
			rek(x + 1);
			if (ssize(tt) < k - 1) {
				tt.emplace_back(x);
				rek(x + 1);
				tt.pop_back();
			}
		};
		rek(1);
		return okk;
	};

	auto no = [&]() {
#ifdef LOCAL
		assert(brute() == false);
		cout << "OK\n";
		exit(0);
#endif
		cout << "NIE\n";
		exit(0);
	};

	if (ok == false)
		no();

	auto wypisz = [&](vector<int> odp) {
#ifdef LOCAL
		assert(brute() == true);
		assert(ssize(odp) == k - 1);
		REP (i, k - 1) {
			assert(1 <= odp[i]);
			assert(odp[i] < n);
		}
		REP (i, k - 2)
			assert(odp[i] < odp[i + 1]);
		int last = 1, val = -1;
		bool okk = false;
		odp.emplace_back(n);
		REP (i, k) {
			int nx = int(1e9 + 7);
			debug(last, odp[i]);
			FOR (j, last - 1, odp[i] - 1) {
				if (t[j] > val) {
					nx = min(nx, t[j]);
				}
			}
			if (nx == int(1e9 + 7))
				okk = true;
			val = nx;
			last = odp[i] + 1;
		}
		assert(okk == true);
		odp.pop_back();
		cout << "OK\n";
		exit(0);
#endif

		cout << "TAK\n";
		REP (i, k - 1) {
			if (i)
				cout << ' ';
			cout << odp[i];
		}
		cout << '\n';
		exit(0);
	};

	auto solve_easy = [&]() {
		debug(t);
		set<int> odp;
		REP (i, n) {
			if (t[i] >= t[i + 1]) {
				odp.insert(i);
				odp.insert(i + 1);
				odp.insert(i + 2);
				break;
			}
		}
		odp.erase(0);
		odp.erase(n);
		debug(odp);
		FOR (i, 1, n - 1) {
			if (ssize(odp) == k - 1)
				break;
			debug(i);
			odp.insert(i);
		}
		debug(odp);
		vector ans(odp.begin(), odp.end());
		debug(ans);
		wypisz(ans);
	};

	auto solve_three = [&]() {
		auto pref = t;
		auto suff = t;
		FOR (i, 1, n - 1)
			pref[i] = min(pref[i], pref[i - 1]);
		for (int i = n - 2; i >= 0; --i)
			suff[i] = max(suff[i], suff[i + 1]);
		FOR (i, 1, n - 2)
			if (pref[i - 1] >= t[i] || suff[i + 1] <= t[i])
				wypisz({i, i + 1});
		no();
	};

	auto solve_two = [&]() {
		auto pref = t;
		auto suff = t;
		FOR (i, 1, n - 1)
			pref[i] = min(pref[i], pref[i - 1]);
		for (int i = n - 2; i >= 0; --i)
			suff[i] = max(suff[i], suff[i + 1]);
		REP (i, n - 1)
			if (pref[i] >= suff[i + 1])
				wypisz({i + 1});
		no();
	};

	if (k >= 4)
		solve_easy();

	if (k == 3)
		solve_three();

	if (k == 2)
		solve_two();
	assert(false);
}