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)

import scala.io.StdIn.{readLine,readInt}
/**
  * AOJ
  */

object Main {

  def main(args: Array[String]): Unit = {

    var dice1 = read
    val dice2 = read

    for(side <- dice1){
      if(!dice2.contains(side)){println("No");return}
    }

    dice1 = findSide(dice2(4),4,"HHH",findSide(dice2(0),0,"WNNNW",dice1))
    println(
      dice1 match {
        case null => "No"
        case dice1 if((dice1 zip dice2).forall(x => x._1 == x._2)) => "Yes"
        case _ => "No"
      }
    )
  }

  def findSide(sideNum:Int, findSide:Int, searchCommands:String, dice:Array[Int]) : Array[Int] = {
    if(dice(findSide) == sideNum){return dice}
    var d = dice
    for(c <- searchCommands.toCharArray){
      d = getNextStatus(c,d)
      if(d(findSide) == sideNum){return d}
    }
    return null
  }

  def getNextStatus(cmd:Char,dice:Array[Int]): Array[Int] = cmd
    match {
      case 'N' => Array(dice(1),dice(5),dice(2),dice(3),dice(0),dice(4))
      case 'W' => Array(dice(2),dice(1),dice(5),dice(0),dice(4),dice(3))
      case 'H' => Array(dice(0),dice(3),dice(1),dice(4),dice(2),dice(5))
    }

  def read() : Array[Int] = {
    readLine().split(" ").map(_.toInt)
  }
}