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
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 1e5 * 5 + 5;
int n,k,a[MAX_N],pref[MAX_N],suff[MAX_N],minimal,maximal,endings[MAX_N];
bool is_possible;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=n;++i)scanf("%d",&a[i]);
    pref[0] = 1e9;
	 for(int i = 1;i<=n;++i)pref[i] = min(pref[i - 1],a[i]);
	for(int i = n;i;--i)suff[i] = max(suff[i + 1],a[i]);
    if( k == 2)
    {    
		if(n == 2)
		{
			if(a[1] < a[2])
			{
				printf("NIE\n");
				return 0;
			}
			else 
			{
				printf("TAK\n");
				 printf("%d", 1);
				return 0;
			}
		}
        for(int i = 2; i < n;++i)
        {
            if(pref[i] >= suff[i + 1])
            {
                printf("TAK\n");
                printf("%d", i);
                return 0;            
            }
        }
        printf("NIE\n");
        return 0;
    }
    else if(k == 3)
    {
        minimal= 1e9;
        for(int i = 2; i < n;++i)
        {
            if(a[i]  <= pref[i - 1] || a[i] >=suff[i + 1])
            {
                printf("TAK\n");
                printf("%d %d",i - 1, i);
                        return 0;
            }
        }
        printf("NIE\n");
        return 0;
    }
    else
    {
		for(int i = 2; i<= n;++i)
		{
			if(a[i - 1] >= a[i])
			{
				endings[i - 2] = 1;
				endings[i - 1] = 1;
				endings[i] = 1;
				is_possible = true;
				break;
			}
		}
		n -=3;
		for(int i = 1;i<n;++i)
		{
			if(endings[i])continue;
			endings[i] = 1;
			--n;
			if(!n)break;
		}
		if(is_possible)
		{
			printf("TAK\n");
			for(int i =1;i<=n;++i)if(endings[i])printf("%d ", i);
		}
		else 
		{
			printf("NIE\n");
		}
		
	}


}