#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000007 int dp[2][22][22][22][22][22]; int main() { clr(dp,0); string s; cin>>s; string s1; rep(i,0,s.sz){ if(s[i]=='K'||s[i]=='U'||s[i]=='R'||s[i]=='O'||s[i]=='I'||s[i]=='?'){ s1 += s[i]; } } s = "I"+s1; dp[0][0][0][0][0][0] = 1; int old = 0; int now = 1; rep(j,1,s.sz){ rep(k,0,21){ rep(u,0,21){ if(u>k)continue; rep(r,0,21){ if(r>u)continue; rep(o,0,21){ if(o>r)continue; rep(i,0,21){ if(i>o)continue; if(dp[old][k][u][r][o][i]==0)continue; if(s[j]=='?'){ dp[now][min(20,k+1)][u][r][o][i] = dp[old][k][u][r][o][i]; dp[now][k][min(k,min(20,u+1))][r][o][i] = dp[old][k][u][r][o][i]; dp[now][k][u][min(u,min(20,r+1))][o][i] = dp[old][k][u][r][o][i]; dp[now][k][u][r][min(r,min(20,o+1))][i] = dp[old][k][u][r][o][i]; dp[now][k][u][r][o][min(o,min(20,i+1))] = dp[old][k][u][r][o][i]; } else if(s[j]=='K'){ dp[now][min(20,k+1)][u][r][o][i] = dp[old][k][u][r][o][i]; } else if(s[j]=='U'){ dp[now][k][min(k,min(20,u+1))][r][o][i] = dp[old][k][u][r][o][i]; } else if(s[j]=='R'){ dp[now][k][u][min(u,min(20,r+1))][o][i] = dp[old][k][u][r][o][i]; } else if(s[j]=='O'){ dp[now][k][u][r][min(r,min(20,o+1))][i] = dp[old][k][u][r][o][i]; } else if(s[j]=='I'){ dp[now][k][u][r][o][min(o,min(20,i+1))] = dp[old][k][u][r][o][i]; } } } } } } clr(dp[old],0); old = 1-old; now = 1-now; } int mx = 0; rep(k,0,21){ rep(u,0,21){ rep(r,0,21){ rep(o,0,21){ rep(i,0,21){ if(dp[old][k][u][r][o][i] > 0){ mx = max(mx,min(k,min(u,min(r,min(o,i))))); } } } } } } cout << mx << endl; return 0; }