#include #include using namespace std; string s; unordered_map dp[101]; int answer = 0; int next(long KUROI, char c) { int k = KUROI & 31; int u = KUROI >> 5 & 31; int r = KUROI >> 10 & 31; int o = KUROI >> 15 & 31; int i = KUROI >> 20 & 31; if(c == 'K') { k = min(k + 1, s.size() / 5); } else if(c == 'U') { u = min(u + 1, k); } else if(c == 'R') { r = min(r + 1, u); } else if(c == 'O') { o = min(o + 1, r); } else if(c == 'I') { i = min(i + 1, o); } return k | (u << 5) | (r << 10) | (o << 15) | (i << 20); } void solve(int k, int KUROI) { if(KUROI == -1) return; if(k == s.size()) { answer = max(answer, (KUROI >> 20) & 31); return; } if(dp[k].count(KUROI)) return; switch(s[k]) { case 'K': case 'U': case 'R': case 'O': case 'I': solve(k + 1, next(KUROI, s[k])); return; case '?': for(int j = 0; j < 5; j++) { solve(k + 1, next(KUROI, "KUROI"[j])); } dp[k][KUROI] = 1; return; default: solve(k + 1, KUROI); return; } } int main() { cin >> s; solve(0, 0); cout << answer << endl; }