import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe (fromJust)

type Dice = [Int]

rot :: Dice -> Char -> Dice
rot d 'E' = [d!!3, d!!1, d!!0, d!!5, d!!4, d!!2]
rot d 'W' = [d!!2, d!!1, d!!5, d!!0, d!!4, d!!3]
rot d 'N' = [d!!1, d!!5, d!!2, d!!3, d!!0, d!!4]
rot d 'S' = [d!!4, d!!0, d!!2, d!!3, d!!5, d!!1]
rot _ _ = undefined

solve :: [[Int]] -> String
solve ([n]:dices) =
    let ls = [(a,b) | a<-dices,b<-dices, a/=b] in
    if (any id $ map equal ls) then
        "No"
    else
        "Yes"
    where
    equal (diceA,diceB) =
        let es = cycle "E" in
        let ns = cycle "N" in
        let cmdSets =   [ take a es ++ take b ns ++ take c es ++ take d ns
                        | a<-[1..4], b<-[1..4], c<-[1..4], d<-[1..4]]
        in
        eq cmdSets
        where
        eq [] = False
        eq (cmd:cmds) =
            if (foldl' rot diceB cmd == diceA) then
                True
            else
                eq cmds

main =
    putStrLn =<< solve . map (map read . words) . lines <$> getContents