#P9098. Toys

    ID: 22257 Type: Default 1000ms 256MiB

Toys

Toys

This problem is adapted from PA 2020 Round 2. In this problem, Bitie and Bytie are brothers with impressive toy collections. Each of them has n toys, where every toy is of one of the 26 types labeled from a to z.

Bitie has arranged his toys from left to right forming a sequence represented by a string of n English letters. Similarly, Bytie has his own sequence. Bitie now wants to rearrange his sequence to match Bytie's.

Bitie is allowed to perform an operation in which he selects a contiguous segment of toys of odd length and reverses their order. In a single move, for instance, if Bitie’s sequence is abcdea, he can reverse the segment from the 2nd to 4th toy to obtain adcbea or reverse the segment from the 1st to 5th toy to obtain edcbaa. However, he is not allowed to choose a segment of even length (e.g. he cannot obtain bacdea in one move).

Your task is to determine whether Bitie can transform his toy sequence into Bytie’s toy sequence using a sequence of such odd-length reversal operations.

Hint: Reversing an odd-length segment preserves the parity (evenness or oddness) of the indices of the toys. This means that the multiset of toys in even positions and the multiset of toys in odd positions remain unchanged after each operation.

Formally, let Bitie’s sequence be s and Bytie’s sequence be t (both of length n). Bitie can successfully transform his sequence into t if and only if:

[ \text{sorted}({ s_i : i \equiv 0 \pmod{2} }) = \text{sorted}({ t_i : i \equiv 0 \pmod{2} }) \quad\text{and}\quad \text{sorted}({ s_i : i \equiv 1 \pmod{2} }) = \text{sorted}({ t_i : i \equiv 1 \pmod{2} }). ]

If the above condition holds, output Yes. Otherwise, output No.

inputFormat

The input consists of three lines:

  • The first line contains an integer n (the number of toys).
  • The second line contains a string of n lowercase letters representing Bitie’s toy sequence.
  • The third line contains a string of n lowercase letters representing Bytie’s toy sequence.

outputFormat

Output a single line with either Yes if Bitie can transform his sequence into Bytie’s sequence using the allowed operations, or No otherwise.

sample

5
ababa
ababa
Yes