#include #include #include #include #include #include #include using namespace std; #define MAX_N 101 #define MAX_M 21 int dp[MAX_N][MAX_M][MAX_M][MAX_M][MAX_M]; string str; void Input(){ cin >> str; for(int i = 0; i < str.length();){ if(str[i] == 'K' || str[i] == 'U' || str[i] == 'R' || str[i] == 'O' || str[i] == 'I' || str[i] == '?'){ i++; } else{ str.erase(i, 1); } } } int Solve(){ memset(dp, -1, sizeof(dp)); int ret = 0; dp[0][0][0][0][0] = 0; for(int i = 0; i < str.length(); i++){ for(int k = 0; k < MAX_M; k++){ for(int u = 0; u < MAX_M; u++){ for(int r = 0; r < MAX_M; r++){ for(int o = 0; o < MAX_M; o++){ if(dp[i][k][u][r][o] == -1) continue; dp[i+1][k][u][r][o] = max(dp[i+1][k][u][r][o], dp[i][k][u][r][o]); if(str[i] == 'K' || str[i] == '?'){ if(k + 1 < MAX_M){ dp[i+1][k+1][u][r][o] = max(dp[i+1][k+1][u][r][o], dp[i][k][u][r][o]); } } if(str[i] == 'U' || str[i] == '?'){ if(u + 1 < MAX_M){ dp[i+1][k][u+1][r][o] = max(dp[i+1][k][u+1][r][o], dp[i][k][u][r][o]); } } if(str[i] == 'R' || str[i] == '?'){ if(r + 1 < MAX_M){ dp[i+1][k][u][r+1][o] = max(dp[i+1][k][u][r+1][o], dp[i][k][u][r][o]); } } if(str[i] == 'O' || str[i] == '?'){ if(o + 1 < MAX_M){ dp[i+1][k][u][r][o+1] = max(dp[i+1][k][u][r][o+1], dp[i][k][u][r][o]); } } if(str[i] == 'I' || str[i] == '?'){ if(k >= 1 && u >= 1 && r >= 1 && o >= 1){ dp[i+1][k-1][u-1][r-1][o-1] = dp[i][k][u][r][o] + 1; } } } } } } } for(int k = 0; k < MAX_M; k++){ for(int u = 0; u < MAX_M; u++){ for(int r = 0; r < MAX_M; r++){ for(int o = 0; o < MAX_M; o++){ ret = max(ret, dp[str.length()][k][u][r][o]); } } } } return ret; } int main(){ Input(); cout << Solve() << endl; return 0; }