#include void chmax(int* a, int b) { if (*a < b) *a = b; } int count(char S[]) { int i, j, k, l, dp[2][501][501], q[2][250001][2], head, tail, cur, prev, tmp; for (l = 0; S[l] != 0; l++); for (i = 0; i <= l; i++) { for (j = 0; j <= l; j++) { dp[0][i][j] = -1; dp[1][i][j] = -1; } } dp[1][0][0] = 0; q[1][0][0] = 0; q[1][0][1] = 0; tail = 1; for (k = 0, cur = 0, prev = 1; k < l; k++, cur ^= 1, prev ^= 1) { for (head = tail - 1, tail = 0; head >= 0; head--) { i = q[prev][head][0]; j = q[prev][head][1]; tmp = dp[prev][i][j]; dp[prev][i][j] = -1; if (dp[cur][i][j] == -1) { q[cur][tail][0] = i; q[cur][tail++][1] = j; } chmax(&(dp[cur][i][j]), tmp); if (S[k] == 'p') { if (j == 0) { if (dp[cur][i+1][j] == -1) { q[cur][tail][0] = i + 1; q[cur][tail++][1] = j; } chmax(&(dp[cur][i+1][j]), tmp); } else if (j % 2 == 0) { if (dp[cur][i][j+1] == -1) { q[cur][tail][0] = i; q[cur][tail++][1] = j + 1; } chmax(&(dp[cur][i][j+1]), tmp); } } else if (S[k] == 'o') { if (i > 0 && j == 0) { if (dp[cur][i-1][j+2] == -1) { q[cur][tail][0] = i - 1; q[cur][tail++][1] = j + 2; } chmax(&(dp[cur][i-1][j+2]), tmp); } else if (j % 2 != 0) { if (dp[cur][i][j+1] == -1) { q[cur][tail][0] = i; q[cur][tail++][1] = j + 1; } chmax(&(dp[cur][i][j+1]), tmp); } } else { if (j > 0 && j % 2 == 0) { if (dp[cur][i][j-2] == -1) { q[cur][tail][0] = i; q[cur][tail++][1] = j - 2; } chmax(&(dp[cur][i][j-2]), tmp + 1); } } } } int ans = 0; for (head = 0; head < tail; head++) { i = q[prev][head][0]; j = q[prev][head][1]; chmax(&ans, dp[prev][i][j]); } return ans; } int main() { int N; char S[501]; scanf("%d", &N); scanf("%s", S); int i, j, k, ans = -1; char c; for (i = 3; i < N - 2; i++) { c = S[i]; S[i] = 0; j = count(S); S[i] = c; k = count(&(S[i])); if (j >= 1 && k >= 1) chmax(&ans, j + k - 2); } printf("%d\n", ans); fflush(stdout); return 0; }