#include #include #include #include #include #include #include #include #include #include using namespace std; //resize(vector, {v1,v2,v3}); void resize(int& val , vector::iterator itr){val = 0;} void resize(long long& val , vector::iterator itr){val = 0;} void resize(double& val , vector::iterator itr){val = 0;} template void resize(vector& vec, vector::iterator itr){ vec.resize(*itr); for(int i=0; i<*itr; i++){ resize(vec[i], itr+1); } } template void resize(T& vec, vector sz){ resize(vec, sz.begin()); } int main(){ string s; cin >> s; int n = s.size(); int m = n/5; vector>>>> dp; resize(dp, {m+1,m+1,m+1,m+1,m+1}); string kuroi = "KUROI?"; int check = 0; for(int i=0; i<5; i++){ check |= 1<<(kuroi[i]-'A'); } check = ~check; dp[0][0][0][0][0] = 1; for(int x=0; x>>>> dp_; resize(dp_, {m+1,m+1,m+1,m+1,m+1}); for(int k=0; k<=m; k++) for(int u=0; u<=k; u++) for(int r=0; r<=u; r++) for(int o=0; o<=r; o++) for(int i=0; i<=o; i++){ */ for(int k=m; k>=0; k--) for(int u=k; u>=0; u--) for(int r=u; r>=0; r--) for(int o=r; o>=0; o--) for(int i=o; i>=0; i--){ int& pos = dp[k][u][r][o][i]; if(pos==0) continue; pos = 0; if(s[x] == '?'){ dp[min(m,k+1)][u][r][o][i] = 1; dp[k][min(k,u+1)][r][o][i] = 1; dp[k][u][min(u,r+1)][o][i] = 1; dp[k][u][r][min(r,o+1)][i] = 1; dp[k][u][r][o][min(o,i+1)] = 1; }else if(s[x]=='K'){ dp[min(m,k+1)][u][r][o][i] = 1; }else if(s[x] == 'U'){ dp[k][min(k,u+1)][r][o][i] = 1; }else if(s[x] == 'R'){ dp[k][u][min(u,r+1)][o][i] = 1; }else if(s[x] == 'O'){ dp[k][u][r][min(r,o+1)][i] = 1; }else if(s[x] == 'I'){ dp[k][u][r][o][min(o,i+1)] = 1; } } //swap(dp, dp_); } int ans = 0; for(int k=0; k<=m; k++) for(int u=0; u<=k; u++) for(int r=0; r<=u; r++) for(int o=0; o<=r; o++) for(int i=0; i<=o; i++){ int& pos = dp[k][u][r][o][i]; if(pos==0) continue; ans = max(ans, i); } cout << ans << endl; return 0; }