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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <algorithm>
#include <cstdint>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

template <typename T> void print_value(const T &v);

template <typename T> void debug(const T &v, const std::string &s) {
  std::cerr << s << ": '";
  print_value(v);
  std::cerr << "'\n";
}

template <> void print_value(const std::vector<int64_t> &v) {
  for (const auto x : v) {
    std::cerr << x << " ";
  }
}
template <> void print_value(const std::vector<int> &v) {
  for (const auto x : v) {
    std::cerr << x << " ";
  }
}
template <> void print_value(const std::unordered_set<int32_t> &v) {
  for (const auto x : v) {
    std::cerr << x << " ";
  }
}

template <typename T> void print_value(const T &v) { std::cerr << v; }

void prelude() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
}

struct Dyn {
  Dyn() {
    for (int i = 0; i < 3; ++i) {
      min_previous[i] = std::numeric_limits<int64_t>::min();
      min_current[i] = std::numeric_limits<int64_t>::max();
      for (int j = 0; j < 3; ++j) {
        history[i][j] = std::numeric_limits<int>::min();
      }
    }
  }
  int64_t min_previous[3];
  int64_t min_current[3];
  int history[3][2];
};

void print_split_list(int k, std::vector<int> forced_split) {
  std::vector<int> result;
  //debug(0, "print");
  if (forced_split.size() < k - 1) {
    std::unordered_set<int> all(forced_split.begin(), forced_split.end());
    //debug(1, "print");
    for (int i = 1; all.size() < k - 1; ++i) {
      if (all.find(i) == all.end()) {
        all.insert(i);
      }
    }
    //debug(2, "print");
    result = {all.begin(), all.end()};
  } else {
    result = {forced_split.begin(), forced_split.end()};
  }
  //debug(3, "print");
  //debug(result, "print result");
  sort(result.begin(), result.end());
  //debug(3.5, "print");
  for (int i = 0; i < k - 2; ++i) {
    std::cout << result[i] << " ";
  }
  //debug(4, "print");
  std::cout << result[k - 2] << "\n";
}

int main() {
  prelude();
  //debug("foo", "foo");
  int n = 0, k = 0;
  std::cin >> n >> k;
  std::vector<int64_t> income(n);

  for (int i = 0; i < n; ++i) {
    std::cin >> income[i];
  }
  if (k >= 4) {
    //debug(0, "big k");
    // - If strictly increasing, division is impossible.
    // - Otherwise, we can isolate two elements that make it not strictly
    // increasing (and we need two more intervals for prefix and suffix).
    int i;
    for (i = 0; i < n - 1; ++i) {
      if (income[i] >= income[i + 1]) {
        break;
      }
    }
    //debug(1, "big k");
    if (i == n - 1) {
      std::cout << "NIE\n";
    } else {

      //debug(2, "big k");
      std::vector<int> result;
      if (i > 0)
        result.push_back(i);
      result.push_back(i + 1);
      if (i + 2 < n)
        result.push_back(i + 2);

      //debug(3, "big k");
      std::cout << "TAK\n";
      print_split_list(k, result);
    }
  } else if (k == 3) {
    // If there is a minimum after first element, or maximum before last, we can
    // isolate it. Otherwise, it's not possible.
    auto first = income[0];
    auto last = income[n - 1];
    int64_t min = std::numeric_limits<int64_t>::max();
    int isolated = -1;
    int64_t max = -1;

    for (int i = 0; i < n; ++i) {
      if (i > 0 && income[i] <= first && min > income[i]) {
        min = income[i];
        isolated = i;
      }
      if (i < n - 1 && income[i] >= last && max < income[i]) {
        max = income[i];
        isolated = i;
      }
    }
    if (isolated != -1) {
      std::cout << "TAK\n";
      std::vector<int> result;
      if (isolated > 0)
        result.push_back(isolated);
      if (isolated + 1 < n)
        result.push_back(isolated + 1);
      print_split_list(k, std::move(result));
    } else {
      std::cout << "NIE\n";
    }
  } else { // k == 2
    std::vector<int64_t> left_mins(n);
    std::vector<int64_t> right_maxes(n);
    left_mins[0] = income[0];
    right_maxes[n-1] = income[n-1];
    for (int i = 1; i < n - 1; ++i) {
      left_mins[i] = std::min(left_mins[i - 1], income[i]);
    }
    for (int i = n - 2; i > 0; --i) {
      right_maxes[i] = std::max(right_maxes[i + 1], income[i]);
    }
    for (int i = 0; i < n - 1; ++i) {
      if (right_maxes[i + 1] <= left_mins[i]) {
        std::cout << "TAK\n";
        std::cout << i + 1 << "\n";
        return 0;
      }
    }
    std::cout << "NIE\n";
  }
  return 0;
}