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

using namespace std;

const int N = 5 * 1E5 + 5;
const int MAX = 1E9;

int n, k, minim, maxim, limit;
int min_poz, max_poz;
int pref[N], suf[N], t[N];

int wyn[N];

bool check;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n >> k;

    min_poz = max_poz = limit = 0;
    minim = MAX + 1;
    maxim = 0;

    pref[0] = MAX + 1;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        pref[i] = min(pref[i - 1], t[i]);

        if (t[i] > maxim) {
            maxim = t[i];
            max_poz = i;
        }
        else if (t[i] == maxim) {
            max_poz = 0;
        }

        if (t[i] < minim) {
            minim = t[i];
            min_poz = i;
        }
        else if (t[i] == minim) {
            min_poz = 0;
        }

        if (i > 1) {
            if (t[i] <= t[i - 1]) 
                limit = i;
        }
    }

    for (int i = n; i >= 1; i--) {
        suf[i] = max(suf[i + 1], t[i]);
    }

    // cout << "LIMIT" << endl << limit << endl << "MAXIM" << endl << maxim << " " << max_poz << endl << "MINIM" << endl << minim << " " << min_poz << endl;

    check = false;

    if (k == 2) {
        for (int i = 1; i < n; i++) {
            if (pref[i] >= suf[i + 1]) {
                wyn[i] = true;
                check = true;
                break;
            }
        }
    }
    else if (k == 3) {
        if (min_poz != 1) {
            check = true;
            if (t[n] == minim) {
                wyn[n - 1] = true;
                wyn[n - 2] = true;
            }
            else {
                for (int i = 2; i < n; i++) {
                    if (t[i] == minim) {
                        wyn[i] = true;
                        wyn[i - 1] = true;
                        break;
                    }
                }
            }
        }
        else if (max_poz != n) {
            check = true;
            if (t[1] == maxim) {
                wyn[1] = true;
                wyn[2] = true;
            }
            else {
                for (int i = 2; i < n; i++) {
                    if (t[i] == maxim) {
                        wyn[i] = true;
                        wyn[i - 1] = true;
                        break;
                    }
                }
            }
        }
    }
    else if (k >= 4) {
        if (limit != 0) {
            check = true;
            if (limit == n) {
                for (int i = 1; i < k; i++) {
                    wyn[limit - i] = true;
                }
            }
            else {
                if (k - 1 <= limit) {
                    for (int i = 1; i < k; i++) {
                        wyn[limit - i + 1] = true;
                    }
                }
                else {
                    for (int i = 1; i < k; i++) {
                        wyn[i] = true;
                    }
                }
            }
        }
    }

    if (!check)
        cout << "NIE";
    else {
        cout << "TAK" << endl;
        for (int i = 1; i < n; i++) {
            if (wyn[i])
                cout << i << " ";
        }
    }
    
}