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: Wrong Answer)

n = gets.chomp.to_i - 1
@dice = gets.split(' ').map(&:to_i)

def throw(a, b)
    temp = @dice[0]
    @dice[0] = @dice[a]
    @dice[a] = @dice[5]
    @dice[5] = @dice[b]
    @dice[b] = temp
end

def check(dice)
    while (dice[1] != @dice[0])
        throw(4, 1)
        break if dice[1] == @dice[0]
        throw(2, 3)
    end
    throw(4, 1)
    4.times do
        throw(2, 3)
        return true if dice == @dice
    end
    false
end

count = 0;

n.times do
    diceN = gets.split(' ').map(&:to_i)
    count += 1 if  check(diceN)
end

puts count != n ? 'Yes' : 'No'