#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string t, x;
  cin >> x;
  reverse(x.begin(), x.end());
  s += x;
  cin >> t;
  cin >> x;
  reverse(x.begin(), x.end());
  t += x;
  string s2, t2;
  s2 = s;
  t2 = t;
  s = "";
  t = "";
  for (auto i : s2)
    if (i != 'X') s += i;
  for (auto i : t2)
    if (i != 'X') t += i;
  for (int i = 1; i <= 5; ++i) {
    if (s == t) {
      cout << "YES" << endl;
      return 0;
    }
    s = s.substr(1) + s[0];
  }
  cout << "NO" << endl;
}
