#include<stdio.h>
#include<string.h>
int main()
{
    char A[11]={'\0'};
    char B[11]={'\0'};
    char C[11]={'\0'};
    int a,b,c;
    printf("Input is given from Standard Input in the following format:\n");
    scanf("%s%s%s",A,B,C);
    a = strlen(A);
    b = strlen(B);
    if(A[a-1]==B[0]&&B[b-1]==C[0]&&B[0]!=B[b-1])printf("YES");
    else printf("NO");
    return 0;
}
