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)


n = gets.chomp.to_i

x = []
n.times do |i|
    x.push(gets.split(" ").map(&:to_i))
end

def rotation(a, i)
    if i.eql?("N") then
        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
    elsif i.eql?("S") then
        a[0], a[1], a[5], a[4] = a[4], a[0], a[1], a[5]
    elsif i.eql?("E") then
        a[0], a[2], a[5], a[3] = a[3], a[0], a[2], a[5]
    elsif i.eql?("W") then
        a[0], a[2], a[5], a[3] = a[2], a[5], a[3], a[0]
    elsif i.eql?("R") then
        a[3], a[1], a[2], a[4] = a[4], a[3], a[1], a[2]
    elsif i.eql?("L") then
        a[3], a[1], a[2], a[4] = a[1], a[2], a[4], a[3]
    end
    
    a
end

def f(a, b)
    "EEEESEEEESEEEESEEEESREEERREEE".each_char do |i|
        a = rotation(a, i)
        if a == b then
            return true
        end
    end

    false
end

x.size.times do |i|
    ((i + 1)...x.size).each do |j|
        if f(x[i], x[j]) then
            print "No\n"
            exit
        end
    end
end

print "Yes\n"