#include <bits/stdc++.h>
const double pi = acos(-1);
using namespace std;
char c[8], b[8];
int main() {
  for (int i = 0; i < 4; i++) {
    cin >> c[i];
    c[i + 4] = c[i];
  }
  swap(c[2], c[3]);
  swap(c[6], c[7]);
  for (int i = 0; i < 4; i++) {
    cin >> b[i];
  }
  swap(b[2], b[3]);
  int j = 0;
  int k = 0;
  if (b[0] == 'X') k++;
  while (c[j] != b[k]) {
    j++;
  }
  bool f = 0;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    count++;
    if (c[j] == 'X') j++;
    if (b[i] == 'X') i++;
    if (b[i] == c[j]) {
      j++;
    } else {
      cout << "NO";
      return 0;
    }
    if (count == 3) break;
  }
  cout << "YES";
  return 0;
}
