#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<> #define rev(x) reverse(x); using ll=long long; using vl=vector; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[9]={0,1,-1,0,1,1,-1,-1,0}; const ll dx[9]={1,0,0,-1,1,-1,1,-1,0}; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } string t="KUROI?"; int main(){ string s;cin >> s; string ns; rep(i,s.size()){ rep(j,6)if(s[i]==t[j])ns+=s[i]; } s=ns; ll dp[21][21][21][21]; memset(dp,-inf,sizeof(dp));dp[0][0][0][0]=0; rep(i,s.size()){ ll ndp[21][21][21][21]; memset(ndp,-inf,sizeof(ndp)); rep(a,21)rep(b,21)rep(c,21)rep(d,21){ chmax(ndp[a][b][c][d],dp[a][b][c][d]); if(s[i]=='K'||s[i]=='?'){ if(a+1<=20)chmax(ndp[a+1][b][c][d],dp[a][b][c][d]); } if(s[i]=='U'||s[i]=='?'){ if(b+1<=20&&a>=1)chmax(ndp[a-1][b+1][c][d],dp[a][b][c][d]); } if(s[i]=='R'||s[i]=='?'){ if(c+1<=20&&b>=1)chmax(ndp[a][b-1][c+1][d],dp[a][b][c][d]); } if(s[i]=='O'||s[i]=='?'){ if(d+1<=20&&c>=1)chmax(ndp[a][b][c-1][d+1],dp[a][b][c][d]); } if(s[i]=='I'||s[i]=='?'){ if(d>=1)chmax(ndp[a][b][c][d-1],dp[a][b][c][d]+1); } } swap(dp,ndp); } ll ans=0; rep(a,21)rep(b,21)rep(c,21)rep(d,21)chmax(ans,dp[a][b][c][d]); cout << ans << endl; }