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
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define e1 first
#define e2 second
#define pb push_back
#define OUT(x) {cout << x << "\n"; exit(0); }
#define TCOUT(x) {cout << x << "\n"; return; }
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define sz(x) int(x.size())
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

vi solve(vi input, int k) {
	int n = sz(input);
	vi pmin(n), smin(n), pmax(n), smax(n);
	rep(i, 0, n) {
		pmin[i] = input[i];
		pmax[i] = input[i];
		if (i > 0) {
			pmin[i] = min(pmin[i], pmin[i-1]);
			pmax[i] = max(pmax[i], pmax[i-1]);
		}
	}
	
	for (int i=n-1; i>=0; --i) {
		smin[i] = input[i];
		smax[i] = input[i];
		if (i != n-1) {
			smin[i] = min(smin[i], smin[i+1]);
			smax[i] = max(smax[i], smax[i+1]);
		}
	}
	
	int inv = -1;
	rep(i, 1, n) {
		if (input[i - 1] >= input[i]) inv = i;
	}
	
	if (inv == -1) return {};
	if (k > 3) {
		vi output = {};
		auto in_range = [&](int point) -> bool {
			return point >= 0 && point < n - 1;
		};
		
		if (in_range(inv - 2)) output.pb(inv - 2);
		if (in_range(inv - 1)) output.pb(inv - 1);
		if (in_range(inv)) output.pb(inv);
		if (in_range(inv + 1)) output.pb(inv + 1);
		rep(i, 0, inv - 2) {
			if (sz(output) < k - 1) output.pb(i);
		}
		rep(i, inv + 2, n -1) {
			if (sz(output) < k - 1) output.pb(i);
		}
		sort(all(output));
		return output;
	}
	else if (k == 3) {
		rep(i, 1, n-1) {
			if (pmin[i-1] >= input[i] || input[i] >= smax[i + 1]) return {i - 1, i};
		}
		return {};
	}
	else {
		assert(k == 2);
		rep(i, 1, n) {
			if (pmin[i-1] >= smax[i]) return {i - 1};
		}
		
		return {};
	}
}

#ifdef DEBUG
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#endif
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif

bool verify(vi input, vi output, int k) {
	if (sz(output) + 1 != k) return false;
	output.push_back(sz(input) - 1);
	for (int i=1; i<sz(output); ++i) {
		if (output[i - 1] >= output[i]) return false; // output sequence must be strictly increasing
	}
	
	int next = 0;
	vi perf = {INT_MIN};
	for (auto ending : output) {
		int cand = INT_MAX;
		for (int i = next; i <= ending; ++i) {
			int value = input[i];
			if (value > perf.back()) cand = min(cand, value);
		}
		if (cand == INT_MAX) return true; // successful - impossible to form an increasing sequence
		perf.push_back(cand);
		next = ending + 1;
	}
	
	return false;
}

int main() {
	boost;
	int n, k; cin >> n >> k;
	vector <int> vec(n);
	rep(i, 0, n) cin >> vec[i];
	auto ans = solve(vec, k);
	if (ans.empty()) cout << "NIE\n";
	else {
		cout << "TAK\n";
		//assert(verify(vec, ans, k));
		trav(entry, ans) cout << entry + 1 << ' ';
		cout << "\n";
	}
}