luogu#P9098. [PA 2020] Zabawki
[PA 2020] Zabawki
Problem Description
This problem is translated from PA 2020 Round 2 Zabawki.
You may not know this, but the brothers Bitie and Bytie have a quite impressive toy collection! Each of them owns toys, and each toy is one of types. For convenience, the brothers label each type of toy with an English letter from to .
In today’s game, Bitie takes out his toys and arranges them from left to right. Therefore, Bitie can describe the arrangement of his toys with a sequence of English letters; the -th character of this sequence denotes the -th toy from the left in Bitie’s sequence. At the same time, Bytie also takes out his toys and arranges them from left to right. Now Bitie wants to become more like Bytie—he wants to rearrange his own toys to match the order of Bytie’s toys.
During the game, Bitie can change the order of his toys by performing flips. In one flip, he can take an odd number of consecutive toys and reverse their order. Thus, if the string describes Bitie’s toy order, then in one flip Bitie can obtain, for example, (by reversing the toys from the second to the fourth) or (by reversing the toys from the first to the fifth). However, he cannot obtain the sequence after a single flip.
Can Bitie obtain exactly the same toy sequence as Bytie’s by using flips?
Input Format
The first line contains an integer , the number of toys each of them has.
The second line contains a string of length , representing Bitie’s toy sequence.
The third line contains a string of length , representing Bytie’s toy sequence.
Output Format
If Bitie can obtain the same toy sequence as Bytie’s by using flips, output TAK; otherwise output NIE.
7
abcdefg
edgbcfa
TAK
5
abcde
fghhh
NIE
Hint
Explanation of Sample 1
For the first sample, Bitie can obtain the same toy sequence as Bytie’s after three flip operations.

Constraints
This problem uses bundled testdata.
For some subtasks, it holds that if the answer for this testdata is TAK, then Bitie needs at most one swap to obtain the same sequence as Bytie.
In addition, about half of the subtasks satisfy .
For of the testdata:
- It is guaranteed that .
- It is guaranteed that the strings contain only lowercase English letters (from to ).
Translated by ChatGPT 5