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

const int N = 500000+2;

int a[N];
long long int m[N];

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

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

void solve2(int n) {
    m[n-1] = a[n-1];
    long long int c = a[n-1];
    for(int i = n-2; i >= 0; --i) {
        m[i] = max(a[i], c);
    }

    c = a[0];
    for(int i = 1; i < n-1; ++i) {
        if(c > m[i]) {
            cout << "TAK\n";
            cout << i << '\n';
            return;
        }
        c = min(c, a[i]);
    }
    cout << "NIE\n";
}

void solve3(int n) {
    int mx = *max_element(a, a+n);
    int mn = *min_element(a, a+n);

    int mni = 0;
    for(int i = 1; i < n; ++i) {
        if(a[i] == mn) {
            mni = i;
            break;
        }
    }

    if(mni > 0) {
         cout << "TAK\n";
        cout << mni << ' ' << mni+1 << '\n';
        return;
    }

    int mxi = n-1;
    for(int i = n-2; i >= 0; --i) {
        if(a[i] == mx) {
            mxi = i;
            break;
        } 
    }

    if(mxi == n-1) {
        cout << "NIE\n";
        return;
    }
     cout << "TAK\n";
    cout << mxi << ' ' << mxi+1 << '\n';
}

void solve4(int n, int k) {
    int id = -1;
    for(int i = 1; i < n; ++i) {
        if(a[i-1] >= a[i]) {
            id = i-1;
            break;
        }
    }

    if(id == -1) {
        cout << "NIE\n";
        return;
    }

    cout << "TAK\n";

    for(int i = 0; i < id && i < k-4; ++i) {
        cout << i+1 << ' ';
    }

    if(id == 0) {
        cout << id+1 << ' ' << id+2 << ' ';
    } else {
        cout << id << ' ' << id+1 << ' ' << id+2 << ' ';
    }

    for(int i = id+2; i < k-1; ++i) {
        cout << i+1 << ' ';
    }

    cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
      
   int n, k;
   cin >> n >> k;

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

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

    return 0;
}