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
#include<bits/stdc++.h>
using namespace std;
int n,parza,parzb,nparza,nparzb;
vector<pair<int,int>>aa;
vector<pair<int,int>>bb;
string a,b;
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin>>n;
    cin>>a;
    cin>>b;
    for(int i=0;i<n;i++)
    {
        aa.push_back(make_pair(a[i],i));
        bb.push_back(make_pair(b[i],i));
    }
    sort(aa.begin(),aa.end());
    sort(bb.begin(),bb.end());
    for(int i=0;i<n;i++)
    {
        if(aa[i].first!=bb[i].first)
        {
            //cout<<aa[i].first<<" "<<bb[i].first<<endl;
            //cout<<i<<endl;
            cout<<"NIE";
            return 0;
        }
        else
        {
            if(aa[i].first!=aa[i+1].first)
            {
                if(aa[i].second%2==0)
                    parza++;
                else nparza++;
                if(bb[i].second%2==0)
                    parzb++;
                else nparzb++;
                if(nparza==nparzb&&parza==parzb)
                {
                    nparza=0;
                    nparzb=0;
                    parza=0;
                    parzb=0;
                }
                else
                {
                    cout<<"NIE";
                    return 0;
                }
            }
            else
            {
                if(aa[i].second%2==0)
                    parza++;
                else nparza++;
                if(bb[i].second%2==0)
                    parzb++;
                else nparzb++;
            }
        }
    }
    cout<<"TAK";
}