/**
 * ???????????? III

Dice I
??¨????§????????????§?????\??????????????°?????????????????????????????????????????????????????????????????????????????????????????????????????°????????????????????????????????????Dice
I
???????????§????????????????????¢???????????????????????????????????????????????????????????????????????°????????¨????????´????????¨?????????????????????????????¨??????????????????

Input
????????????????????????????????????????????¢?????°???????????????????????????????????????????????§?????????????????????
????????????????????????????????????????????¢?????°???????????????????????????????????????????????§?????????????????????

Output
??????????????????????????????????????° "Yes" ??¨?????°??????????????° "No"
??¨????????????????????????????????????

Constraints
0??? ??\?????????????????????????????¢?????°??? ???100

Sample Input 1
1 2 3 4 5 6
6 2 4 3 5 1

Sample Output 1
Yes

Sample Input 2
1 2 3 4 5 6
6 5 4 3 2 1

Sample Output 2
No
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

class Dice {
private:
  std::map<std::string, unsigned short> DiceState;

public:
  Dice() : Dice("1 2 3 4 5 6") {}

  Dice(std::string Param) { setDiceLabels(Param); }

  unsigned short getTop();
  unsigned short getLabel(std::string);
  unsigned short getRight(unsigned short, unsigned short);
  void lotate(std::string);
  void lotateToTop(unsigned short Label);
  void lotateToFront(unsigned short Label);
  void setDiceLabels(std::string);
  std::string findPosition(unsigned short);
  std::string getDiceLabels();
};

unsigned short Dice::getTop() { return DiceState["Top"]; }
unsigned short Dice::getLabel(std::string SurfaceName) {
  return DiceState[SurfaceName];
}

void Dice::lotate(std::string Direction) {
  for (const auto &e : Direction) {
    unsigned int Tmp;
    if (e == 'N') {
      Tmp = DiceState["Rear"];
      DiceState["Rear"] = DiceState["Top"];
      DiceState["Top"] = DiceState["Front"];
      DiceState["Front"] = DiceState["Bottom"];
      DiceState["Bottom"] = Tmp;
    } else if (e == 'E') {
      Tmp = DiceState["Right"];
      DiceState["Right"] = DiceState["Top"];
      DiceState["Top"] = DiceState["Left"];
      DiceState["Left"] = DiceState["Bottom"];
      DiceState["Bottom"] = Tmp;
    } else if (e == 'W') {
      Tmp = DiceState["Left"];
      DiceState["Left"] = DiceState["Top"];
      DiceState["Top"] = DiceState["Right"];
      DiceState["Right"] = DiceState["Bottom"];
      DiceState["Bottom"] = Tmp;
    } else if (e == 'S') {
      Tmp = DiceState["Front"];
      DiceState["Front"] = DiceState["Top"];
      DiceState["Top"] = DiceState["Rear"];
      DiceState["Rear"] = DiceState["Bottom"];
      DiceState["Bottom"] = Tmp;
    }
  }
}

void Dice::lotateToTop(unsigned short Label) {
  std::string StartPosition = findPosition(Label);
  if (StartPosition == "Front") {
    lotate("N");
  } else if (StartPosition == "Right") {
    lotate("W");
  } else if (StartPosition == "Left") {
    lotate("E");
  } else if (StartPosition == "Rear") {
    lotate("S");
  } else if (StartPosition == "Bottom") {
    lotate("EE");
  }
}

void Dice::lotateToFront(unsigned short Label) {
  std::string StartPosition = findPosition(Label);
  if (StartPosition == "Right") {
    lotate("WSE");
  } else if (StartPosition == "Left") {
    lotate("ESW");
  } else if (StartPosition == "Rear") {
    lotate("SSEE");
  } else if (StartPosition == "Top") {
    lotate("S");
  } else if (StartPosition == "Bottom") {
    lotate("N");
  }
}

void Dice::setDiceLabels(std::string Str) {
  std::istringstream iss(Str);
  unsigned short n;
  size_t i = 0;

  while (iss >> n) {
    size_t j = i;
    i++;
    switch (j) {
    case 0:
      DiceState["Top"] = n;
      break;
    case 1:
      DiceState["Front"] = n;
      break;
    case 2:
      DiceState["Right"] = n;
      break;
    case 3:
      DiceState["Left"] = n;
      break;
    case 4:
      DiceState["Rear"] = n;
      break;
    case 5:
      DiceState["Bottom"] = n;
      break;
    }
  }
}

unsigned short Dice::getRight(unsigned short Top, unsigned short Front) {
  lotateToTop(Top);
  lotateToFront(Front);
  return getLabel("Right");
}

std::string Dice::findPosition(unsigned short Label) {
  auto its =
      find_if(DiceState.begin(), DiceState.end(),
              [Label](std::map<std::string, unsigned short>::value_type &p) {
                return p.second == Label;
              });
  return its->first;
}

std::string Dice::getDiceLabels() {
  std::ostringstream oss;

  oss << DiceState["Top"] << " ";
  oss << DiceState["Front"] << " ";
  oss << DiceState["Right"] << " ";
  oss << DiceState["Left"] << " ";
  oss << DiceState["Rear"] << " ";
  oss << DiceState["Bottom"];

  return oss.str();
}

int main(int argc, char const *argv[]) {
  std::string D1Labels, D2Labels;
  std::istringstream iss;

  getline(std::cin, D1Labels);
  // Top,Front,Right,Left,Rear,Bottom;
  Dice D1(D1Labels);

  getline(std::cin, D2Labels);
  Dice D2(D2Labels);

  D2.lotateToTop(D1.getTop());
  // std::cout << D2.getDiceLabels() << std::endl;
  D2.lotateToFront(D1.getLabel("Front"));
  bool isSame = false;
  if (D1Labels == D2.getDiceLabels()) {
    isSame = true;
  } else {
    for (size_t i = 0; i < 3; i++) {
      for (size_t i = 0; i < 3; i++) {
        for (size_t i = 0; i < 4; i++) {
          D2.lotate("N");
          if (D1Labels == D2.getDiceLabels()) {
            isSame = true;
            break;
          }
          D2.lotate("W");
          if (D1Labels == D2.getDiceLabels()) {
            isSame = true;
            break;
          }
          D2.lotate("S");
          if (D1Labels == D2.getDiceLabels()) {
            isSame = true;
            break;
          }
        }
        D2.lotate("N");
        if (D1Labels == D2.getDiceLabels()) {
          isSame = true;
          break;
        }
      }
      D2.lotate("E");
      if (D1Labels == D2.getDiceLabels()) {
        isSame = true;
        break;
      }
    }
  }
  if (isSame) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3208