#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) #define indexOf(v,x) (find(all(v),x)-v.begin()) int dp[2][22][22][22][22]; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int (*cur)[22][22][22],(*nxt)[22][22][22]; cur = dp[0]; nxt = dp[1]; memset(cur, -1, sizeof(dp[0])); cur[0][0][0][0] = 0; rep(i,s.size()) { memset(nxt,-1,sizeof(dp[0])); rep(d,21)rep(c, 21)rep(b, 21)rep(a, 21) { int v = cur[d][c][b][a]; if (v == -1)continue; nxt[d][c][b][a] = max(nxt[d][c][b][a], v); if (s[i] == 'K' || s[i] == '?') nxt[d][c][b][a + 1] = max(nxt[d][c][b][a + 1], v); if ((s[i] == 'U' || s[i] == '?') && a) nxt[d][c][b + 1][a - 1] = max(nxt[d][c][b + 1][a - 1], v); if ((s[i] == 'R' || s[i] == '?') && b) nxt[d][c + 1][b - 1][a] = max(nxt[d][c + 1][b - 1][a], v); if ((s[i] == 'O' || s[i] == '?') && c) nxt[d + 1][c - 1][b][a] = max(nxt[d + 1][c - 1][b][a], v); if ((s[i] == 'I' || s[i] == '?') && d) nxt[d - 1][c][b][a] = max(nxt[d - 1][c][b][a], v + 1); } swap(cur, nxt); } cout << *max_element((int*)cur[0], (int*)cur[22]) << endl; return 0; }