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 nn toys, and each toy is one of 2626 types. For convenience, the brothers label each type of toy with an English letter from a\texttt a to z\texttt z.

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 nn English letters; the ii-th character of this sequence denotes the ii-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 abcdea\texttt{abcdea} describes Bitie’s toy order, then in one flip Bitie can obtain, for example, adcbea\texttt{adcbea} (by reversing the toys from the second to the fourth) or edcbaa\texttt{edcbaa} (by reversing the toys from the first to the fifth). However, he cannot obtain the sequence bacdea\texttt{bacdea} 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 nn, the number of toys each of them has.

The second line contains a string of length nn, representing Bitie’s toy sequence.

The third line contains a string of length nn, 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 n2×103n \le 2\times 10^3.

For 100%100\% of the testdata:

  • It is guaranteed that 1n3×1051\le n\le 3\times 10^5.
  • It is guaranteed that the strings contain only lowercase English letters (from a\texttt a to z\texttt z).

Translated by ChatGPT 5