def max_operations(s): count = 0 prev = None while True: # Apply operation 1 as many times as possible cnt1 = 0 new_s = [] i = 0 n = len(s) while i <= n - 5: if s[i:i+5] == 'phnom': new_s.append('penh') cnt1 += 1 i += 5 else: new_s.append(s[i]) i += 1 # Add remaining characters while i < n: new_s.append(s[i]) i += 1 if cnt1 > 0: count += cnt1 s = ''.join(new_s) prev = None continue # go back to check operation 1 again # Apply operation 2 once if possible # Check if applying operation 2 changes the string # Step 1: remove all 'h's temp = s.replace('h', '') # Step 2: replace all 'e's with 'h's temp2 = temp.replace('e', 'h') if temp2 != s: count += 1 s = temp2 prev = s else: break # no more operations possible return count s = input().strip() print(max_operations(s))