{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf
import Debug.Trace

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

readNWords = readInt >>= flip replicateM getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readNWords >>= putStrLn . which "Yes" "No" . uncurry (&&) . ( solve1 &&& solve2 )

solve1 = all ( == 1 ) . map length . group . sort

solve2 [ _ ] = True
solve2 ( a : rest@( b : ws ) )
	| last a == head b = solve2 rest
	| otherwise = False