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
#include <iostream>

using namespace std;

void cin_tab(int a[], int n) {
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
}

void cout_tab(int a[], int n) {
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
}

void front_min(int a[], int fmin[], int n) {
    fmin[0] = a[0];
    for (int i = 1; i < n; ++i) {
        fmin[i] = min(fmin[i - 1], a[i]);
    }
}

void back_max(int a[], int bmax[], int n) {
    bmax[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        bmax[i] = max(bmax[i + 1], a[i]);
    }
}

int k2(int a[], int n) {
    int fmin[n];
    front_min(a, fmin, n);
    int bmax[n];
    back_max(a, bmax, n);
    for (int i = 0; i < n - 1; ++i) {
        if (fmin[i] > bmax[i + 1]) {
            return i + 1;
        }
    }
    return -1;
}

int max_tab(int a[], int n) {
    int idx = -1;
    int val = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] > val) {
            val = a[i];
            idx = i;
        }
    }
    return idx;
}

int min_tab(int a[], int n) {
    int idx = -1;
    int val = 1000000001;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= val) {
            val = a[i];
            idx = i;
        }
    }
    return idx;
}

int inc_tab(int tab[], int n) {
    int rift = -1;
    for (int i = 0; i < n - 1; ++i) {
        if (tab[i] >= tab[i + 1]) {
            rift = i;
        }
    }
    return rift;
}

int fill_a(int tab[], int n, int rift) {
    int idx = -1;
    for (int i = 0; i < n && i < rift - 1; ++i) {
        tab[i] = i + 1;
        idx = i;
    }
    return idx;
}

void fill_b(int tab[], int n, int start, int rift_end) {
    int inc = 0;
    for (int i = start; i < n; ++i) {
        tab[i] = rift_end + inc;
        inc++;
    }
}

void comp(int a[], int b[], int n, int k) {

    if (k == 2) {
        b[0] = k2(a, n);
        if (b[0] > 0) {
            cout << "TAK" << '\n';
            cout_tab(b, k - 1);
        } else {
            cout << "NIE" << '\n';
        }
    } else if (k == 3) {
        int max3 = max_tab(a, n);
        if (max3 == 0) {
            b[0] = 1;
            b[1] = 2;
            cout << "TAK" << '\n';
            cout_tab(b, k - 1);
        } else if (max3 == n - 1) {
            int min3 = min_tab(a, n);
            if (min3 == 0) {
                cout << "NIE" << '\n';
            } else {
                b[0] = min3;
                b[1] = min3 + 1;
                cout << "TAK" << '\n';
                cout_tab(b, k - 1);
            }
        } else {
            b[0] = max3;
            b[1] = max3 + 1;
            cout << "TAK" << '\n';
            cout_tab(b, k - 1);
        }

    } else {
        int rift = inc_tab(a, n);
        if (rift >= 0) {
            if (rift == 0 || rift == 1) {
                b[0] = 1;
                b[1] = 2;
                b[2] = 3;
                fill_b(b, k - 1, 3, 4);
                cout << "TAK" << '\n';
                cout_tab(b, k - 1);
            } else if (rift == n - 2) {
                fill_a(b, k - 4, rift);
                b[k - 2] = n - 1;
                b[k - 3] = n - 2;
                b[k - 4] = n - 3;
                cout << "TAK" << '\n';
                cout_tab(b, k - 1);
            } else {
                int idx = fill_a(b, k - 4, rift);
                b[idx + 1] = rift;
                b[idx + 2] = rift + 1;
                b[idx + 3] = rift + 2;
                fill_b(b, k - 1, idx + 4, rift + 3);
                cout << "TAK" << '\n';
                cout_tab(b, k - 1);
            }
        } else {
            cout << "NIE" << '\n';
        }
    }
}

int main() {

    int n;
    cin >> n;
    int k;
    cin >> k;
    int a[n];
    cin_tab(a, n);
    int b[k - 1];
    comp(a, b, n, k);
    return 0;
}