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 C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
class itp1_11_a{
  public static void Main(){
    String[] str1 = Console.ReadLine().Split(' ');
    Dice d1 = new Dice(str1[0], str1[1], str1[2], str1[3], str1[4], str1[5]);
    String[] str2 = Console.ReadLine().Split(' ');
    Dice d2 = new Dice(str2[0], str2[1], str2[2], str2[3], str2[4], str2[5]);
    Rotate rtt = new Rotate();
    bool top_correct = false;
    int[] count = new int[100];
    for(int i=0; i<6; i++){
      count[int.Parse(str1[i])-1]++;
    }
    int min = 6;
    int pos = 7;
    for(int i=0; i<6; i++){
      if(min > count[i] && count[i] != 0){
        min = count[i];
        pos = i+1;
      }
    }
    switch(pos){
      case 1:
        break;
      case 2:
        rtt.north(d1);
        break;
      case 3:
        rtt.west(d1);
        break;
      case 4:
        rtt.east(d1);
        break;
      case 5:
        rtt.south(d1);
        break;
      case 6:
        rtt.north(d1);
        rtt.north(d1);
        break;
      default:
        break;
    }
    for(int i=0; i<4; i++){
      if(d1.top == d2.top){
        top_correct = true;
        break;
      }
      rtt.north(d2);
    }
    if(!top_correct){
      for(int i=0; i<4; i++){
        if(d1.top == d2.top){
          top_correct = true;
          break;
        }
        rtt.east(d2);
      }
    }
    for(int i=0; i<4; i++){
      if(d1.front == d2.front){
        break;
      }
      rtt.turn_right(d2);
    }
    if(isSame(d1,d2))
      Console.WriteLine("Yes");
    else
      Console.WriteLine("No");
  }
  public static bool isSame(Dice d1, Dice d2){
    return d1.top == d2.top && d1.front == d2.front && d1.right == d2.right
      && d1.left == d2.left && d1.behind == d2.behind && d1.bottom == d2.bottom;
  }
}


class Rotate{
  public void north(Dice d){
    int temp = d.top;
    d.top = d.front;
    d.front = d.bottom;
    d.bottom = d.behind;
    d.behind = temp;
  }
  public void south(Dice d){
    int temp = d.top;
    d.top = d.behind;
    d.behind = d.bottom;
    d.bottom = d.front;
    d.front = temp;
  }
  public void east(Dice d){
    int temp = d.top;
    d.top = d.left;
    d.left = d.bottom;
    d.bottom = d.right;
    d.right = temp;
  }
  public void west(Dice d){
    int temp = d.top;
    d.top = d.right;
    d.right = d.bottom;
    d.bottom = d.left;
    d.left = temp;
  }
  public void turn_right(Dice d){
    int temp = d.front;
    d.front = d.left;
    d.left = d.behind;
    d.behind = d.right;
    d.right = temp;
  }
  public void turn_left(Dice d){
    int temp = d.front;
    d.front = d.right;
    d.right = d.behind;
    d.behind = d.left;
    d.left = temp;
  }
}

class Dice{
  public int top { get; set; }
  public int front { get; set; }
  public int right { get; set; }
  public int left { get; set; }
  public int behind { get; set; }
  public int bottom { get; set; }
  public Dice(){
    top = 1;
    front = 2;
    right = 3;
    left = 4;
    behind = 5;
    bottom = 6;
  }
  public Dice(int t, int f, int r, int l, int be, int bo){
    top = t;
    front = f;
    bottom = bo;
    behind = be;
    right = r;
    left = l;
  }
  public Dice(String t, String f, String r, String l, String be, String bo){
    top = int.Parse(t);
    front = int.Parse(f);
    right = int.Parse(r);
    left = int.Parse(l);
    behind = int.Parse(be);
    bottom = int.Parse(bo);
  }
}