#include using namespace std; using ll = long long; int op1(string& s) { int cnt = 0; int state = 0; string res = ""; for (char c : s) { if (c == "phnom"[state]) { state++; if (state == 5) { res += "penh"; state = 0; cnt++; } } else { for (int i = 0; i < state; ++i) { res += "phnom"[i]; } state = (c == 'p'); res += c; } } for (int i = 0; i < state; ++i) { res += "phnom"[i]; } s = res; return cnt; } int op2(string& s) { int cnt = 0; string res = ""; for (char c : s) { if (c == 'h') { cnt = 1; continue; } else if (c == 'e') { cnt = 1; res += 'h'; } else { res += c; } } s = res; return cnt; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s; cin >> s; int ans = 0; while (true) { int cnt1 = op1(s); ans += cnt1; //cerr << s << endl; int cnt2 = op2(s); ans += cnt2; //cerr << s << endl; if (cnt1 == 0 && cnt2 == 0) break; } cout << ans << "\n"; return 0; }