# Codeforces Round #313 (Div. 2)560D. Equivalent Strings

D. Equivalent Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
#define maxn 200010
char a[maxn], b[maxn];
bool dfs(char s1[], char s2[], int len){
if(!strncmp(s1, s2, len)) return 1;
if(len % 2 == 1) return 0;
int m = len/2;
if(dfs(s1+m, s2, m)&&dfs(s1, s2+m, m)) return 1;
if(dfs(s1, s2, m)&&dfs(s1+m, s2+m, m)) return 1;
}
int main(){
scanf("%s %s", a, b);
int len = strlen(a);
if(dfs(a, b, len)) printf("YES\n");
else printf("NO\n");
}


• 本文已收录于以下专栏：

## Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

A:Game With Sticks 水题。。。每次操作，都会拿走一个横行，一个竖行。 所以一共会操作min（横行，竖行）次。 #include #include #include #include ...
• rowanhaoa
• 2014年07月25日 14:39
• 1468

## 【解题报告】Codeforces Round #401 (Div. 2)

• TRiddle
• 2017年02月25日 17:55
• 408

## Codeforces Round #395 (Div. 2)(ABCD)

ps:打完这场cf才知道自己真的很菜，还是停留在AB题的水平，有时候CD其实很简单，但就是想不到，别人一眼看出而我就是想不到，有时候想到了点子上但就是突破不了 题目链接：  Codeforc...
• qq_34731703
• 2017年02月03日 12:50
• 484

## Codeforces Round #460 (Div. 2) D. Substring（拓扑排序）

• cyf199775
• 2018年02月01日 13:55
• 33

## Codeforces Round #378 (Div. 2) E. Sleep in Class

• Fsss_7
• 2016年11月15日 13:48
• 355

## Codeforces Round #442 (Div. 2)

A. #include using namespace std; typedef long long ll; int main() { string s; cin >> s; ...
• Egqawkq
• 2017年10月24日 02:15
• 236

## Codeforces Round #428 (Div. 2)：D. Winter is here（组合数公式）

D. Winter is here time limit per test 3 seconds memory limit per test 256 megabytes input stan...
• Jaihk662
• 2017年08月14日 14:52
• 341

## Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B

A. Gotta Catch Em’ All!time limit per test:1 secondmemory limit per test:256 megabytesinput:standard...
• qq_33183401
• 2017年01月16日 17:12
• 239

## Codeforces Round #460 (Div. 2) D. Substring

• litmxs
• 2018年01月31日 23:25
• 57

## Codeforces Round #327 (div.2)(A B C D)

codeforces round #327 (div.2)
• lincifer
• 2015年10月26日 13:11
• 1085

举报原因： 您举报文章：Codeforces Round #313 (Div. 2)560D. Equivalent Strings 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)