#include using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) #define PREFIX "#" TOSTRING(__LINE__) "| " #define debug(x) \ { \ std::cout << PREFIX << #x << " = " << x << std::endl; \ } std::ostream& output_indent(std::ostream& os, int ind) { for(int i = 0; i < ind; i++) os << " "; return os; } template std::ostream& operator<<(std::ostream& os, const std::pair& p); template std::ostream& operator<<(std::ostream& os, const std::vector& v); template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return (os << "(" << p.first << ", " << p.second << ")"); } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << "["; for(int i = 0;i < v.size();i++) os << v[i] << ", "; return (os << "]"); } template static inline std::vector ndvec(size_t&& n, T val) { return std::vector(n, std::forward(val)); } template static inline auto ndvec(size_t&& n, Tail&&... tail) { return std::vector(tail)...))>(n, ndvec(std::forward(tail)...)); } template struct chain { Cond cond; chain(Cond cond) : cond(cond) {} template bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; } }; template chain make_chain(Cond cond) { return chain(cond); } int main() { i64 N; string SS; cin >> N >> SS; vector S(N); rep(i,0,N) { if(SS[i] == 'p') S[i] = 0; if(SS[i] == 'o') S[i] = 1; if(SS[i] == 'n') S[i] = 2; } auto dp = ndvec(501, 501, i64(0)); for(int l = 3; l <= N; l++) { for(int i = 0; i + l <= N; i++) { int j = i + l; for(int m = i + 1; m < j; m++) { dp[i][j] = std::max(dp[i][j], dp[i][m] + dp[m][j]); } for(int m = i + 1; m < j; m++) { if(S[i] == 0 && S[j - 1] == 2 && S[m] == 1) { dp[i][j] = std::max(dp[i][j], dp[i + 1][m] + dp[m + 1][j - 1] + 1); } } } } i64 ans = -1; for(int m = 1; m < N; m++) { if(dp[0][m] > 0 && dp[m][N] > 0) ans = std::max(ans, dp[0][m] + dp[m][N] - 2); } cout << ans << endl; }