#include #include #include #define llint long long #define mod 1000000007 using namespace std; string s; llint calc(string &s) { llint ret = 0; for(int i = 0; i < s.size(); i++){ if(s[i] == 'e') ret = 2; if(s[i] == 'h') ret = 1; } llint mx = 0, sum = 0, phn = 0, penh = 0; for(int i = 0; i < s.size(); i++){ if(i+2 < s.size() && s.substr(i, 3) == "phn"){ i += 3; llint cnt = 0; bool flag = false; for(; i < s.size();){ if(!flag && s[i] == 'o') flag = true, i++; else if(flag && s[i] == 'm') flag = false, i++, cnt++; else if(s[i] == 'e' && cnt >= 2) i++; else if(s[i] == 'h' && cnt >= 1) i++; else break; } if(cnt >= 1){ mx = max(mx, cnt); sum += cnt; } i--; } if(i+3 < s.size() && s.substr(i, 4) == "penh"){ i += 4; llint cnt = 1; bool flag = false; for(; i < s.size();){ if(!flag && s[i] == 'o') flag = true, i++; else if(flag && s[i] == 'm') flag = false, i++, cnt++; else if(s[i] == 'e' && cnt >= 2) i++; else if(s[i] == 'h' && cnt >= 1) i++; else break; } mx = max(mx, cnt); sum += cnt; penh++; i--; } } if(mx >= 1){ llint tmp = sum + mx + 1 - penh; ret = max(ret, tmp); } return ret; } bool ope(string &s) { string t = s; s = ""; bool flag = false; for(int i = 0; i < t.size(); i++){ if(t[i] == 'h'){ flag = true; } else if(t[i] == 'e'){ s += 'h'; flag = true; } else s += t[i]; } return flag; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> s; llint ans = calc(s); if(ope(s)) ans = max(ans, calc(s)+1); if(ope(s)) ans = max(ans, calc(s)+2); cout << ans << endl; return 0; }