main :: IO ()
main = do
  [a, b, c] <- words <$> getLine
  putStrLn $ solve a b c

solve :: String -> String -> String -> String
solve a b c = if f1 && f2
              then "YES"
              else "NO"        
  where
    f1 = last a == head b
    f2 = last b == head c
