object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val words = List.fill(3)(sc.next())
  println(if (words.zip(words.tail).forall { case (l, r) => l.last == r.head }) "YES" else "NO")
}
