import Control.Applicative ((<$>))

solve a b b' c
  | a == b && b' == c = "YES"
  | otherwise = "NO"

main = do
  [a, b, c] <- words <$> getLine
  let a' = last a
      bhead = head b
      blast = last b
      c' = head c in
    putStrLn (solve a' bhead blast c')
