#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-7;
const int INF = 1E9;
const int MAXN = 200500;
string s[2], curS;
int K, L;
int ind[2][MAXN];
vector<string> lib, lib2;
int main() {
  for (int i = 0; i < (int)(2); i++) cin >> s[i];
  L = s[0].size();
  while (L != 1 && (L % 2 == 0)) L >>= 1;
  K = s[0].size() / L;
  lib.resize(K);
  for (int i = 0; i < (int)(K); i++) {
    lib[i] = "";
    for (int j = L * i; j < L * (i + 1); j++) lib[i] += s[0][j];
  }
  sort((lib).begin(), (lib).end());
  lib2.push_back(lib[0]);
  for (int i = (int)(1); i < (int)(lib.size()); i++)
    if (lib[i - 1] != lib[i]) lib2.push_back(lib[i]);
  lib = lib2;
  for (int id = 0; id < (int)(2); id++) {
    for (int i = 0; i < (int)(K); i++) {
      curS = "";
      for (int j = L * i; j < L * (i + 1); j++) curS += s[id][j];
      auto it = lower_bound((lib).begin(), (lib).end(), curS);
      if (it == lib.end()) {
        cout << "NO";
        return 0;
      }
      int pos = it - lib.begin();
      if (lib[pos] != curS) {
        cout << "NO";
        return 0;
      }
      ind[id][i] = pos;
    }
  }
  for (int id = 0; id < (int)(2); id++) {
    int step = 1;
    while (step < K) {
      for (int i = 0; i < K; i += step * 2) {
        bool cmp = 0;
        for (int j = i; j < (i + step); j++) {
          if (ind[id][j] < ind[id][j + step]) break;
          if (ind[id][j] > ind[id][j + step]) {
            cmp = 1;
            break;
          }
        }
        if (cmp) {
          for (int j = i; j < (i + step); j++)
            swap(ind[id][j], ind[id][j + step]);
        }
      }
      step *= 2;
    }
  }
  for (int i = 0; i < (int)(K); i++)
    if (ind[0][i] != ind[1][i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
