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
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
    string s1, s2, sp1, sp2, sp3, sp4;
    int n;
    cin >> n;
    cin >> s1;
    cin >> s2;
    
    if(n <= 2){
        if(s1==s2){
            cout << "TAK";
            return 0;
        }
    }else if(n == 3){
        sp1 = s1[0];
        sp1 += s1[2];
        sp2 = s2[0];
        sp2 += s2[2];
        sort(sp1.begin(),sp1.end());
        sort(sp2.begin(),sp2.end());
        if(sp1 == sp2 && s1[1] == s2[1]){
            cout << "TAK";
            return 0;
        }
    }else if(n == 4){
        sp1 = s1[0];
        sp1 += s1[2];
        sp2 = s2[0];
        sp2 += s2[2];
        sp3 = s1[1];
        sp3 += s1[3];
        sp4 = s2[1];
        sp4 += s2[3];
        sort(sp1.begin(),sp1.end());
        sort(sp2.begin(),sp2.end());
        sort(sp3.begin(),sp3.end());
        sort(sp4.begin(),sp4.end());
        if(sp1== sp2 && sp3==sp4){
            cout << "TAK";
            return 0;
        }
    }else{
        sp1 = s1[0];
        sp2 = s1[1];
        for (int i=2; i<=s1.size()-1; i++){
            if(i%2 == 0){
                sp1 += s1[i];
            }else{
                sp2 += s1[i];
            }
        }
        sp3 = s2[0];
        sp4 = s2[1];
        for (int i=2; i<=s2.size()-1; i++){
            if(i%2 == 0){
                sp3 += s2[i];
            }else{
                sp4 += s2[i];
            }
        }
        sort(sp1.begin(), sp1.end());
        sort(sp2.begin(), sp2.end());
        sort(sp3.begin(), sp3.end());
        sort(sp4.begin(), sp4.end());
        if(sp1==sp3 && sp2 == sp4){
            cout << "TAK";
            return 0;
        }
    }
    
    cout << "NIE";
    return 0;
}