#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 countt = 0; for (int i = 0;i < s.size();i++) { if (s[i] == '?') { countt++; } } if (countt == 0) { return 1; } 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; } } if (s[i] == 'U' || s[i] == '?') { if (k + 1 <= 25) { dp[i + 1][j][k+1][kk][kkk] = max(dp[i + 1][j][k+1][kk][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j][k + 1][kk][kkk] = true; //continue; } } if (s[i] == 'R' || s[i] == '?') { if (kk + 1 <= 25) { dp[i + 1][j][k][kk+1][kkk] = max(dp[i + 1][j][k][kk+1][kkk], dp[i][j][k][kk][kkk]); use[i + 1][j][k][kk + 1][kkk] = true; // continue; } } if (s[i] == 'O' || s[i] == '?') { if (kkk + 1 <= 25) { dp[i + 1][j][k][kk][kkk+1] = max(dp[i + 1][j][k][kk][kkk+1], dp[i][j][k][kk][kkk]); use[i + 1][j][k][kk][kkk + 1] = true; // continue; } } 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; }