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

int n;
string A, B;
vector<int>LitA[26];
vector<int>LitB[26];

bool F (int X, int Y)
{
    return X%2<Y%2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n;
    cin>>A>>B;

    for (int i=0; i<n; ++i){
        LitA[A[i]-'a'].push_back(i);
        LitB[B[i]-'a'].push_back(i);
    }

    for (int i=0; i<26; ++i)
        if (LitA[i].size()!=LitB[i].size()){
            cout<<"NIE";
            return 0;
        }

    for (int i=0; i<26; ++i){
        int x0=0, x1=LitA[i].size()-1;

        if (LitA[i].size()==0)
            continue;
        else
            sort(LitB[i].begin(), LitB[i].end(), F);

        for (int j=0; j<LitA[i].size(); ++j){
            if (LitA[i][j]%2==0){
                if (LitB[i][x0]%2==0)
                    ++x0;
                else{
                    cout<<"NIE";
                    return 0;
                }
            }
            else{
                if (LitB[i][x1]%2==1)
                    --x1;
                else{
                    cout<<"NIE";
                    return 0;
                }
            }
        }
    }

    cout<<"TAK";


    return 0;
}