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
#include <iostream>
#include<vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n, k;
    int granica = 0;
    cin >> n >> k;
    vector<int> tab(n+1,0);
    for (int i = 1; i< n+1; i++) {
        cin >> tab[i];
    }

    if (k == 2) {
        vector<int> miny(n+1, 0);
            vector<int> maksy(n+1, 0);
            miny[0] = tab[1];
        for (int i = 1; i < n+1; i++) {
            if (tab[i] < miny[i - 1]) miny[i] = tab[i];
            else miny[i] = miny[i - 1];
        }
        maksy[n] = tab[n];
        for (int i = n-1; i > 0; i--) {
            if (tab[i] > maksy[i + 1]) maksy[i] = tab[i];
            else maksy[i] = maksy[i + 1];
           
        }
        int pom = 0;
        
        for (int i = 1; i < n; i++) {
            if (miny[i] >= maksy[i+1]) {
                cout << "TAK" << '\n';
                cout << i;
                pom = 1;
                break;
            }
        }

        if (pom == 0) cout << "NIE";

    }
    else if (k==3) {
        vector<int>kolejnosc(n + 1);
        partial_sort_copy(tab.begin(),tab.end(),kolejnosc.begin(),kolejnosc.end());
       
        
        if (tab[1] == kolejnosc[1] && tab[n] == kolejnosc[n]) {
            if (tab[2] == kolejnosc[1] || tab[2] == kolejnosc[n]) {
                cout << "TAK" << '\n';
                cout << 1 << ' ' << 2;
            }
            else cout << "NIE";
        }
        else {
            for (int i = 2; i < n; i++) {
                if (tab[i] == kolejnosc[1] || tab[i] == kolejnosc[n]) {
                    cout << "TAK" << '\n';
                    cout << i-1 << ' ' << i;
                    break;
                }
            }
        }

    }
    else if (k > 3) {
        for (int i = 2; i < n; i++) {
            if (tab[i - 1] >= tab[i]) {
                granica = i;
                break;
            }
        }

        if (granica != 0 && granica != 2) {
            cout << "TAK"<<'\n';
            int ind = 1;
            for (int i = 0; i < k - 4; i++) {
                if (ind == granica - 2) {
                    ind += 3;
                    cout << granica - 2<<' ';
                    cout << granica-1 << ' ';
                    cout << granica << ' ';
                }
                cout << ind << ' ';
                ind++;
            }
            if (ind < granica) {
                cout << granica - 2 << ' ';
                cout << granica - 1 << ' ';
                cout << granica << ' ';
            }
        }
        else if (granica == 2) {
            cout << "TAK" << '\n';
            cout << 1 << ' ';
            cout << 2 << ' ';
            for (int i = 3; i < k +1; i++) {
                cout << i << ' ';
            }
        }
        else if (granica == 0) {
            cout << "NIE" << '\n';
        }



    }


}