#include int ri() { int n; scanf("%d", &n); return n; } int64_t rs64() { int64_t n; scanf("%" SCNd64, &n); return n; } bool type2(std::string &s) { int n = s.size(); std::string t; for (auto c : s) if (c != 'h') t.push_back(c); std::replace(t.begin(), t.end(), 'e', 'h'); bool res = t != s; s = t; return res; } // 1, 2 std::pair solve(std::string s) { int r0 = 0, r1 = 0; while (1) { while (s.substr(0, 5) != "phnom") { if (!type2(s)) break; r1++; } if (s.substr(0, 5) != "phnom") break; r0++; int index = 5; int cnt = 0; while (index + 1 < (int) s.size() && s[index] == 'o' && s[index + 1] == 'm') index += 2, cnt++; r0 += cnt; r1 += cnt; s[0] = 'p'; s[1] = 'e'; s[2] = 'n'; s[3] = 'h'; s.erase(s.begin() + 4, s.begin() + index); for (int i = 0; i < std::min(2, cnt); i++) type2(s); } return {r0, r1}; } int main() { std::string s; std::cin >> s; int n = s.size(); std::vector > all; int first = n; for (int i = 0; i < n; i++) { if (s[i] == 'p') { first = std::min(first, i); int j = i + 1; for (; j < n && s[j] != 'p'; j++); all.push_back(solve(s.substr(i, j - i))); } } if (first) { int cnt = 0; std::string tmp = s.substr(0, first); while (type2(tmp)) cnt++; all.push_back({0, cnt}); } int res = 0, max = 0; for (auto &i : all) res += i.first, max = std::max(max, i.second); printf("%d\n", res + max); return 0; }