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


void sortString(string &str)
{
    sort(str.begin(), str.end());
}
void zamiana(string &str, int beginz, int endz)
{
    while (beginz!=endz)
    {
        char c=str[beginz];
        str[beginz]=str[endz];
        str[endz]=c;

        beginz++;
        endz--;

    }

}
int main()
{
    int  n; //osobno liczba zabawek Bitusia i Bajtusia
    string Bitus="", Bajtus="";
    cin>>n;

    for (int i=0; i<2; i++)
    {

        if(i==0)
        {
            cin>>Bitus;
        }

        else
        {
            cin>>Bajtus;
        }

    }
string pomoc1 = Bitus;
string pomoc2 = Bajtus;
sortString(pomoc1);
sortString(pomoc2);

for (int i=0; i<n; i++)
{
    if (pomoc1[i]!=pomoc2[i])
    {
        cout<<"NIE";
        return 0;
    }

}
int suma=1;
while(Bitus!=Bajtus)
{
    for (int i=suma; i<=n; i++)
    {

        if(Bajtus[suma-1]==Bitus[i-1] && (i-suma+1)%2==1)
        {
            zamiana(Bitus,suma-1,i-1);
        }


    }
 suma++;
    if (suma==2*n)
    {
        cout<<"NIE";
        return 0;
    }
}
cout<<"TAK";
    return 0;
}