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

using namespace std;

vector <int> tab;
long long int tab2[12] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800};
vector <int> tabid;
vector <int> factorial;
vector <int> factorialClear;
vector <int> number;
vector <int> buff;
vector <int> goodnumber;

void tablica(int m)
{
    int l = tab.size();
    for(int j = 1; j < m; j++)
    {
        for(int i = 0; i < l; i++)
        {
            tab.push_back(tab[i] + j);
        }
    }
}

void id()
{
    for(int i = 0; i < tab.size(); i++)
    {
        if(tab[i] == tab[tab.size() - i - 1])
        {
            tabid.push_back(i);
            //cout << " * " << i << endl;
        }
    }
}

void fac(long long int o)
{
    for(int i = 11; i > 0; i--)
    {
        if(tab2[i] <= o)
        {
            for(int j = 1; j > 0; j++)
            {
                if(tab2[i] * j > o)
                {
                    factorial.push_back(j - 1);
                    o -= (tab2[i] * (j - 1));
                    break;
                }
            }
        }
        else
        {
            factorial.push_back(0);
        }
    }
    factorial.push_back(0);
}

int main()
{
    long long int n;
    long long int k;

    tab.push_back(0);
    tab.push_back(1);
    tab.push_back(1);
    tab.push_back(2);
    tab.push_back(2);
    tab.push_back(3);
    cin >> n;
    cin >> k;
    //cout << (n * (n - 1) / 2) << endl;
    for(int i = 0; i < n; i++)
    {
        number.push_back(i + 1);
    }

    if((n * (n - 1) / 2) % 2 == 0 && n != 1)
    {
        int siz = 3;
        while(siz < n)
        {
            siz++;
            tablica(siz);
        }

        id();

        if(k > tabid.size())
        {
            cout << "NIE" << endl;
        }
        else
        {
            cout << "TAK" << endl;
            fac(tabid[k - 1]);
            for(int j = factorial.size() - n; j < factorial.size(); j++)
            {
                factorialClear.push_back(factorial[j]);
            }

            for(int i = 0; i < factorialClear.size(); i++)
            {
                goodnumber.push_back(number[factorialClear[i]]);
                //cout << "= " << factorialClear[i] << endl;
                for(int j = 0; j < number.size(); j++)
                {
                    if(j != factorialClear[i])
                    {
                        buff.push_back(number[j]);
                        //cout << " * " << number[j];
                    }
                }
                //cout << endl;
                number.clear();
                for(int k = 0; k < buff.size(); k++)
                {
                    number.push_back(buff[k]);
                }
                buff.clear();
            }

            for(int i = 0; i < number.size(); i++)
            {
                goodnumber.push_back(number[i]);
                //cout << number[i] << endl;
            }

            for(int i = 0; i < goodnumber.size(); i++)
            {
                cout << goodnumber[i];
                if(i != goodnumber.size() - 1)
                {
                    cout << " ";
                }
                else
                {
                    cout << endl;
                }
            }
        }

        //for(int i = 0; i < tab.size(); i++)
        //{
            //cout << tab[i] << endl;
        //}
    }
    else
    {
        cout << "NIE" << endl;
    }
    return 0;
}