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
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<char>napis1(n);
    vector<char>napis2(n);
    map<char, int>m1;
    map<char, int>m2;
    map<char, vector<int>>x1;
    map<char, vector<int>>x2;
    for (char i = 'a'; i <= 'z'; i++)
    {
        m1[i] = 0;
        m2[i] = 0;
        x1[i] = {};
        x2[i] = {};
    }
    for (int i = 0; i < n; i++)
    {
        cin >> napis1[i];
        m1[napis1[i]]++;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> napis2[i];
        m2[napis2[i]]++;
    }
    bool flag = true;
    for (char i = 'a'; i <= 'z'; i++)
    {
        if (m1[i] != m2[i])
        {
            flag = false;
            break;
        }
    }
    if (flag == false)
    {
        cout << "NIE";
        return 0;
    }

    for (int i = 0; i < n; i++)
    {
        x1[napis1[i]].push_back(i % 2);
        x2[napis2[i]].push_back(i % 2);
    }
    for (char i = 'a'; i <= 'z'; i++)
    {
        sort(x1[i].begin(), x1[i].end());
        sort(x2[i].begin(), x2[i].end());
    }
    for (char i = 'a'; i <= 'z'; i++)
    {
        for (int j = 0; j < x1[i].size(); j++)
        {
            if (x1[i][j] != x2[i][j])
            {
                flag = false;
                cout << "NIE";
                return 0;
            }
        }
    }
    cout << "TAK";

    return 0;
}