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
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <ranges>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int INF = 1e9 + 1;

vector<int> solve3(vector<int> a, int k) {
    int n = (int)a.size();

    if (k == 2) {
        vector<int> pref(n), suf(n);

        partial_sum(all(a), pref.begin(),
                    [](int x, int y) { return min(x, y); });

        partial_sum(rall(a), suf.rbegin(),
                    [](int x, int y) { return max(x, y); });

        for (int i = 0; i < n - 1; i++) {
            if (pref[i] >= suf[i + 1]) {
                return {i};
            }
        }
        return {};
    }
    if (k == 3) {
        int mx = *max_element(all(a));
        int mn = *min_element(all(a));
        for (int i = 1; i < n - 1; i++) {
            if (a[i] == mx || a[i] == mn) {
                return {i - 1, i};
            }
        }
        return {};
    }
    for (int i = 0; i < n - 1; i++) {
        if (!(a[i] < a[i + 1])) {
            vector<int> res;
            for (int j = max(0, i - 1); j <= min(i + 1, n - 2); j++) {
                res.push_back(j);
            }
            return res;
        }
    }
    return {};
}

vector<int> solve2(vector<int> a, int k) {
    int n = (int)a.size();
    vector<int> r = solve3(a, k);
    if (r.empty()) return r;

    vector<int> res;
    for (int i = n - 2; i >= 0; i--) {
        if (!r.empty() && r.back() == i) {
            res.push_back(i);
            r.pop_back();
        } else if (r.size() + res.size() < k - 1) {
            res.push_back(i);
        }
    }
    reverse(all(res));
    return res;
}

void check(vector<int> a, int k, vector<int> res) {
    cout.flush();
    int n = (int)a.size();

    assert(res.size() == k - 1);
    int prev = -INF;
    for (auto &v : res) {
        assert(prev < v);
        assert(1 <= v + 1);
        assert(v + 1 < n);
        prev = v;
    }

    prev = -1;
    res.push_back(n - 1);

    vector<vector<int>> s;
    for (auto x : res) {
        s.push_back({});
        for (int i = prev + 1; i <= x; i++) s.back().push_back(a[i]);
        prev = x;
    }

    int sum = 0;
    for (auto x : s) sum += (int)x.size();
    assert(sum == n);

    assert(s.size() > 0);
    for (int i = 0; i < s.size() - 1; i++) {
        if (*min_element(all(s[i])) >= *max_element(all(s[i + 1]))) return;
    }
    assert(false);
}
void solve() {
    int n, k;
    vector<int> a;
    cin >> n >> k;
    a.resize(n);
    for (auto &x : a) cin >> x;

    vector<int> res = solve2(a, k);
    if (res.empty()) {
        cout << "NIE\n";
    } else {
        cout << "TAK\n";
        for (auto x : res) cout << (x + 1) << " ";
        cout << "\n";
        // check(a, k, res);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    cin.tie(0);
    solve();
}