import System.Random
import Control.Monad
main = do
  n <- readLn::IO Int
  xs <- (return . map (read::String->Int) . words) =<< getLine
  yss <- replicateM (n-1) $ (return . map (read::String->Int) . words) =<< getLine
  cs <- replicateM 1000 $ (return . (toEnum::Int->Command)) =<< randomRIO (0, 3)
  putStrLn $ (\b -> if b then "No" else "Yes") . or $ map (\ys -> any (== ys) $ scanl f1 xs cs) yss
  
data Command = N | S | E | W deriving (Show, Enum)
f1 :: [Int] -> Command -> [Int]
f1 [x1,x2,x3,x4,x5,x6] N = [x2,x6,x3,x4,x1,x5]
f1 [x1,x2,x3,x4,x5,x6] S = [x5,x1,x3,x4,x6,x2]
f1 [x1,x2,x3,x4,x5,x6] E = [x4,x2,x1,x6,x5,x3]
f1 [x1,x2,x3,x4,x5,x6] W = [x3,x2,x6,x1,x5,x4]
f0 c | c == 'N' = N
f0 c | c == 'S' = S
f0 c | c == 'E' = E
f0 c | c == 'W' = W
