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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// Karol Kosinski 2022
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i)
#define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) int((c).size())
#define TIE(x...) int x;tie(x)
#define X first
#define Y second
#ifndef ENABLE_DEBUG
#define DEB(k,p,f,x...)
#else
#define DEB(k,p,f,x...) {if(k)printf("--------%4d : %s\n",__LINE__,__FUNCTION__);if(p)f(x);}
#endif
#define DEBL DEB(1,1,void,0)
#define DEBF(f,x...) DEB(1,1,f,x)
#define DEBC(p,x...) DEB(0,p,printf,x)
#define DEBUG(x...) DEB(0,1,printf,x)
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;

constexpr int NX = 500'005;

int A[NX], Res[NX], Minc[NX], Mdec[NX];
bool Was[NX];

bool is_inc_sorted(int n)
{
    FOR(i,1,n) if ( A[ i - 1 ] >= A[i] ) return false;
    return true;
}

int check_pivot(int n)
{
    int local_min = 1e9 + 4, local_max = -1;
    FR_( i, 0, n - 1 )
    {
        local_min = min( A[i], local_min );
        Minc[i] = local_min;
    }
    FD_( i, n - 1, 0 )
    {
        local_max = max( A[i], local_max );
        Mdec[i] = local_max;
    }
    FOR(i,1,n)
    {
        if ( Minc[ i - 1 ] >= Mdec[i] ) return i;
    }
    return -1;
}

int get_local_noninc(int n)
{
    FD_( i, n - 1, 1 )
    {
        if ( A[ i - 1 ] >= A[i] ) return i;
    }
    return -1; // unreachable
}

bool solve(int n, int k)
{
    if ( is_inc_sorted(n) )
    {
        return false;
    }
    if ( k == 2 )
    {
        int h = check_pivot(n);
        Res[0] = h;
        return h != -1;
    }
    if ( k == 3 )
    {
        int mx = max_element( A, A + n ) - A;
        if ( mx == n - 1 )
        {
            int h = check_pivot( n - 1 );
            Res[0] = h;
            Res[1] = mx;
            return h != -1;
        }
        if ( mx == 0 )
        {
            Res[0] = 1;
            Res[1] = 2;
        }
        else
        {
            Res[0] = mx;
            Res[1] = mx + 1;
        }
        return true;
    }
    int mx = max_element( A, A + n ) - A, limit = -1;
    if ( mx == n - 1 )
    {
        int p = get_local_noninc(n);
        if ( p == 1 )
        {
            Was[1] = Was[2] = Was[3] = true;
        }
        else
        {
            Was[ p - 1 ] = Was[p] = Was[ p + 1 ] = true;
        }
        limit = k - 4;
    }
    else
    {
        if ( mx == 0 )
        {
            Was[1] = Was[2] = true;
        }
        else
        {
            Was[mx] = Was[ mx + 1 ] = true;
        }
        limit = k - 3;
    }
    int j = 1;
    while ( limit -- )
    {
        while ( Was[j] ) ++ j;
        Was[j] = true;
    }
    int rind = 0;
    FOR(i,1,n)
    {
        if ( Was[i] ) Res[ rind ++ ] = i;
    }
    return true;
}

void validate(int n, int k)
{
    FOR( i, 0, k - 1 )
    {
        if ( not ( 1 <= Res[i] and Res[i] < n ) )
        {
            fprintf(stdout, "Illegal index!\n");
            return;
        }
    }
    FOR( i, 1, k - 1 )
    {
        if ( Res[ i - 1 ] >= Res[i] )
        {
            fprintf(stdout, "Wrong index order!\n");
            return;
        }
    }
    int low = 0, prev_min = -1;
    FOR( i, 0, k - 1 )
    {
        int local_min = 1e9 + 4;
        bool checked = false;
        FOR( j, low, Res[i] )
        {
            if ( prev_min < A[j] and A[j] < local_min )
            {
                checked = true;
                local_min = A[j];
            }
        }
        if ( not checked )
        {
            // fprintf(stderr, "OK\n");
            return;
        }
        low = Res[i];
        prev_min = local_min;
    }
    int local_min = 1e9 + 4;
    bool checked = false;
    FOR( j, low, n )
    {
        if ( prev_min < A[j] and A[j] < local_min )
        {
            checked = true;
            local_min = A[j];
        }
    }
    if ( not checked )
    {
        // fprintf(stderr, "OK\n");
        return;
    }
    fprintf(stdout, "Wrong partition!\n");
}

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    FOR(i,0,n)
    {
        int a; scanf("%d", &a);
        A[i] = a;
    }
    if ( solve(n, k) )
    {
        printf("TAK\n");
        FOR(i,1,k) printf("%d ", Res[ i - 1 ]);
        printf("\n");
        // validate(n, k);
    }
    else
    {
        printf("NIE\n");
    }
    return 0;
}