#include <iostream>

int main () {
	std::string a, b, c;
      
  std::cin >> a >> b >> c;
 
  if(a.substr(a.size()-1, 1) == b.substr(0, 1) && b.substr(b.size()-1, 1) == c.substr(0, 1)) {
  	std::cout << "YES" << std::endl;
  }else {
  	std::cout << "NO" << std::endl;
  }
}
#include <stdio.h>

int main() {
  char str[31], ctr = 0;
  scanf("%[^\n]", str);

  for(int i = 0; str[i] != '\0'; i++) {
    if(str[i] == ' ' && str[i-1] == str[i+1]) {
      ctr++;
    }
  }
  if(ctr == 2) {
    puts("YES");
  }
  else {
    puts("NO");
  }
  return 0;
}