Problem:
Score : 100 points

Problem Statement

A Hitachi string is a concatenation of one or more copies of the string hi.

For example, hi and hihi are Hitachi strings, while ha and hii are not.

Given a string S, determine whether S is a Hitachi string.

Constraints

The length of S is between 1 and 10 (inclusive).

S is a string consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S is a Hitachi string, print Yes; otherwise, print No.

Sample Input 1

hihi

Sample Output 1

Yes

hihi is the concatenation of two copies of hi, so it is a Hitachi string.

Sample Input 2

hi

Sample Output 2

Yes

Sample Input 3

ha

Sample Output 3

No

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)


import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        Stack<Integer> stack = null;
        if (s.length()==1){
            System.out.println("No");
        }else if (s.length()==2){
            if (s.charAt(0)=='h' && s.charAt(1) == 'i'){
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }
        }else {
            for (int i = 0; i < s.length()-3; i++) {
                if (s.charAt(i)=='h' && s.charAt(i+1) == 'i'){
                    stack.push(i);
                    if(s.charAt(i+2) == 'i'){
                        stack.pop();
                    }
                }
            }
            if(!stack.isEmpty() || (s.charAt(s.length()-2)=='h' && s.charAt((s.length()-1))=='i')){
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }
        }
    }
}