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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] str = sc.next().toCharArray();
        char[] target = "keyence".toCharArray();

        int i = 0;
        int j = 0;
        int gap = 0;
        int prev = -1;
        while (i < str.length) {
            if (j == target.length) {
                break;
            }
            else if (str[i] == target[j]) {
                i++;
                j++;
            } else if (i < str.length && gap == 0 && str[i] != target[j]) {
                prev = i;
                while (i < str.length && str[i] != target[j]) {
                    i++;
                }
                gap = 1;
            } else if (i < str.length && gap == 1 && str[i] != target[j]) {
                j=0;
                gap = 0;
                i = prev;
            }
        }
        if (j == target.length) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}