#include #define NIL (-1) #define ll long long using namespace std; const double PI = acos(-1.0); int main() { string S; cin >> S; int s = S.find("pain"); if (s == string::npos) { cout << -1 << endl; return 0; } //cout << s << endl; string T = S.substr(0, s); //cout << T.size() - 2 << endl; if (T.size() < 3) { cout << -1 << endl; return 0; } int co = 0; for (int i = 0; i < T.size()-2; i++) { string t = T.substr(i, 3); if (t == "pon") co++; } if (co < 2) { cout << -1 << endl; return 0; } cout << co - 1 << endl; return 0; }