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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, k;
    cin >> n >> k;
    ll a[n];
    ll aSorted[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    if(k == 2) {
        vector <ll> prefixMinimum;
        vector <ll> suffixMaximum;
        for (ll i = 0; i < n; i++) {
            if (i == 0) {
                prefixMinimum.push_back(a[i]);
            }else {
                prefixMinimum.push_back(min(prefixMinimum[i-1], a[i]));
            }
        }
        for (ll i = n - 1; i >= 0; i--) {
            if (i == n - 1) {
                suffixMaximum.push_back(a[i]);
            }else {
                suffixMaximum.push_back(max(suffixMaximum[n - i - 2], a[i]));
            }
        }
        reverse(suffixMaximum.begin(), suffixMaximum.end());
        for (ll i = 0; i < n-1; i++) {
            if (prefixMinimum[i] >= suffixMaximum[i+1]) {
                cout << "TAK" << endl;
                cout << i + 1 << endl;
                return 0;
            }
        }
    }else if(k == 3) {
        vector <ll> prefixMinimum;
        for (ll i = 0; i < n; i++) {
            if (i == 0) {
                prefixMinimum.push_back(a[i]);
            }else {
                prefixMinimum.push_back(min(prefixMinimum[i-1], a[i]));
            }
        }
        for (ll i = 0; i < n-1; i++) {
            if (prefixMinimum[i] >= a[i+1]) {
                cout << "TAK" << endl;
                cout << i + 1 << " " << i + 2 << endl;
                return 0;
            }
        }
    }
    for (ll i = 0; i < n; i++) {
        aSorted[i] = a[i];
    }
    sort(aSorted, aSorted + n);
    ll maximum = aSorted[n - 1];
    ll indexOfMaximum = 0;
    for (ll i = 0; i < n; i++) {
        if (a[i] == maximum) {
            indexOfMaximum = i + 1;
            break;
        }
    }
    if (indexOfMaximum != n) {
        if ((indexOfMaximum != 1 && k == 2)) {
            cout << "NIE" << endl;
            return 0;
        } else if (indexOfMaximum == 1 && k == 2) {
            cout << "TAK" << endl;
            cout << 1 << endl;
            return 0;
        } else if (indexOfMaximum == 1 && k > 2) {
            cout << "TAK" << endl;
            for (ll i = 1; i < k; i++) {
                cout << i << " ";
            }
            return 0;
        }
        cout << "TAK" << endl;
        ll more = 0;
        for (ll i = 0; i < k - 3; i++) {
            if (i + 1 == indexOfMaximum - 1) {
                more = k-3-i;
                break;
            }
            cout << i + 1 << " ";
        }
        cout << indexOfMaximum - 1<< " ";
        cout << indexOfMaximum << " ";
        for (ll i = 0; i < more; i++) {
            cout << indexOfMaximum + i + 1 << " ";
        }
    }else {
        if (a[0] >= a[1] && a[1] == aSorted[n-2]) {
            cout << "TAK" << endl;
            for (ll i = 0; i < k; i++) {
                cout << i + 1 << " ";
            }
            return 0;
        }else if(a[0] >= a[1] && k > 2) {
            cout << "TAK" << endl;
            for (ll i = 0; i < k; i++) {
                cout << i + 1 << " ";
            }
            return 0;
        }else if (k == 2 || k == 3) {
            cout << "NIE" << endl;
            return 0;
        }
        ll minIndex = 0;
        for (ll i = 0; i < n-1; i++) {
            if (a[i] >= a[i + 1]) {
                minIndex = i + 1;
                break;
            }
        }
        if (minIndex == 0) {
            cout << "NIE" << endl;
            return 0;
        }
        cout << "TAK" << endl;
        ll more = 0;
        for (ll i = 0; i < k - 4; i++) {
            if (i + 1 == minIndex - 1) {
                more = k-4-i;
                break;
            }
            cout << i + 1 << " ";
        }
        cout << minIndex - 1 << " ";
        cout << minIndex << " ";
        cout << minIndex + 1 << " ";
        for (ll i = 0; i < more; i++) {
            cout << minIndex + 2 + i << " ";
        }
    }
    return 0;
}