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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;


#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(9)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;
typedef unsigned long long              ull;
typedef long long                       ll;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467093870598391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e16 + 9;

///tagliatelle here
template<typename T>
class LazyTree{                 ///(0,1,...n-1)
private:
    vector<T> Tree, lazy;
    int leafcount = 1;
public:
    void push(T v){                   ///accumulates lazy values in leaves but they don't matter
        Tree[v * 2] += lazy[v];         ///pushing the lazy value to tree node
        lazy[v * 2] += lazy[v];         ///pushing the lazy indicator to the tree node
        Tree[v * 2 + 1] += lazy[v];
        lazy[v * 2 + 1] += lazy[v];
        lazy[v] = 0;                    ///no actions further postponed for this node
    }

    void rangeupdate(int l, int r, T val, int from = 0, int to = -1, int akt = 1){
        if(to == -1)
            to += leafcount;
        if(l > r)
            return;
        if(from == l && r == to){
            Tree[akt] += val;
            lazy[akt] += val;
        }else if(from <= l && r <= to){
            push(akt);
            int mid = from + (to - from) / 2;
            if(r <= mid)
                rangeupdate(l, r, val, from, mid, 2 * akt);
            else if(mid + 1 <= l)
                rangeupdate(l, r, val, mid + 1, to, 2 * akt + 1);
            else{
                rangeupdate(l, mid, val, from, mid, 2 * akt);
                rangeupdate(mid + 1, r, val, mid + 1, to, 2 * akt + 1);
            }
            Tree[akt] = Tree[akt * 2] + Tree[2 * akt + 1];
        }
    }

    T rangequery(int l, int r, int from = 0, int to = -1, int akt = 1){
        if(to == -1)
            to += leafcount;
        if(l > r)
            return 0;
        if(from == l && r == to){
            return Tree[akt];
        }else if(from <= l && r <= to){
            push(akt);
            int mid = from + (to - from) / 2;
            if(r <= mid)
                return rangequery(l, r, from, mid, 2 * akt);
            else if(mid + 1 <= l)
                return rangequery(l, r, mid + 1, to, 2 * akt + 1);
            else{
                return rangequery(l, mid, from, mid, 2 * akt) + rangequery(mid + 1, r, mid + 1, to, 2 * akt + 1);
            }
        }
        return 0;
    }

    LazyTree(int _n){
        while(leafcount < _n)
            leafcount *= 2;
        Tree.resize(2 * leafcount);
        lazy.resize(2 * leafcount);
        for(int i = 0; i < 2 * leafcount; i++)
            Tree[i] = 0, lazy[i] = 0;
    }

};
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){
}

void solve(){
    int n;
    cin >> n;
    string s[2];
    cin >> s[0] >> s[1];
    string t1 = "", t2 = "";
    for(int i = 0; i < n; i++){
        if(i % 2 == 1){
            t1.pb(s[0][i]);
            t2.pb(s[1][i]);
        }
    }
    sortall(t1);
    sortall(t2);
    if(t1 != t2){
        cout << "NIE" << endl;
        return;
    }
    t1.clear();
    t2.clear();
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            t1.pb(s[0][i]);
            t2.pb(s[1][i]);
        }
    }
    sortall(t1);
    sortall(t2);
    if(t1 != t2){
        cout << "NIE" << endl;
        return;
    }
    cout << "TAK" << endl;
}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
//#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
    fastio;
    int T = 1;
    prep();
    //cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test number " << i << endl;
        solve();
        //cout << "end" << endl;
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/