#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int dp[105][21][21][21][21]; int main(){ ios::sync_with_stdio(false); string S; cin >> S; rep(i,105) rep(a,21) rep(b,21) rep(c,21) rep(d,21) dp[i][a][b][c][d] = -1; int ret = 0; dp[0][0][0][0][0] = 0; rep(i,S.length()){ rep(a,21) rep(b,21) rep(c,21) rep(d,21){ int v = dp[i][a][b][c][d]; if(v < 0) continue; //cout << i << " " << a << " " << b << " " << c << " " << d << " " << v << endl; dp[i+1][a][b][c][d] = max(dp[i+1][a][b][c][d], dp[i][a][b][c][d]); /* if(S[i] == 'K' || S[i] == '?') if(a<20) dp[i+1][a+1][b][c][d] = max(dp[i+1][a+1][b][c][d], v); if(S[i] == 'U' || S[i] == '?') if(b<20 && a>0) dp[i+1][a-1][b+1][c][d] = max(dp[i+1][a-1][b+1][c][d], v); if(S[i] == 'R' || S[i] == '?') if(c<20 && b>0) dp[i+1][a][b-1][c+1][d] = max(dp[i+1][a][b-1][c+1][d], v); if(S[i] == 'O' || S[i] == '?') if(d<20 && c>0) dp[i+1][a][b][c-1][d+1] = max(dp[i+1][a][b][c-1][d+1], v); if(S[i] == 'I' || S[i] == '?') if(d>0){ ret = max(ret, v+1); dp[i+1][a][b][c][d-1] = max(dp[i+1][a][b][c][d-1], v+1); } */ if(S[i] == 'K' || S[i] == '?') if(a<20) dp[i+1][a+1][b][c][d] = max(dp[i+1][a+1][b][c][d], v); if(S[i] == 'U' || S[i] == '?') if(b<20 && a>0) dp[i+1][a][b+1][c][d] = max(dp[i+1][a][b+1][c][d], v); if(S[i] == 'R' || S[i] == '?') if(c<20 && a>0 && b>0) dp[i+1][a][b][c+1][d] = max(dp[i+1][a][b][c+1][d], v); if(S[i] == 'O' || S[i] == '?') if(d<20 && a>0 && b>0 && c>0) dp[i+1][a][b][c][d+1] = max(dp[i+1][a][b][c][d+1], v); if(S[i] == 'I' || S[i] == '?') if(a>0 && b>0 && c>0 && d>0){ ret = max(ret, v+1); dp[i+1][a-1][b-1][c-1][d-1] = max(dp[i+1][a-1][b-1][c-1][d-1], v+1); } } } cout << ret << endl; return 0; }