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
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>

std::string split(std::string line, int word_index, char split = ' ')
{
	if(line.length() < 3 || word_index > line.length())
	{
		return "-1";
	}

	int c = 0;
	std::string to_return = "";

	for (int i = 0; i < line.length(); i++)
	{
		if (line[i] == split && c != word_index)
		{
			c++;
		}
		else if (line[i] == split && c == word_index)
		{
			return to_return;
		}
		else if(c == word_index)
		{
			to_return += line[i];
		}
	}

	return to_return;
}

int sumChar(std::string word)
{
	int c = 0;

	for (int i = 0; i < word.length(); i++)
	{
		c += word[i];
	}

	return c;
}

int main()
{
	std::string line;

	getline(std::cin, line);
	int len = stoi(line);

	getline(std::cin, line);
	std::string w1 = line;

	getline(std::cin, line);
	std::string w2 = line;

	if(sumChar(w1) != sumChar(w2))
	{
		std::cout << "NIE";
		return 0;
	}

	int i = 0;
	while(i < len)
	{
		if(w2[i] != w1[i])
		{
			int flag = 0;
			for (int ii = i+2; ii < len; ii++)
			{
				if(w1[ii] == w2[i] && abs(ii - i) % 2 == 0)
				{
					//Swap
					char tem = w1[i];
					w1[i] = w1[ii];
					w1[ii] = tem;
					flag = 1;
					break;
				}
			}

			if (flag == 0)
			{
				std::cout << "NIE";
				return 0;
			}
		}
		else
		{
			i++;
		}
	}

	if (w1 == w2)
	{
		std::cout << "TAK";
	}
	else
	{
		std::cout << "NIE";
	}

	return 0;
}