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
#define _CRT_SECURE_NO_WARNINGS
#define ONLINE_JUDGE
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cassert>
using namespace std;

class Solver
{
public:
    static bool solve(const string& firstString, const string& secondString)
    {
        string firstEven = extractEverySecondCharacter(firstString, 0);
        sort(firstEven.begin(), firstEven.end());

        string secondEven = extractEverySecondCharacter(secondString, 0);
        sort(secondEven.begin(), secondEven.end());

        string firstOdd = extractEverySecondCharacter(firstString, 1);
        sort(firstOdd.begin(), firstOdd.end());

        string secondOdd = extractEverySecondCharacter(secondString, 1);
        sort(secondOdd.begin(), secondOdd.end());

        return firstEven == secondEven && firstOdd == secondOdd;
    }
private:
    static string extractEverySecondCharacter(const string& input, int offset)
    {
        string result;

        for (int i = offset; i < input.size(); i += 2)
            result += input[i];
        
        return result;
    }
};

int main()
{
#ifndef ONLINE_JUDGE
    assert(Solver::solve("a", "b") == false);
    assert(Solver::solve("a", "a") == true);
    assert(Solver::solve("ab", "ab") == true);
    assert(Solver::solve("ab", "ba") == false);
    assert(Solver::solve("aa", "aa") == true);
    assert(Solver::solve("aaa", "aaa") == true);
    assert(Solver::solve("abc", "cba") == true);
    assert(Solver::solve("abc", "cab") == false);
#endif
    int length;
    scanf("%d\n", &length);
    char buffer[300001];
    scanf("%s", buffer);
    string firstString = buffer;
    scanf("%s", buffer);
    string secondString = buffer;

    if (Solver::solve(firstString, secondString))
        printf("TAK\n");
    else
        printf("NIE\n");
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}