#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int v, c; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int dp[101][51][34][26], _dp[101][51][34][26]; int main() { for (int k = 0; k <= 100; k++) for (int u = 0; u <= 50; u++) for (int r = 0; r <= 33; r++) for (int o = 0; o <= 25; o++) dp[k][u][r][o] = -1; dp[0][0][0][0] = 0; string S; cin >> S; for (int i = 0; i < S.length(); i++) { char c = S[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++) { if (dp[k][u][r][o] == -1) continue; if (c == 'K' || c == '?') _dp[k + 1][u][r][o] = max(_dp[k + 1][u][r][o], dp[k][u][r][o]); if ((c == 'U' || c == '?') && k >= 1) _dp[k - 1][u + 1][r][o] = max(_dp[k - 1][u + 1][r][o], dp[k][u][r][o]); if ((c == 'R' || c == '?') && u >= 1) _dp[k][u - 1][r + 1][o] = max(_dp[k][u - 1][r + 1][o], dp[k][u][r][o]); if ((c == 'O' || c == '?') && r >= 1) _dp[k][u][r - 1][o + 1] = max(_dp[k][u][r - 1][o + 1], dp[k][u][r][o]); if ((c == 'I' || c == '?') && o >= 1) _dp[k][u][r][o - 1] = max(_dp[k][u][r][o - 1], dp[k][u][r][o] + 1); } swap(dp, _dp); } int maxi = 0; for (int k = 0; k <= 100; k++) for (int u = 0; u <= 50; u++) for (int r = 0; r <= 33; r++) for (int o = 0; o <= 25; o++) maxi = max(maxi, dp[k][u][r][o]); cout << maxi << endl; }