#include #include using namespace std; bool useable(char c, char required) { return (c == required || c == '?'); } void update(int &a, int b){ if(b > a)a = b; } int dp[2][21][21][21][21]; int main() { string S; cin >> S; int crr = 0, nxt = 1; memset(dp[crr], -1, sizeof(dp[crr])); dp[crr][0][0][0][0] = 0; for(char c : S) { memset(dp[nxt], -1, sizeof(dp[nxt])); for(int K=0;K<=20;K++) for(int U=0;U<=K;U++) for(int R=0;R<=U;R++) for(int O=0;O<=R;O++){ int now = dp[crr][K][U][R][O]; if(now == -1) continue; update(dp[nxt][K][U][R][O], now); if(useable(c, 'K') && K + 1 <= 20) update(dp[nxt][K+1][U][R][O], now); if(useable(c, 'U') && U + 1 <= K) update(dp[nxt][K][U+1][R][O], now); if(useable(c, 'R') && R + 1 <= U) update(dp[nxt][K][U][R+1][O], now); if(useable(c, 'O') && O + 1 <= R) update(dp[nxt][K][U][R][O+1], now); if(useable(c, 'I') && now + 1 <= O) update(dp[nxt][K][U][R][O], now + 1); } swap(crr, nxt); } int res = 0; for(int K=0;K<=20;K++) for(int U=0;U<=K;U++) for(int R=0;R<=U;R++) for(int O=0;O<=R;O++){ res = max(res, dp[crr][K][U][R][O]); } cout << res << endl; return 0; }