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:
import sys

s=input()
a,b,c,d,e,f,g=0
while s[a]!="k":
    a+=1
    if a==len(s):
        print("NO")
        sys.exit()
b=a+1
while s[b]!="e":
    b+=1
    if b==len(s):
        print("NO")
        sys.exit()
c=b+1
while s[c]!="y":
    c+=1
    if c==len(s):
        print("NO")
        sys.exit()
d=c+1
while s[d]!="e":
    d+=1
    if d==len(s):
        print("NO")
        sys.exit()
e=d+1
while s[e]!="n":
    e+=1
    if e==len(s):
        print("NO")
        sys.exit()
f=e+1
while s[f]!="c":
    f+=1
    if f==len(s):
        print("NO")
        sys.exit()
g=f+1
while s[g]!="e":
    g+=1
    if not "e" in s[g]:
        print("NO")
        sys.exit()
if s=="keyence":print("YES")
else:
    if b+g==c+f==d+e:
        print("YES")
    elif a==0 and b!=1 and(c==b+1 and d==c+1 and e==d+1 and f==e+1 and g==f+1):
        print("YES")
    elif a==0 and b==1 and c!=2 and(d==c+1 and e==d+1 and f==e+1 and g==f+1):
        print("YES")
    elif a==0 and b==1 and c==2 and d!=3 and (e==d+1 and f==e+1 and g==f+1):
        print("YES")
    elif a==0 and b==1 and c==2 and d==3 and e!=4 and (f==e+1 and g==f+1):
        print("YES")
    elif a==0 and b==1 and c==2 and d==3 and e==4 and f!=5 and g==f+1:
        print("YES")
    elif a==0 and b==1 and c==2 and d==3 and e==4 and f!=5 and g!=6:
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
S = list(input())
ans = ['k','e','y','e','n','c','e']

for i in range(len(ans)):
  if S[i] == ans[i]:
    S[i] = ans[i] = ''
  else:
    break
S = list(''.join(S))
ans = list(''.join(ans))

if ans != []:
  for i in range(len(ans)):
    for j in range(len(S)):
      if S[j] != ans[i]:
        S[j] = ''
      else:
        break
    else:
      continue
    break
  S = list(''.join(S))

  for i in range(len(ans)):
    if S[i] == ans[i]:
      S[i] = ans[i] = ''
    else:
      break
  S = list(''.join(S))
  ans = list(''.join(ans))

  if ans == [] and S == []:
    print('YES')
  else:
    print('NO')
else:
 print('YES')

Submission status: Runtime Error

Solution code:
k_str = 'keyence'
patterns = [[k_str[:i], k_str[i:]] for i in range(0, len(k_str))]
for pattern in patterns:
    if pattern[0] in S:
        print('YES')

Submission status: Runtime Error

Solution code:
text = input()
i = 0
ans = "keyence"
for ob_n in range(len(lists)):
    if text[i] != ans[ob_n]:
        if text.endswith(ans[ob_n:]):
            flag = 1
            break
        else:
            flag = 0
            break
    i+=1
    if i == len(text):
        flag = 1
        break
if flag == 1:
    print("YES")
else :
    print("NO")

Submission status: Runtime Error

Solution code:
s=list(input())
k=["k","e","y","e","n","c","e"]
ans="NO"
c=0
if len(s)>=7:
    while True:
        if s[c]!=k[c]:
            break
        c+=1
    if c==7:
        ans="YES"
    for i in range(7-c):
        if s[-i-1]!=k[-i-1]:
            break
    else:
        ans="YES"
print(ans)

Submission status: Runtime Error

Solution code:
text = input()
i = 0
ans = "keyence"
for ob_n in range(len(lists)):
    if text[i] != lists[ob_n]:
        if text.endswith(ans[ob_n:]):
            flag = 1
            break
        else:
            flag = 0
            break
    i+=1
    if i == len(text):
        flag = 1
        break
if flag == 1:
    print("YES")
else :
    print("NO")

Submission status: Runtime Error

Solution code:
S = input()
K = "keyence"
i = 0
j = 0
flag = 0
while i < len(S):
  if(j >= 6):
    if(len(S) - i != 1):
      flag = flag + 1
    break
  if(S[i]==K[j]):
    j = j + 1
    i = i + 1
  if(S[i]!=K[j]):
    flag = flag + 1
    while S[i] != K[j]:
      i = i + 1
    
if flag == 0 or flag == 1:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
k_str = 'keyence'
patterns = [[k_str[:i], k_str[i:]] for i in range(0, len(k_str))]
for pattern in patterns:
    if pattern[0] in S:
        next_starting_idx = S.index(pattern[0]) + len(pattern[0])
        if pattern[1] in S[next_starting_idx:]:
            print('YES')

Submission status: Runtime Error

Solution code:
text = input()
i = 0
ans = "keyence"
for ob_n in range(len(lists)):
    if text[i] != lists[ob_n]:
        if text.endswith(ans[ob_n:]):
            flag = 1
            break
        else:
            flag = 0
            break
    i+=1
    if i == len(text):
        flag = 1
        break
if flag == 1:
    print("YES")
else :
    print("NO")

Submission status: Runtime Error

Solution code:
k_str = 'keyence'
patterns = [[k_str[:i], k_str[i:]] for i in range(0, len(k_str))]
for pattern in patterns:
    if pattern[0] in S:
        next_starting_idx = S.index(pattern[0]) + len(pattern[0])
        if pattern[1] in S[next_starting_idx:]:
            print('YES')
            break
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s=list(input())
k=["k","e","y","e","n","c","e"]
ans="NO"
if len(s)>=7:
    while c<7:
        if s[i]!=k[i]:
            break
        c+=1
    for i in range(7-c):
        if s[-i-1]!=k[-i-1]:
            break
    else:
        ans="YES"
print(ans)

Submission status: Runtime Error

Solution code:
k_str = 'keyence'
patterns = [[k_str[:i], k_str[i:]] for i in range(len(k_str))]
for pattern in patterns:
    if pattern[0] in S:
        next_starting_idx = S.index(pattern[0]) + len(pattern[0])
        if pattern[1] in S[next_starting_idx:]:
            print('YES')
            break
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s=input()
x='keyence'
if s==x:
  print('YES')
  exit()
if s.count(x)>0:
  p=s.split('keyence')
  if p[0]=='' or p[1]=='':
    print('YES')
    exit()
  elif p[0]+p[1]=='keyence':
    print('YES')
    exit()
for i in range(1,len(x)):
  a=x[:i]
  b=x[i:]
  if s.index(a)==0 and s[len(s)-len(b):]==b:
    print('YES')
    exit()
  else:
    continue
print('NO')

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
for i in range(0,N+1):
    for j in range(i,N+1):
        if "".join(S[:i] + S[j:]) == 'keyence':
            print("YES")
            exit(1)
else:
    print('NO')

Submission status: Runtime Error

Solution code:
S=list('keyekeyencence')
N=len(S)
for i in range(0,N+1):
    for j in range(i,N+1):
        if "".join(S[:i] + S[j:]) == 'keyence':
            print("YES")
            exit(1)
else:
    print('NO')

Submission status: Runtime Error

Solution code:
# 分割のパターンを洗い出す方法
k_str = 'keyence'
patterns = [[k_str[:i], k_str[i:]] for i in range(len(k_str))]
for pattern in patterns:
    if pattern[0] in S:
        next_starting_idx = S.index(pattern[0]) + len(pattern[0]) 
        if pattern[1] in S[next_starting_idx:]:
            print('YES')
            break
    
else:
    print('NO')

Submission status: Runtime Error

Solution code:
if S.startswith('k') and S.endswith('eyence'):
    print('YES')
elif S.startswith('ke') and S.endswith('yence'):
    print('YES')
elif S.startswith('key') and S.endswith('ence'):
    print('YES')
elif S.startswith('keye') and S.endswith('nce'):
    print('YES')
elif S.startswith('keyen') and S.endswith('ce'):
    print('YES')
elif S.startswith('keyenc') and S.endswith('e'):
    print('YES')
elif S == 'keyence':
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
import re
if S.startswith('k') and S.endswith('eyence'):
    print('YES')
elif S.startswith('ke') and S.endswith('yence'):
    print('YES')
elif S.startswith('key') and S.endswith('ence'):
    print('YES')
elif S.startswith('keye') and S.endswith('nce'):
    print('YES')
elif S.startswith('keyen') and S.endswith('ce'):
    print('YES')
elif S.startswith('keyenc') and S.endswith('e'):
    print('YES')
elif S == 'keyence':
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()
search="keyence"
idx=0
flg = False
ans="NO"
if s.find(search)>=0:
    print("YES")
elif:
    for i in range(7):
        x=s.find(search[0:i+1])
        print("ps=%s, ns=%s, reduce=%s" %(search[0:i+1], search[i+1:], s[x+i+1:]))
        if x == -1:
            break
        if x == 0:
            if s[x+i:].find(search[i+1:])>=0:
                ans = "YES"
                break
    print(ans)

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 count == 2:
        break

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

Submission status: Runtime Error

Solution code:
import sys
S = input().strip()
keyence = "keyence"

for i in range(len(keyence)):
    if keyence[:i] in S:
        s = S.find(keyence[:i]) + i
        S2 = S[s:]
        if keyence[i:] in S2:
            print("YES")
            sys.exit()

print("NO")
~

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
input_str = input()
target_lst = ['k','e','y','e','n','c','e']

i = 0
del_list = []
for elm in input_str:
  if elm in target_lst:
    target_lst.remove(elm)
    del_list.append(i)
  i+=1

if len(target_lst) !=  0:
  print('NO')
else:
  for i in del_list:
    if i == 0:
      continue
    else:
      if del_list[i] < del_list[i-1]:
        print('NO')
        exit()

  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)-1):
    if(s[i]==a[j]):
        j+=1
        count+=1
        if(count==7):
            if(s[i+1]!=a[j] and i<len(s)-1):
                dif_count+=1
            break
        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()
target = "keyence"
cnt = 0

for moji in S:
    if target in S:
        print("YES")
        break
    if moji == target[cnt]:
        cnt += 1
    else:
        if target[cnt:] in S:
            #print(target[cnt:])
            print("YES")
            break
        cnt += 1

Submission status: Runtime Error

Solution code:
a = 0
b = 0
c = 0
for i in range(len(ss)):
    if s[i] == ss[i]:
        continue
    else:
        a = i
        break
else:
    print('YES')
    exit()


sss = ss[a:]
print(sss)
for i in range(len(sss)):
    if sss[len(sss)-i-1] == s[len(s)-i-1]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')

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
    else:
      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:
def main(pro):
    ans = 'keyence'
    try:
        lokasi = pro.index(ans)
        if lokasi > 0 and lokasi + len(ans) < len(pro):
            raise ValueError()
            return
        else:
            print('YES')
            return
    except:
        # it is split
        for i in range(len(ans)):
            if ans[i] != pro[i]:
                break
        r = len(ans) - i
        for a in range(1,r+1):
            if ans[-r] != pro[-r]:
                print('NO')
                return
        print('YES')
while True:
    main(input())

Submission status: Runtime Error

Solution code:
s = input()
ans = "keyence"
a = [0] * len(ans)
j = 0


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

b = [a[i + 1] - a[i] for i in range(len(a) - 1)]

if len(b) - 1 <= b.count(1):
    out = "YES"
else:
    out = "NO"

print(out)

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.sub('.*keyence', '', N)=="")==True:
        print("YES")
        break
    if (re.sub('keyence.*', '', N)=="")==True:
        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:
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_b

import re

S = input()

if "keyence" == S:
    print("YES")
else:
    patterns = ["^keyence*", "^k*eyence$", "^ke*yence$", "^key*ence$", "^keye*nce$", "^keyen*ce$", "^keyenc*e$", "*keyence$"]

    matched = False
    for pattern in patterns:
        matchOB = re.search(pattern, S)
        if matchOB:
            matched = True
            break
    if matched:
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
s = input()
search="keyence"
idx=0
flg = False
ans="NO"
for c in s:
    if c == search[idx]:
        idx += 1
    if idx >= 7:
        flg=True
        break
if flg:
    idx = -1
    for i in range(7):
        x=s.find(search[0:i])
        #print("ps=%s, ns=%s, reduce=%s" %(search[0:i], search[i+1:], s[x+i+i:]))
        if s[x+i+1:].find(search[i+1:]):
            ans = "YES"
            break
    print(ans)
else:
    print(ans)
~

Submission status: Runtime Error

Solution code:


num_list = input()
key = 'keyence'

i = 0
ans =False
while num_list[i]==key[i]:
    i+=1
n = i
if n >= 6:
    print('YES')



i = -1
while num_list[i]==key[i]:
    i -= 1
    n += 1

if n >= 6:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

i = 0
ans =False
while num_list[i]==key[i]:
    i+=1
n = i
if n >= 6:
    print('YES')
else:
    print('NO')


i = -1
while num_list[i]==key[i]:
    i -= 1
    n += 1

if n >= 6:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:


num_list = input()
key = 'keyence'

i = 0
ans =False
while num_list[i]==key[i] and i<100:
    i+=1
n = i

i = -1
while num_list[i]==key[i] and i>-100:
    i -= 1
    n += 1

if n >= 6:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
k = input()
n = 'keyence'
for i in range(len(k)):
    if k[i] == 'k':
        z = 0
        for j in range(len(n)):
            if k[i+j] != n[j]:
                z = 1
                for p in range(i+j, len(k)):
                    
                    if n[j:] in k[p:]:
                        print('YES')
                        break
                    else:
                        z = 2
                        break
                
            break
            
    if i == len(k):
        z = 2
    

if z == 0:
    print('YES')
elif z == 2:
    print('NO')

Submission status: Runtime Error

Solution code:
s = input()
ans = "keyence"
a = []
j = 0


for i in range(len(s)):
    if s[i] == ans[j]:
        a.append(i)
        j += 1

b = [a[i + 1] - a[i] for i in range(len(a) - 1)]

if len(b) - 1 <= b.count(1):
    out = "YES"
else:
    out = "NO"

print(out)

Submission status: Runtime Error

Solution code:

num_list = input()
key = 'keyence'

i = 0
ans =False
while num_list[i]==key[i]:
    i+=1
n = i

i = -1
while num_list[i]==key[i]:
    i -= 1
    n += 1

if n >= 6:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
k = input()
n = 'keyence'
for i in range(len(k)):
    if k[i] == 'k':
        z = 0
        for j in range(len(n)):
            if k[i+j] != n[j]:
                z = 1
                for p in range(i+j, len(k)):
                    
                    if n[j:] in k[p:]:
                        break
                        break
                    else:
                        z = 2
                        break
            break
            
    if i == len(k):
        z = 2
    

if z == 0 or z == 1:
    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 len(s_count) < s_count:
        if not ng_flag:
            count += 1
            ng_flag = True
        continue
    elif 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:
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":
                                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")