Problem:
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I , and determines whether they are all different. For the determination, use the same way as Dice III . Input In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III . Output Print " Yes " if given dices are all different, otherwise " No " in a line. Constraints  $2 \leq n \leq 100$  $0 \leq $ the integer assigned to a face $ \leq 100$  Sample Input 1 3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1 Sample Output 1 No Sample Input 2 3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6 Sample Output 2 Yes

Solution (Python):
class Dice:
    def __init__(self):
        self.state =[1, 2, 3, 4, 5, 6]

    def setState(self, li):  
        self.state = li

    def move(self, str_direction):
        if str_direction == "N":
            self.state = [self.state[1], self.state[5],self.state[2],
                          self.state[3], self.state[0], self.state[4]]
        if str_direction == "W":
            self.state = [self.state[2], self.state[1], self.state[5],
                          self.state[0], self.state[4], self.state[3]]
        if str_direction == "E":
            self.state = [self.state[3], self.state[1], self.state[0],
                          self.state[5], self.state[4], self.state[2]]
        if str_direction == "S":
            self.state = [self.state[4], self.state[0], self.state[2],
                          self.state[3], self.state[5], self.state[1]]

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

    def sameDice1(self, dice1):
        set1 = list()
        for _ in range(4):
            for __ in range(4):
                set1.append(self.state)
                self.rotate()
            self.move("N")
        self.move("E")
        for _ in range(4):
            set1.append(self.state)
            self.rotate()
        self.move("E")
        self.move("E")
        for _ in range(4):
            set1.append(self.state)
            self.rotate()
        if dice1.state in set1:
            return "Yes"
        return "No"


def main():
    n = int(input())
    dices = []
    for i in range(n):
        dices.append(Dice())
        dices[i].setState(list(map(int, input().split())))
    bl = False
    result = "Yes"
    for i in range(n):
        for j in range(n):
            if i == j:
                break
            if dices[i].sameDice1(dices[j]) == "Yes":
                result = "No"
                bl = True
                break
        if bl:
            break
    print(result)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())

    dices = []
    for i in range(n):
        dices.append(Dice(list(map(int, input().split(' ')))))

    if not equals_any(dices):
        print('Yes')
    else:
        print('No')

def equals_any(dices):
    for i, d1 in enumerate(dices):
        for d2 in [d for d in dices[i+1:]]:
            if equals(d1, d2):
                return True

    return False

def equals(d1, d2):
    for i in range(4):
        for j in range(4):
            if d1.equals(d2):
                return True
            d2.toE()
        d2.toN()

    d2.toE().toN()

    for i in range(2):
        for j in range(4):
            if d1.equals(d2):
                return True
            d2.toE()
        d2.toN().toN()

    return False

class Dice:
    def __init__(self, labels):
        self.labels = labels

        self._tb = (0, 5)
        self._fb = (1, 4)
        self._lr = (3, 2)

    def toN(self):
        tb = self._tb
        self._tb = self._fb
        self._fb = tuple(reversed(tb))

        return self

    def toS(self):
        tb = self._tb
        self._tb = tuple(reversed(self._fb))
        self._fb = tb

        return self

    def toW(self):
        tb = self._tb
        self._tb = tuple(reversed(self._lr))
        self._lr = tb

        return self

    def toE(self):
        tb = self._tb
        self._tb = self._lr
        self._lr = tuple(reversed(tb))

        return self

    def get_top(self):
        return self.labels[self._tb[0]]

    def get_bottom(self):
        return self.labels[self._tb[1]]

    def get_front(self):
        return self.labels[self._fb[0]]

    def get_back(self):
        return self.labels[self._fb[1]]

    def get_left(self):
        return self.labels[self._lr[0]]

    def get_right(self):
        return self.labels[self._lr[1]]

    top    = property(get_top)
    bottom = property(get_bottom)
    front  = property(get_front)
    back   = property(get_back)
    left   = property(get_left)
    right  = property(get_right)

    def equals(self, other):
        if not (self.top == other.top and self.bottom == other.bottom):
            return False

        if not (self.front == other.front and self.back == other.back):
            return False

        if not (self.left == other.left and self.right == other.right):
            return False

        return True

    def __str__(self):
        return str([self.top, self.front, self.right, self.left, self.back, self.bottom])

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]

def compare(x, y):
    succeed = False
    for i in range(6):
        match = True
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                match = False
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        if match:
            if 2 in order:
                succeed = True
                break
            if (z[i][3] == 0 or z[i][3] == 3) and sum(order) % 2:
                succeed = True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                succeed = True
                break
    if succeed:
        return True
    else:
        return False

different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        break
if different:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]

def compare(x, y):
    succeed = False
    for i in range(6):
        match = True
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                match = False
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        if match:
            if 2 in order:
                succeed = True
                break
            if (z[i][3] == 0 or z[i][3] == 3) and sum(order) % 2:
                succeed = True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                succeed = True
                break
    if succeed:
        return True
    else:
        return False

different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        break
if different:
    print('Yes')
else:
    print('No')

Solution (Python):
def compare(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False
 
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        break
if different:
    print('Yes')
else:
    print('No')

Solution (Python):
def compare(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False
 
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        break
if different:
    print('Yes')
else:
    print('No')

Solution (Python):
def compare(x, y): 
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] 
different = True
for i in range(n):
    for j in range(i+1, n, 1): 
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
def compare(x, y): 
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] 
different = True
for i in range(n):
    for j in range(i+1, n, 1): 
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
def compare(x, y): 
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] 
different = True
for i in range(n):
    for j in range(i+1, n, 1): 
        if compare(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def compare(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or z[i][3] == sum(order) % 2:
                return True
                break
    return False
 
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 1], [0, 2, 1, 0], [2, 1, 0, 0], [1, 0, 2, 0], [2, 0, 1, 1], [1, 2, 0, 1]]
different = True
for i in range(n):
    for j in range(i+1, n, 1): 
        if compare(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo
    
    def E(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.r = a
        self.bo = b
        self.l = c
        self.t = d
    
    def N(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.ba = a
        self.bo = b
        self.f = c
        self.t = d
    
    def S(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.f = a
        self.t = b
        self.ba = c
        self.bo = d
    
    def W(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.l = a
        self.t = b
        self.r = c
        self.bo = d

def hantei(dice1,dice2):
    global flag
    if dice1.t == dice2.f:
        dice2.N()
    elif dice1.t == dice2.r:
        dice2.W()
    elif dice1.t == dice2.l:
        dice2.E()
    elif dice1.t == dice2.ba:
        dice2.S()
    elif dice1.t == dice2.bo:
        dice2.E()
        dice2.E()
    if dice1.bo != dice2.bo:
        dice2.N()
        for i in range(4):
            if dice1.t == dice2.t and dice1.bo == dice2.bo:
                break
            dice2.E()
    for i in range(4):
        if dice1.t == dice2.t and dice1.f == dice2.f and dice1.r == dice2.r and dice1.l == dice2.l and dice1.ba == dice2.ba and dice1.bo == dice2.bo:
            flag = 1
            break
        dice2.N()
        dice2.E()
        dice2.S()
        

n = int(input())
dice = []
flag = 0
for i in range(n):
    s = input().split(" ")
    dice.append(Dice(s[0],s[1],s[2],s[3],s[4],s[5]))
hantei(dice[0],dice[1])
for i in range(n-1):
    if flag == 1:
        break
    for j in range(i+1,n):
        hantei(dice[i],dice[j])
        if flag == 1:
            break

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

Solution (Python):
class Dice:
    def __init__(self):
        self.dice = [
                    [0, 1, 2, 3, 4, 5],
                    [0, 2, 4, 1, 3, 5],
                    [0, 4, 3, 2, 1, 5],
                    [0, 3, 1, 4, 2, 5],
                    [1, 5, 2, 3, 0, 4],
                    [1, 2, 0, 5, 3, 4],
                    [1, 0, 3, 2, 5, 4],
                    [1, 3, 5, 0, 2, 4],
                    [2, 1, 5, 0, 4, 3],
                    [2, 5, 4, 1, 0, 3],
                    [2, 4, 0, 5, 1, 3],
                    [2, 0, 1, 4, 5, 3],
                    [3, 1, 0, 5, 4, 2],
                    [3, 0, 4, 1, 5, 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, 5, 3, 2, 0, 1],
                    [4, 3, 0, 5, 2, 1],
                    [5, 1, 3, 2, 4, 0],
                    [5, 2, 1, 4, 3, 0],
                    [5, 4, 2, 3, 1, 0],
                    [5, 3, 4, 1, 2, 0]]

    def math(self, dice_p1, dice_p2):
        dice_t = []
        not_match = "Yes"
        for dice_p in self.dice:
            for i in range(6):
                dice_t.append(dice_p1[dice_p[i]])
            if dice_t == dice_p2:
                not_match = "No"
            dice_t = []
        return not_match

n = int(input())
dice_p = []
for j in range(n):
    dice_p.append([int(dice_p) for dice_p in input().split()])

d = Dice()
for j in range(n-1):
    k = j + 1
    for k in range(k, n):
        dice_p1 = dice_p[j]
        dice_p2 = dice_p[k]
        not_match = d.math(dice_p1, dice_p2)
        if not_match == "No":
            print("No")
            break
    if not_match == "No":
            break
if not_match == "Yes":
    print("Yes")

Solution (Python):
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or z[i][3] == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 1], [0, 2, 1, 0], [2, 1, 0, 0], [1, 0, 2, 0], [2, 0, 1, 1], [1, 2, 0, 1]]
different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
different = True
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
z = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[a[i][j]], y[-a[i][j]-1]}:
                break
            if x[j] == y[a[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n, 1):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[a[i][j]], y[-a[i][j]-1]}:
                break
            if x[j] == y[a[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[a[i][j]], y[-a[i][j]-1]}:
                break
            if x[j] == y[a[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(input())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
import sys
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(sys.stdin.readline())
x = [input().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
import sys
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(sys.stdin.readline())
x = [sys.stdin.readline().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
import sys
def check(x, y):
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            k = a[i][j]
            if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
                break
            if x[j] == y[k]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
    return False

a = [[0, 1, 2], [2, 0, 1], [1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]
n = int(sys.stdin.readline())
x = [sys.stdin.readline().split() for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Solution (Python):
n=int(input())
 
def rot(d, r):
    if r == 'N':
        return (d[1], d[5], d[2], d[3], d[0], d[4])
    if r == 'E':
        return (d[3], d[1], d[0], d[5], d[4], d[2])
    if r == 'W':
        return (d[2], d[1], d[5], d[0], d[4], d[3])
    if r == 'S':
        return (d[4], d[0], d[2], d[3], d[5], d[1])
    return d
 
def gen_all( d1 ):
    ds = { d1 }
    while 1:
        ds2 = { rot(d, r) for d in ds for r in list('NEWS') }.union(ds)
        if ds == ds2: break
        ds = ds2
    return ds
 
ds = {}
 
for i in range(n):
    d=tuple(map(int,input().split()))
    ds[i] = (d, gen_all(d))
 
dep=any ([ ds[i][0] in ds[j][1] for i in range(n) for j in range(i+1,n) ])
     
print('No' if dep else 'Yes')

Solution (Python):
import sys
n=int(input())
x1=[int(i)for i in input().split()]
for i in range(n-1):
    x2=[int(i)for i in input().split()]
    for i in range(6):
        if x2[i]==x1[0]:
            count=i
            if x2[5-i]==x1[5]:
                break
    if x2[count]==x1[0] and x2[5-count]==x1[5]:
        if count==0 or count==5:
            if count==5:
                for i in range(2):
                    x2[1],x2[0]=x2[0],x2[1]
                    x2[5],x2[1]=x2[1],x2[5]
                    x2[4],x2[5]=x2[5],x2[4]
        else:
            if count==1 or count==4:
                while x1[0]!=x2[0] or x1[5]!=x2[5]:
                    x2[1],x2[0]=x2[0],x2[1]
                    x2[5],x2[1]=x2[1],x2[5]
                    x2[4],x2[5]=x2[5],x2[4]
            else:
                while x1[0]!=x2[0] or x1[5]!=x2[5]:
                    x2[3],x2[0]=x2[0],x2[3]
                    x2[5],x2[3]=x2[3],x2[5]
                    x2[2],x2[5]=x2[5],x2[2]
        for i in range(4):
            if x2[2]==x1[2] and x2[3]==x1[3] and x2[4]==x1[4] and x2[1]==x1[1] :
                print('No')
                sys.exit()
            else:
                x2[1],x2[2]=x2[2],x2[1]
                x2[2],x2[4]=x2[4],x2[2]
                x2[4],x2[3]=x2[3],x2[4]
print('Yes')