#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string S; //--------------------------------------------------------------------------------------------------- pair ope1(string s) { int cnt = 0; string res = ""; int n = s.length(); rep(i, 0, n) { if (i + 5 <= n && s.substr(i, 5) == "phnom") { cnt++; res += "penh"; i += 4; } else res += s[i]; } return { res, cnt }; } pair ope2(string s) { int cnt = 0; string res = ""; fore(c, s) { if (c == 'h') cnt = 1; else res += c; } fore(c, res) if (c == 'e') { c = 'h'; cnt = 1; } return { res, cnt }; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> S; int ans = 0; rep(i, 0, 2) { int tot = 0, res; string s = S; if (i == 0) tie(s, tot) = ope2(s); rep(_, 0, 5) { int res; tie(s, res) = ope1(s); tot += res; tie(s, res) = ope2(s); tot += res; } int n = s.length(); int ma = 0; rep(i, 0, n - 4) if (s.substr(i, 5) == "phnom") { int cnt = 0; int j = i + 3; while (j < n - 1) { if (s.substr(j, 2) != "om") break; cnt++; j += 2; } chmax(ma, cnt); tot += cnt; } if (ma == 0) { tie(s, res) = ope2(s); tot += res; } else tot += ma + 1; chmax(ans, tot); } cout << ans << endl; }