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)

class Dice
	def initialize(array)
		@data = array
	end
	
	def move(dir)
		case dir.downcase
		when "e"
			tmp=@data[0]
			@data[0]=@data[3]
			@data[3]=@data[5]
			@data[5]=@data[2]
			@data[2]=tmp
		when "n"
			tmp=@data[0]
			@data[0]=@data[1]
			@data[1]=@data[5]
			@data[5]=@data[4]
			@data[4]=tmp
		when "s"
			tmp=@data[0]
			@data[0]=@data[4]
			@data[4]=@data[5]
			@data[5]=@data[1]
			@data[1]=tmp
		when "w"
			tmp=@data[0]
			@data[0]=@data[2]
			@data[2]=@data[5]
			@data[5]=@data[3]
			@data[3]=tmp
		end
	end
	
	def rotate
		tmp=@data[1]
		@data[1]=@data[2]
		@data[2]=@data[4]
		@data[4]=@data[3]
		@data[3]=tmp
	end
	
	def top
		return @data[0]
	end
	
	def front
		return @data[1]
	end
	
	def left
		return @data[3]
	end
	
	def right
		return @data[2]
	end
	
	def back
		return @data[4]
	end
	
	def bottom
		return @data[5]
	end
	
	def all
		return @data
	end
end

n = gets.chomp.to_i
dice = Array.new

n.times { |idx|
	dice[idx] = Dice.new(gets.chomp.split(" ").map(&:to_i))
}

(n-1).times { |idx1|
	d1 = dice[idx1].clone
	m = idx1+1
	while m<n
		flg = -1
		dice[m].all.each{
			d2 = dice[m].clone
			if d1.top==d2.top && flg<0
				flg=0
			elsif d1.top==d2.front && flg<1
				d2.move("N")
				flg=1
			elsif d1.top==d2.left && flg<2
				d2.move("E")
				flg=2
			elsif d1.top==d2.right && flg<3
				d2.move("W")
				flg=3
			elsif d1.top==d2.back && flg<4
				d2.move("S")
				flg=4
			elsif d1.top==d2.bottom && flg<5
				d2.move("S")
				d2.move("S")
				flg=5
			end
			
			4.times {
				if d1.front!=d2.front
					d2.rotate
				else
					break
				end
			}
			
			if d1.all == d2.all
				puts "No"
				exit(0)
			end
		}
		m+=1
	end
}
puts "Yes"