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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N,K;
    const int C = 500000;
    int a[C];
    cin>>N>>K;
    for(int i=0; i<N; ++i) {
        cin>>a[i];
    }
    if(K == 3) {
        int MX,MN;
        bool cz = false;
        int ans;
        MN = a[0];
        for(int i=1; i<N; ++i) {
            if(a[i] < MN) MN = a[i];
        }
        for(int i=1; i<N; ++i) {
            if(a[i] == MN) {
                cz = true;
                if(i<N-1)
                    ans = i;
                else
                    ans = i-1;
            }
        }
        MX = a[N-1];
        for(int i=0; i<N-1; ++i) {
            if(a[i] > MX) MX = a[i];
        }
        for(int i=0; i<N-1; ++i) {
            if(a[i] == MX) {
                cz = true;
                if(i>0)
                    ans = i;
                else
                    ans = i+1;
            }
        }
        if(cz == false) cout<<"NIE"<<endl;
        else {
            cout<<"TAK"<<endl;
            cout<<ans<<" "<<ans+1<<endl;
        }
    }
    if(K >= 4) {
        bool cz = false;
        int m;
        for(int i=0; i<N-1; ++i) {
            if(a[i] >= a[i+1]) {
                cz = true;
                m = i;
            }
        }
        vector<int> V;
        bool b[C+1];
        for(int i=0; i<=N; ++i) b[i] = false;
        if(cz) {
            if(m == 0) {
                V.push_back(m+1); b[m+1] = true;
                V.push_back(m+2); b[m+2] = true;
            }
            else if(m<N-2) {
                V.push_back(m); b[m] = true;
                V.push_back(m+1); b[m+1] = true;
                V.push_back(m+2); b[m+2] = true;
            }
            else {
                V.push_back(m); b[m] = true;
                V.push_back(m+1); b[m+1] = true;
            }
            int t=1;
            while(V.size() < K-1) {
                if(b[t] == false) {
                    V.push_back(t);
                    b[t] = true;
                }
                t++;
            }
            sort(V.begin(),V.end());
            cout<<"TAK"<<endl;
            for(int i=0; i<V.size(); ++i) cout<<V[i]<<" ";
            cout<<endl;
        }
        if(cz == false) cout<<"NIE"<<endl;
    }
    if(K == 2) {
        int mn[C],mx[C];
        int MN = 1 << 30, MX = 0;
        bool cz = false;
        int ans = -1;
        for(int i=0; i<N; ++i) {
            if(a[i] < MN) MN = a[i];
            mn[i] = MN;
        }
        for(int i=N-1; i>=0; --i) {
            if(a[i] > MX) MX = a[i];
            mx[i] = MX;
        }
        for(int i=0; i<N-1; ++i) {
            if(mn[i] >= mx[i+1]) {
                cz = true;
                ans = i+1;
            }
        }
        if(cz == false) cout<<"NIE"<<endl;
        else {
            cout<<"TAK"<<endl;
            cout<<ans<<endl;
        }
    }
    
    return 0;
}