S = input().strip() ans = 0 while True: # Apply operation1 as much as possible operation1_done = False while True: # Count and replace all occurrences of 'phnom' new_S = [] i = 0 count_op1 = 0 len_S = len(S) while i <= len_S - 5: if S[i:i+5] == 'phnom': new_S.append('penh') count_op1 += 1 i += 5 else: new_S.append(S[i]) i += 1 # Add remaining characters new_S.extend(S[i:]) new_S_str = ''.join(new_S) if count_op1 == 0: break ans += count_op1 S = new_S_str operation1_done = True if operation1_done: # Check if new S contains 'phnom' again after replacing if 'phnom' in S: continue # Restart the loop to process operation1 again else: operation1_done = False # Apply operation2 as many times as possible applied_op2 = False while True: s1 = S.replace('h', '').replace('e', 'h') if s1 == S: break # No change, can't apply # Apply once ans += 1 applied_op2 = True prev_S = S S = s1 # Check after first application if 'phnom' in S: break # Need to restart loop for operation1 # Apply second time if possible s2 = S.replace('h', '').replace('e', 'h') if s2 == S: break # No further change ans += 1 S = s2 # Check after second application if 'phnom' in S: break if applied_op2 and 'phnom' in S: continue # Restart loop for operation1 else: break # No more possible operations print(ans)