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.*;

public class Main {
	static String KEYENCE = "keyence";

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		in.close();
		List<String> startStrs = startStrs(line);
		List<String> endStrs = endStrs(line);
		boolean enable = false;
		for (String startStr : startStrs) {
			for (String endStr : endStrs) {
				if (KEYENCE.equals(startStr + endStr)) {
					enable = true;
					break;
				}
			}
			if (enable) {
				break;
			}
		}
		if (line.startsWith(KEYENCE)) {
			enable = true;
		}
		if (line.endsWith(KEYENCE)) {
			enable = true;
		}
		if (enable) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	static List<String> startStrs(String line) {
		List<String> result = new ArrayList<>();
		for (int i = 0; i <= 0; ++i) {
			if (line.charAt(i) != 'k') {
				continue;
			}
			int end = i;
			for (int j = i; j < Math.min(i + KEYENCE.length(), line.length()); ++j) {
				if (line.charAt(j) != KEYENCE.charAt(j - i)) {
					break;
				}
				end = j;
			}
			result.add(line.substring(i, end + 1));
		}
		return result;
	}

	static List<String> endStrs(String line) {
		List<String> result = new ArrayList<>();
		for (int end = line.length() - 1; end >= line.length() - 1; --end) {
			if (line.charAt(end) != 'e') {
				continue;
			}
			int start = end;
			for (int j = end; j >= Math.max(end + 1 - KEYENCE.length(), 0); --j) {
				// System.out.println(j + ", " + (KEYENCE.length() - 1 - (end - j)));
				if (line.charAt(j) != KEYENCE.charAt(KEYENCE.length() - 1 - (end - j))) {
					break;
				}
				start = j;
			}
			result.add(line.substring(start, end + 1));
		}
		return result;
	}

}