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
#include <stdio.h>
#define P(x) x
int sequence[1000000];
int min2[1000000];
int max2[1000000];
int result[1000000];
int n, k;

void solve2() {
	min2[0] = sequence[0];
	for(int i=1; i<n; i++){
		min2[i] = min2[i-1];
		if(min2[i] > sequence[i])
			min2[i] = sequence[i];
	}
	max2[n-1] = sequence[n-1];
	for(int i=n-2; i>=0; i--){
		max2[i] = max2[i+1];
		if(max2[i] < sequence[i])
			max2[i] = sequence[i];
	}
	for(int i=0; i<n-1; i++)
		if(min2[i] >= max2[i+1]){
			printf("TAK\n");
			P(printf("%d\n", i+1));
			return;
		}
	printf("NIE\n");
}

void solve3() {
	//pair on edges - TAK
	if(sequence[0] == sequence[1]) {
		printf("TAK\n");
		P(printf("%d %d\n", 1, 2));
		return;
	}
	else if(sequence[n-1] == sequence[n-2]) {
		printf("TAK\n");
		P(printf("%d %d\n", n-2, n-1));
		return;
	}
	int lastMin = sequence[0];
	int lastMinIdx = 0;	
	for(int i=0; i < n; i++) {
		if(lastMin >= sequence[i]){
			lastMin = sequence[i];
			lastMinIdx = i;
		}
	}
	if(lastMinIdx > 0) {
		printf("TAK\n");
		if(lastMinIdx < n-1)
			P(printf("%d %d\n", lastMinIdx, lastMinIdx+1));
		else
			P(printf("%d %d\n", lastMinIdx-1, lastMinIdx));
		return;
	}
	int firstMax = sequence[0];
	int firstMaxIdx = 0;
	for(int i=0; i < n; i++) {
		if(firstMax < sequence[i]){
			firstMax = sequence[i];
			firstMaxIdx = i;
		}
	}
	if(firstMaxIdx < n-1) {
		printf("TAK\n");
		if(firstMaxIdx > 0)
			P(printf("%d %d\n", firstMaxIdx, firstMaxIdx+1));
		else
			P(printf("%d %d\n", firstMaxIdx+1, firstMaxIdx+2));//1 2
		return;
	}
	printf("NIE\n");
}

void fillResult() {
	for(int i=0; i<k-1; i++)
		result[i] = i+1;
}
void printResult() {
	for(int i=0; i<k-1; i++)
		printf("%d ", result[i]);
	printf("\n");	
}

void solveAbove3(){
	int prev = sequence[0];
	for(int i=1; i < n; i++) {
		if(prev >= sequence[i]){
			//three i-1 i i+1
			printf("TAK\n");
			fillResult();
			if(result[k-2] < i+1) {
				result[k-2] = i+1;
				result[k-3] = i;
				result[k-4] = i-1;
			}
			P(printResult());
			return;
		}
		prev = sequence[i];
	}
	printf("NIE\n");
}

int main() {
	scanf("%d", &n);
	scanf("%d", &k);
	for(int i=0; i < n; i++) {
		int a; scanf("%d ", &a);
		sequence[i] = a;
	}
	if(k==2)
		solve2();
	else if(k==3)
		solve3();
	else if(k>=4)
		solveAbove3();
	return 0;
}