main:: IO ()
main = do
    ss <- words <$> getLine
    putStrLn $ if solve ss then "YES" else "NO"

-- |
--
-- >>> solve ["rng", "gorilla", "apple"]
-- True
--
-- >>> solve ["yakiniku", "unagi", "sushi"]
-- False
solve :: [String] -> Bool
solve (a:b:c:_) = y1 && y2
  where
    y1 = last a == head b
    y2 = last b == head c
