Dice IV: Write a program to determine if a given set of dice are all different. The input consists of the number of dice, followed by the face values of each die. Output "Yes" if the dice are all different, otherwise output "No". Constraints: 2 ≤ n ≤ 100, 0 ≤ face value ≤ 100.

# Buggy version:
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    dices = []
    n = int(input())
    for i in range(n):
        dices.append(Dice([int(x) for x in input().split()]))

    flag = False
    for i in range(n):
        j = i + 1
        while j < n:
            if dices[i].is_same_dice(dices[j]):
                flag = True
                break
            j += 1

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


if __name__ == '__main__':
    main()

# Fixed version:
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    dices = []
    n = int(input())
    for i in range(n):
        dices.append(Dice([int(x) for x in input().split()]))

    flag = False
    for i in range(n):
        j = i + 1
        while j < n:
            if dices[i].is_same_dice(dices[j].label):
                flag = True
                break
            j += 1

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


if __name__ == '__main__':
    main()

# Buggy version:
n = int(input())

def rot(dice,rotation):
    if rotation == "E":
        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])
    elif rotation == "W":
        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])
    elif rotation == "N":
        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])
    elif rotation == "S":
        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])
    return dice

def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern

dice = [0 for i in range(n)]
for i in range(n):
    dice[i] = tuple(map(int,input().split()))

for j in range(1):
    if n > 24:
        print("No")
        break
    pattern = set()
    for i in range(n-1):
        pattern = pattern.union(make_all_pattern(dice[i]))
        if dice[i] in pattern:
            print("No")
            break
    else:
        print("Yes")
    

# Fixed version:
n = int(input())

def rot(dice,rotation):
    if rotation == "E":
        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])
    elif rotation == "W":
        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])
    elif rotation == "N":
        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])
    elif rotation == "S":
        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])
    return dice

def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern

dice = [0 for i in range(n)]
for i in range(n):
    dice[i] = tuple(map(int,input().split()))


pattern = set()
for i in range(n-1):
    pattern = pattern.union(make_all_pattern(dice[i]))
    if dice[i+1] in pattern:
        print("No")
        break

else:
    print("Yes")

# Buggy version:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

n = int(input())
ans = "Yes"
ds =[]

for i in range(n):
    ds.append(dice(list(map(int,input().split()))))

for i in range(len(ds)-1):
    for j in range(i+1,len(ds)):
        d_tmp = dice(ds[j].pip)
        for op in "EEENEEENEEESEEESEEENEEEN":
            if ds[i].pip == d_tmp.pip:
                ans = "No"
                break

print(ans)

# Fixed version:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

n = int(input())
ans = "Yes"
ds =[]

for i in range(n):
    ds.append(dice(list(map(int,input().split()))))

for i in range(len(ds)-1):
    for j in range(i+1,len(ds)):
        d_tmp = dice(ds[j].pip)
        for op in "EEENEEENEEESEEESEEENEEEN":
            if ds[i].pip == d_tmp.pip:
                ans = "No"
                break
            d_tmp.move(op)

print(ans)

# Buggy version:
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]):
            print(i, j)
            different = False
            break
    if not different:
        break
if different:
    print('Yes')
else:
    print('No')

# Fixed version:
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')

# Buggy version:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
for i in range(n-1):
 d=a[i]
 for j in range(i+1,n):
  e=a[j]
  for p in('012345','152043','215304','302541','410352','514320'):
   f=[d[int(k)]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    [t=1 for k in range(4)if f[k:k+4]==e[1:5]]
print(('Yes','No')[t])


# Fixed version:
import sys
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for i in range(n-1):
 d=a[i][:];d[3],d[4]=d[4],d[3]
 for j in range(i+1,n):
  e=a[j][:];e[3],e[4]=e[4],e[3]
  for p in('012345','152043','215304','302541','410352','514320'):
   f=[d[int(k)]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:print('No');sys.exit()
print('Yes')

# Buggy version:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
b=a[k];b[3],b[4]=b[4],b[3]
def f():
 for i in range(n-1):
  d=a[i]
  for j in range(i+1,n):
   e=a[j]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return 'No'
 return 'Yes'
print(f())


# Fixed version:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if(f[0]==e[0])*(f[5]==e[5]):
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())

# Buggy version:
import itertools
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]]
def checker(d1,d2):
    for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
        d1.korokoro(com)
        if d1.number == d2.number:
            ans = 'Yes'
            break
        else:
            ans = 'No'
    return ans
n = int(input())
saikoro = {}
for _ in range(n):
    saikoro[_] = dice([int(x) for x in input().split()])
l = list(itertools.combinations(saikoro.keys(),2))
for __ in l:
    test1 = saikoro[__[0]]
    test2 = saikoro[__[1]]
    if checker(test1,test2) == 'Yes':
        answer = 'Yes'
        break
    else:
        anser = 'No'
print(answer)



# Fixed version:
import itertools
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]]
def checker(d1,d2):
    for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
        d1.korokoro(com)
        if d1.number == d2.number:
            ans = 'Yes'
            break
        else:
            ans = 'No'
    return ans
n = int(input())
saikoro = {}
for _ in range(n):
    saikoro[_] = dice([int(x) for x in input().split()])
l = list(itertools.combinations(saikoro.keys(),2))
for __ in l:
    test1 = saikoro[__[0]]
    test2 = saikoro[__[1]]
    if checker(test1,test2) == 'Yes':
        answer = 'No'
        break
    else:
        answer = 'Yes'
print(answer)

# Buggy version:
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    b = is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")


# Fixed version:
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    b += is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")

# Buggy version:
def g():
 from itertools import*
 n=int(input())
 a=[input().split()for _ in[0]*n]
 for b in a:
  b[3:5]=b[4],b[3]
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(g())


# Fixed version:
from itertools import*
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:
 b[3:5]=b[4],b[3]
def g():
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[::5]==e[::5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(g())

# Buggy version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for u in range(n-1):
    for t in range(u+1,n):
        for j in s:
            for r in w:
                if dice.a[t]==dice.a[u]:
                    ans='No'
                    break
                dice.roll(r,t)
            else:
                dice.roll(j,t)
                continue
            break
        else:
            continue
        break
    else:
        continue
    break
print(ans)



# Fixed version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
n=int(input())
for i in range(n):
    if i==0:
        t, f, r, l, b, u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for u in range(n-1):
    for t in range(u+1,n):
        for j in s:
            for r in w:
                if dice.a[t]==dice.a[u]:
                    ans='No'
                    break
                dice.roll(r,t)
            else:
                dice.roll(j,t)
                continue
            break
        else:
            continue
        break
    else:
        continue
    break
print(ans)

# Buggy version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
try:
    for u in range(n-1):
        for t in range(u+1, n):
            for j in s:
                for r in w:
                    print(dice.a[t],dice.a[u])
                    if dice.a[t] == dice.a[u]:
                        ans = 'No'
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
except Exception:
    pass
print(ans)




# Fixed version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
n=int(input())
for i in range(n):
    if i==0:
        t, f, r, l, b, u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
try:
    for u in range(n - 1):
        for t in range(u + 1, n):
            for j in s:
                for r in w:
                    if dice.a[t] == dice.a[u]:
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
    else:
        print('Yes')
except:
    print('No')

# Buggy version:
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]
     for k in range(4):
      if b[k-4:k-1]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())


# Fixed version:
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if b[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

# Buggy version:
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):
    if sorted(dice1) != sorted(dice2):
        return False
    
    for i in range(6):
        if i:tmp_dice = set_top(dice2, i)
        for j in range(4):
            if j:tmp_dice = twist(tmp_dice)
            if dice1 == tmp_dice:
                return True
    return False

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')

# Fixed version:
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):
    if sorted(dice1) != sorted(dice2):
        return False
    
    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

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')