Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:   They are equal.  If we split string a into two halves of the same size a_1 and a_2, and string b into two halves of the same size b_1 and b_2, then one of the following is correct:   a_1 is equivalent to b_1, and a_2 is equivalent to b_2  a_1 is equivalent to b_2, and a_2 is equivalent to 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!


-----Input-----

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


-----Output-----

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


-----Examples-----
Input
aaba
abaa

Output
YES

Input
aabb
abab

Output
NO



-----Note-----

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".

Difficulty: competition

Starter code:

Solutions:
def main():
    a = list(input())
    b = list(input())

    n = len(a)
    k = n
    while k % 2 == 0:
        k = k // 2

    while k != n:
        pairs = n // (k * 2)
        for i in range(0, pairs * 2, 2):
            if a[k * i:k * (i + 1)] > a[k * (i + 1):k * (i + 2)]:
                a[k * i:k * (i + 1)], a[k * (i + 1):k * (i + 2)] = a[k * (i + 1):k * (i + 2)], a[k * i:k * (i + 1)]
            if b[k * i:k * (i + 1)] > b[k * (i + 1):k * (i + 2)]:
                b[k * i:k * (i + 1)], b[k * (i + 1):k * (i + 2)] = b[k * (i + 1):k * (i + 2)], b[k * i:k * (i + 1)]
        k *= 2

    if a == b:
        print('YES')
    else:
        print('NO')


main()


import collections

a = input()
b = input()
ca = collections.Counter(a)
cb = collections.Counter(b)


def eq(a, b, ah, at, bh, bt):
    if a[ah:at] == b[bh:bt]:
        return True
    len_a = at - ah
    if (len_a % 2) == 1:
        return False
    half = len_a // 2
    am = ah + half
    bm = bh + half
    return (eq(a, b, ah, am, bm, bt) and eq(a, b, am, at, bh, bm)) or (eq(a, b, ah, am, bh, bm) and eq(a, b, am, at, bm, bt))

if ca != cb:
    print('NO')
elif eq(a, b, 0, len(a), 0, len(b)):
    print('YES')
else:
    print('NO')


import collections

a = input()
b = input()
ca = collections.Counter(a)
cb = collections.Counter(b)


def eq(a, b):
    if a == b:
        return True
    len_a = len(a)
    if (len_a % 2) == 1:
        return False
    half = len_a // 2
    a1 = a[:half]
    a2 = a[half:]
    b1 = b[:half]
    b2 = b[half:]
    return (eq(a1, b2) and eq(a2, b1)) or (eq(a1, b1) and eq(a2, b2))

if ca != cb:
    print('NO')
elif eq(a, b):
    print('YES')
else:
    print('NO')

def F(s):
    if len(s)%2==1:return s
    s1 = F(s[:len(s)//2])
    s2 = F(s[len(s)//2:])
    if s1 < s2:return s1 + s2
    return s2 + s1
if F(input()) == F(input()):
    print("YES")
else:
    print("NO")


def read_list(t): return [t(x) for x in input().split()]
def read_line(t): return t(input())
def read_lines(t, N): return [t(input()) for _ in range(N)]

def smallest(s):
    len_s = len(s)
    if len_s & 1:
        return s
    s1 = smallest(s[:len_s//2])
    s2 = smallest(s[len_s//2:])
    return s1 + s2 if s1 < s2 else s2 + s1

S1 = read_line(str)
S2 = read_line(str)
print('YES' if smallest(S1) == smallest(S2) else 'NO')


def read_list(t): return [t(x) for x in input().split()]
def read_line(t): return t(input())
def read_lines(t, N): return [t(input()) for _ in range(N)]

def smallest(s):
    len_s = len(s)
    if len_s & 1:
        return s
    s1 = smallest(s[:len_s//2])
    s2 = smallest(s[len_s//2:])
    return s1 + s2 if s1 < s2 else s2 + s1


S1 = read_line(str)
S2 = read_line(str)
print('YES' if smallest(S1) == smallest(S2) else 'NO')


def g(s):
 l=len(s)
 return s if l%2==1 else sorted([g(s[:l//2]),g(s[l//2:])])
print('YES'if g(input())==g(input())else'NO')

def g(s):
 l=len(s)
 return sorted([g(s[:l//2]),g(s[l//2:])])if l%2==0 else s
i=input
print('YES'if g(i())==g(i())else'NO')

def g(s):
 l=len(s)
 return sorted([g(s[:l//2]),g(s[l//2:])])if l%2==0 else s
print('YES'if g(input())==g(input())else'NO')

def g(s):
 l=len(s);return sorted([g(s[:l//2]),g(s[l//2:])])if l%2==0 else s
print('YES'if g(input())==g(input())else'NO')

def g(s):l=len(s);return sorted([g(s[:l//2]),g(s[l//2:])])if l%2==0 else s
print('YES'if g(input())==g(input())else'NO')

def mini(s):
    x = len(s)
    if x%2==1:
        return s
    x//=2
    a = mini(s[0:x])
    b = mini(s[x::])
    return a+b if a<b else b+a
a,b = input(),input()
print("YES" if mini(a)==mini(b) else "NO")


def reorder(a):
    length = len(a)
    if length % 2 == 1:
        return a
    else:
        p_a = reorder(a[:length//2])
        s_a = reorder(a[length//2:])
        if p_a < s_a:
            return p_a + s_a
        else:
            return s_a + p_a

if reorder(input()) == reorder(input()):
    print("YES")
else:
    print("NO")


def reorder(a):
    length = len(a)
    if length % 2 == 1:
        return a
    else:
        return sorted([reorder(a[:length//2]), reorder(a[length//2:])])

if reorder(input()) == reorder(input()):
    print("YES")
else:
    print("NO")


def reorder(a):
    length = len(a)
    if length % 2 == 1:
        return a
    else:
        return sorted([reorder(a[:length//2]), reorder(a[length//2:])])

if reorder(input()) == reorder(input()):
    print("YES")
else:
    print("NO")


a=input()
b=input()
mas={}
def rasch(a, b):
    nonlocal mas
    s= a+b
    if a==b:
        mas[s]=2
        return True
    else:

        if mas.get(s): return True if mas[s]==2 else False
        if len(a)%2==0:
            a1=a[0:len(a)//2]
            a2=a[len(a)//2:]
            b1=b[0:len(a)//2]
            b2=b[len(a)//2:]
            res =(rasch(a1,b1) and rasch(a2,b2)) or(rasch(a1,b2) and rasch(a2,b1))
            mas[s]=(2 if res else 1)
            return res
        else: return False
print("YES") if rasch(a, b) else print("NO")

input1 = input()
input2 = input()

def sort(s, length):
    half, one = divmod(length, 2)
    if one == 1:
        return s
    else:
        s1, s2 = sort(s[:half], half), sort(s[half:], half)
        if s1 < s2:
            return s1 + s2
        else:
            return s2 + s1


if sort(input1, len(input1)) == sort(input2, len(input2)):
    print("YES")
else:
    print("NO")

def getmin(s):
    ls = len(s)
    if ls % 2 == 1:
        return s

    s1 = getmin(s[:ls//2])
    s2 = getmin(s[ls//2:])
    return s1 + s2 if s1 < s2 else s2 + s1


s1 = input()
s2 = input()
print("YES") if getmin(s1) == getmin(s2) else print("NO")

def f(s):
    if len(s) % 2:
        return s
    a = f(s[:len(s) // 2])
    b = f(s[len(s) // 2:])
    if a < b:
        return a+b
    else:
        return b+a

if f(input()) == f(input()):
    print("YES")
else:
    print("NO")


s1 = input()
s2 = input()

def Sort(string):
	l = len(string)
	if l % 2 == 1:
		return string 
	s1 = Sort(string[:l // 2:])
	s2 = Sort(string[l // 2::])
	if s1 < s2:
		return s1 + s2
	else:
		return s2 + s1

if Sort(s1) == Sort(s2):
	print("YES")
else:
	print("NO")	


str1 = input()
str2 = input()

saved = {}

def str_equal(str1, str2):
    
    if (str1, str2) in saved:
        return saved[(str1, str2)]
    elif str1 == str2:
        val = True
    elif len(str1) % 2 == 1:
        val = False
    else:
        new_len = len(str1) // 2

        val = ( (str_equal(str1[:new_len], str2[:new_len]) and str_equal(str1[new_len:], str2[new_len:])) or (str_equal(str1[:new_len], str2[new_len:]) and str_equal(str1[new_len:], str2[:new_len])))
    
    saved[(str1, str2)] = val
    return val
    
print('YES' if str_equal(str1, str2) else 'NO')

def main():
    a = list(input())
    b = list(input())
    
    n = len(a)
    k = n
    while k % 2 == 0:
        k = k // 2
    
    while k != n:
        pairs = n // (k * 2)
        for i in range(0, pairs * 2, 2):
            if a[k * i:k * (i + 1)] > a[k * (i + 1):k * (i + 2)]:
                a[k * i:k * (i + 1)], a[k * (i + 1):k * (i + 2)] = a[k * (i + 1):k * (i + 2)], a[k * i:k * (i + 1)]
            if b[k * i:k * (i + 1)] > b[k * (i + 1):k * (i + 2)]:
                b[k * i:k * (i + 1)], b[k * (i + 1):k * (i + 2)] = b[k * (i + 1):k * (i + 2)], b[k * i:k * (i + 1)]
        k *= 2
    
    if a == b:
        print('YES')
    else:
        print('NO')


main()

memo_dict = {}

def equivalent(a, b):
    if a == b:
        return True

    if (a, b) in memo_dict:
        return memo_dict[(a, b)]

    strlen = len(a)

    if strlen % 2 != 0:
        return False

    a1, a2 = a[:strlen//2], a[strlen//2:]
    b1, b2 = b[:strlen//2], b[strlen//2:]

    res = (equivalent(a1, b1) and equivalent(a2, b2)) or (equivalent(a1, b2) and equivalent(a2, b1))

    memo_dict[(a, b)] = res
    memo_dict[(b, a)] = res

    return res


a = input()
b = input()

if equivalent(a, b):
    print('YES')
else:
    print('NO')


from heapq import merge
def f(s):
    l = len(s)
    return [list(merge(f(s[:l>>1]),f(s[l>>1:])))] if l & 1 == 0 else [s] 
print('YES' if f(input()) == f(input()) else 'NO')