#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define smax(x,y) (x)=max((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() string S, KUROI = "KUROI"; int N, dp[101][22][22][22][22]; int main(){ cin >> S; N = sz(S); MEM(dp, -1); dp[0][0][0][0][0] = 0; rep(cur, N){ auto f = [&](){ rep(k, 21)rep(u, 21)rep(r, 21)rep(o, 21){ int val = dp[cur][k][u][r][o]; if(val == -1)continue; if(S[cur] == 'K')smax(dp[cur + 1][k + 1][u][r][o], val); if(k && S[cur] == 'U')smax(dp[cur + 1][k - 1][u + 1][r][o], val); if(u && S[cur] == 'R')smax(dp[cur + 1][k][u - 1][r + 1][o], val); if(r && S[cur] == 'O')smax(dp[cur + 1][k][u][r - 1][o + 1], val); if(o && S[cur] == 'I')smax(dp[cur + 1][k][u][r][o - 1], val + 1); smax(dp[cur + 1][k][u][r][o], val); } }; if(S[cur] == '?'){ each(c, KUROI){ S[cur] = c; f(); } } else{ f(); } } int ans = 0; rep(k, 21)rep(u, 21)rep(r, 21)rep(o, 21)smax(ans, dp[N][k][u][r][o]); cout << ans << endl; }