def max_operations(s): s_list = list(s) n = len(s_list) count = 0 while True: # Try Operation 1 phnom_pos = [] for i in range(n - 4): if ''.join(s_list[i:i+5]) == 'phnom': phnom_pos.append(i) if phnom_pos: # Perform Operation 1 on the first occurrence for pos in phnom_pos: s_list[pos:pos+5] = list('penh') count += 1 # After replacement, break and restart n = len(s_list) break continue # Restart the loop after Operation 1 # Try Operation 2 # Step 1: Remove all 'h's new_s = [] has_h = False for c in s_list: if c == 'h': has_h = True else: new_s.append(c) if has_h: # Step 2: Replace 'e's with 'h's has_e = False for i in range(len(new_s)): if new_s[i] == 'e': new_s[i] = 'h' has_e = True # Check if the string changed changed = has_h or has_e if changed: s_list = new_s count += 1 n = len(s_list) continue # If no operations can be performed break return count # Read input s = input().strip() # Compute and print the result print(max_operations(s))