#include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x void choose_max(T &a, T b) { a = max(a, b); } int main(void) { string s; cin >> s; int n = s.size(); vector>>>> dp(n+1, vector>>>(22, vector>>(22, vector>(22, vector(22))))); dp[0][0][0][0][0] = 1; for(int i : range(n)) { for(int ck : range(21)) { for(int cu : range(ck+1)) { for(int cr : range(cu+1)) { for(int co : range(cr+1)) { if(!dp[i][ck][cu][cr][co]) { continue; } char c = s[i]; bool joker = c == '?'; choose_max(dp[i+1][ck+(c=='K'||joker)][cu][cr][co], dp[i][ck][cu][cr][co]); choose_max(dp[i+1][ck][cu+(c=='U'||joker)][cr][co], dp[i][ck][cu][cr][co]); choose_max(dp[i+1][ck][cu][cr+(c=='R'||joker)][co], dp[i][ck][cu][cr][co]); choose_max(dp[i+1][ck][cu][cr][co+(c=='O'||joker)], dp[i][ck][cu][cr][co]); if((c == 'I'||joker) && ck && cu && cr && co) { choose_max(dp[i+1][ck-1][cu-1][cr-1][co-1], char(dp[i][ck][cu][cr][co] + 1)); } } } } } } char res = 0; for(int i : range(n+1)) { for(int ck : range(21)) { for(int cu : range(ck+1)) { for(int cr : range(cu+1)) { for(int co : range(cr+1)) { choose_max(res, char(dp[i][ck][cu][cr][co] - 1)); } } } } } printf("%d\n", int(res)); return 0; }