#include using namespace std; typedef pairP; typedef vectorVI; #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define maxv(a,b) (a)=max((a),(b)) string kuroi="KUROI"; string s; VI v; int dp[2][25][25][25][25]; int main(){ cin>>s; rep(i,s.size()){ int tmp=-1; rep(j,5)if(kuroi[j]==s[i])tmp=j; if(~tmp)v.pb(tmp); else if(s[i]=='?')v.pb(-1); } bool b=0; memset(dp,-1,sizeof(dp)); dp[0][0][0][0][0]=0; rep(x,v.size()){ rep(u,21)rep(r,21)rep(o,21)rep(i,21){ if(dp[b][u][r][o][i]==-1)continue; maxv(dp[!b][u][r][o][i],dp[b][u][r][o][i]); if(v[x]==0){ maxv(dp[!b][u+1][r][o][i],dp[b][u][r][o][i]); } else if(v[x]==1){ if(u)maxv(dp[!b][u-1][r+1][o][i],dp[b][u][r][o][i]); } else if(v[x]==2){ if(r)maxv(dp[!b][u][r-1][o+1][i],dp[b][u][r][o][i]); } else if(v[x]==3){ if(o)maxv(dp[!b][u][r][o-1][i+1],dp[b][u][r][o][i]); } else if(v[x]==4){ if(i)maxv(dp[!b][u][r][o][i-1],dp[b][u][r][o][i]+1); } else if(v[x]==-1){ maxv(dp[!b][u+1][r][o][i],dp[b][u][r][o][i]); if(u)maxv(dp[!b][u-1][r+1][o][i],dp[b][u][r][o][i]); if(r)maxv(dp[!b][u][r-1][o+1][i],dp[b][u][r][o][i]); if(o)maxv(dp[!b][u][r][o-1][i+1],dp[b][u][r][o][i]); if(i)maxv(dp[!b][u][r][o][i-1],dp[b][u][r][o][i]+1); } dp[b][u][r][o][i]=-1; } b=!b; } int ans=0; rep(u,21)rep(r,21)rep(o,21)rep(i,21)maxv(ans,dp[v.size()&1][u][r][o][i]); printf("%d\n",ans); return 0; }