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
#include <bits/stdc++.h>
#define turbo cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define inf 1999999999
#define pb push_back

using namespace std;

bool impossible (vector <int> &input) {
    for (int i = 1; i < input.size(); i++)
        if (input[i] <= input[i - 1])
            return false;
    return true;
}

void solve2(vector <int> &input) {
    vector <int> pref_min = input;
    vector <int> suf_max = input;
    for (int i = 1; i < input.size(); i++)
        pref_min[i] = min(pref_min[i], pref_min[i - 1]);
    for (int i = input.size() - 2; i >= 0; i--)
        suf_max[i] = max(suf_max[i], suf_max[i + 1]);
    for (int i = 0; i < input.size() - 1; i++) {
        if (pref_min[i] >= suf_max[i + 1]) {
            cout << "TAK\n";
            cout << i + 1 << " ";
            return;
        }
    }
    cout << "NIE\n";
    return;
}

void solve3(vector <int> &input) {
    int mini = input[0];
    int maxi = input[0];
    for (auto &i : input) {
        mini = min(mini, i);
        maxi = max(maxi, i);
    }
    for (int i = 1; i < input.size() - 1; i++) {
        if (input[i] == maxi || input[i] == mini) {
            cout << "TAK\n";
            cout << i << " " << i + 1;
            return;
        }
    }
    if (input[0] = maxi && input[input.size() - 1] == mini) {
        cout << "TAK\n";
        cout << 1 << " " << input.size() - 1 << "\n";
        return;
    }
    cout << "NIE\n";
    return;
}

void solve4(vector <int> &input, int k) {
    set <int> result;
    for (int i = 1; i < input.size(); i++) {
        if (input[i] <= input[i - 1]) {
            result.insert(i);
            result.insert(i + 1);
            if (i - 1 > 0)
                result.insert(i - 1);
            int ptr = 1;
            while (result.size() < k) {
                if (result.count(ptr) == 0)
                    result.insert(ptr);
                ptr++;
            }
            break;
        }
    }
    cout << "TAK\n";
    for (auto &i : result)
        cout << i << " ";
}

int main() {
    turbo;
    int n, k;
    cin >> n >> k;
    vector <int> input(n);
    vector <int> pref_min(n);
    for (int i = 0; i < n; i++)
        cin >> input[i];
    // cout << n << " " << k << "\n";
    // for (auto &i : input)
    //     cout << i << " ";
    // cout << "\n";
    if (impossible(input)) {
        cout << "NIE\n";
        return 0;
    }
    if (k == 2) {
        solve2(input);
        return 0;
    }
    if (k == 3) {
        solve3(input);
        return 0;
    }
    solve4(input, k - 1);
    return 0;
}