Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice III

Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.

Input

In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.

In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.

Output

Print "Yes" if two dices are identical, otherwise "No" in a line.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 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

Solution in Scala (judge verdict: Accepted)


object Main extends App {

  override def main(args: Array[String]): Unit = {
    val str, str2 = io.StdIn.readLine.split(' ')

    val dice = new Dice(str(0), str(1), str(2), str(3), str(4), str(5))
    val dice2 = new Dice(str2(0), str2(1), str2(2), str2(3), str2(4), str2(5))

    val res = dice2.getAsTopAndSouthIs(dice.top, dice.south).exists(rot => rot == dice)

    if (res) println("Yes")
    else println("No")
  }

  case class Dice(top: String, south: String, east: String, west: String, north: String, buttom: String) {

    def toNorth: Dice = {
      new Dice(south, buttom, east, west, top, north)
    }
    def toSouth: Dice = {
      new Dice(north, top, east, west, buttom, south)
    }
    def toEast: Dice = {
      new Dice(west, south, top, buttom, north, east)
    }
    def toWest: Dice = {
      new Dice(east, south, buttom, top, north, west)
    }
    def rotRight: Dice = {
      new Dice(top, east, north, south, west, buttom)
    }
    def rotLeft: Dice = {
      new Dice(top, west, south, north, east, buttom)
    }

    def getAsTop(toTop: String): List[Dice] =  List(
        if (top == toTop) List(this) else List.empty,
        if (south == toTop) List(toNorth) else List.empty,
        if (north == toTop) List(toSouth) else List.empty,
        if (west == toTop) List(toEast) else List.empty,
        if (east == toTop) List(toWest) else List.empty,
        if (buttom == toTop) List(toEast.toEast) else List.empty
        ).flatten

    def getAsSouthByRot(toSouth: String): List[Dice] = List(
        if (south == toSouth) List(this) else List.empty,
        if (north == toSouth) List(rotLeft.rotLeft) else List.empty,
        if (west == toSouth) List(rotLeft) else List.empty,
        if (east == toSouth) List(rotRight) else List.empty
        ).flatten

    def getAsTopAndSouthIs(top: String, south: String): List[Dice] = {
      getAsTop(top).flatMap(_.getAsSouthByRot(south))
    }

  }

}