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: Time Limit Exceeded)

//
//  main.c
//  1-11.c
//
//  Created by x15002xx on 2017/05/24.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

void throwdice_N(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[1];
    x[1] = x[5];
    x[5] = x[4];
    x[4] = tmp;
}
void throwdice_E(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[3];
    x[3] = x[5];
    x[5] = x[2];
    x[2] = tmp;
}
void throwdice_S(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[4];
    x[4] = x[5];
    x[5] = x[1];
    x[1] = tmp;
}
void throwdice_W(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[2];
    x[2] = x[5];
    x[5] = x[3];
    x[3] = tmp;
}

#include <stdio.h>
int main(int argc, const char * argv[]) {
    int i, top, front, left, right, back, bottom, count=0;
    int top2, front2, left2, right2, back2, bottom2;
    int x[6], x2[6];
    for(i=0; i<6; i++) {
        scanf("%d",&x[i]);
    }
    back = x[4];
    top = x[0];
    right = x[2];
    left = x[3];
    bottom = x[5];
    front =x[1];
    
    for(i=0; i<6; i++) {
        scanf("%d",&x2[i]);
    }
    back2 = x2[4];
    top2 = x2[0];
    right2 = x2[2];
    left2 = x2[3];
    bottom2 = x2[5];
    front2 =x2[1];
    
    while (x2[1] != front) {
        if((x2[1] != back) &&
           (x2[1] != top) &&
           (x2[1] != right) &&
           (x2[1] != left) &&
           (x2[1] != bottom) &&
           (x2[1] != front) ){
            count++;
            break;
        }
        if (x2[2] == front2 || x2[3] == front2) {
            throwdice_E(x2);
        }
        throwdice_N(x2);
    }
    while(x2[5] != bottom){
        if(0 < count) break;
        throwdice_E(x2);
    }
    while (x2[0] != top) {
        if(0 < count) break;
        throwdice_E(x2);
    }
    
    back2 = x2[4];
    top2 = x2[0];
    right2 = x2[2];
    left2 = x2[3];
    bottom2 = x2[5];
    front2 =x2[1];
    
    if(back == back2 &&
       top == top2 &&
       right == right2 &&
       left == left2 &&
       bottom == bottom2 &&
       front == front2){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}