#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string s; int dp[102][25][25][25][25]; bool use[102][25][25][25][25]; int main() { cin >> s; int ans = 0; use[0][0][0][0][0] = true; for (int i = 0;i < s.size();i++) { for (int j = 0;j <= 20;j++) { for (int k = 0;k <= 20;k++) { for (int kk = 0;kk <= 20;kk++) { for (int kkk = 0;kkk <= 20;kkk++) { if (use[i][j][k][kk][kkk]) { // cout << j << " " << k << " " << kk << " " << kkk << endl; dp[i + 1][j][k][kk][kkk] = max(dp[i + 1][j][k][kk][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j][k][kk][kkk] = true; if (s[i] == 'K'||s[i]=='?') { if (j+ 1 <= 25) { dp[i + 1][j + 1][k][kk][kkk] = max(dp[i + 1][j + 1][k][kk][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j + 1][k][kk][kkk] = true; //continue; } } int mint = j; if (s[i] == 'U' || s[i] == '?') { if (min(mint,k + 1) <= 25) { dp[i + 1][j][min(mint,k+1)][kk][kkk] = max(dp[i + 1][j][min(mint,k+1)][kk][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j][min(mint,k + 1)][kk][kkk] = true; //continue; } } mint = min(mint, k); if (s[i] == 'R' || s[i] == '?') { if (kk + 1 <= 25) { dp[i + 1][j][k][min(mint,kk+1)][kkk] = max(dp[i + 1][j][k][min(kk+1,mint)][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j][k][min(mint,kk + 1)][kkk] = true; // continue; } } mint = min(mint, kk); if (s[i] == 'O' || s[i] == '?') { if (min(mint,kkk + 1) <= 25) { dp[i + 1][j][k][kk][min(mint,kkk+1)] = max(dp[i + 1][j][k][kk][min(mint,kkk+1)], dp[i][j][k][kk][kkk]); use[i + 1][j][k][kk][min(mint,kkk + 1)] = true; // continue; } } mint = min(mint, kkk); if (s[i] == 'I' || s[i] == '?') { if (j&&k&&kk&&kkk) { dp[i + 1][j-1][k-1][kk-1][kkk-1] = max(dp[i + 1][j-1][k-1][kk-1][kkk-1], dp[i][j][k][kk][kkk] + 1); ans = max(ans, dp[i + 1][j-1][k-1][kk-1][kkk-1]); use[i + 1][j-1][k-1][kk-1][kkk-1] = true; } } } } } } } } cout << ans << endl; return 0; }