Problem:


Score : 200 points

Problem Statement

A string is called a KEYENCE string when it can be changed to keyence by removing its contiguous substring (possibly empty) only once.

Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Constraints

The length of S is between 7 and 100 (inclusive).

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S is a KEYENCE string, print YES; otherwise, print NO.

Sample Input 1

keyofscience

Sample Output 1

YES

keyence is an abbreviation of key of science.

Sample Input 2

mpyszsbznf

Sample Output 2

NO

Sample Input 3

ashlfyha

Sample Output 3

NO

Sample Input 4

keyence

Sample Output 4

YES



Sample input:
keyofscience


Sample output:
YES

Submission status: Runtime Error

Solution code:
S=[*input()]
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    for i in range(len(S)):
        if S[i]=="k":
            if S[i+1]=="e":
                if S[i+2]=="y":
                    if S[i+3]=="e":
                        if S[i+4]=="n":
                            if S[i+5]=="c":
                                if S[i+6]=="e":
                                    print("YES")
                                    break
                                else:
                                    if S[-1]=="e":
                                        print("YES")
                                        break
                                    else:
                                        print("No")
                                        break
                            else:
                                if S[-1]=="e" and S[-2]=="c":
                                    print("YES")
                                    break
                                else:
                                    for j in range(len(S)-i-5):
                                        if S[i+5+j]=="c":
                                            if S[i+5+j+1]=="e":
                                                if i+5+j+2==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                        else:
                            if S[-1]=="e" and S[-2]=="c" and S[-3]=="n":
                                print("YES")
                                break
                            else:
                                for j in range(len(S)-i-4):
                                        if S[i+4+j]=="n":
                                            if S[i+4+j+1]=="c":
                                                if S[i+4+j+2]=="e":
                                                    if i+4+j+3==len(S):
                                                        print("YES")
                                                        break
                                                    else:
                                                        print("NO")
                                                        break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                    else:
                        if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e":
                            print("YES")
                            break
                        else:
                            for j in range(len(S)-i-3):
                                if S[i+3+j]=="e":
                                    if S[i+3+j+1]=="n":
                                        if S[i+3+j+2]=="c":
                                            if S[i+3+j+3]=="e":
                                                if i+3+j+4==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                else:
                    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y":
                            print("YES")
                            break
                    else:
                        for j in range(len(S)-i-2):
                            if S[i+2+j]=="y":
                                if S[i+2+j+1]=="e":
                                    if S[i+2+j+2]=="n":
                                        if S[i+2+j+3]=="c":
                                            if S[i+2+j+4]=="e":
                                                if i+2+j+5==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
            else:
                if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e":
                    print("YES")
                    break
                else:
                    for j in range(len(S)-i-1):
                        if S[i+1+j]=="e":
                            if S[i+1+j+1]=="y":
                                if S[i+1+j+2]=="e":
                                    if S[i+1+j+3]=="n":
                                        if S[i+1+j+4]=="c":
                                            if S[i+1+j+5]=="e":
                                                if i+1+j+6==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
                            else:
                                print("NO")
                                break
else:
    print("NO")

Submission status: Runtime Error

Solution code:
import re
from sys import stdin
N=(stdin.readline().rstrip())

for i in range(7):
    mae="keyence"[0:i+1]
    ato="keyence"[i+1:8]
    if re.match(".*keyence.*",N):
        print("YES")
        break
    if re.match("%s.*%s"%(mae, ato),N):
        print("YES")
        cnt+=1
        break
if i==6:
    print("NO")

Submission status: Runtime Error

Solution code:
str = input()
key = 'keyence'

flag = 0

for i in range(len(str)):
    if str[i] != key[i]:
        break
    
if i > 7:
    flag = 1

for j in range(i, len(str)):
    if str[j] == key[i]:
        break
    
for k in range(len(str) - j):
    if str[j + k] != key[i]:
        break
    i += 1

if i == 7 or flag == 1:
    print('YES')
else :
    print('NO')

Submission status: Runtime Error

Solution code:
text = input()
ans = ["k","e","y","e","n","c","e"]
count = 2
flag = 1
i = 0
plus = 0
for ob in ans:
    if i >= len(text):
        flag = 0
        break
        
    if ob == text[i]:
        i+=1
        continue
    
    else:
        while ob != text[i]:
            i+=1
            if i >= len(text) - 1:
                continue
            else:
                while text[i] == text[i+1]:
                    i+=1
                    if i >= len(text):
                        flag = 0
                        break
            if i >= len(text):
                flag = 0
                break
        i+=1
        count -=1
        if count == 0:
            flag =0
            break
if i < len(text):
    count -=1
    if count == 0:
        flag = 0
if flag == 1:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()
ans = 'keyence'
j = 0
for i in range(len(s)):
    if(ans[j] == s[i]):
        j += 1
print(['NO','YES'][j==7])

Submission status: Runtime Error

Solution code:
s = str(input())

while True:
    if s[0] == "k":
        break
    else:
        s = s[1:]
if len(s) < 7:
    print("NO")
else:
    middlerange = len(s) - 7
    if s[0]+s[middlerange+1:] == "keyence":
        print("YES")
    elif s[0:2]+s[middlerange+2:] == "keyence":
        print("YES")
    elif s[0:3]+s[middlerange+3:] == "keyence":
        print("YES")
    elif s[0:4]+s[middlerange+4:] == "keyence":
        print("YES")
    elif s[0:5]+s[middlerange+5:] == "keyence":
        print("YES")
    elif s[0:6]+s[middlerange+6:] == "keyence":
        print("YES")
    elif s[0:7]+s[middlerange+7:] == "keyence":
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
data = input()
comp_s = ['k', 'e', 'y', 'e', 'n', 'c', 'e']

flag = False
ng_flag = False
count = 0
s_count = 0
for s in data:
    if s == comp_s[s_count]:
        s_count += 1
        ng_flag = False
    else:
        if not ng_flag:
            count += 1
            ng_flag = True

if len(comp_s) == s_count and count <= 1:
    flag = True

if flag:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
a = list(input())
k = list("keyence")
count = 0
for i in a:
  if i ==  k[0]:
    if count == 1:
      k.pop(0)
      count = 2
    elif count == 0:
      k.pop(0)
    elif count == 2:
      k.pop(0)
  else:
    if count == 0:
      count = 1
    if count == 2:
      print("NO")
      exit()

if len(k) == 0:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
S = input()

tag = 'keyence'

ans = 0

for i in range(1, 7):
    f_tag = tag[0:i]
    a_tag = tag[i:7]
    f1 = 1
    now = 0
    
    for j in range(len(S)-7):
        for k in range(i):
            if not S[j+k]==f_tag[k]:
                break
        else:
            f1 = f1 + 1
            now = j+i
    
    for j in range(now, len(S)-i):
        for k in range(7-i):
            if not S[j+k]==a_tag[k]:
                break
        else:
            f1 = f1+1
    if f1==3 or (f1==2 and i==0) or (f1==2 and i==7):
        ans =1
    
for i in range(len(S)-6):
    for j in range(7):
        if not S[i+j]==tag[j]:
            break
    else:
        ans = 1
    
if ans==1:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
a = 'keyence'
s = input()
S = len(s)
c = 0
i = 0
while i < S:
    if s[i] == a[c]:
        c += 1
    i += 1
if c == 7:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S = input()
tmp = "keyence"
count = 0
flag = 0
index = 0

for i in range(0, len(S)):
    if(S[i] == tmp[index]):
        index += 1
        flag = 0
    elif flag == 0:
        count += 1
        flag = 1

if index == 7 and count <= 1:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()
ans = ['k', 'e', 'y', 'e', 'n', 'c', 'e']
count = 0
j = 0
for i in range(len(s)):
    if(ans[j] == s[i]):
        j += 1
    else:
        continue
if(j == 7):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S=list(input())
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    for i in range(len(S)):
        if S[i]=="k":
            if S[i+1]=="e":
                if S[i+2]=="y":
                    if S[i+3]=="e":
                        if S[i+4]=="n":
                            if S[i+5]=="c":
                                print("YES")
                                break
                            else:
                                for j in range(len(S)-i-5):
                                    if S[i+5+j]=="c":
                                        if S[i+5+j+1]=="e":
                                            if i+5+j+2==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                        else:
                            for j in range(len(S)-i-4):
                                    if S[i+4+j]=="n":
                                        if S[i+4+j+1]=="c":
                                            if S[i+4+j+2]=="e":
                                                if i+4+j+3==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                    else:
                        for j in range(len(S)-i-3):
                            if S[i+3+j]=="e":
                                if S[i+3+j+1]=="n":
                                    if S[i+3+j+2]=="c":
                                        if S[i+3+j+3]=="e":
                                            if i+3+j+4==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                else:
                    for j in range(len(S)-i-2):
                        if S[i+2+j]=="y":
                            if S[i+2+j+1]=="e":
                                if S[i+2+j+2]=="n":
                                    if S[i+2+j+3]=="c":
                                        if S[i+2+j+4]=="e":
                                            if i+2+j+5==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                            else:
                                print("NO")
            else:
                    for j in range(len(S)-i-1):
                        if S[i+1+j]=="e":
                            if S[i+1+j+1]=="y":
                                if S[i+1+j+2]=="e":
                                    if S[i+1+j+3]=="n":
                                        if S[i+1+j+4]=="c":
                                            if S[i+1+j+5]=="e":
                                                if i+1+j+6==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                            else:
                                print("NO")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
a = "keyence"

b = input()

k = len(b)
j = 0
jj = 0
kk = [0 for i in range(8)]
if k == 7:
	if a == b:
		print("YES")
	else:
		print("NO")
elif k >= 8:
	for i in range(k):
		if j == -1:
			print("NO")
			break
		if b[i] == a[j]:
			j += 1
			if jj == 1:
				jj = 2
		elif jj == 0:
			jj = 1
		elif jj == 2:
			jj = 3
		if j == 7 and (jj == 0 or jj == 1 or jj == 2):
			j = -1
		if j == -1 and i == k-1:
			print("YES")
			break
	if j != -1:
		print("NO")

else:
	print("NO")

Submission status: Runtime Error

Solution code:
S = input()

def is_keyence(S):
    keyence_str = "keyence"
    i = 0
    is_change = False
    change_num = 0
    for j in range(len(S)):
        if S[j] != keyence_str[i]:
            if is_change: change_num += 1
            else:
                if change_num > 0:
                    return False
                is_change = True
                change_num += 1
        else:
            if is_change: is_change = False
            i += 1
    if i == len(keyence_str):
        return True
    else: return False


if is_keyence(S):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()

a="keyence"

j=0

count=0

dif_count=0

if(s[0]!=a[0]):
    dif_count=1

for i in range(len(s)):
    if(s[i]==a[j]):
        j+=1
        count+=1
        if(s[i+1]!=a[j] and i<len(s)-1):
            dif_count+=1
            
        
        
if(count==7 and dif_count<2):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

def is_keyence(S):
    keyence_str = "keyence"
    i = 0
    is_change = False
    change_num = 0
    for j in range(len(S)):
        print(i, j, S[j],keyence_str[i])
        if S[j] != keyence_str[i]:
            if is_change: change_num += 1
            else:
                if change_num > 0:
                    # 二回以上修正箇所がある
                    return False
                is_change = True
                change_num += 1
        else:
            if is_change: is_change = False
            i += 1
    if i == len(keyence_str):
        return True
    else: return False


if is_keyence(S):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
for i in range(7):
    mae="keyence"[0:i+1]
    if re.match("%s.*%s"%(mae, ato),N):
        print("YES")
        break
if i==6:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()
string="keyence"
flag1=0
flag2=0
flag3=0
v=0

for i in range(len(s)):
  if s[i]==string[v]:
    v+=1
    if flag1==1:
      flag2=1
  else:
    flag1=1
    if flag1==1 and flag2==1:
      print("NO")
      exit()

if flag1==0 and flag2==0:
  print('YES')
elif flag2==0:
  print('NO')
else:
  print('YES')

Submission status: Runtime Error

Solution code:
s=input()

a="keyence"

j=0

count=0

dif_count=0

if(s[0]!=a[0]):
    dif_count=1

for i in range(len(s)):
    if(s[i]==a[j]):
        j+=1
        count+=1
        if(s[i+1]!=a[j]):
            dif_count+=1
            
        
        
if(count==7 and dif_count<2):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

keyence_str = "keyence"

def is_keyence(S):
    i = 0
    is_change = False
    change_num = 0
    for j in range(len(S)):
        print(i, j, S[j],keyence_str[i])
        if S[j] != keyence_str[i]:
            if is_change: change_num += 1
            else:
                if change_num > 0:
                    # 二回以上修正箇所がある
                    return False
                is_change = True
                change_num += 1
        else:
            if is_change: is_change = False
            i += 1
    if i == len(keyence_str):
        return True
    else: return False


if is_keyence(S):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

keyence = list("keyence")

for char in S:
    if char == keyence[0]:
        del keyence[0]

if len(keyence) == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
a = "keyence"

b = input()

k = len(b)
j = 0
jj = 0
kk = [0 for i in range(8)]
if k == 7:
	if a == b:
		print("YES")
	else:
		print("NO")
elif k >= 8:
	for i in range(k):
		if b[i] == a[j]:
			j += 1
			if jj == 1:
				jj = 2
		elif jj == 0:
			jj = 1
		elif jj == 2:
			jj = 3
	if j == 7 and (jj == 0 or jj == 1 or jj == 2):
		j = -1
	if j == -1:
		print("YES")
	else:
		print("NO")

else:
	print("NO")

Submission status: Runtime Error

Solution code:
# 2019/01/13
# KEYENCE Programming Contest 2019 - B

# Input
s = input()

# Init
key_str = "keyence"
search_idx = 0
okflg = 0
ngcnt = 0

# Search
for idx in range(len(s)):
    if s[idx] == key_str[search_idx]:
        search_idx += 1
        okflg = 1
    else:
        if okflg == 1:
            ngcnt += 1
            okflg = 0
        if ngcnt > 1:
            break

# Check
if search_idx == len(key_str):
    ans = "YES"
else:
    ans = "NO"

# Output
print(ans)

Submission status: Runtime Error

Solution code:
import re

m = re.match('.*k.*e.*y.*e.*n.*c.*e.*')
if m:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
S = list(input())
s1 = list("keyence")

x = 0
y = 0
z = 0
for i in range(len(S)):
  if S[i] == s1[x]:
    x += 1
    z = 0
  elif z != 0:
    y += 1
    z = 1


if y <= 1 and x != 0:
  print("YES")  
else:
  print("NO")

Submission status: Runtime Error

Solution code:
wlist=[ i for i in input()]
klist=["k","e","y","e","n","c","e"]
a=0
b=0
while b<=6:
    if wlist[a]==klist[b]:
        a+=1
        b+=1
    else:
        a+=1
if b==7:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()ß
s=list(s)
a=list('keyence')
for i in range(8):
    if s[:i]==a[:i] and s[i-7:]==a[i-7:]:
        print('YES')
        quit()
print('NO')

Submission status: Runtime Error

Solution code:
s=list(input())
t=list("keyence")
j=0
c=0
for i in range(len(s)):
    if s[i]==t[c]:
        j+=1
        if j==7:
            if s[i+1]="":
                print("YES")
                exit()
            else:
                break
        c+=1
print("NO")

Submission status: Runtime Error

Solution code:
s = input()
t = 'keyence'
cnt = 0
j = False
p = 0
for i in range(len(s)):
  if t[p] == s[i]:
    if j == True:
      j = False
      cnt = cnt + 1
    p = p + 1
  else:
    j = True
print('YES' if p == len(t) and cnt <= 1 else 'N0')

Submission status: Runtime Error

Solution code:
S = input().strip()

T = "keyence"

count = 0
j = 0
is_last = False
for i in range(0,len(S)):
    if count == 0 and T[j] == S[i]:
        j += 1
        continue
    elif count > 0 and T[j] == S[i]:
        is_last = True
        j += 1
    elif is_last and T[j] != S[i]:
        print("NO")
        exit()
    elif T[j] != S[i]:
        count += 1

if j == len(T):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s = input()
tmp = "keyence"
# if s == "keyence":
#     print("YES")
#     exit()
cnt = 0
aaa = True
for i in s:
    if i == tmp[0]:
        aaa = True
        tmp = tmp[1:]
    else:
        if aaa and cnt == 0:
            aaa = False
            cnt += 1
        elif not aaa and cnt == 1:
            pass
        else:
            break

print("YES" if len(tmp) == 0 else "NO")

Submission status: Runtime Error

Solution code:
s=list(input())
t=list("keyence")
j=0
c=0
for i in s:
    if i==t[c]:
        j+=1
        if j==7:
            print("YES")
            exit()
    c+=1
print("NO")

Submission status: Runtime Error

Solution code:
File Edit Options Buffers Tools YASnippet Complete In/Out Signals Help                                                                     
l = raw_input()
flag = False
if len(l) == 7:
    if l == "keyence":
        flag = True
elif len(l) == 8:
    for i in range(8):
        tmp = l[:i] + l[i+1:]
        if tmp == "keyence":
            flag = True
else:
    flag = False
if flag == True:
    print "YES"
else:
    print "NO"

Submission status: Runtime Error

Solution code:
s = input()
search="keyence"
idx=0
ans="NO"
for c in s:
    if c == search[idx]:
        idx += 1
    if idx >= 7:
        ans = "YES"
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
K = 'keyence'

bf = False
judge = False
kn = 0
for i in range(len(S)):
    if S[i] == K[kn]:
        if bf == True:
            judge = True
        kn += 1
    else:
        if judge == True:
            print('NO')
            exit()
        if bf == True:
            continue
        else:
            bf = True

if kn == 7:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
  S = input()
ans = 'keyence'

if S[0] == 'k':
    flag = True
    for i in range(1, 7):
        if S[i] != ans[i]:
            flag = False
            break
    if flag:
        print('YES')

    else:
        if ans[i:] == S[-len(ans[i:]):]:
            print('YES')
        else:
            print('NO')
else:
    if S[-7:] == ans:
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
s=list(input())
n=["k","e","y","e","n","c","e"]
ans=0
for i in n:
  for j in s:
    s.remove(j)
    if i==J:
      ans+=1
      break
  if ans==7:
    break
if ans=7:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:

s = input()

f = "keyence"
h = 0
for i in range(7):

    first = f[:i+1]
    second = f[i+1:]
    check = len(first)
    find1 = s.find(first)
    find2 = s.find(second,find1+check)

    if find2 + len(second) < n:
        continue

    if find1 != -1 and find2!=-1:
        print("YES")
        h = 1
        break



if h == 0:
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()

keyword = 'keyence'
cnt = 0
for moji in S:
    if moji == keyword[0]:
        cnt += 1
        keyword = keyword[1:]

if cnt == 7:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
ans = list("keyence")

S = input()
for i in range(len(S)):
  if S[i] == ans[0]:
    ans.pop(0)

if len(ans) == 0:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
s=input()
k="keyence"
c=0
for i in range(len(s)):
    if s[i]==k[c]:
        c+=1
if c==7:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
s=input()

target="keyence"
j=0

for i in range(len(s)):
    if s[i]==target[j]:
        j+=1

if j==len(target):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = input()

S = 'keyence'
index = 0
for item in N:
    if S[index] == item:
        index += 1

print('YES' if index == len(S) else 'NO')

Submission status: Runtime Error

Solution code:
s = input()
ls = len(s)

t = 'keyence'
idx = 0

for i in range(ls):
    if s[i] == t[idx]:
        idx += 1

if idx == len(t):
    print('YES')
else:
    print('NO')