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 Control.Monad
import Data.List

data Dice = Dice {top :: Int,
                  south :: Int,
                  east :: Int,
                  west :: Int,
                  north :: Int,
                  bottom :: Int} deriving Eq
fromList :: [Int] -> Dice
fromList [t,s,e,w,n,b] = Dice t s e w n b
allState :: Dice -> [Dice]
allState d = nub $ [rotateAll d' direction |
                    d' <- map (rotateAll d) ["","N","S","W","E","NN"],
                    direction <- inits "ccc" ]

rotate :: Dice -> Char -> Dice
rotate d 'N' = d {bottom = north d,
                  north = top d,
                  top = south d,
                  south = bottom d}
rotate d 'S' = d {bottom = south d,
                  south = top d,
                  top = north d,
                  north = bottom d}
rotate d 'E' = d {bottom = east d,
                  east = top d,
                  top = west d,
                  west = bottom d}
rotate d 'W' = d {bottom = west d,
                  west = top d,
                  top = east d,
                  east = bottom d}
rotate d 'c' = d {north = west d,
                  west = south d,
                  south = east d,
                  east = north d}
rotate d 'C' = rotateAll d "ccc"

rotateAll :: Dice -> [Char] -> Dice
rotateAll d [] = d
rotateAll d (op:ops) = rotateAll (rotate d op) ops

main :: IO ()
main = do
  n <- readLn
  ds <- replicateM n $ fmap (fromList . map read . words) getLine
  let dSs = map allState ds
  putStrLn $ if ds == (nub ds) &&
                and [null $ intersect ds1 ds2 |
                     ds1 <- dSs, ds2 <- dSs, ds1 /= ds2]
             then "Yes" else "No"