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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


vector<int> odd_pos[26];
vector<int> even_pos[26];

int
main()
{
    ios_base::sync_with_stdio(NULL);
    cout.tie(NULL);
    cin.tie(NULL);

    int N;
    string S1, S2;
    string S3, S4;

    cin >> N;
    cin >> S1 >> S2;
    S3 = S1.substr(0, N);
    S4 = S2.substr(0, N);
    sort(S3.begin(), S3.end());
    sort(S4.begin(), S4.end());

    for(int i = 0; i < N; ++i) {
        int curr_c = S2[i] - 'a';
        if (i % 2 == 0) {
            even_pos[curr_c].push_back(i);
        } else {
            odd_pos[curr_c].push_back(i);
        }
    }

    if (S3 == S4) {
        for(int i = 0; i < N; ++i) {
            int curr_c = S1[i] - 'a';
            if (i % 2 == 0) {
                if (even_pos[curr_c].empty()) {
                    cout << "NIE";
                    return 0;
                }
                even_pos[curr_c].pop_back();
            } else {
                if (odd_pos[curr_c].empty()) {
                    cout << "NIE";
                    return 0;
                }
                odd_pos[curr_c].pop_back();
            }
        }
    } else {
        cout << "NIE";
        return 0;
    }

    cout << "TAK";

    return 0;
}