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
#include <stdio.h>
#include <stdbool.h>

#define INF 1000000007
#define MAX_N 500007

int n, k;
int a[MAX_N];
int min_pref[MAX_N];
int max_suf[MAX_N];

int min(int a, int b) {
    if (a < b)
        return a;

    return b;
}

int max(int a, int b) {
    if (a > b)
        return a;

    return b;
}

void preprocess() {
    min_pref[0] = INF;
    max_suf[n + 1] = 0;

    for (int i = 1; i <= n; i++) {
        min_pref[i] = min(min_pref[i - 1], a[i]);
        max_suf[n - i + 1] = max(max_suf[n - i + 2], a[n - i + 1]);
    }
}

bool is_increasing() {
    for (int i = 1; i < n; i++)
        if (a[i] >= a[i + 1])
            return false;

    return true;
}

void solve2() {
    for (int i = 1; i < n; i++) {
        if (min_pref[i] >= max_suf[i + 1]) {
            printf("TAK\n");
            printf("%d\n", i);
            return;
        }
    }

    printf("NIE\n");
    return;
}

void solve3() {
    int i = 2;

    while (i <= n && min_pref[i - 1] < a[i]) {
        i++;
    }

    if (i < n) {
        printf("TAK\n");
        printf("%d %d\n", i - 1, i);
        return;
    }

    if (i == n) {
        printf("TAK\n");
        printf("%d %d\n", n - 2, n - 1);
        return;
    }

    i = n - 1;

    while (i >= 1 && a[i] < max_suf[i + 1]) {
        i--;
    }

    if (i > 1) {
        printf("TAK\n");
        printf("%d %d\n", i - 1, i);
        return;
    }

    if (i == 1) {
        printf("TAK\n");
        printf("1 2\n");
        return;
    }

    printf("NIE\n");
}

void solve4() {
    int i = 1;
    int j;
    int cnt = 0;

    while (i < n && a[i] < a[i + 1]) {
        i++;
    }

    printf("TAK\n");

    if (i == 1) {
        j = 1;

        for (; cnt < k - 1; cnt++) {
            printf("%d ", j);
            j++;
        }
    } else if (i == n - 1) {
        j = n - k + 1;

        for (; cnt < k - 1; cnt++) {
            printf("%d ", j);
            j++;
        }
    } else {
        j = 1;

        while (j < i - 1 && cnt < k - 4) {
            printf("%d ", j);
            j++;
            cnt++;
        }

        printf("%d %d %d ", i - 1, i, i + 1);
        j = i + 2;
        cnt += 3;

        while (j < n && cnt < k - 1) {
            printf("%d ", j);
            j++;
            cnt++;
        }
    }

    printf("\n");
}

int main() {
    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    if (is_increasing()) {
        printf("NIE\n");
    } else {
        preprocess();

        if (k == 2) {
            solve2();
        } else if (k == 3) {
            solve3();
        } else {
            solve4();
        }
    }

    return 0;
}