Buggy python submission (verdict: Time Limit Exceeded):
class Dice:
    def __init__(self, men):
        self.men = men

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]
        elif direction == "C":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[2]
            men[2] = pmen[4]
            men[3] = pmen[1]
            men[4] = pmen[3]
            men[5] = pmen[5]
        elif direction == "U":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[3]
            men[2] = pmen[1]
            men[3] = pmen[4]
            men[4] = pmen[2]
            men[5] = pmen[5]

    def makeUe(self, ue):
        if(self.men[2] == ue or self.men[3] == ue):
            self.throw("E")

        while (self.men[0] != ue):
            self.throw("S")

n = int(raw_input())
anti2 = []
antiNot2 = []
for i in range(n):
    men = map(int, (raw_input()).split(" "))
    d = Dice(men)
    d.makeUe(1)
    if d.men[5] == 2:
        while (d.men[1] != 3):
            d.throw("C")
        S = d.men[2:5]
        anti2.append(S)
    else:
        while (d.men[1] != 2):
            d.throw("C")
        S = d.men[2:6]
        antiNot2.append(S)

flag = False
for i in range(len(anti2)-1):
    if anti2[i] == anti2[i+1]:
        flag = True

for i in range(len(antiNot2)-1):
    if antiNot2[i] == antiNot2[i+1]:
        flag = True

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

Fixed submission:
class Dice:
    def __init__(self, men):
        self.men = men[:]

    def throw(self, direction):
        if direction == "E":
            pmen = self.men[:]
            self.men[0] = pmen[3]
            self.men[1] = pmen[1]
            self.men[2] = pmen[0]
            self.men[3] = pmen[5]
            self.men[4] = pmen[4]
            self.men[5] = pmen[2]
        elif direction == "W":
            pmen = self.men[:]
            self.men[0] = pmen[2]
            self.men[1] = pmen[1]
            self.men[2] = pmen[5]
            self.men[3] = pmen[0]
            self.men[4] = pmen[4]
            self.men[5] = pmen[3]
        elif direction == "S":
            pmen = self.men[:]
            self.men[0] = pmen[4]
            self.men[1] = pmen[0]
            self.men[2] = pmen[2]
            self.men[3] = pmen[3]
            self.men[4] = pmen[5]
            self.men[5] = pmen[1]
        elif direction == "N":
            pmen = self.men[:]
            self.men[0] = pmen[1]
            self.men[1] = pmen[5]
            self.men[2] = pmen[2]
            self.men[3] = pmen[3]
            self.men[4] = pmen[0]
            self.men[5] = pmen[4]
        elif direction == "C":
            pmen = self.men[:]
            self.men[0] = pmen[0]
            self.men[1] = pmen[2]
            self.men[2] = pmen[4]
            self.men[3] = pmen[1]
            self.men[4] = pmen[3]
            self.men[5] = pmen[5]
        elif direction == "U":
            pmen = self.men[:]
            self.men[0] = pmen[0]
            self.men[1] = pmen[3]
            self.men[2] = pmen[1]
            self.men[3] = pmen[4]
            self.men[4] = pmen[2]
            self.men[5] = pmen[5]

n = int(raw_input())
mens = []
for i in range(n):
    men = map(int,(raw_input()).split(" "))
    mens.append(men)

flag = False

for p in range(n-1):
    for q in range(p+1, n):
        d1 = Dice(mens[p][:])
        d2 = Dice(mens[q][:])

        for i in range(4):
            d1.throw("W")
            for j in range(4):
                d1.throw("S")
                if d1.men == d2.men:
                    flag = True

        for i in range(4):
            d1.throw("C")
            for j in range(4):
                d1.throw("S")
                if d1.men == d2.men:
                    flag = True
if flag:
    print "No"
else:
    print "Yes"