#include const int inf = -(1 << 30); void chmax(int* a, int b) { if (*a < b) *a = b; } int main() { int N; char S[501]; scanf("%d", &N); scanf("%s", S); int i, j, k, l, dp[501][501][6], ans = -1, max[2]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) for (k = 0; k < 6; k++) dp[i][j][k] = inf; for (i = 0; i < N; i++) { dp[i][i][0] = 0; if (S[i] == 'p') dp[i][i][1] = 0; else if (S[i] == 'o') dp[i][i][2] = 0; else dp[i][i][3] = 0; } for (l = 1; l < N; l++) { for (i = 0; i < N - l; i++) { j = i + l; for (k = 0; k < 6; k++) { chmax(&(dp[i][j][k]), dp[i+1][j][k]); chmax(&(dp[i][j][k]), dp[i][j-1][k]); } if (S[i] == 'p') { chmax(&(dp[i][j][0]), dp[i+1][j][5] + 1); for (k = 0; k < 6; k++) chmax(&(dp[i][j][1]), dp[i+1][j][k]); chmax(&(dp[i][j][4]), dp[i+1][j][2]); } else if (S[i] == 'o') { chmax(&(dp[i][j][2]), dp[i+1][j][0]); chmax(&(dp[i][j][5]), dp[i+1][j][3]); } else { chmax(&(dp[i][j][3]), dp[i+1][j][0]); } if (S[j] == 'p') { chmax(&(dp[i][j][1]), dp[i][j-1][0]); } else if (S[j] == 'o') { chmax(&(dp[i][j][2]), dp[i][j-1][0]); chmax(&(dp[i][j][4]), dp[i][j-1][1]); } else { chmax(&(dp[i][j][0]), dp[i][j-1][4] + 1); for (k = 0; k < 6; k++) chmax(&(dp[i][j][3]), dp[i][j-1][k]); chmax(&(dp[i][j][5]), dp[i][j-1][2]); } } } for (i = 0; i < N - 1; i++) { for (k = 0, max[0] = 0, max[1] = 0; k < 6; k++) { chmax(&(max[0]), dp[0][i][k]); chmax(&(max[1]), dp[i+1][N-1][k]); } if (max[0] > 0 && max[1] > 0) chmax(&ans, max[0] + max[1] - 2); } printf("%d\n", ans); fflush(stdout); return 0; }