#include <bits/stdc++.h>
using namespace std;
const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string a, b, x, y;
  cin >> a >> b >> x >> y;
  reverse((b).begin(), (b).end());
  reverse((y).begin(), (y).end());
  a = a + b;
  x = x + y;
  string s, t;
  for (char c : a) {
    if (c != 'X') {
      s += c;
    }
  }
  for (char c : x) {
    if (c != 'X') {
      t += c;
    }
  }
  t += t;
  if (t.find(s) != string::npos) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}
