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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <vector>


void checkForKEqual2(std::vector<long> &numbers) {
	long first = numbers.front();
	bool valid{true};
	for (long i = 1; i < numbers.size(); i++) {
		if (numbers[i] > first) {
			valid = false;
			break;
		}
	}
	if (valid) {
		std::cout << "TAK" << std::endl;
		std::cout << 1 << std::endl;
		return;
	}
	valid = true;
	long last = numbers.back();
	for (long i = 0; i < numbers.size() - 1; i++) {
		if (numbers[i] < last) {
			valid = false;
			break;
		}
	}
	if (valid) {
		std::cout << "TAK" << std::endl;
		std::cout << numbers.size() - 1 << std::endl;
		return;
	}
	std::cout << "NIE" << std::endl;
}

void checkForKEqual3(std::vector<long> &numbers) {
	long tmp{};
	std::vector<long> minFromLeft;
	tmp = numbers.front();
	for (auto i : numbers) {
		tmp = std::min(tmp, i);
		minFromLeft.push_back(tmp);
	}
	std::vector<long> maxFromRight(numbers.size(), 0);
	tmp = numbers.back();
	long i = numbers.size() - 1;
	for (auto it = numbers.rbegin(); it != numbers.rend(); it++) {
		tmp = std::max(tmp, *it);
		maxFromRight[i--] = tmp;
	}
	for (long i = 1; i < numbers.size(); i++) {
		if (minFromLeft[i - 1] >= numbers[i]) {
			std::cout << "TAK" << std::endl;
			if (i < numbers.size() - 1) {
				std::cout << i << " " << i + 1 << std::endl;
			} else {
				std::cout << i - 1 << " " << i << std::endl;
			}
			return;
		}
	}
	for (long i = numbers.size() - 2; i >= 0; i--) {
		if (numbers[i] >= maxFromRight[i + 1]) {
			std::cout << "TAK" << std::endl;
			if (i > 0) {
				std::cout << i << " " << i + 1 << std::endl;
			} else {
				std::cout << i + 1 << " " << i + 2 << std::endl;
			}
			return;
		}
	}
	std::cout << "NIE" << std::endl;
}

void printAnswerForIndex(std::vector<long> &numbers, long index, long k) {
	long spaceRemainingFromLeft = index;
	long spaceRemainingFromRight = numbers.size() - (index + 2);
	long neededBeforeIndex = ((index > 0) ? 1 : 0);
	long neededAfterIndex = ((index + 2 < numbers.size()) ? 1 : 0);

	long indexesToInsertBefore = k - 1 - neededAfterIndex - 1 - neededBeforeIndex;
	std::vector<long> result;
	for (long i = 0; i < indexesToInsertBefore && i < index - 1; i++) {
		result.push_back(i);
	}
	if (neededBeforeIndex != 0) {
		result.push_back(index - 1);
	}
	result.push_back(index);
	if (neededAfterIndex != 0) {
		result.push_back(index + 1);
	}
	long remainingToInsert = k - 1 - result.size();
	
	long tmp = result.back() + 1;
	for (long i = 0; i < remainingToInsert; i++) {
		result.push_back(tmp++);
	}
	std::cout << "TAK" << std::endl;
	for (long i = 0; i < result.size(); i++) {
		std::cout << result[i] + 1;
		if (i < result.size() - 1) {
			std::cout << " ";
		}
	}
	std::cout << std::endl;
}

void checkForKGreaterThan3(std::vector<long> &numbers, long k) {
	long tmp{};
	std::vector<long> indexes;
	for (int i = 1; i < numbers.size(); i++) {
		if (numbers[i - 1] >= numbers[i]) {
			printAnswerForIndex(numbers, i - 1, k);
			return;	
		}
	}
	std::cout << "NIE" << std::endl;
}

int main() {
	long n{};
	long k{};
	std::cin >> n >> k;
	std::vector<long> numbers;
	for (long i = 0; i < n; ++i) {
		long tmp{};
		std::cin >> tmp;
		numbers.push_back(tmp);
	}

	if (k == 2) {
		checkForKEqual2(numbers);
		return 0;
	} else if (k == 3) {
		checkForKEqual3(numbers);
		return 0;
	}
	checkForKGreaterThan3(numbers, k);
	return 0;
}