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: Wrong Answer)


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): Option[Dice] = toTop match {
        case str if str == top    => Option(this)
        case str if str == east   => Option(toWest)
        case str if str == west   => Option(toEast)
        case str if str == south  => Option(toNorth)
        case str if str == north  => Option(toSouth)
        case str if str == buttom => Option(toNorth.toNorth)
        case _ => Option.empty
  }

    def getAsSouthByRot(toSouth: String): Option[Dice] = toSouth match{
        case str if str == south => Option(this)
        case str if str == east  => Option(rotRight)
        case str if str == west  => Option(rotLeft)
        case str if str == north => Option(rotRight.rotRight)
        case _ => Option.empty
    }

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

  }

}