import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List
import Data.Array.ST
import Data.Array


isSiritori :: String -> String -> Bool
isSiritori a b = t == h
    where
        t = last a
        h = head b

solve :: String -> String -> String -> Bool
solve a b c = (isSiritori a b) && (isSiritori b c)

toYesNo :: Bool -> String
toYesNo True = "YES"
toYesNo _ = "NO"

main :: IO()
main = do
    (a:b:c:_) <- map BS.unpack . BS.words <$> BS.getLine
    putStrLn $ toYesNo $ solve a b c