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

#dice3
def r(D,s):
    if s==0:
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif s==2:
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif s==3:
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif s==1:
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t
    elif s==4:
        D=r(r(D,1),1)
    return D
def ch(C,D):
    k=0
    while k<6 and C[k]==D[k]:
        k+=1
    if k==6:
        return 1
    else:
        return 0
C=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
nd=0
if ch(C,D)==1:
    nd=1
i=0
while i<4 and nd==0:
    D=r(D,i)
    j=i+1
    j%=4
    k=0
    if ch(C,D)==1:
        nd=1
 #   if i==0:
    #    print(D)
    while k<3 and nd==0:
        D=r(D,j)
        if ch(C,D)==1:
            nd=1
        k+=1
  #      if i==0:
        #    print(D)
    D=r(D,j)
 #   if i==0:
   #     print(D)
    m=i+2
    m%=4
 #   if i==0:
    #    print(m)    
    D=r(D,m)
 #   if i==0:
 #       print(D)
    i+=1
i=0
while nd==0 and i<4:
    D=r(D,0)
    D=r(D,1)
    D=r(D,0)
    if ch(C,D)==1:
        nd=1
    D=r(r(D,0),0)
    if ch(C,D)==1:
        nd=1
    i+=1
if nd==1:
    p="Yes"
else:
    p="No"
print(p)