You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
 - The last character in A and the initial character in B are the same.
 - The last character in B and the initial character in C are the same.
If both are true, print YES. Otherwise, print NO.

-----Constraints-----
 - A, B and C are all composed of lowercase English letters (a - z).
 - 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

-----Input-----
Input is given from Standard Input in the following format:
A B C

-----Output-----
Print YES or NO.

-----Sample Input-----
rng gorilla apple

-----Sample Output-----
YES

They form a word chain.

Difficulty: introductory

Starter code:

Solutions:
s1,s2,s3 = input().split()
print("YES") if s1[-1]==s2[0] and s2[-1]==s3[0] else print("NO")

a,b,c = input().split()

if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
  print('YES')
else:
  print('NO')

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
  print('YES')
else:
  print('NO') 

def iroha():
    a, b, c = input().split()
    
    s = a[len(a)-1]
    sshead = b[0]
    sstail = b[len(b)-1]
    sss = c[0]

    if s == sshead and sstail == sss:
        print("YES")
    else:
        print("NO")





def __starting_point():
    iroha()


__starting_point()

A, B, C = map(str, input().split())
if A[-1] == B[0] and B[-1] == C[0]:
    result = 'YES'
else:
    result = 'NO'
print(result)

# A - Shiritori


def f(x):
    f_list = []
    for i in x:
        f_list.append(i)
    return f_list


# 標準入力 a b c
a, b, c = list(map(str, input().split(maxsplit=3)))

word_list_a = f(a)
word_list_b = f(b)
word_list_c = f(c)

if word_list_a.pop() == word_list_b[0] and word_list_b.pop() == word_list_c[0]:
    print('YES')
else:
    print('NO')


A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a,b,c=map(str,input().split())
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print("YES")
else:
    print("NO")

A, B, C = input().split()

print("YES" if A[-1] == B[0] and B[-1] == C[0] else "NO")

'''
abc060 A - Shiritori
https://atcoder.jp/contests/abc060/tasks/abc060_a
'''

s = list(input().split())
if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
    ans = 'YES'
else:
    ans = 'NO'
print(ans)


a,b,c = map(str,input().split())
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

A,B,C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a, b, c = input().split()

A = list(a)
B = list(b)
C = list(c)

if A[len(A) -1 ] == B[0] and B[len(B)-1] == C[0]:
    print("YES")
else:
    print("NO")

A,B,C = map(str,input().split())
if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

A,B,C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a,b,c = input().split()
if a [-1] == b[0] and b[-1] == c [0]:
    print('YES')
else:
    print('NO')

s=input().split()
print("YES" if all(s[i][-1]==s[i+1][0] for i in range(len(s)-1)) else "NO")

a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print("YES")
else:
  print("NO")

'''
問題：
    文字列 A, B, Cが与えられます。
    これがしりとりになっているか判定してください。

    つまり、
        A の最後の文字と B の最初の文字が同じ
        B の最後の文字と C の最初の文字が同じ
    この 2つが正しいか判定してください。
    両方とも正しいならば YES、そうでないならば NO を出力してください。
'''

'''
制約：
    A, B, C は全て英小文字(a ~ z)からなる。
    1 ≦ |A|, |B|, |C| ≦ 10
    なお、
    |A|, |B|, |C| は文字列A, B, Cの長さを表します。
'''

# 標準入力から A, B, C を取得する
a, b, c = list(map(str, input().split()))

result = 'ret'

if ( a[-1] == b[0] ) and (b[-1] == c[0]) :
    result = 'YES'
else:
    result = 'NO'

print(result)


# A - Shiritori
# https://atcoder.jp/contests/abc060/tasks/abc060_a

a, b, c = list(map(str, input().split()))

if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')


A, B, C = list(map(str,input().split()))

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')


A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:print('YES')
else:print('NO')

a,b,c=map(str,input().split())

if a[len(a)-1]==b[0] and b[len(b)-1]==c[0]:
    ans="YES"
else:
    ans="NO"
print(ans)

A,B,C = list(map(str,input().split()))

if A[-1] == B[0] and B[-1] == C[0]:
    result = "YES"
else:
    result = "NO"

print(result)


A, B, C = input().split()

print("YES" if A[-1] == B[0] and B[-1] == C[0] else "NO")

A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")



A, B, C = map(str, list(input().split())) # 文字列を一文字ずつのリスト化し複数のリストに入れる


if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

a,b,c = input().split()
print("YES" if a[-1]==b[0] and b[-1]==c[0] else "NO")


def resolve():
    a, b, c = input().split()
    print(('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO'))

def __starting_point():
    resolve()

__starting_point()

s = [x for x in input().split()]
if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
  print("YES")
else:
  print("NO")

A, B, C = list(input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a,b,c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:
  print("YES")
else:
  print("NO")


A,B,C = map(str,input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')

else:
    print('NO')

A,B,C = input().split()
print(['NO','YES'][A[-1:]==B[0] and B[-1:]==C[0]])

a, b, c = map(str, input().split())
if a[-1] == b[0] and b[-1] == c[0]:
  print("YES")
else:
  print("NO")

import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10**9)
INF = float('inf')
MOD = 10**9 + 7
#MOD = 998244353


def si(): return input()
def ii(): return int(input())
def fi(): return float(input())
def lstr(): return input().split()
def lint(): return list(map(int, input().split()))
def lintdec(): return list(map(lambda x:int(x) - 1, input().split()))
def lnstr(n): return [input() for _ in range(n)]
def lnint(n): return [int(input()) for _ in range(n)]
def lint_list(n): return [lint() for _ in range(n)]



############################################################
A, B, C = lstr()
print('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")

#60
A,B,C=input().split()
if A[-1]==B[0] and B[-1]==C[0]:
    print('YES')
else:
    print('NO')


a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")


A,B,C=map(str,input().split())
if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")

a, b, c = input().split()
print(('YES', 'NO')[a[-1] + c[0] != b[0] + b[-1]])

a, b, c = input().split()
print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")

a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else:
  print('NO')

A, B, C = map(str, input().split())

A_num = len(A)
B_num = len(B)
if A[A_num - 1] == B[0] and B[B_num - 1] == C[0]:
    print("YES")
else:
    print("NO")

a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print("YES")
else:
  print("NO")

A,B,C = map(str, input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print('YES')
else:
    print('NO')

A, B, C = open(0).read().split()
print('YES' if (A[len(A)-1] == B[0]) and (B[len(B)-1] == C[0]) else 'NO')

A, B, C=input().split(" ")

if A[len(A)-1]==B[0] and B[len(B)-1]==C[0]:
  print('YES')
else:
  print('NO')

A, B, C = map(str, input(). split())

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

a,b,c=input().split()
print("YES" if a[-1]==b[0]and b[-1]==c[0] else "NO")

a, b, c = input().split()

if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print('YES')
else:
    print('NO')

a, b, c = input().split()
len_a = len(a)
len_b = len(b)

if(a[len_a-1] == b[0] and b[len_b-1] == c[0]):
    print("YES")
else:
    print("NO")

a, b, c = input().split()
print('YES' if a[-1]==b[0] and b[-1]==c[0] else 'NO')

A,B,C = input().split()
print("YES" if A[-1] == B[0] and B[-1] == C[0] else "NO")

A, B, C = map(str, input(). split())

if A[-1] == B[0] and B[-1] == C[0]:
    print( "YES" )
else:
    print( "NO" )

A, B, C = input().split()

def answer(A: int, B: int, C: int) -> str:
    if A[-1] == B[0] and B[-1] == C[0]:
        return 'YES'
    else:
        return 'NO'

print((answer(A, B, C)))


a,b,c=map(str,input().split())

print('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO')

a, b, c = map(str, input().split())
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

a, b, c = input().split()

if (a[-1] == b[0]) and (b[-1] == c[0]):
    print('YES')
else:
    print('NO')


s = (input().split())
t = len(s)
cnt = 0
for i in range(t):
    if i != t - 1:
        if (s[i][-1]) == s[i + 1][0]:
            cnt += 1
    else:
        break

if cnt == t - 1:print("YES")
else:print("NO")

A, B, C = input().split()
if A[len(A)-1:len(A)] == B[0:1] and B[len(B)-1:len(B)] == C[0:1]:
    print('YES')
else:
    print('NO')


a,b,c = input().split()
# しりとりが成り立っているかを確認
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

# 060_a
A, B, C = input().split()

if (1<=len(A) and len(A)<=10 and A.islower()) and (1<=len(B) and len(B)<=10 and B.islower())\
        and (1<=len(C) and len(C)<=10 and C.islower()):
    if (A[len(A) - 1] == B[0]) and (B[len(B) - 1] == C[0]):
        print('YES')
    else:
        print('NO')


A,B,C = list(map(str,input().split()))
if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')



A, B, C = map(str, input().split())

# 文字列 A,B,Cが与えられます。これがしりとりになっているか判定してください。
# 正しいならば YES、そうでないならば NO を出力してください。

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

# 数値を取得
word_list = input().split()
w_cnt = len(word_list)

# 語頭語尾の抽出
s_list = []
e_list = []
for cnt in range(0,w_cnt,1):
    s_list.append(word_list[cnt][0])
    e_list.append(word_list[cnt][-1])

# 成立してるか検査後結果を出力
judge = "YES"
for cnt in range(1,w_cnt,1):
    if s_list[cnt] != e_list[cnt-1]:
        judge = "NO"
print(judge)

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
  print("YES")
else:
  print("NO")


a, b, c = map(str, input().split())

if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

def atc_060a(input_value: str) -> str:
    A, B, C = list(map(str, input_value.split(" ")))
    if A[-1] == B[0] and B[-1] == C[0]:
        return "YES"
    else:
        return "NO"

input_value = input()
print((atc_060a(input_value)))


a,b,c = input().split()
if a[len(a) -1] == b[0] and b[len(b) -1] == c[0]:
    print('YES')
else:
    print('NO')

a, b, c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
  print('YES')
else:
  print('NO')

a, b, c = input().split()

if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")


A,B,C=input().split()
if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")


def atc_060a(input_value: str) -> str:
    A, B, C = map(str, input_value.split(" "))
    if A[-1] == B[0] and B[-1] == C[0]:
        return "YES"
    else:
        return "NO"

input_value = input()
print(atc_060a(input_value))

a, b, c = list(map(str, input().split()))
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')


a,b,c = input().split()
if a[-1]==b[0] and b[-1]==c[0]:
  print("YES")
else:
  print("NO")

a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print("YES")
else:
  print("NO")

A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

# A の末とB の頭文字、B の末とC の頭文字が一致しているか

A, B, C = list(map(str, input().split()))

initial_1 = A[-1]
end_1 = B[0]
initial_2 = B[-1]
end_2 = C[0]

if initial_1 == end_1 and initial_2 == end_2:
    print("YES")
else:
    print("NO")


A, B, C = map(str,input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

A, B, C = list(map(str, input().split()))
if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

#ABC060A
a,b,c = input().split()
print("YES" if (a[-1] == b[0]) and (b[-1] == c[0]) else "NO")

#答えはあってるけどWA
A, B, C = input().split()

if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")

A,B,C=map(str,input().split())
if A[-1]==B[0] and B[-1]==C[0] :
  print("YES")
else :
  print("NO")

a,b,c = input().split()
if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print("YES")
else:
    print("NO")

A,B,C=list(map(str,input().split()))

if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")


A, B, C = input().split()
print('YES' if B.startswith(A[-1]) and C.startswith(B[-1]) else 'NO')

A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

a,b,c = input().split()
print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")

S = input().split()
print('YES' if S[0][-1] == S[1][0] and S[1][-1] == S[2][0] else 'NO')

a, b, c = list(map(str, input().split()))

if a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:
    print('YES')
else:
    print('NO')




a=input().split(" ")
print("YES") if a[0][-1]==a[1][0] and a[1][-1]==a[2][0] else print("NO")

a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else :
  print('NO')