#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[3];
  char b[3];
  char aa[4];
  char bb[4];
  int j = 0, c = 0;
  for (int i = 0; i < 4; i++) {
    cin >> aa[i];
  }
  for (int i = 0; i < 4; i++) {
    cin >> bb[i];
  }
  if (aa[0] != 'X') {
    a[0] = aa[0];
    j++;
  }
  if (aa[1] != 'X') {
    a[j] = aa[1];
    j++;
  }
  j = 0;
  if (aa[2] != 'X') {
    a[2] = aa[2];
    j++;
  }
  if (aa[3] != 'X') {
    a[2 - j] = aa[3];
  }
  j = 0;
  if (bb[0] != 'X') {
    b[0] = bb[0];
    j++;
  }
  if (bb[1] != 'X') {
    b[j] = bb[1];
    j++;
  }
  j = 0;
  if (bb[2] != 'X') {
    b[2] = bb[2];
    j++;
  }
  if (bb[3] != 'X') {
    b[2 - j] = bb[3];
  }
  j = 0;
  for (int i = 0; i < 9; i++) {
    for (int k = 0; k < 6; k++) {
      if (b[k % 3] == a[i % 3]) {
        j++;
        i++;
      } else {
        if (j >= 3) {
          c = 1;
          break;
        }
        j = 0;
      }
    }
    if (c == 1) {
      break;
    }
  }
  if (c == 1) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
