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

int countInv(std::vector<int>& series) {
    int count = 0;
    for(auto it = series.begin(); it != series.end(); ++it) {
        for(auto i = it+1; i != series.end(); ++i) {
            if(*it > *i) ++count;
        }
    }
    return count;
}

bool isStabile(std::vector<int>& series) {
    std::vector<int> rev;
    rev.reserve(series.size());
    for(auto a : series) {
        rev.push_back(a);
    }
    std::reverse(std::begin(rev), std::end(rev));
    if(countInv(series) == countInv(rev)) {
        return true;
    }
    return false;
}

int main() {
    int n;
    unsigned long long k;
    std::cin >> n >> k;
    unsigned long long count = 0;
    if(n<4) {
        std::cout << "NIE\n";
        return 0;
    }
    std::vector<int> series;
    for(int i=0; i<n; ++i) {
        series.push_back(i+1);
    }
    do {
        if(isStabile(series)) {
            ++count;
            if(count == k) {
                std::cout << "TAK\n";
                for(auto& a : series) std::cout << a << ' ';
                return 0;
            }
            //std::cout << "I: " << countInv(series) << " ::  ";
            //for(auto& a : series) std::cout << a << ' ';
            //std::cout << '\n';
        }
    } while(std::next_permutation(series.begin(), series.end()));
    std::cout << "NIE\n";
    return 0;
}