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
#include<bits/stdc++.h>
using namespace std;
#ifdef LOC
template <class T, class U> auto &operator<<(ostream &out, pair<T, U> a) { return out << "(" << a.first << ", " << a.second << ")"; }
template <class T, class = class enable_if<!is_same<T, string>(), class T::iterator>::type> auto &operator<<(ostream &out, T a) {
    out << "{";
    bool fi = 1;
    for(auto b : a) {
        if(fi) {out<<b; fi=0;}
        else out<<", "<<b;
    }
    return out << "}";
}

template <class T, class X, class Y> auto &operator<<(ostream &out, const priority_queue<T,X,Y>& a) {auto b = a; vector<T> v; while(!b.empty()) {v.push_back(b.top()); b.pop();} return out<<v; }
void dump(){
   cerr << "\e[39m"<<"\n";
}
template <class T, class... Ts> void dump(T a, Ts... x) {
   cerr << a << ", ";
   dump(x...);
}
#define debug(...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<"[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#define debug(...) ;
#endif

#define fwd(i, a, b) for(int i=(a);i<(int)(b);i++)
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(X) (X).begin(), (X).end()
#define sz(X) ((int)(X).size())
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

pair<bool, vi> solve2(vi tab, int n) {
    vi rgh = tab;
    for(int i=n-2;i>=0;i--) rgh[i] = max(rgh[i+1], tab[i]);
    int minL = tab[0];
    fwd(i,1,n) {
        if(minL >= rgh[i])
            return {true, {i-1}};
        minL = min(minL, tab[i]);
    }
    return {false, {}};
}

pair<bool, vi> solve3(vi tab, int n) {
    int m = *min_element(all(tab));
    int M = *max_element(all(tab));
    if(tab[n-1] == m) {return {true, {n-3, n-2}};}
    if(tab[0] == M) {return {true, {0,1}};}
    fwd(i,1,n-1) if(tab[i] == m) {return {true, {i-1,i}};};
    fwd(i,1,n-1) if(tab[i] == M) {return {true, {i-1,i}};};
    return {false, {}};
}

pair<bool, vi> solveK(vi tab, int n, int k) {
    rep(i,n-1) {
        if(tab[i] >= tab[i+1]) {
            vi splits(n-1);
            int cnt = k-2;
            splits[i] = 1;

            if(i+1 != n-1) {
                splits[i+1] = 1;
                cnt--;
            }
            if(i != 0) {
                splits[i-1] = 1;
                cnt--;
            }
            for(int j=0;j<sz(splits) && cnt>0; j++) {
                if(splits[j] == 0) {
                    splits[j] = 1; 
                    cnt--;
                }
            }
            vi idxs;
            rep(j,n-1) if(splits[j]) idxs.push_back(j);
            return {true, idxs};
        }
    }
    return {false, {}};
}

pair<bool, vi> solve(vi tab, int n, int k) {
    if(k == 2) return solve2(tab,n);
    if(k == 3) return solve3(tab,n);
    return solveK(tab,n,k);
}

void validate(vi tab, int n, int k, vi ans) {
    assert(sz(ans) == k-1);
    ans.push_back(n-1);
    rep(i,sz(ans)-1) assert(ans[i] < ans[i+1]);
    assert(ans[0] >= 0);

    int prvMin = 2e9, prvMax = 0;
    int i=0;
    for(auto a:ans) {
        int curMin = 2e9, curMax = 0;
        while(i <= a) {
            curMax = max(curMax, tab[i]);
            curMin = min(curMin, tab[i]);
            i++;
        }
        if(curMax <= prvMin) return;
        prvMin = curMin;
        prvMax = curMax;
    }
    assert(false);
}

int32_t main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vi tab(n);
    rep(i,n) cin >> tab[i];
    auto [r, ans] = solve(tab,n,k);
    if(!r) cout<<"NIE\n";
    else {
        cout<<"TAK\n";
        for(auto a:ans) cout<<a+1<<" ";
        cout<<"\n";
        // validate(tab,n,k,ans);
    }
}