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 {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    val t1, s1, e1, w1, n1, b1 = scanner.nextInt
    var dice1 = Dice(t1, n1, e1, s1, w1, b1)
    val t2, s2, e2, w2, n2, b2 = scanner.nextInt
    var dice2 = Dice(t2, n2, e2, s2, w2, b2)

    var areSame = false
    for(_ <- 1 to 4) {
      for(_ <- 1 to 4) {
        if(dice1.equals(dice2)) areSame = true
        dice1 = dice1.rotN()
      }
      dice1 = dice1.rotE()
    }
    println(if(areSame) "Yes" else "No")
  }
}

case class Dice(t: Int, n: Int, e: Int, s: Int, w: Int, b: Int) {
  def rotN(): Dice = Dice(s, t, e, b, w, n)
  def rotS(): Dice = Dice(n, b, e, t, w, s)
  def rotW(): Dice = Dice(e, n, b, s, t, w)
  def rotE(): Dice = Dice(w, n, t, s, b, e)
  def rot(): Dice = Dice(t, e, s, w, n, b)
  def equals(that: Dice): Boolean = (t == that.t && n == that.n && e == that.e && s == that.s && w == that.w && b == that.b)
}