#include <bits/stdc++.h>
using namespace std;
inline long long getnum() {
  char c = getchar();
  int num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
char G[10], G2[10], temp[10];
int main() {
  gets(temp + 1);
  gets(temp + 3);
  swap(temp[3], temp[4]);
  int i;
  for (i = 1; temp[i] != 'A'; i++)
    ;
  for (int cnt = 2; cnt; i++) {
    if (i == 5) i = 1;
    if (temp[i] == 'X' || temp[i] == 'A') continue;
    if (temp[i] == 'B') G[cnt] = 'B';
    if (temp[i] == 'C') G[cnt] = 'C';
    cnt--;
  }
  gets(temp + 1);
  gets(temp + 3);
  swap(temp[3], temp[4]);
  for (i = 1; temp[i] != 'A'; i++)
    ;
  for (int cnt = 2; cnt; i++) {
    if (i == 5) i = 1;
    if (temp[i] == 'X' || temp[i] == 'A') continue;
    if (temp[i] == 'B') G2[cnt] = 'B';
    if (temp[i] == 'C') G2[cnt] = 'C';
    cnt--;
  }
  if (G[1] == G2[1] && G[2] == G2[2])
    puts("YES");
  else
    puts("NO");
}
