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
#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<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n)
        cin >> a[i];
    debug(n, k, a);

    const auto nin = n;
    const auto kin = k;
    const auto ain = a;
    const auto is_ok = [&nin, &kin, &ain](vector<int> v) {
        debug(v);

        assert(ssize(v) == kin - 1);
        assert(v[0] >= 0);
        assert(v.back() < nin - 1);
        REP(i, ssize(v) - 1)
            assert(v[i] < v[i + 1]);

        int last = 0;
        const int INF = (*max_element(ain.begin(), ain.end())) + 1;
        v.insert(v.begin(), -1);
        v.emplace_back(nin - 1);
        REP(i, ssize(v) - 1) {
            int cur = INF;
            FOR(j, v[i] + 1, v[i + 1]) {
                if (ain[j] > last) {
                    cur = min(cur, ain[j]);
                }
            }
            if (cur == INF) {
                return true;
            }
            last = cur;
        }
        return false;
    };

    const auto answer_no = [&] {
        cout << "NIE\n";
        exit(0);
    };
    const auto answer_yes = [&](const vector<int>& v) {
        cout << "TAK\n";
#ifdef LOCAL
        assert(is_ok(v));
#else
        for (auto e : v)
            cout << e + 1 << ' ';
        cout << '\n';
#endif
        exit(0);
    };

    if (k == 2) {
        vector<int> pref_min(n);
        pref_min[0] = a[0];
        FOR(i, 1, n - 1)
            pref_min[i] = min(pref_min[i - 1], a[i]);

        vector<int> suff_max(n);
        suff_max[n - 1] = a[n - 1];
        for (int i = n - 2; i >= 0; --i)
            suff_max[i] = max(suff_max[i + 1], a[i]);

        REP(i, n - 1) {
            if (pref_min[i] >= suff_max[i + 1]) {
                answer_yes({i});
            }
        }
        answer_no();
    }
    else if (k == 3) {
        const int min_elem = *min_element(a.begin(), a.end());
        const int max_elem = *max_element(a.begin(), a.end());
        FOR(i, 0, n - 2) {
            if (a[i] == max_elem) {
                vector<int> ans = {i};
                if (i == 0)
                    ans.emplace_back(i + 1);
                else
                    ans.emplace_back(i - 1);
                sort(ans.begin(), ans.end());
                answer_yes(ans);
            }
        }
        FOR(i, 1, n - 1) {
            if (a[i] == min_elem) {
                answer_yes({i - 1, i});
            }
        }
        answer_no();
    }
    else {
        assert(k >= 4);
        REP(i, n - 1) {
            if (a[i] >= a[i + 1]) {
                vector<int> ans;
                vector used(n - 1, false);
                auto take = [&](int x) {
                    if (x < 0 or x >= n - 1)
                        return;
                    if (not used[x]) {
                        used[x] = true;
                        ans.emplace_back(x);
                    }
                };
                take(i);
                take(i + 1);
                if (i > 0)
                    take(i - 1);
                int x = 0;
                while (ssize(ans) < k - 1) {
                    take(x);
                    ++x;
                }
                sort(ans.begin(), ans.end());
                answer_yes(ans);
            }
        }
        answer_no();
    }
    assert(false);
}