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
#include <bits/stdc++.h>
using namespace std;
const int MX=500100;
int n,m,i,j,a[MX],mnl[MX],mxl[MX],mnr[MX],mxr[MX];
int main() {
  scanf("%d%d",&n,&m);
  for (i=1; i<=n; i++) scanf("%d",&a[i]);
  mnl[1]=mxl[1]=a[1];
  for (i=2; i<=n; i++) {
    mnl[i]=min(mnl[i-1],a[i]);
    mxl[i]=max(mxl[i-1],a[i]);
  }
  mnr[n]=mxr[n]=a[n];
  for (i=n-1; i>0; i--) {
    mnr[i]=min(mnr[i+1],a[i]);
    mxr[i]=max(mxr[i+1],a[i]);
  }
  if (m==2) {
    for (i=1; i<n; i++) if (mnl[i]>=mxr[i+1]) break;
    if (i<n) {
      puts("TAK");
      printf("%d\n",i);
    } else puts("NIE");
    return 0;
  }
  if (mnl[n]==mxl[n]) {
    puts("TAK");
    for (i=1; i<m; i++) printf("%d ",i);
    return 0;
  }
  if (m>3) {
    for (i=1; i<n; i++) if (a[i]>=a[i+1]) break;
    if (i<n) {
      puts("TAK");
      vector<int> ans;
      if (i>1) ans.push_back(i-1);
      ans.push_back(i);
      ans.push_back(i+1);
      for (j=1; j<i-1 && ans.size()+1<m; j++) ans.push_back(j);
      for (j=i+2; j<n && ans.size()+1<m; j++) ans.push_back(j);
      sort(ans.begin(),ans.end());
      for (int x: ans) printf("%d ",x);
    } else puts("NIE");
    return 0;
  }
  for (j=2; j<n; j++) if (a[j]==mnl[n] || a[j]==mxl[n]) {
    puts("TAK");
    printf("%d %d\n",j-1,j);
    return 0;
  }
  puts("NIE");
  return 0;
}