Problem: Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

<image>

In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

Input

The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

Output

Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

Examples

Input

AB
XC
XB
AC


Output

YES


Input

AB
XC
AC
BX


Output

NO

Note

The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
long long int SIZE(const T (&t)[N]) {
  return N;
}
template <typename T>
long long int SIZE(const T &t) {
  return t.size();
}
string to_string(const string s, long long int x1 = 0, long long int x2 = 1e9) {
  return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(const bool b) { return (b ? "true" : "false"); }
string to_string(const char c) { return string({c}); }
template <size_t N>
string to_string(const bitset<N> &b, long long int x1 = 0,
                 long long int x2 = 1e9) {
  string t = "";
  for (long long int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
       __iii__ <= __jjj__; ++__iii__) {
    t += b[__iii__] + '0';
  }
  return '"' + t + '"';
}
template <typename A, typename... C>
string to_string(const A(&v), long long int x1 = 0, long long int x2 = 1e9,
                 C... coords);
long long int l_v_l_v_l = 0, t_a_b_s = 0;
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  l_v_l_v_l++;
  string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
  l_v_l_v_l--;
  return res;
}
template <typename A, typename... C>
string to_string(const A(&v), long long int x1, long long int x2, C... coords) {
  long long int rnk = rank<A>::value;
  string tab(t_a_b_s, ' ');
  string res = "";
  bool first = true;
  if (l_v_l_v_l == 0) res += "\n";
  res += tab + "[";
  x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
  auto l = begin(v);
  advance(l, x1);
  auto r = l;
  advance(r, (x2 - x1) + (x2 < SIZE(v)));
  for (auto e = l; e != r; e = next(e)) {
    if (!first) {
      res += ", ";
    }
    first = false;
    l_v_l_v_l++;
    if (e != l) {
      if (rnk > 1) {
        res += "\n";
        t_a_b_s = l_v_l_v_l;
      };
    } else {
      t_a_b_s = 0;
    }
    res += to_string(*e, coords...);
    l_v_l_v_l--;
  }
  res += "]";
  if (l_v_l_v_l == 0) res += "\n";
  return res;
}
void dbgm() { ; }
template <typename Heads, typename... Tails>
void dbgm(Heads H, Tails... T) {
  cout << to_string(H) << " | ";
  dbgm(T...);
}
template <typename T = long long int>
std::vector<std::vector<T>> ReadMatrix(long long int row_count = 0,
                                       long long int column_count = 0,
                                       std::istream &in_stream = std::cin);
template <typename T = long long int>
std::vector<T> ReadArray(long long int size = 0,
                         std::istream &in_stream = std::cin);
bool checker = false;
const long long int N = 1000000;
bitset<N> vis;
bitset<N> vis1;
long long int prime = 5;
void generateCombinations(vector<vector<char>> &arr) {
  long long int k =
      (arr[0][0] - 'A') * prime + (arr[0][1] - 'A') * (prime ^ 2) +
      (arr[1][0] - 'A') * (prime ^ 3) + (arr[1][1] - 'A') * (prime ^ 4);
  if (vis[k] == 1) {
    return;
  }
  vis[k] = 1;
  for (long long int i = 0; i < 2; i++) {
    for (long long int j = 0; j < 2; j++) {
      if (arr[i][j] == 'X') {
        if (i > 0) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i - 1][j];
          arr1[i - 1][j] = 'X';
          generateCombinations(arr1);
        }
        if (j > 0) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i][j - 1];
          arr1[i][j - 1] = 'X';
          generateCombinations(arr1);
        }
        if (j < 1) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i][j + 1];
          arr1[i][j + 1] = 'X';
          generateCombinations(arr1);
        }
        if (i < 1) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i + 1][j];
          arr1[i + 1][j] = 'X';
          generateCombinations(arr1);
        }
      }
    }
  }
}
void generateCombinations1(vector<vector<char>> &arr) {
  long long int k =
      (arr[0][0] - 'A') * prime + (arr[0][1] - 'A') * (prime ^ 2) +
      (arr[1][0] - 'A') * (prime ^ 3) + (arr[1][1] - 'A') * (prime ^ 4);
  if (vis[k] == 1) {
    checker = true;
    return;
  }
  if (vis1[k] == 1) {
    return;
  }
  vis1[k] = 1;
  for (long long int i = 0; i < 2; i++) {
    for (long long int j = 0; j < 2; j++) {
      if (arr[i][j] == 'X') {
        if (i > 0) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i - 1][j];
          arr1[i - 1][j] = 'X';
          generateCombinations1(arr1);
        }
        if (j > 0) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i][j - 1];
          arr1[i][j - 1] = 'X';
          generateCombinations1(arr1);
        }
        if (j < 1) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i][j + 1];
          arr1[i][j + 1] = 'X';
          generateCombinations1(arr1);
        }
        if (i < 1) {
          auto arr1 = arr;
          arr1[i][j] = arr1[i + 1][j];
          arr1[i + 1][j] = 'X';
          generateCombinations1(arr1);
        }
      }
    }
  }
}
void solve() {
  std::vector<std::vector<char>> arr(2, std::vector<char>(2));
  for (long long int i = 0; i < 2; i++) {
    char c;
    for (long long int j = 0; j < 2; j++) {
      cin >> c;
      arr[i][j] = c;
    }
  }
  std::vector<std::vector<char>> arr2(2, std::vector<char>(2));
  for (long long int i = 0; i < 2; i++) {
    char c;
    for (long long int j = 0; j < 2; j++) {
      cin >> c;
      arr2[i][j] = c;
    }
  }
  generateCombinations(arr);
  generateCombinations1(arr2);
  if (checker) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
}
void init_code() {
  std::ios::sync_with_stdio(0);
  std::cout.tie(0);
  std::cin.tie(0);
}
int32_t main() {
  init_code();
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
template <typename T>
std::vector<T> ReadArray(long long int size, std::istream &in_stream) {
  if (!size) {
    in_stream >> size;
  }
  std::vector<T> array(size);
  for (auto &element : array) {
    in_stream >> element;
  }
  return array;
}
template <typename T>
std::vector<std::vector<T>> ReadMatrix(long long int row_count,
                                       long long int column_count,
                                       std::istream &in_stream) {
  if (!row_count) {
    in_stream >> row_count >> column_count;
  } else if (!column_count) {
    column_count = row_count;
  }
  std::vector<std::vector<T>> matrix(row_count,
                                     std::vector<long long int>(column_count));
  for (auto &row : matrix) {
    for (auto &entry : row) {
      in_stream >> entry;
    }
  }
  return matrix;
}