import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [as, bs, cs] <- words <$> getLine
    if and [ last as == head bs
           , last bs == head cs
           ]
        then putStrLn "YES"
        else putStrLn "NO"