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, ary):
        self.top, self.south, self.east, self.west, self.north, self.bottom = ary

    def roll_n(self):
        self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom

    def roll_e(self):
        self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom

    def twist(self):
        self.north, self.east, self.south, self.west = self.west, self.north, self.east, self.south

    def isEqual(self, dice):
        if self.top == dice.top and self.south == dice.south and self.east == dice.east and self.west == dice.west and self.north == dice.north and self.bottom == dice.bottom:
            return True
        else:
            return False

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

flag = False

for i in range(6):
    if i % 2 == 0:
        dice1.roll_n()
    else:
        dice1.roll_e()

    for j in range(4):
        if dice1.isEqual(dice2):
            flag = True
            break
        else:
            dice1.twist()

    if flag:
        break

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

Solution (Python):



class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        self.rotate(frontRot[iFront])

    def copy(self):
        return Dice(self.label[:])

    def __eq__(self, other):
        if set(self.label) != set(other.label):
            return False
        for rs in ['', 'S', 'N', 'W', 'SS']:
            for r in rs:
                tmp = self.copy()
                tmp.rotate(r)
                top = tmp.getLabel(1) == other.getLabel(1)
                bottom = tmp.getLabel(6) == other.getLabel(6)
                side, n = False, 3
                while not side and n > 0:
                    if tmp.label[1:6] == other.label[1:6]:
                        side = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                if top and bottom and side:
                    return True
        else:
            return False


def main():
    face1 = map(int, raw_input().split())
    face2 = map(int, raw_input().split())
    
    if set(face1) != set(face2):
        print 'No'
    
    elif len(face1) == len(set(face1)):
        d1 = Dice(face1)
        d2 = Dice(face2)
        d2.matchTopFront(d1.getLabel(1), d1.getLabel(2))
        print 'Yes' if d1.label == d2.label else 'No'
    
    else:
        d1 = Dice(face1)
        d2 = Dice(face2)
        print 'Yes' if d1 == d2 else 'No'

if __name__ == '__main__':
    main()

Solution (Python):



class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        self.rotate(frontRot[iFront])

    def copy(self):
        return Dice(self.label[:])

    def __eq__(self, other):
        for rs in ['', 'S', 'N', 'W', 'SS']:
            tmp = self.copy()
            for r in rs:
                tmp.rotate(r)
            top = tmp.getLabel(1) == other.getLabel(1)
            bottom = tmp.getLabel(6) == other.getLabel(6)
            side, n = False, 3
            while not side and n > 0:
                if tmp.label[1:6] == other.label[1:6]:
                    side = True
                else:
                    tmp.rotate('T')
                    n -= 1
            if top and bottom and side:
                return True
        else:
            return False


def main():
    face1 = map(int, raw_input().split())
    face2 = map(int, raw_input().split())
    
    if set(face1) != set(face2):
        print 'No'
    
    elif len(face1) == len(set(face1)):
        d1 = Dice(face1)
        d2 = Dice(face2)
        d2.matchTopFront(d1.getLabel(1), d1.getLabel(2))
        print 'Yes' if d1.label == d2.label else 'No'
    
    else:
        d1 = Dice(face1)
        d2 = Dice(face2)
        print 'Yes' if d1 == d2 else 'No'

if __name__ == '__main__':
    main()

Solution (Python):



class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        self.rotate(frontRot[iFront])

    def copy(self):
        return Dice(self.label[:])

    def __eq__(self, other):
        
        for rs in ['', 'S', 'N', 'E', 'W', 'SS']:
            tmp = self.copy()
            for r in rs:
                tmp.rotate(r)
            
            top = tmp.getLabel(1) == other.getLabel(1)
            bottom = tmp.getLabel(6) == other.getLabel(6)
            
            
            def side():
                result, n = False, 3
                while not result and n > 0:
                    if tmp.label[1:5] == other.label[1:5]:
                        result = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                return result
            if top and bottom and side():
                return True
        else:
            return False


def main():
    face1 = map(int, raw_input().split())
    face2 = map(int, raw_input().split())
    
    if set(face1) != set(face2):
        print 'No'
    
    elif len(face1) == len(set(face1)):
        d1 = Dice(face1)
        d2 = Dice(face2)
        d2.matchTopFront(d1.getLabel(1), d1.getLabel(2))
        print 'Yes' if d1.label == d2.label else 'No'
    
    else:
        d1 = Dice(face1)
        d2 = Dice(face2)
        print 'Yes' if d1 == d2 else 'No'

if __name__ == '__main__':
    main()

Solution (Python):
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def checksame(self, faces):
        if self.number(2) in (faces.number(3), faces.number(4)):
            faces.roll_west()
        while self.number(2) != faces.number(2):
            faces.roll_north()
        while self.number(1) != faces.number(1):
            faces.roll_west()
        return self.number(3) == faces.number(3)

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

print("Yes" if dice1.checksame(dice2) else "No")

Solution (Python):
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def checksame(self, faces):
        self_opposite_face = dict(zip([self.number(i) for i in range(1, 7)],
                                      [self.number(i) for i in range(6, 0, -1)]))
        other_opposite_face = dict(zip([faces.number(i) for i in range(1, 7)],
                                       [faces.number(i) for i in range(6, 0, -1)]))
        if self_opposite_face != other_opposite_face:
            return False
        if self.number(2) in (faces.number(3), faces.number(4)):
            faces.roll_west()
        while self.number(2) != faces.number(2):
            faces.roll_north()
        while self.number(1) != faces.number(1):
            faces.roll_west()
        return self.number(3) == faces.number(3)

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

print("Yes" if dice1.checksame(dice2) else "No")

Solution (Python):
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

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

print("Yes" if dice1.issame(dice2) else "No")

Solution (Python):
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

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

print("Yes" if dice1.issame(dice2) else "No")

Solution (Python):
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'S':
            dice[0], dice[1], dice[5], dice[4] = dice[4], dice[0], dice[1], dice[5]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]
        elif command == 'E':
            dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2], dice[0]

A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(4):
    for j in range(4):
        for commands in itertools.permutations('S' * i + 'W' * j):
            a = A[::]
            roll(a, commands)
            if B == a:
                print('Yes')
                exit()
print('No')

Solution (Python):
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]


def solve():
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(4):
        for j in range(4):
            for commands in itertools.permutations('N' * i + 'W' * j):
                a = A[::]
                roll(a, commands)
                if B == a:
                    return True
    return False


if __name__ == '__main__':
    print('Yes' if solve() else 'No')

Solution (Python):
import itertools


def solve():
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(4):
        for j in range(4):
            for commands in itertools.permutations('N' * i + 'W' * j):
                a = A[::]
                for command in commands:
                    if command == 'N':
                        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
                    elif command == 'W':
                        a[0], a[3], a[5], a[2] = a[2], a[0], a[3], a[5]
                if B == a:
                    return True
    return False


if __name__ == '__main__':
    print('Yes' if solve() else 'No')

Solution (Python):
import random

class Dice:
  def __init__(self, list = map(str, range(1, 7))):
    self.top = list[0]
    self.front = list[1]
    self.right = list[2]
    self.left = list[3]
    self.back = list[4]
    self.bottom = list[5]

    self.dic = {}
    for i in xrange(6):
      if list[i] in self.dic:
        self.dic[list[i]] += 1
      else:
        self.dic[list[i]] = 1

  def print_all(self):
    print "top = " + self.top + ", front = " + self.front + ", right = " + self.right + ", left = " + self.left + ", back = " + self.back + ", bottom = " + self.bottom

  def roll_N(self):
    temp = self.top
    self.top = self.front
    self.front = self.bottom
    self.bottom = self.back
    self.back = temp

  def roll_S(self):
    temp = self.top
    self.top = self.back
    self.back = self.bottom
    self.bottom = self.front
    self.front = temp

  def roll_W(self):
    temp = self.top
    self.top = self.right
    self.right = self.bottom
    self.bottom = self.left
    self.left = temp

  def roll_E(self):
    temp = self.top
    self.top = self.left
    self.left = self.bottom
    self.bottom = self.right
    self.right = temp

  def roll_C(self):
    temp = self.front
    self.front = self.right
    self.right = self.back
    self.back = self.left
    self.left = temp

  def random_roll(self):
    ram = random.randint(1, 4)
    if ram == 1:
      self.roll_E()
    elif ram == 2:
      self.roll_N()
    elif ram == 3:
      self.roll_S()
    else:
      self.roll_W()

  def getDifference(self, dice):
    same_list = []
    different_list = []
    if self.top == dice.top:
      same_list.append("top")
    else:
      different_list.append("top")
    if self.front == dice.front:
      same_list.append("front")
    else:
      different_list.append("front")
    if self.left == dice.left:
      same_list.append("left")
    else:
      different_list.append("left")
    if self.back == dice.back:
      same_list.append("back")
    else:
      different_list.append("back")
    if self.right == dice.right:
      same_list.append("right")
    else:
      different_list.append("right")
    if self.bottom == dice.bottom:
      same_list.append("bottom")
    else:
      different_list.append("bottom")

    result_list = [same_list, different_list]
    return result_list

  def getList(self):
    list = [self.top, self.front, self.right, self.left, self.back, self.bottom]
    return list

first_dice = Dice(raw_input().split(" "))
second_dice = Dice(raw_input().split(" "))

def print_dices():
  print "first dice: "
  first_dice.print_all()
  print "second dice: "
  second_dice.print_all()
  print first_dice.dic

line = "

flag = False
num = 0
debug = 0
while num < 4:
  
  
  
  

  dic1_keys = first_dice.dic.keys()
  for i in xrange(len(dic1_keys)):
    if first_dice.dic[dic1_keys[i]] != second_dice.dic[dic1_keys[i]]:
      num = 4
      break

  for i in xrange(len(dic1_keys)):
    if first_dice.dic[dic1_keys[i]] == 6 or first_dice.dic[dic1_keys[i]] == 5:
      num = 4
      flag = True
      break

  

  diferece = first_dice.getDifference(second_dice)
  

  same_num = len(diferece[0])
  if same_num == 6:
    break
  elif same_num == 5:
    num = 4
    break

  if "front" in diferece[0] or "back" in diferece[0]:
    first_dice.roll_W()
    num += 1
  elif "left" in diferece[0] or "right" in diferece[0]:
    first_dice.roll_S()
    num += 1
  elif "top" in diferece[0] or "bottom" in diferece[0]:
    first_dice.roll_C()
    num += 1
  else:
    first_dice.random_roll()

if flag == True:
  print "Yes"
elif num == 4:
  print "No"
else:
  print "Yes"

Solution (Python):



POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)


def main():
    dice1 = Dice(input().split())  
    dice2 = Dice(input().split())  
    if dice1.faces["south"] == dice2.faces["west"]:
        dice2.roll("E")
    elif dice1.faces["south"] == dice2.faces["east"]:
        dice2.roll("W")
    while dice1.faces["south"] != dice2.faces["south"]:
        dice2.roll("N")
    for n in range(4):
        if (dice1.faces["top"] == dice2.faces["top"] and
                dice1.faces["east"] == dice2.faces["east"]):
            print("Yes")
            break
        else:
            dice2.roll("E")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')

Solution (Python):
class Dice(object):

    def __init__(self, num):
        self.num = num

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rotate_M(self):
        self.num = [self.num[0], self.num[2], self.num[4], self.num[1], self.num[3], self.num[5]]

dice1 = Dice(map(int, raw_input().split()))
dice2 = Dice(map(int, raw_input().split()))
yes_flg = False
if len(set(dice1.num) - set(dice2.num)) != 0:
    print 'No'
else:
    num = []
    for i in range(6):
        if dice1.num[0] == dice2.num[i]:
            num.append(i)
    for j in num:
        if j == 1:
            dice2.rotate_N()
        elif j == 2:
            dice2.rotate_W()
        elif j == 3:
            dice2.rotate_E()
        elif j == 4:
            dice2.rotate_S()
        elif j == 5:
            dice2.rotate_S()
            dice2.rotate_S()

        if dice1.num[5] == dice2.num[5]:
            for i in range(4):
                if (dice1.num[1] == dice2.num[1]) & (dice1.num[2] == dice2.num[2]) & (dice1.num[3] == dice2.num[3]):
                    yes_flg = True
                    break
                dice1.rotate_M()
            if yes_flg:
                break
    if yes_flg:
        print 'Yes'
    else:
        print 'No'

Solution (Python):
import copy

class Dice(object):
	def __init__(self,List):
		self.face=List
		
	def n_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp
		return List
		
 	def s_spin(self,a_list):
 		List=copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[4]
 		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp
		return List
		
	def e_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp
		return List
		
 	def w_spin(self,a_list):
 		List = copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[2]
 		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp
		return List

dice_1=Dice(map(int,raw_input().split()))
dice_2=Dice(map(int,raw_input().split()))
emer=copy.copy(dice_2.face)
face_storage=[]
face_storage.append(emer)
judge=False
for a in range(24):
	face_storage.append(dice_2.n_spin(face_storage[a]))
	face_storage.append(dice_2.s_spin(face_storage[a]))
	face_storage.append(dice_2.e_spin(face_storage[a]))
	face_storage.append(dice_2.w_spin(face_storage[a]))
for c in face_storage:
	if c==dice_1.face:
		judge=True
if judge :
	print("Yes")
else :
	print("No")

Solution (Python):
class Dice:
    same_dice_index = ('123456', '135246', '142536', '154326',
                       '214365', '231645', '246135', '263415',
                       '312564', '326154', '351624', '365214',
                       '415263', '421653', '456123', '462513',
                       '513462', '536142', '541632', '564312',
                       '624351', '632541', '645231', '653421')

    def __init__(self, num_list):
        self.faces = num_list

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            example_faces = []
            for j in i:
                example_faces.append(self.faces[int(j) - 1])
            if example_faces == dice.faces:
                return 'Yes'
        return 'No'

num_list1 = list(map(int, input().split()))
num_list2 = list(map(int, input().split()))

dice1 = Dice(num_list1)
dice2 = Dice(num_list2)

ans = dice1.is_same(dice2)

print(ans)

Solution (Python):
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')