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
#include<bits/stdc++.h>
using namespace std;
int tab[500006];
int m[500006];
void f2(int k,int n)
{
   for(int i=n;i>0;i--)m[i]=max(tab[i],m[i+1]);
   int mi=tab[1];
   for(int i=1;i<n;i++)
   {
      mi=min(mi,tab[i]);
      if(m[i+1]<=mi)
      {
         cout<<"TAK\n"<<i<<"\n";
         return;
      }
   }
   cout<<"NIE\n";
}
void f3(int k,int n)
{
   if(tab[1]>=tab[n])
   {
      cout<<"TAK\n"<<1<<" "<<n-1<<"\n";
      return;
   }
   int mi=tab[1];
   for(int i=1;i<n-1;i++)
   {
      mi=min(mi,tab[i]);
      if(tab[i+1]<=mi)
      {
         cout<<"TAK\n"<<i<<" "<<i+1<<"\n";
         return;
      }
   }
   int ma=tab[n];
   for(int i=n;i>2;i--)
   {
      ma=max(ma,tab[i]);
      if(tab[i-1]>=ma)
      {
         cout<<"TAK\n"<<i-2<<" "<<i-1<<"\n";
         return;
      }
   }

   cout<<"NIE\n";
}
void f4(int k,int n)
{
   for(int i=2;i<=n;i++)
   {
      if(tab[i]<=tab[1])
      {
         cout<<"TAK\n";
         if(i==n)cout<<1<<" "<<2<<" "<<i-1<<"\n";
         else if(i==2)cout<<"1 2 3\n";
         else cout<<1<<" "<<i-1<<" "<<i<<"\n";
         return;
      }
   }
   for(int i=n-1;i>=1;i--)
   {
      if(tab[n]<=tab[i])
      {
         cout<<"TAK\n";
         if(i==1)cout<<1<<" "<<2<<" "<<n-1<<"\n";
         else if(i==n-1)cout<<"1 "<<n-2<<" "<<n-1<<"\n";
         else cout<<i-1<<" "<<i<<" "<<n-1<<"\n";
         return;

      }
   }
   for(int i=1;i<n;i++)
   {
      if(tab[i]>=tab[i+1])
      {
         cout<<"TAK\n";
         cout<<i-1<<" "<<i<<" "<<i+1<<"\n";
         return;
      }
   }
   cout<<"NIE\n";
}
void f5(int k,int n)
{
   int p1=1,p2=0;
   m[n]=tab[n];
   for(int i=n-1;i>0;i--)m[i]=min(tab[i],m[i+1]);
   int ma=tab[1];
   for(int i=1;i<n;i++)
   {
      if(ma<=tab[i])
      {
         p1=i;
         ma=tab[i];
      }
      if(ma>=m[i+1])
      {
         for(int j=i+1;j<=n;j++)
         {
            if(tab[j]<=tab[p1])
            {  
               p2=j;
               break;
            }
         }
         break;
      }
   }
   if(p2==0)
   {
      cout<<"NIE\n";
      return;
   }
   cout<<"TAK\n";
  // cout<<p1<<" "<<p2<<" p\n";
   if(p2-p1>1)
   {
      if(p1!=1&&p2!=n)k-=5;
      else if(p1==1&&p2==n)k-=3;
      else k-=4;
   }
   else
   {
      if(p1!=1&&p2!=n)k-=4;
      else k-=3;
   }
   for(int i=1;i<n;i++)
   {
      if(i==p1-1||i==p2-1||i==p1||i==p2)cout<<i<<" ";
      else if(k>0)
      {
         cout<<i<<" ";
         k--;
      }
   }
   cout<<"\n";
}
int main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,k;cin>>n>>k;

   for(int i=1;i<=n;i++)cin>>tab[i];

   if(k==2)f2(k,n);
   if(k==3)f3(k,n);
   if(k==4)f4(k,n);
   if(k>=5)f5(k,n);
}