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
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> ans; ans.reserve(k - 1);
    for (int i = 0; i < n; i++) cin >> a[i];
    int flip = 0;
    for (int i = 1; i < n; i++) if (a[i] <= a[i - 1]) flip = i;
    if (!flip) goto bad;
    if (k >= 4) {
        // flip - 1 is >= flip
        // we'll take flip - 2, flip - 1, flip
        k--;
        int expecteds = 1;
        if (flip - 1 > 0) expecteds++;
        if (flip + 1 < n) expecteds++;;
        // if (flip != n - 1) k--;
        for (int i = 1; i < flip - 1; i++) {
            if (k <= expecteds) break;
            k--;
            ans.push_back(i);
        }
        if (flip - 1 > 0) {
            ans.push_back(flip - 1); k--;
        } 
        ans.push_back(flip); k--;
        if (flip + 1 < n) {
            ans.push_back(flip + 1); k--;
        }
        for (int i = flip + 2; i < n; i++) {
            if (!k) break;
            k--;
            ans.push_back(i);
        }
        goto ok;
    }
    if (k == 3) {
        int mn = a[0], mx = a[0];
        int mni = 0, mxi = 0;
        for (int i = 0; i < n; i++) {
            int v = a[i];
            if (v <= mn) {
                mn = v;
                mni = i;
            } 
            if (v >= mx) {
                if (v > mx) {
                    mxi = i;
                }
                mx = v;
                mxi = min(mxi, i);
            }
        }
        // cerr << mni << ' ' << mxi << endl;
        if (mni == 0 && mxi == n - 1) goto bad;
        if (mni != 0) {
            if (mni < n - 1) {
                ans = {mni, mni + 1};
            } else {
                ans = {1, mni};
            }
            goto ok;
        } else {
            if (mxi != 0) {
                ans = {mxi, mxi + 1};
            } else {
                ans = {1, 2};
            }
            goto ok;
        }
    }
    if (k == 2) {
        vector<int> mini(n), maxi(n);
        mini[0] = a[0];
        for (int i = 1; i < n; i++) mini[i] = min(mini[i - 1], a[i]);
        int mx = a[n - 1];
        for (int i = n - 1; i > 0; i--) {
            mx = max(mx, a[i]);
            if (mx <= mini[i - 1]) {
                ans = {i};
                goto ok;
            }
        }
        goto bad;
        // multiset<int> left, right;
        // for (int i = 0; i < n; i++) {
        //     right.insert(a[i]);
        // }
        // for (int i = 0; i < n - 1; i++) {
        //     right.erase(right.find(a[i]));
        //     left.insert(a[i]);
        //     if (*left.begin() >= *right.rbegin()) {
        //         ans.push_back(i + 1);
        //         goto ok;
        //     }
        // }
        // goto bad;
    }
    ok:
    cout << "TAK" << endl;
    for (int v : ans) cout << v << ' ';
    cout << endl; 
    return;
    bad:
    cout << "NIE" << endl; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

// #ifdef LOCAL
//     int t; cin >> t; while (t--)
// #endif

    solve();

    cout.flush();
}