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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <bits/stdc++.h>

using namespace std;

constexpr int MINF = 1, INF = 1000000000;

void print(vector<int> const& v) {
    for (int i : v)
        cout << i << ' ';
    cout << '\n';
}

void solve2(int n, vector<int> const& a) {
    vector<int> mins(n + 1), maxs(n + 1);
    mins[0] = INF;
    for (int i = 1; i <= n; ++i)
        mins[i] = min(mins[i - 1], a[i - 1]);

    maxs[n] = MINF;
    for (int i = n - 1; i >= 0; --i)
        maxs[i] = max(maxs[i + 1], a[i]);

    for (int i = 1; i < n; ++i) {
        if (mins[i] >= maxs[i]) {
            cout << "TAK\n";
            vector<int> r {i};
            print(r);
            return;
        }
    }

    cout << "NIE\n";
}

pair<bool, bool> is_special(int n, vector<int> const& a) {
    bool min_special = true;
    for (int i = 1; i < n; ++i) {
        if (a[0] >= a[i])
            min_special = false;
    }

    bool max_special = true;
    for (int i = 0; i < n - 1; ++i) {
        if (a[n - 1] <= a[i])
            max_special = false;
    }

    return make_pair(min_special, max_special);
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int &i : a)
        cin >> i;

    bool strictly_increasing = true;
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] >= a[i])
            strictly_increasing = false;
    }

    if (strictly_increasing) {
        cout << "NIE\n";
        return;
    } // exists i s.t. a[i - 1] >= a[i]

    if (k >= 4) {
        // for i s.t. a[i - 1] >= a[i]
        // [...|a[i - 1]|a[i]|...]
        cout << "TAK\n";

        int j;
        for (int i = 1; i < n; ++i) {
            if (a[i - 1] >= a[i]) {
                j = i;
                break;
            }
        }

        vector<int> r;

        if (j == 1) {
            r.push_back(j);
            r.push_back(j + 1);
            int to_print = k - 3, x = 2;
            while (to_print > 0) {
                r.push_back(j + x);
                ++x;
                --to_print;
            }
        } else if (j == n - 1) {
            r.push_back(j);
            int to_print = k - 2, x = 1;
            while (to_print > 0) {
                r.push_back(j - x);
                ++x;
                --to_print;
            }
            reverse(r.begin(), r.end());
        } else {
            int to_print = k - 4, print_now = 1;
            while (to_print > 0) {
                if (print_now == j - 1)
                    break;
                r.push_back(print_now++);
                --to_print;
            }

            r.push_back(j - 1);
            r.push_back(j);
            r.push_back(j + 1);
            print_now = j + 2;

            while (to_print > 0) {
                r.push_back(print_now++);
                --to_print;
            }
        }

        print(r);

        return;
    } // k <- [2, 3]

    if (k == 2) {
        solve2(n, a);
        return;
    } // k = 3

    auto [min_spec, max_spec] = is_special(n, a);
    if (min_spec && max_spec) {
        cout << "NIE\n";
        return;
    } // is not special

    // single out a min or a max
    cout << "TAK\n";

    if (min_spec) {
        // single out a max
        auto it = std::max_element(a.begin(), a.end());
        auto i = std::distance(a.begin(), it) + 1;
        vector<int> r;
        if (i == 1) {
            r.push_back(i);
            r.push_back(i + 1);
        } else {
            r.push_back(i - 1);
            r.push_back(i);
        }
        print(r);
    } else {
        // single out a min
        auto it = std::min_element(a.begin(), a.end());
        auto i = std::distance(a.begin(), it) + 1;
        if (i == 1) {
            it = std::min_element(++it, a.end());
            i = std::distance(a.begin(), it) + 1;
        }
        vector<int> r;
        r.push_back(i - 1);
        r.push_back(i);
        print(r);
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}