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
#include <cstdio>
#include <cstring>

int main() {
    long n;
    scanf("%ld", &n);

    char a[n], b[n], aL, bL;
    int aPosition = 97;
    long countsA[26 + aPosition+1] = {0};
    long countsB[26 + aPosition+1] = {0};

    long oddPositionsA[26 + aPosition+1] = {0};
    long oddPositionsB[26 + aPosition+1] = {0};

    long toLeft = 0;
    long toRight = 0;
    
    scanf("%s", a);
    scanf("%s", b);

    if(strcmp(a, b) == 0) {
        printf("TAK\n");
        return 0;
    } else if (n == 2) {
        printf("NIE\n");
        return 0;
    }

    for(long i = 0; i < n; i++) {
        aL = a[i];
        bL = b[i];
        countsA[(int)aL]++;
        countsB[(int)bL]++;

        if(i % 2 == 1) {
            oddPositionsA[(int)aL]++;
            oddPositionsB[(int)bL]++;
        }
    }

    for(int i = aPosition; i < 26 + aPosition; i++) {
        if(countsA[i] != countsB[i]) {
            printf("NIE\n");
            return 0;
        }

        if(oddPositionsA[i] % 2 != oddPositionsB[i] % 2) {
            printf("NIE\n");
            return 0;
        }
    }

    printf("TAK\n");

    return 0;
}