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
#include <cstdint>
#include <cstring>
#include <map>
#include <set>
#include <utility>

namespace  {

using u32 = std::uint32_t;

constexpr u32 MAX = 300000+3;

char s1[MAX];
char s2[MAX];

u32 a[26][2];
u32 b[26][2];
}

void count(char(&s)[MAX], u32(&c)[26][2], u32 len)
{
    u32 odd = 0;
    for(u32 i=0; i<len; ++i)
    {
        c[s[i]-'a'][odd] ++;
        odd ^= 1;
    }
}

int main()
{
    u32 n;

    scanf("%u", &n);
    scanf("%s", s1);
    scanf("%s", s2);

    bool ok = false;
    if(n > 2) {
        count(s1, a, n);
        count(s2, b, n);
        ok = (0 == memcmp(a, b, sizeof(a)));
    }
    else {
        ok = (0 == strncmp(s1, s2, n));
    }

    printf("%s", ok ? "TAK" : "NIE");

    return 0;
}