#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> a(4), b(4);
  cin >> a[0] >> a[1] >> a[3] >> a[2];
  cin >> b[0] >> b[1] >> b[3] >> b[2];
  int i1, i2;
  for (int i = 0; i < 4; i++)
    if (a[i] == 'A') i1 = i;
  for (int i = 0; i < 4; i++)
    if (b[i] == 'A') i2 = i;
  bool clock1;
  for (int i = 0; i < 4; i++) {
    int ind = (i1 + i) % 4;
    if (a[ind] == 'B') {
      clock1 = true;
      break;
    } else if (a[ind] == 'C') {
      clock1 = false;
      break;
    }
  }
  bool clock2;
  for (int i = 0; i < 4; i++) {
    int ind = (i2 + i) % 4;
    if (b[ind] == 'B') {
      clock2 = true;
      break;
    } else if (b[ind] == 'C') {
      clock2 = false;
      break;
    }
  }
  if (clock1 == clock2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
