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
// Tadeusz Kielak

#include <iostream>

using namespace std;

#define MAX_CHAR 300002

char bajtus[ MAX_CHAR ];
char bitus[ MAX_CHAR];

long znajdz( char c, long k, long n )
{
    for( long l = k; l < n; l += 2 )
        if( bitus[ l ] == c )
            return l;
    return -1;
}

void zamien( long k, long l)
{
    char d = bitus[ k ];
    bitus[ k ] = bitus[ l ];
    bitus[ l ] = d;

}

int main()
{
    long n, i;


    cin >> n;
    cin >> bitus;
    cin >> bajtus;

    i = 0;
    while( i < n)
    {
        if( bitus[ i ] == bajtus[ i ])
            i ++;
        else
        {
            char c = bajtus[ i ];
            long h = znajdz( c, i + 2, n);
            if( h == -1 )
            {
                cout << "NIE\n";
                return 0;
            }
            zamien( i, h );
            i ++;
        }
    }

    cout << "TAK\n";
    return 0;
}