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

import Data.List

n :: [Int] -> [Int]
n [a,b,c,d,e,f] = [b,f,c,d,a,e]

w :: [Int] -> [Int]
w [a,b,c,d,e,f] = [c,b,f,a,e,d]

turn :: [Int] -> [[Int]]
turn [a,b,c,d,e,f]
  = [a,b,c,d,e,f] : [a,c,e,b,d,f] : [a,e,d,c,b,f] : [a,d,b,e,c,f] : []

solve :: String -> [Int] -> [[Int]]
solve [] _ = []
solve (x:xs) list
  | 'f' == x = turn list ++ solve xs list
  | 'n' == x = (turn . n) list ++ solve xs (n list)
  | 'w' == x = (turn . w) list ++ solve xs (w list)

main = do
  n <- fmap (*24) readLn
  m <- fmap (map (solve "fnnwnn". map read . words) . lines) getContents
  if a m == b m then putStrLn "Yes" else putStrLn "No"
  where a = sum . map (length . nub)
        b = length . nub . concat