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
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector> 
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    bool inc = true;
    for (int i = 2; i <= n; i++) if(a[i] <= a[i-1])
    {
        inc = false;
        break;
    }
    if (inc)
    {
        cout << "NIE\n";
        return 0;
    }
    vector<bool> koniec(n+1);
    if (k >= 4)
    {
        for (int i = 2; i <= n; i++)
        {
            
            if (a[i] <= a[i-1])
            {
                koniec[i-2] = koniec[i-1] = koniec[i] = true;
                k-=3;
                if (koniec[0]) k++;
                break;
            }
        }
        if (!koniec[n])
        {
            koniec[n] = true;
            k--;
        }
        for (int i = 1; i <= n && k > 0; i++)
        {
            if (!koniec[i])
            {
                koniec[i] = true;
                k--;
            }
        }
        cout << "TAK\n";
        for (int i = 1; i < n; i++)
        {
            if (koniec[i]) cout << i << ' ';
        }
        return 0;
    }
    if (k == 3)
    {
        pair<int, int> minn = {2e9, -1}, maxx = {0, -1};
        for (int i = 1; i <= n; i++)
        {
            if (a[i] <= minn.st) minn = {a[i], i};
        }
        for (int i = n; i >= 1; i--)
        {
            if (a[i] >= maxx.st) maxx = {a[i], i};
        }
        if (minn.nd != 1)
        {
            koniec[minn.nd] = koniec[minn.nd-1] = true;
            k-=2;
        }
        else if (maxx.nd != n)
        {
            koniec[maxx.nd] = koniec[maxx.nd-1] = true;
            k-=2;
        }
        else
        {
            cout << "NIE\n";
            return 0;
        }
        if (koniec[0]) k++;
        if (!koniec[n]) k--;
        for (int i = 1; i <= n && k>0; i++)
        {
            if (!koniec[i])
            {
                koniec[i] = true;
                k--;
            }
        }
        cout << "TAK\n";
        for (int i = 1; i < n; i++) if(koniec[i]) cout << i << ' ';
        return 0;
    }
    if (k == 2)
    {
        vector<int> minpref(n+1), maxsuf(n+1);
        minpref[1] = a[1];
        for (int i = 2; i <= n; i++) minpref[i] = min(minpref[i-1], a[i]);
        maxsuf[n] = a[n];
        for (int i = n-1; i >= 1; i--) maxsuf[i] = max(maxsuf[i+1], a[i]);
        for (int i = 2; i <= n; i++)
        {
            if (maxsuf[i] <= minpref[i-1])
            {
                cout << "TAK\n" << i-1 << ' ';
                return 0;
            }
        }
        cout << "NIE\n";
        return 0;

    }
}