Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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 in Ruby (judge verdict: Accepted)

Dice = Struct.new(:top, :front, :right, :left, :back, :bottom) do
    def roll(x)
        case x
        when "E"
            k = self.top
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = k
        when "N"
            k = self.top
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = k
        when "S"
            k = self.top
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = k
        when "W"
            k = self.top
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left =k
        end
    end
    
    def twist
        k = self.front
        self.front = self.right
        self.right = self.back
        self.back = self.left
        self.left = k
    end
end

dice_ary = []
dice_tmp = Dice.new

n = gets.to_i

n.times{|i|
    tmp = Dice.new
    tmp.top, tmp.front, tmp.right, tmp.left, tmp.back, tmp.bottom = gets.split
    dice_ary.push(tmp)
}

founded = false

ary = ["","N","W","E","S","NN"]

for i in 1..(dice_ary.length - 1)
    for c in ary 
        dice_tmp = dice_ary[i].dup
        if c != "" then
            for x in c.split("")
                dice_tmp.roll(x)
            end
        end
        4.times{
            dice_tmp.twist
            if dice_ary[0] == dice_tmp then
                founded = true
                break
            end
        }
    end
end

if !founded then
    puts "Yes"
else
    puts "No"
end