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

using namespace std;

bool sprawdz_czy_mozna(const int &n, const unsigned long long &k){
    
    unsigned long long perm = 1;
    
    for(int i = 2; i <= n; i++){
        
        perm *= i;
        if(perm >= k) return true;
    }
    
    return false;
}


void szukaj(const int &n, const unsigned long long &k){
    
    vector<int> w;
    
    for(int i = 1; i <= n; i++) w.push_back(i);
    
    unsigned long long ktora = 0;
    
    do{
        
        int ile1 = 0, ile2 = 0;
        
        for(int i = 0; i < w.size(); i++){
            if(w[i] > (i + 1)) ile1 ++;
            if(w[i] > (n - i)) ile2 ++;
        }
        
        if(ile1 == ile2){
            
            if(ktora == k){
                
                printf("TAK\n");
                for(int i = 0; i < w.size(); i++) printf("%d ", w[i]);
                printf("\n");
                
                return;
            }
            
            ktora ++;
        }
        
    }while (next_permutation(w.begin(), w.end()));
    
}

int main() {
    
    int n;
    unsigned long long k;
    scanf("%d%llu", &n, &k);
    
    if(!sprawdz_czy_mozna(n, k)){
        printf("NIE\n");
        return 0;
    }
    
    szukaj(n, k);
    
    return 0;
}