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 = {

    val dice1 = read
    val dice2 = read

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

  def find(dice1:Array[Int],dice2:Array[Int]) : Boolean = {
    if(diceMatch(dice1,dice2)){return true}
    var d1_1 = dice1
    for(c1 <- "WNNNW".toCharArray){
      d1_1 = getNextStatus(c1,d1_1)
      if(diceMatch(d1_1,dice2)){return true}
      var d1_2 = d1_1
      for(c2 <- "HHH".toCharArray){
        d1_2 = getNextStatus(c2,d1_2)
        if(diceMatch(d1_2,dice2)){return true}
      }
    }
    return false
  }

  def diceMatch(dice1:Array[Int],dice2:Array[Int]):Boolean = (dice1 zip dice2).forall(x => x._1 == x._2)

  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)}
}