#define _USE_MATH_DEFINES #include using namespace std; long long ans = 0; string doit (string s) { int n = (int) s.size(); string res; for (int i = 0; i < n; i++) { if (s.substr(i, 5) == "phnom") { i += 4; res += "penh"; ans++; } else { res += s[i]; } } s = res; n = (int) s.size(); bool found = false; res = ""; for (int i = 0; i < n; i++) { if (s[i] == 'h' || s[i] == 'e') { found = true; } if (s[i] == 'e') res += 'h'; else if (s[i] != 'h') res += s[i]; } if (found) ans++; return res; } vector doit2 (string s) { int n = (int) s.size(); int cnt = 0; int phn = false; vector res; for (int i = 0; i < n; i++) { if (s.substr(i, 3) == "phn") { cnt = 0; phn = true; i += 2; continue; } if (s.substr(i, 2) == "om" && phn) { cnt++; i += 1; } else { if (cnt > 0) res.push_back(cnt); phn = false; cnt = 0; } } if (cnt > 0) res.push_back(cnt); return res; } signed main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; for (int i = 0; i < 10; i++) s = doit(s); auto v = doit2(s); if (v.empty()) { int e = 0, h = 0; int n = (int) s.size(); for (int i = 0; i < n; i++) { if (s[i] == 'e') e++; if (s[i] == 'h') h++; } if (e > 0) ans += 2; else if (h > 0) ans += 1; } else { for (int i : v) ans += i; ans += *max_element(v.begin(), v.end()); ans++; } cout << ans << endl; return 0; }