#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int dp[110][21][21][21][21]; int main() { string S; cin >> S; int N = S.size(); memset(dp, -1, sizeof(dp)); dp[0][0][0][0][0] = 0; int ans = 0; for (int i = 0; i < N; ++i) { char ch = S[i]; if (i > 0) { memcpy(dp[i + 1], dp[i], sizeof(dp[i])); } for (int k = 0; k <= 20; ++k) { for (int u = 0; u <= 20; ++u) { for (int r = 0; r <= 20; ++r) { for (int o = 0; o <= 20; ++o) { int cnt = dp[i][o][r][u][k]; if (cnt < 0) continue; if ((ch == 'K' || ch == '?') && k < 20) { dp[i + 1][o][r][u][k + 1] = max(dp[i + 1][o][r][u][k + 1], cnt); } if ((ch == 'U' || ch == '?') && u < 20 && k > 0) { dp[i + 1][o][r][u + 1][k - 1] = max(dp[i + 1][o][r][u + 1][k - 1], cnt); } if ((ch == 'R' || ch == '?') && r < 20 && u > 0) { dp[i + 1][o][r + 1][u - 1][k] = max(dp[i + 1][o][r + 1][u - 1][k], cnt); } if ((ch == 'O' || ch == '?') && o < 20 && r > 0) { dp[i + 1][o + 1][r - 1][u][k] = max(dp[i + 1][o + 1][r - 1][u][k], cnt); } if ((ch == 'I' || ch == '?') && o > 0) { ans = max(ans, cnt + 1); dp[i + 1][o - 1][r][u][k] = max(dp[i + 1][o - 1][r][u][k], cnt + 1); } } } } } } cout << ans << endl; return 0; }