// #define DEBUGGING #include #define endl '\n' #define ALL(V) begin(V), end(V) #define ALLR(V) rbegin(V), rend(V) using ll = std::int64_t; using ull = std::uint64_t; using PLL = std::pair; using TLL = std::tuple; template using V = std::vector; template using VV = V>; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); } template void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } #define mv_rec make_v(init, tail...) template T make_v(T init) { return init; } template auto make_v(T init, size_t s, Tail... tail) { return V(s, mv_rec); } #undef mv_rec using namespace std; #ifdef DEBUGGING #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif // 0 : nothing // 1 : phn // 2: ph*eh*n ll jleft(const string &s, ll idx) { ll hcnt = 0, ecnt = 0, othcnt = 0; ll level = 0; for (ll i = idx - 1; !othcnt && 0 <= i; i--) { if (s[i] == 'p') { if (hcnt == 1 && ecnt == 0) level = 1; else if (ecnt == 1 && othcnt == 0) level = 2; break; } else { if (s[i] == 'n') break; (s[i] == 'h' ? hcnt : s[i] == 'e' ? ecnt : othcnt)++; } } return level; } // 0 : nothing // 1 : normal // 2 : h exist // 3 : e exist PLL jright(const string &s, ll idx) { ll omcnt = 0, hcnt = 0, ecnt = 0, othcnt = 0; ll level = 0; bool is_o = false; for (ll i = idx + 1; !othcnt && i < s.size(); i++) { if (s[i] == 'm') { if (is_o && !othcnt) { is_o = false; omcnt++; chmax(level, (ll)1); } else { othcnt++; } } else if (s[i] == 'o') { if (!is_o && !othcnt) { is_o = true; } else { othcnt++; } } else if (s[i] == 'h') { hcnt++; if (omcnt < 1) chmax(level, (ll)2); } else if (s[i] == 'e') { ecnt++; if (omcnt < 2) chmax(level, 3 - omcnt); } else { othcnt++; if (s[i] == 'n') break; } } return PLL(level, omcnt); } int main() { string s; cin >> s; ll last = 0; for (char c : s) { if (c == 'h') chmax(last, (ll)1); if (c == 'e') chmax(last, (ll)2); } ll cnt = 0; ll maxcnt = 0; for (ll i = 0; i < s.size(); i++) { if (s[i] != 'n') continue; ll lvl, lvr, omcnt; lvl = jleft(s, i); tie(lvr, omcnt) = jright(s, i); if (lvr < lvl) continue; cnt += omcnt; DEBUG(lvr); chmax(maxcnt, omcnt + lvr - 1); } DEBUG(cnt, maxcnt); ll ans = last; chmax(ans, cnt + maxcnt + 1); cout << ans << endl; return 0; }