#P4656. Equivalent Strings

Equivalent Strings

Equivalent Strings

题面翻译

给定两个字符串a,ba,b,询问它们是不是等价的(EquivalentEquivalent,等效的,等价的)。

关于等价的定义:(以字符串ss为例)

  1. 如果s|s|为奇数,那与ss等价的字符串为它本身;
  2. 如果s|s|为偶数,那把ss平分为两份,记作s1,s2s_{1},s_{2},与ss等价的字符串为s1s2s_{1}s_{2}s2s1s_{2}s_{1}

s200000|s|≤200000

题目描述

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a a and b b of equal length are called equivalent in one of the two cases:

  1. They are equal.
  2. If we split string a a into two halves of the same size a1 a_{1} and a2 a_{2} , and string b b into two halves of the same size b1 b_{1} and b2 b_{2} , then one of the following is correct:
  3. a1 a_{1} is equivalent to b1 b_{1} , and a2 a_{2} is equivalent to b2 b_{2}
  4. a1 a_{1} is equivalent to b2 b_{2} , and a2 a_{2} is equivalent to b1 b_{1}

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it's your turn!

输入格式

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 1 to 200000 200000 and consists of lowercase English letters. The strings have the same length.

输出格式

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

样例 #1

样例输入 #1

aaba
abaa

样例输出 #1

YES

样例 #2

样例输入 #2

aabb
abab

样例输出 #2

NO

提示

In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".

In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".