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
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using llf = long double;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 1050000;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(69);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &x : a)
		cin >> x;
	auto report = [&](vector<pi> v) {
		assert(sz(v) == k);
		int cur = 0;
		bool good = 0;
		for (int i = 0; i < k; i++) {
			int nxtMin = 2e9;
			for (int j = v[i][0]; j <= v[i][1]; j++) {
				if (a[j] > cur)
					nxtMin = min(nxtMin, a[j]);
			}
			if (nxtMin > 1.9e9) {
				good = 1;
				break;
			}
			cur = nxtMin;
		}
		assert(good);
		cout << "TAK\n";
		// assert(v[0][0] == 0 && v[k - 1][1] == n - 1);
		for (int i = 1; i < k; i++) {
			//	assert(v[i - 1][1] + 1 == v[i][0]);
			cout << v[i][0] << " ";
		}
		cout << "\n";
	};
	int decpos = -1;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] >= a[i]) {
			decpos = i;
		}
	}
	if (decpos == -1) {
		cout << "NIE\n";
		return 0;
	}
	if (k >= 4) {
		int l = decpos - 1, r = decpos;
		int curInterval = 2 + (l > 0) + (r < n - 1);
		while (l - 1 > 0 && curInterval < k) {
			l--;
			curInterval++;
		}
		while (r + 1 < n - 1 && curInterval < k) {
			r++;
			curInterval++;
		}
		vector<pi> intv;
		if (l > 0)
			intv.push_back({0, l - 1});
		for (int i = l; i <= r; i++)
			intv.push_back({i, i});
		if (r + 1 < n)
			intv.push_back({r + 1, n - 1});
		report(intv);
		return 0;
	}
	if (k == 3) {
		int minval = *min_element(all(a));
		int maxval = *max_element(all(a));
		if (a[0] != minval) {
			int p = 0;
			while (a[p] != minval)
				p++;
			vector<pi> intv;
			if (p < n - 1) {
				intv.push_back({0, p - 1});
				intv.push_back({p, p});
				intv.push_back({p + 1, n - 1});
			} else {
				intv.push_back({0, p - 2});
				intv.push_back({p - 1, p - 1});
				intv.push_back({p, p});
			}
			report(intv);
			return 0;
		}
		if (a[n - 1] != maxval) {
			int p = n - 1;
			while (a[p] != maxval)
				p--;
			vector<pi> intv;
			if (p > 0) {
				intv.push_back({0, p - 1});
				intv.push_back({p, p});
				intv.push_back({p + 1, n - 1});
			} else {
				intv.push_back({0, 0});
				intv.push_back({1, 1});
				intv.push_back({2, n - 1});
			}
			report(intv);
			return 0;
		}
		for (int i = 1; i < n - 1; i++) {
			if (a[i] == minval || a[i] == maxval) {
				vector<pi> intv;
				intv.push_back({0, i - 1});
				intv.push_back({i, i});
				intv.push_back({i + 1, n - 1});
				report(intv);
				return 0;
			}
		}
		cout << "NIE\n";
		return 0;
	}
	assert(k == 2);
	vector<int> curmax = a;
	for (int i = n - 2; i >= 0; i--) {
		curmax[i] = max(curmax[i], curmax[i + 1]);
	}
	int curmin = 2e9;
	for (int i = 1; i < n; i++) {
		curmin = min(curmin, a[i - 1]);
		if (curmin >= curmax[i]) {
			vector<pi> intv;
			intv.push_back({0, i - 1});
			intv.push_back({i, n - 1});
			report(intv);
			return 0;
		}
	}
	cout << "NIE\n";
	return 0;
}