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

Solution in Haskell (GHC 7.10.3) (judge verdict: Wrong Answer)

import Data.List
import qualified Data.Text as T

main = do
    s <- getLine :: IO String
    let ls = length s
    -- let parts = [("k","eyence",s), ("ke","yence",s), ("key","ence",s), ("keye","nce",s), ("keyen","ce",s), ("keyenc","e",s)]
    -- let pairs = [("k","eyence"), ("ke","yence"), ("key","ence"), ("keye","nce"), ("keyen","ce"), ("keyenc","e")]
    let flag = take 7 s == "keyence" || drop (ls-7) s == "keyence"
    let ans = flag || (solve s [])
    -- print $ map chk parts
    if ans then putStrLn $ "YES" else putStrLn $ "NO"

solve :: String -> String -> Bool
solve rest@(s:ss) path
    | isMF == True = solve ss (s:path)
    | otherwise = if (length $ T.splitOn (T.pack $ getPair path) (T.pack rest)) == 2 then True else False
        where 
            isMF = isMathchFirst $ s:path

getPair :: String -> String
getPair rx = drop (length path) "keyence"
    where 
        path = reverse rx

isMathchFirst :: String -> Bool
isMathchFirst s = case s of
    "k" -> True 
    "ek" -> True 
    "yek" -> True 
    "eyek" -> True 
    "neyek" -> True 
    "cneyek" -> True 
    _ -> False