#include <bits/stdc++.h>
using namespace std;
int main() {
  int af, as, flag = 1;
  string a = "", b = "";
  char x;
  for (int i = 0; i < 4; i++) {
    cin >> x;
    a += x;
  }
  for (int i = 0; i < 4; i++) {
    cin >> x;
    b += x;
  }
  swap(a[2], a[3]);
  swap(b[2], b[3]);
  b.erase(b.begin() + b.find('X'));
  a.erase(a.begin() + a.find('X'));
  af = a.find('A');
  as = b.find('A');
  int i = af, j = as;
  for (int k = 0; k < 3; k++) {
    if (a[i] != b[j]) flag = 0;
    i = (i + 1) % 3;
    j = (j + 1) % 3;
  }
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
