unittest
{
	assert( [ "rng gorilla apple" ].parse.expand.solve == "YES" );
	assert( [ "yakiniku unagi sushi" ].parse.expand.solve == "NO" );
	assert( [ "a a a" ].parse.expand.solve == "YES" );
	assert( [ "aaaaaaaaab aaaaaaaaaa aaaaaaaaab" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split;
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( string a, string b, string c )
{
	return ( a[ $ - 1 ] == b[ 0 ] && b[ $ - 1 ] == c[ 0 ] ) ? "YES" : "NO";
}
