#include <bits/stdc++.h>
const int N = 2e6 + 6;
int T, lenA, lenB, len, Wi, id[N], idx;
int a[N], m;
std ::pair<int, int> p[N];
char s[N];
inline bool cmp(const int &x, const int &y) {
  for (int i = 0; i < Wi; ++i) {
    if (s[x + i] < s[y + i]) return true;
    if (s[x + i] > s[y + i]) return false;
  }
  return false;
}
inline bool equal(const int &x, const int &y) {
  for (int i = 0; i < Wi; ++i)
    if (s[x + i] != s[y + i]) return false;
  return true;
}
inline bool compare(const int &x, const int &y) { return p[x] < p[y]; }
int main() {
  T = 1;
  while (T--) {
    scanf("%s", s + 1), lenA = strlen(s + 1);
    scanf("%s", s + lenA + 1), lenB = strlen(s + lenA + 1);
    if (lenA != lenB) {
      puts("NO");
      continue;
    }
    len = 1;
    while (!(lenA % (len << 1))) len <<= 1;
    Wi = lenA / len;
    idx = m = 0;
    for (int i = 1; i <= lenA + lenB; i += Wi) id[++idx] = i;
    std ::sort(id + 1, id + idx + 1, cmp);
    for (int i = 1, k; k = id[i], i <= idx; ++i) {
      if (i == 1 || !equal(k, id[i - 1])) ++m;
      a[(k - 1) / Wi] = m;
    }
    for (int k = len; k > 1; k >>= 1) {
      int nidx = 0, nm = 0;
      for (int i = 0; i < idx; i += 2) {
        if (a[i] > a[i + 1]) std ::swap(a[i], a[i + 1]);
        p[nidx++] = std ::make_pair(a[i], a[i + 1]);
      }
      for (int i = 0; i < nidx; ++i) id[i] = i;
      std ::sort(id, id + nidx, compare);
      for (int i = 0; i < nidx; ++i) {
        if (!i || p[id[i]] != p[id[i - 1]]) ++nm;
        a[id[i]] = nm;
      }
      idx = nidx, m = nm;
    }
    puts(m == 1 ? "YES" : "NO");
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
