let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)

let a, b, c = readStringArray() |> fun x -> (x.[0], x.[1], x.[2])

if (a |> Seq.last) = b.[0] && (b |> Seq.last) = c.[0] then "YES" else "NO"
|> printfn "%s"