Problem:


Score : 100 points

Problem Statement

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 1

rng gorilla apple

Sample Output 1

YES

They form a word chain.

Sample Input 2

yakiniku unagi sushi

Sample Output 2

NO

A and B form a word chain, but B and C do not.

Sample Input 3

a a a

Sample Output 3

YES

Sample Input 4

aaaaaaaaab aaaaaaaaaa aaaaaaaaab

Sample Output 4

NO



Sample input:
rng gorilla apple


Sample output:
YES

Submission status: Runtime Error

Solution code:

s,y,j=input().split()
sss=len(s)
yyy=len(y)
jjj=len(j)

ss=s[0:1]
ssss=s[sss-1:sss]
yy=y[0:1]
yyyy=y[yyy-1:yyy]
jj=j[0:1]
jjjj=j[jjj-1:jjj]

if ssss==yy:
    nyan=1
    
if yyyy==jj:
    nyan+=1
    
if nyan==2:
    print('YES')
else:   
    print('NO')

Submission status: Runtime Error

Solution code:
A, B, C = input().split()]

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

Submission status: Runtime Error

Solution code:
A, B, C = input().split()


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

Submission status: Runtime Error

Solution code:
#Shiritori

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

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#-------
# Initialize
A,B,C = map(list, input().split())

#-------
# Define

#-------
# Do

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

#-------
# Output

Submission status: Runtime Error

Solution code:
i = input().split()
a = int(i[0])
b = int(i[1])
c = int(i[2])

answer = "NO"
while a <= a*b:
    if a%b==c:
        answer = "YES"
        break
    a += a 
    
print(answer)

Submission status: Runtime Error

Solution code:
def solve():
  ar = raw_input().split(' ')
  A = int(ar[0])
  B = int(ar[1])
  C = int(ar[2])

  s = set([])
  sum = 0
  while True:
    sum = sum + A
    m = sum % B
    #print 'sum=',sum,'m=',m
    if (m == C): return 'Yes'
    if (m in s): return 'No'
    s.add(m)

if __name__ == '__main__' :
  print solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# input
NW = [int(x) for x in input().split(" ")]
N = NW[0]
W = NW[1]

w = []
v = []

for _ in range(N):
	wv = [int(x) for x in input().split(" ")]
	w.append(wv[0])
	v.append(wv[1])

# 品物i-Nまでを使って容量Wのナップサックにいれられる品物の価値の総和の最大値
def rec(i, Wrec):
	if i >= N:
		return 0

	a = -1
	if Wrec - w[i] >= 0:
		a = v[i]+rec(i+1, Wrec-w[i])
	return max(
		a, #品物iを入れる
		rec(i+1, Wrec) #品物iを入れない
		)

print(rec(0,W))

Submission status: Runtime Error

Solution code:

T = int(input().split(" ")[1])
t = [int(x) for x in input().split(" ")]
t.append(100000000000)

ret = 0

for i in range(len(t)-1):
	ret += min(T,t[i+1] - t[i])

print(ret)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def shiritori(a, b):
    return a[len(a)-1:] == b[:1]


a, b, c = map(input().split())
if shiritori(a, b) is True and shiritori(b, c) is True:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def shiritori(a, b):
    return a[len(a)-1:] == b[:1]


a, b, c = map(int, raw_input().split())
if shiritori(a, b) is True and shiritori(b, c) is True:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
a, b, c = [int(x) for x in input().split()]

def foo(a, b, c):
    for i in range(1, b+1):
        if (a*i)%b == c:
            return "YES"
    return "NO"
    
print(foo(a, b, c))

Submission status: Runtime Error

Solution code:
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO"
    else:
        return "YES"
    
print(foo(a, b, c))

Submission status: Runtime Error

Solution code:
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO:
    else:
        return "YES"

print(foo(a, b, c))

Submission status: Runtime Error

Solution code:
str1=input()
str2=input()
str3=input()

if str1[-1:]==str2[:1] and str2[-1:]==str3[:1]:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
str1=input()
str2=input()
str3=input()

slice1=str1[-1:]
slice2=str2[:1]
slice3=str2[-1:]
slice4=str3[:1]

if slice1==slice2 and slice3==slice4:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = raw_input().split()
A = s[0]
B = s[1]
C = s[2]
if A[len(A)]==B[0] && B[len(B)]==C[0]:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input(),split())
d=0

for n=range(1,b+1):
    if n*a%b==c:
        d=d+1
    else:
        d=d:
if d>0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# coding: utf-8 
N,T = [int(i) for i in input().split(" ")]
array = input().split(" ")
ans = 0
fin = 0
for x in array:
    time = int(x)
    if time <= fin:
        ans += (time + T - fin)
    else:
        ans += T
    fin = time + T
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]
  ans='YES'
print(ans)

Submission status: Runtime Error

Solution code:
a, b, c = map(int, input().split())

result = "NO"
for i in range(1, 100):
    if a * i % b == c:
        result = "YES"
print(result)

Submission status: Runtime Error

Solution code:
a,b,c = input().split()

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

Submission status: Runtime Error

Solution code:
a,b,c = input().split()

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

Submission status: Runtime Error

Solution code:
a,b,c = input().split()

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

Submission status: Runtime Error

Solution code:
a,b,c = input().split()

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

Submission status: Runtime Error

Solution code:
def main():
        s = raw_input().split()

        if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()

Submission status: Runtime Error

Solution code:
def main():
        s = raw_input().split()

        if s[0][-1] == s[1][0] && s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()

Submission status: Runtime Error

Solution code:
a, b, c = [int(i) for i in input().split()]
for i in range(2, b+1):
    if a*i % b == c:
        print("YES")
        break
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
N,W=list(map(int,input().split()))
v=[[],[],[],[]]
kosu=[0,0,0,0]
kr=list(map(int,input().split()))
v[0].append(kr[1])
w0=kr[0]
for i in range(1,N):
    kr=list(map(int,input().split()))
    v[kr[0]-w0].append(kr[1])
for i in range(4):
    v[i].sort()
    v[i].reverse()
kos=[len(v[0]),len(v[1]),len(v[2]),len(v[3])]
kk=[-1]*((kos[0]+1)*(kos[1]+1)*(kos[2]+1)*(kos[3]+1))
def toru(a,b,c,d,nw):
    global kk
    if kk[a+(kos[0]+1)*(b+((kos[1]+1)*(c+(kos[2]+1)*d)))]!=-1:
        return kk[a+(kos[0]+1)*(b+((kos[1]+1)*(c+(kos[2]+1)*d)))]
    max=0
    if a<kos[0] and W>=nw+w0 and max<toru(a+1,b,c,d,nw+w0)+v[0][a]:
        max=toru(a+1,b,c,d,nw+w0)+v[0][a]
    if b<kos[1] and W>=nw+w0+1 and max<toru(a,b+1,c,d,nw+w0+1)+v[1][b]:
        max=toru(a,b+1,c,d,nw+w0+1)+v[1][b]
    if c<kos[2] and W>=nw+w0+2 and max<toru(a,b,c+1,d,nw+w0+2)+v[2][c]:
        max=toru(a,b,c+1,d,nw+w0+2)+v[2][c]
    if d<kos[3] and W>=nw+w0+3 and max<toru(a,b,c,d+1,nw+w0+3)+v[3][d]:
        max=toru(a+1,b,c,d+1,nw+w0+3)+v[3][d]
    kk[a+(kos[0]+1)*(b+((kos[1]+1)*(c+(kos[2]+1)*d)))]=max
    return max


maxv=toru(0,0,0,0,0)

print(maxv)

Submission status: Runtime Error

Solution code:
N, t = map(int, raw_input().split())
n = map(int, raw_input().split())
total = 0
next = t
for i in range(N-1):
	if(next < n[i+1]):
		total += t
		next = n[i+1]
	else:
		total += n[i+1]-n[i]
		next = n[i+1] +t
total += t
print(total)

Submission status: Runtime Error

Solution code:
ABC = input().split()
A=int(ABC[0])
B=int(ABC[1])
C=int(ABC[2])


count = 1000


for index in range(count+1):
    if (A*index)%B ==C:
        print("Yes")
        break
    elif index ==800:
        print("NO")

Submission status: Runtime Error

Solution code:
import numpy as np

def generate():
    newGen = np.zeros(n)
    for p in range(pop):
        gen = np.random.rand(n)
        for i in range(n):
            if gen[i] > 0.5:
                gen[i] = 1
            else:
                gen[i] = 0
        newGen = np.vstack([newGen,gen])
    newGen = np.vsplit(newGen,[1])[1]
    return newGen

def evaluate(gen):
    sum = np.zeros(pop)
    for p in range(pop):
        for i in range(n):
            sum[p] += v[i][1] * gen[p][i]
    sum = sum.reshape(pop, 1)
    gen = np.hstack([gen, sum])
    return gen

def best(gen):
    best0 = gen[0]
    for p in range(1,pop):
        if best0[-1] < gen[p][-1]:
            best0 = gen[p]
    return best0

def select(b,p):
    parents = np.zeros(b.shape[1])
    for i in range(p):
        p1 = b[np.random.randint(0, b.shape[0] - 1)]
        p2 = b[np.random.randint(0, b.shape[0] - 1)]
        if p1[-1] < p2[-1]:
            parents = np.vstack([parents, p2])
        else:
            parents = np.vstack([parents, p1])
    return np.vsplit(parents,[1])[1]

def crossover(parents):
    parents = np.hsplit(parents, [-1])[0]
    newGen = np.zeros(parents.shape[1])
    for i in range(parents.shape[0] / 2):
        l = np.random.randint(1, parents.shape[1] - 1)
        p1_0, p1_1 = np.hsplit(parents[i * 2], [l])
        p2_0, p2_1 = np.hsplit(parents[i * 2 + 1], [l])
        c1 = np.hstack([p1_0, p2_1])
        c2 = np.hstack([p1_1, p2_0])
        newGen = np.vstack([newGen, c1])
        newGen = np.vstack([newGen, c2])
    return np.vsplit(newGen, [1])[1]

def mutation(newGen):
    for p in range(pop):
        w_sum = 0
        for i in range(n):
            w_sum += newGen[p][i] * v[i][0]
        if w_sum > w:
            ran = np.random.permutation(np.arange(n))
            while(w_sum > w):
                ran, q = np.hsplit(ran,[-1])
                if newGen[p][q] == 1:
                    w_sum -= newGen[p][q] * v[q][0]
                    newGen[p][q] = 0
    return newGen


pop = 10
n, w = map(int,raw_input().split())
v = []
N = 500
for i in range(n):
    v.append(map(int,raw_input().split()))

eval = evaluate(generate())
c = mutation(crossover(select(eval,pop)))
eval = evaluate(c)
be = best(eval)
for i in range(N):
    c = mutation(crossover(select(eval,pop)))
    eval = evaluate(c)
    if be[-1] < best(eval)[-1]:
        be = best(eval)
print int(be[-1])

Submission status: Runtime Error

Solution code:
##N T
#t1 t2 ... tN
N, T = map(int,input().split())
a = list(map(int, input().split()))
b = []
"""
for i in range(N):
    set1 = set()
    for j in range(T):
        set1.add(a[i] + j)
    b.append(set1)
d = set()
for n in range(len(b)):
    d = d | b[n]
"""
d = set()
for i in range(N):
    d = d | set(range(a[i], a[i] + T))


print(len(d))

Submission status: Runtime Error

Solution code:
def sentou(NT, ts):
    N, T = map(int, NT.split())
    before_oshitano = None
    total_s = 0
    for t in map(int, ts.split()):
        if before_oshitano is None:
            before_oshitano = t
            continue
        elif T > (t - before_oshitano):
            total_s += t - before_oshitano
        else:
            total_s += T
        before_oshitano = t
    total_s += T

    print(total_s)


# sentou("9 10", "0 3 5 7 100 110 200 300 311")
sentou(input(), input())

Submission status: Runtime Error

Solution code:
strs = input().split()
if strs[0][len(strs[0]) -1] == strs[1][0] and strs[1][len(strs[0]) -1] == strs[2][0]:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
l = input().split()
def shiritori (letter):
    if letter[0][-1:] == letter[1][:1]:
        if letter[1][-1:] == letter[2][:1]:
            return('YES')
        else return('NO')
    else return('NO')
shiritori(l)

Submission status: Runtime Error

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