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

int main() {
	std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
	
	int n, k;
	std::cin >> n >> k;
	
	std::vector<int> input(n);
	
	for (int i = 0; i < n; ++i) {
		std::cin >> input[i];
	}
	
	std::vector<int> prefmin(n);
	std::vector<int> sufmax(n);
	
	prefmin[0] = input[0];
	for (int i = 1; i < n; ++i) {
		prefmin[i] = std::min(prefmin[i-1], input[i]);
	}
	
	sufmax[n-1] = input[n-1];
	for (int i = n-2; i >= 0; --i) {
		sufmax[i] = std::max(sufmax[i+1], input[i]);
	}
	
	if (k == 2) {
		for (int i = 0; i < n-1; ++i) {
			if (prefmin[i] >= sufmax[i+1]) {
				std::cout << "TAK\n" << (i +1) << '\n';
				return 0;
			}
		}
		std::cout << "NIE\n";
		return 0;
	}
	
	if (k >= 4) {
		if (input[0] >= input[1]) {
			std::cout << "TAK\n" << "1 2";
			int cnt = 2;
			for (int i = 2; cnt < k-1 && i < n; ++i) {
				std::cout << ' ' << (i +1);
				++cnt;
			}
			std::cout << '\n';
			return 0;
		}
		if (input[n-2] >= input[n-1]) {
			std::cout << "TAK\n";
			int cnt = 2;
			for (int i = 0; cnt < k-1 && i < n-3; ++i) {
				std::cout << (i +1) << ' ';
				++cnt;
			}
			std::cout << (n-3 +1) << ' ' << (n-2 +1) << '\n';
			return 0;
		}
		for (int i = 2; i < n-1; ++i) {
			if (input[i-1] >= input[i]) {
				std::cout << "TAK\n";
				int cnt = 3;
				for (int j = 0; cnt < k-1 && j < i-2; ++j) {
					std::cout << (i +1) << ' ';
					++cnt;
				}
				std::cout << (i-2 +1) << ' ' << (i-1 +1) << ' ' << (i +1);
				for (int j = i+1; cnt < k-1 && j < n; ++j) {
					std::cout << ' ' << (i +1);
					++cnt;
				}
				std::cout << '\n';
				return 0;
			}
		}
		std::cout << "NIE\n";
		return 0;
	}
	
	
	if (k == 3) {
		
		int maxval = -1;
		for (int i = 0; i < n; ++i) {
			if (input[i] >= maxval) {
				maxval = input[i];
			}
		}
		
		for (int i = 1; i < n-1; ++i) {
			if (input[i] == maxval) {
				std::cout << "TAK\n" << (i-1 +1) << ' ' << (i +1) << '\n';
				return 0;
			}
		}
		
		int minval = INT_MAX;
		for (int i = 0; i < n; ++i) {
			if (input[i] <= minval) {
				minval = input[i];
			}
		}
		
		for (int i = 1; i < n-1; ++i) {
			if (input[i] == minval) {
				std::cout << "TAK\n" << (i-1 +1) << ' ' << (i +1) << '\n';
				return 0;
			}
		}
		
		// That means the only minimum and maximum elements in the array are on its ends
		
		if (input[0] < input[n-1]) {
			std::cout << "NIE\n";
		} else {
			std::cout << "TAK\n" << "1 2\n";
		}
	}
	
	return 0;
}