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 JAVA (judge verdict: Wrong Answer)

// ITP1_11_C Dice 3
import java.io.*;

public class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      Dice[] dice = new Dice[2];

      try {
         String[][] input = new String[2][];
         for (int i = 0; i < 2; i++)
            input[i] = br.readLine().split(" ");
         int[][] roll = new int[2][6];
         for (int i = 0; i < roll.length; i++)
            for (int j = 0; j < input[i].length; j++)
               roll[i][j] = Integer.parseInt(input[i][j]);
         dice[0] = new Dice(roll[0][0], roll[0][1], roll[0][2], roll[0][3], roll[0][4], roll[0][5]);
         dice[1] = new Dice(roll[1][0], roll[1][1], roll[1][2], roll[1][3], roll[1][4], roll[1][5]);

         if ((dice[1].FRONT == dice[0].FRONT) && (dice[1].BACK == dice[0].BACK))
            while (dice[1].TOP != dice[0].TOP)
               dice[1].east();
         if ((dice[1].RIGHT == dice[0].RIGHT) && (dice[1].LEFT == dice[1].LEFT))
            while (dice[1].TOP != dice[0].TOP)
               dice[1].north();

         if ((dice[0].TOP    == dice[1].TOP)
          && (dice[0].FRONT  == dice[1].FRONT)
          && (dice[0].RIGHT  == dice[1].RIGHT)
          && (dice[0].LEFT   == dice[1].LEFT)
          && (dice[0].BACK   == dice[1].BACK)
          && (dice[0].BOTTOM == dice[1].BOTTOM))
            System.out.println("Yes");
         else
            System.out.println("No");
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
}

class Dice {
   int TOP;
   int FRONT; 
   int RIGHT;
   int LEFT;
   int BACK;
   int BOTTOM;
   int work;

   Dice(int top, int front, int right, int left, int back, int bottom) {
      TOP    = top;
      LEFT   = left;
      BACK   = back;
      FRONT  = front;
      RIGHT  = right;
      BOTTOM = bottom;
   }

   public void north() {
      work   = TOP;
      TOP    = FRONT;
      FRONT  = BOTTOM;
      BOTTOM = BACK;
      BACK   = work;
   }
   public void east() {
      work   = TOP;
      TOP    = LEFT;
      LEFT   = BOTTOM;
      BOTTOM = RIGHT;
      RIGHT  = work;
   }
   public void west() {
      work   = TOP;
      TOP    = RIGHT;
      RIGHT  = BOTTOM;
      BOTTOM = LEFT;
      LEFT   = work;
   }
   public void south() {
      work   = TOP;
      TOP    = BACK;
      BACK   = BOTTOM;
      BOTTOM = FRONT;
      FRONT  = work;
   }
}