#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll = long long; bool proc1(stack& q) { if (q.size() < 5)return false; string s; rep(i, 5) { s += q.top(); q.pop(); } if (s == "phnom") { s = "hnep"; for (char c : s) { q.push(c); } return true; } else { reverse(s.begin(), s.end()); for (char c : s) { q.push(c); } return false; } } bool proc2(stack& q) { bool res = false; stack l; while (!q.empty()) { char c = q.top(); q.pop(); if (c == 'h') { res = true; } else { l.push(c); } } // reverse while (!l.empty()) { char c = l.top(); l.pop(); if (c == 'e') { res = true; q.push('h'); } else { q.push(c); } } return res; } pair analyze(stack& q) { int n1 = 0, n2 = 0; int cnt = 0; while (true) { // try n1 cnt++; while (proc1(q)) { n1++; cnt = 0; } if (cnt >= 2)break; // try n2 if (proc2(q)) { n2++; cnt = 0; } else { cnt++; } if (cnt >= 2)break; } return { n1,n2 }; } int main() { string s; cin >> s; vector> qs; while (!s.empty()) { stack q; while (!s.empty() && s.back() != 'p') { q.push(s.back()); s.pop_back(); } if (!s.empty()) { q.push('p'); s.pop_back(); qs.push_back(q); } } int n1 = 0, n2 = 0; for (auto& q : qs) { int tn1, tn2; tie(tn1, tn2) = analyze(q); n1 += tn1; n2 = max(n2, tn2); //cout << tn1 << " " << tn2 << endl; } cout << n1 + n2 << endl; //cout << endl; //cout << n1 << " " << n2 << endl; // debug /* for (auto& q : qs) { while (!q.empty())cout << q.top(), q.pop(); cout << endl; } */ return 0; }