#include<stdio.h>
#include<string.h>
char before , now;
char a[4][11];
int len[4];
bool ans = true;
int main(){
	scanf("%s",a[1]);
	len[1] = strlen(a[1]);
	before = a[1][len[1] - 1]; 
	for(int i = 2; i <= 3 ; i++)
	{
		scanf("%s",a[i]);
		len[i] = strlen(a[i]);

		now = a[i][0];
		if(now != before)
			ans = false;
		before = a[i][len[i] - 1]; 
		
	}
	if(ans)
		printf("YES");
	else
		printf("NO");
     return 0;
}
