Problem:
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 (Python):


class Dice:

    def __init__(self, diceList):
        self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList

    def diceRoll(self, r):
        if(r == 'N'):
            self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5

        elif(r == 'E'):
            self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3

        elif(r == 'W'):
            self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4

        elif(r == 'S'):
            self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2


def main():

    orderList = ['N', 'E', 'W', 'S']
    inputDiceList1 = list(map(int, input().split()))
    inputDiceList2 = list(map(int, input().split()))

    dice1 = Dice(inputDiceList1)
    dice2 = Dice(inputDiceList2)

    cmd = "N" * 4 + ("W" + "N" * 4) * 3 + "NE" + "N" * 4 + "EE" + "N" * 4

    for i in cmd:
        if(dice1.d1 == dice2.d1 and dice1.d2 == dice2.d2 and dice1.d3 == dice2.d3 and dice1.d4 == dice2.d4 and dice1.d5 == dice2.d5 and dice1.d6 == dice2.d6):
            print('Yes')
            return 0
        else:
            dice2.diceRoll(i)

    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
def main_1_11_A():
    values = list(map(int, input().split()))
    query = input()

    dice = Dice(values)
    for d in query:
        dice.roll(d)


def main_1_11_B():
    values = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        t_value, s_value = map(int, input().split())

        print(_B(values, t_value, s_value))


def main_1_11_C():
    values_1 = list(map(int, input().split()))
    values_2 = list(map(int, input().split()))

    dice1 = Dice(values_1)
    dices = (
        make_dices(values_2) +
        list(map(lambda dice: rot_n(dice, 1), make_dices(values_2))) +
        list(map(lambda dice: rot_n(dice, 2), make_dices(values_2))) +
        list(map(lambda dice: rot_n(dice, 3), make_dices(values_2)))
    )
    for dice in dices:
        
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            if eq_dice(dice1, dice):
                print("Yes")
                return

    print("No")


def eq_dice(d1, d2):
    return (
        d1.top_value == d2.top_value and
        d1.bottom_value == d2.bottom_value and
        d1.north_value == d2.north_value and
        d1.south_value == d2.south_value and
        d1.west_value == d2.west_value and
        d1.east_value == d2.east_value
    )


def rot_n(dice, n):
    for _ in range(n):
        dice.roll("N").roll("E").roll("S")
    return dice


def make_dices(values):
    
    return [
        Dice(values),
        Dice(values).roll("N"),
        Dice(values).roll("N").roll("N"),
        Dice(values).roll("N").roll("N").roll("N"),
        Dice(values).roll("E"),
        Dice(values).roll("W"),
    ]


def _B(values, t_value, s_value):
    """
    ????????¢?????????????????¨??????
    ??´??¢???????????¢?????????????????§???????????????????????¨?????????
    ??????????????????????????¢???????¢??????????
    """
    dices = (
        make_dices(values) +
        list(map(lambda dice: rot_n(dice, 1), make_dices(values))) +
        list(map(lambda dice: rot_n(dice, 2), make_dices(values))) +
        list(map(lambda dice: rot_n(dice, 3), make_dices(values)))
    )
    for dice in dices:
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            if (dice.top_value, dice.south_value) == (t_value, s_value):
                return dice.east_value


class Dice:

    def __init__(self, values):
        self.values = values
        
        self.t = 1
        self.b = 6
        self.w = 4
        self.e = 3
        self.n = 5
        self.s = 2

    def __repr__(self):
        labels = {
            "t": self.t,
            "b": self.b,
            "w": self.w,
            "e": self.e,
            "n": self.n,
            "s": self.s,
        }
        return "<%s (%s, %s)>" % (self.__class__, self.values, labels)

    def roll(self, direction):
        if direction == "E":
            after_lables = self.t, self.b, self.e, self.w
            self.e, self.w, self.b, self.t = after_lables
        elif direction == "W":
            after_lables = self.t, self.b, self.e, self.w
            self.w, self.e, self.t, self.b = after_lables
        elif direction == "S":
            after_lables = self.t, self.b, self.n, self.s
            self.s, self.n, self.t, self.b = after_lables
        elif direction == "N":
            after_lables = self.t, self.b, self.n, self.s
            self.n, self.s, self.b, self.t = after_lables

        return self

    @property
    def bottom_value(self):
        return self.values[self.b - 1]

    @property
    def north_value(self):
        return self.values[self.n - 1]

    @property
    def west_value(self):
        return self.values[self.w - 1]

    @property
    def top_value(self):
        return self.values[self.t - 1]

    @property
    def south_value(self):
        return self.values[self.s - 1]

    @property
    def east_value(self):
        return self.values[self.e - 1]

if __name__ == "__main__":
    
    
    main_1_11_C()

Solution (Python):
dice = [
	[1, 2, 4, 3, 5],
	[5, 2, 0, 3, 4],
	[1, 5, 4, 0, 3],
	[1, 0, 4, 5, 2],
	[0, 2, 5, 3, 1],
	[1, 3, 4, 2, 0]
]

def getRound(D, top):
	result = []
	for index in dice[top]:
		result.append(D[index])
	return result

def compareRound(l1, l2):
	if l1[4] != l2[4]:
		return False
	elif l1[0] not in l2:
		return False
	offset = l2.index(l1[0])
	
	for i in range(4):
		if l1[i] != l2[(i+offset)%4]:
			return False
	return True

def compare(D1, D2, i1):
	if D1[i1] not in D2:
		return False
	i2 = D2.index(D1[i1])
	return compareRound(getRound(D1, i1), getRound(D2, i2))

D1 = input().split(" ")
D2 = input().split(" ")
isSame = False
for i in range(6):
	if compare(D1, D2, i):
		isSame = True
if isSame:
	print("Yes")
else:
	print("No")

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)]
e[3],e[4]=e[4],e[3]
t=0
for i in range(6):
 m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}[i]
 f=[d[int(j)]for j in m];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1;break
print(('No','Yes')[t==1])

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
for i in range(6):
 m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}[i]
 f=[d[int(j)]for j in m];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t==1])

Solution (Python):
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

faces1 = list(map(int, input().split()))
dice1 = Dice(faces1)
faces2 = list(map(int, input().split()))
dice2 = Dice(faces2)

flag = False

for i in range(10000):
    dice2.roll(random.randint(0, 3))
    if dice1.is_equal(dice2):
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
dice = list(map(int, input().split()))
dice2 = list(map(int, input().split()))
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }

a, b = dice2[0], dice2[1]

find = False

for i in range(4):

    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['N']]

dice = [dice[x] for x in mask['R']]
dice = [dice[x] for x in mask['N']]
for j in range(4):
    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['R']]

dice = [dice[x] for x in mask['N']]
dice = [dice[x] for x in mask['N']]
for j in range(4):
    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['R']]

if find:

    print("Yes")
else:
    print("No")

Solution (Python):
from copy import deepcopy, copy
class dice:
    men = [0] * 7
    def __init__(self, li = [0] * 6):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "A":
            pass
        elif h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
        else:
            print("笆ｲ繧ｨ繝ｩ繝ｼ")
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
saikoro1 = dice(list(map(int, input().split())))
saikoro2 = dice(list(map(int, input().split())))
ans = []
saikoro3 = deepcopy(saikoro2)
for i in range(6):
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3.move("L")
    ans.append(saikoro3.men[:])
    saikoro3 = deepcopy(saikoro2)
    saikoro3.move("SWENOOO"[i])
print("Yes" if saikoro1.men in ans else "No")

Solution (Python):
class dice:
    def __init__(self, li = [0] * 6):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
        else:
            print("▲err")
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
def solve():
    saikoro1 = dice(list(map(int, input().split())))
    li = list(map(int, input().split()))
    for i in range(6):
        saikoro3 = dice(li)
        if i:
            saikoro3.move("_SWENOOO"[i])
        if saikoro3.men == saikoro1.men:
            return "Yes"
        for _ in range(3):
            saikoro3.move("L")
            if saikoro3.men == saikoro1.men:
                return "Yes"
    return "No"
print(solve())

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}
for i in range(6):
 f=[d[int(j)]for j in m[i]];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t==1])

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}
for i in range(6):
 f=[d[int(j)]for j in m[i]];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t==1])

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
m={0:'012345',1:'152304',2:'215043',3:'310542',4:'402351',5:'513240'}
for i in range(6):
 f=[d[int(j)]for j in m[i]];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
for p in ['012345','152304','215043','310542','402351','513240']:
 f=[d[int(j)]for j in p];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
d,e=[[s for s in input().split()]for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Solution (Python):
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def clock(self):
        t = dict(self._men)
        self._men["E"] = t["N"]
        self._men["N"] = t["W"]
        self._men["W"] = t["S"]
        self._men["S"] = t["E"]


    def simpleequal(self, d2):
        if self._men == d2._men:
            return True
        else:
            return False


    def equal(self, d2):
        for _ in range(4):
            d2.roll("N")

            for _ in range(4):
                d2.clock()
                if self.simpleequal(d2):
                    return True

        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True


        d2.roll("E")
        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True



    def gettop(self):
        return self._men["T"]

def decode():
    numlist1 = [int(x) for x in input().split()]
    numlist2 = [int(x) for x in input().split()]

    return numlist1, numlist2


if __name__ == '__main__':

    numlist1, numlist2 = decode()
    d1 = dice(numlist1)
    d2 = dice(numlist2)

    if d1.equal(d2):
        print("Yes")
    else:
        print("No")

Solution (Python):
import random

class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_num(self, place):
        return self.num[self.face[place]]
    
    def getFace(self):
        for k, v in sorted(self.face.items()):
            yield self.num[v]
    
        
if __name__ == '__main__':
    dice1 = Dice([int(x) for x in input().split()])
    dice2 = Dice([int(x) for x in input().split()])
    d = ['E', 'W', 'N', 'S']
    for k in range(1000):
        c = 0
        rand_num = random.randint(0, 3)
        dice2.move(d[rand_num])
        
        for v1, v2 in zip(dice1.getFace(), dice2.getFace()):
            if v1 == v2:
                c += 1
        if c == 6:
            print ('Yes')
            break
        if k == 999:
            print ('No')

Solution (Python):
import random
class Dice:
    def __init__(self, top, dside, rside, lside, uside, bottom):
        self.top = top
        self.dside = dside
        self.rside = rside
        self.lside = lside
        self.uside = uside
        self.bottom = bottom
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice(num1[0], num1[1], num1[2], num1[3], num1[4], num1[5])
dice2 = Dice(num2[0], num2[1], num2[2], num2[3], num2[4], num2[5])
if len(set(num1))<4:
    while(dice1.top!=dice2.top or dice1.rside!=dice2.rside
          or dice1.dside!=dice2.dside):
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
else:
    while dice1.top!=dice2.top or dice1.rside!=dice2.rside:
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
if dice1.bottom==dice2.bottom and dice1.lside==dice2.lside:
    if dice1.dside==dice2.dside: 
        print("Yes")
    else: 
        print("No")
else:
    print("No")

Solution (Python):
class dice():
    def __init__(self,number):
        self.number = number

    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
d1 = dice([int(x) for x in input().split()])
d2 = dice([int(x) for x in input().split()])
for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
    d1.korokoro(com)
    if d1.number == d2.number:
        ans = 'Yes'
        break
    else:
        ans = 'No'
print(ans)

Solution (Python):
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def isSameDice(self, anotherDice):
        if \
        self.dice[0] == anotherDice.dice[0] and \
        self.dice[1] == anotherDice.dice[1] and \
        self.dice[2] == anotherDice.dice[2] and \
        self.dice[3] == anotherDice.dice[3] and \
        self.dice[4] == anotherDice.dice[4] and \
        self.dice[5] == anotherDice.dice[5]:
            return True
        return False


import random

nums1 = list(map(int, input().split()))
nums2 = list(map(int, input().split()))
dice1 = Dice(nums1)
dice2 = Dice(nums2)

flag = False


for i in range(1000):
    k = random.randint(0, 4)
    if k == 0:
        dice2.east()
    elif k == 1:
        dice2.west()
    elif k == 2:
        dice2.north()
    else:
        dice2.south()
    if dice2.isSameDice(dice1):
        flag = True
        break

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):



import sys

side = ((2-1, 3-1, 5-1, 4-1), (6-1, 3-1, 1-1, 4-1), (1-1, 2-1, 6-1, 5-1),
        (1-1, 5-1, 6-1, 2-1), (1-1, 3-1, 6-1, 4-1), (5-1, 3-1, 2-1, 4-1))

def check_rotate(face1, face2, f2_index):
    f1_bot = face1[5]
    if face2[5-f2_index] != f1_bot:
        return False
    f2_side_index = side[f2_index] * 2
    f2_side = [face2[f2_side_index[i]] for i in range(len(f2_side_index))]
    f1_side = [face1[i] for i in (2-1, 3-1, 5-1, 4-1)]
    

    for i in range(4):
        if f1_side == f2_side[i:i+4]:
            return True

    return False

def check_ident(face1, face2):
    f1_top = face1[0]
    for index in range(len(face2)):
        if face2[index] == f1_top:
            if check_rotate(face1, face2, index):
                return True

    return False


face1 = sys.stdin.readline().split()
face2 = sys.stdin.readline().split()

if check_ident(face1, face2):
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
        self.t = dice[0]
        self.s = dice[1]
        self.e = dice[2]
        self.w = dice[3]
        self.n = dice[4]
        self.b = dice[5]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def spin(self):
        self.dice[1] = self.buff[3]
        self.dice[2] = self.buff[1]
        self.dice[4] = self.buff[2]
        self.dice[3] = self.buff[4]
        self.buff = [n for n in self.dice]
    def to_be_the_same_direction(self, anotherDice):
        if self.t == anotherDice.t:
            pass
        elif self.t == anotherDice.e:
            anotherDice.west()
        elif self.t == anotherDice.w:
            anotherDice.east()
        elif self.t == anotherDice.n:
            anotherDice.south()
        elif self.t == anotherDice.s:
            anotherDice.north()
        else:
            anotherDice.north()
            anotherDice.north()
    def isSameDice(self, anotherDice):
        if  self.dice[0] == anotherDice.dice[0] and \
            self.dice[1] == anotherDice.dice[1] and \
            self.dice[2] == anotherDice.dice[2] and \
            self.dice[3] == anotherDice.dice[3] and \
            self.dice[4] == anotherDice.dice[4] and \
            self.dice[5] == anotherDice.dice[5]:
                return True
        return False
    def compare(self, anotherDice):
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.west()
        self.west()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()
        return False

nums1 = [int(x) for x in input().split()]
nums2 = [int(x) for x in input().split()]
dice1 = Dice(nums1)
dice2 = Dice(nums2)

if dice1.compare(dice2):
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_right(self):
        tmp = self.num[:]
        self.num[1] = tmp[3]
        self.num[2] = tmp[1]
        self.num[3] = tmp[4]
        self.num[4] = tmp[2]
    def print_dice(self):
        print(self.num)

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))
flg = False
for i in range(20):
    if flg == True:
        break
    dice2.roll_north()
    for k in range(20):
        if flg == True:
            break
        dice2.roll_east()
        for l in range(20):
            dice2.roll_right()
            if dice1.num == dice2.num:
                flg = True
                break
if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice:
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.faces = [(v1, v6), (v2, v5), (v3, v4)]

    def rotate_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, rgt, bck, fnt, lft, btm)

    def rotate_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, lft, fnt, bck, rgt, btm)

    def turn_back(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(fnt, btm, rgt, lft, top, bck)

    def turn_front(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(bck, top, rgt, lft, btm, fnt)

    def turn_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(lft, fnt, top, btm, bck, rgt)

    def turn_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(rgt, fnt, btm, top, bck, lft)

    def __str__(self):
        return "<{}>".format(",".join([str(t) for t in self.faces]))

    def __eq__(self, other):
        def equals(d1, d2):
            return d1.faces == d2.faces

        (top, btm) = self.faces[0]
        if (top, btm) in other.faces:
            return (equals(self, other)
                    or equals(self.rotate_right(), other)
                    or equals(self.rotate_left(), other)
                    or equals(self.turn_right(), other)
                    or equals(self.turn_front(), other)
                    or equals(self.rotate_left().rotate_left(), other)
                    or equals(self.turn_back().rotate_left(), other)
                    or equals(self.turn_front().rotate_right(), other)
                    or equals(self.turn_right().rotate_left(), other)
                    or equals(self.turn_left().rotate_right(), other)
                    or equals(self.turn_right().turn_back().turn_back(),
                              other)
                    or equals(self.turn_front().turn_right().turn_right(),
                              other))
        elif (btm, top) in other.faces:
            return self.turn_front().turn_front() == other
        else:
            return False


def run():
    dice1 = Dice(*[int(i) for i in input().split()])
    dice2 = Dice(*[int(i) for i in input().split()])

    if dice1 == dice2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    run()