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 Control.Applicative

data Op = S | E | N | W deriving (Show, Eq, Enum)

fromChar c | c == 'S' = S
           | c == 'E' = E
           | c == 'N' = N
           | c == 'W' = W
           | otherwise = error $ "Invalid char " ++ [c]

fromString [] = []
fromString (x:xs) = (fromChar x):(fromString xs)

data Dice = Dice { top :: Int, front :: Int, right :: Int, left :: Int, back :: Int, bottom :: Int }
  deriving (Show, Eq)

makeDice [t, f, r, l, ba, bo] = Dice t f r l ba bo

roll (Dice t f r l ba bo) S = Dice ba t r l bo f
roll (Dice t f r l ba bo) N = Dice f bo r l t ba
roll (Dice t f r l ba bo) E = Dice l f t bo ba r
roll (Dice t f r l ba bo) W = Dice r f bo t ba l
rolls = foldl roll :: Dice -> [Op] -> Dice

equal dice1 dice2 = foldr (||) False [(> 0) $ length $ filter (\x -> x == dice2) $ scanl rolls d [[N, E, S], [N, E, S], [N, E, S]] | d <- ds]
  where ds = scanl roll dice1 [N, E, N, E, N]

someEqual xs = foldl1 (||) $ [equal x y | x <- xs, y <- xs, x /= y]

solve xs | someEqual xs = "No"
         | otherwise = "Yes"

main = do
  n <- readLn :: IO Int
  dices <- map (makeDice . map read . words) <$> replicateM n getLine :: IO [Dice]
  putStrLn . solve $ dices