#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; class Dinic { int MAX_V; int INF; struct edge{ int to, cap, rev, icap, flow; }; vector< vector > G; vector level; //sからの距離 vector iter; //どこまで調べたか void max_flow_bfs(int s){ fill(level.begin(), level.end(), -1); queue que; level[s] = 0; que.push(s); while(!que.empty()){ int v = que.front(); que.pop(); for(int i=0; i0 && level[e.to]<0){ level[e.to] = level[v] + 1; que.push(e.to); } } } } int max_flow_dfs(int v, int t, int f){ if(v==t) return f; for(int &i=iter[v]; i0 && level[v]0){ e.cap -= d; G[e.to][e.rev].cap += d; e.flow += d; return d; } } } return 0; } public: Dinic(int N):MAX_V(N),G(N),level(N),iter(N){ INF = 99999999; } void add_edge(int from, int to, int cap){ G[from].push_back((edge){to, cap, G[to].size(), cap, 0}); G[to].push_back((edge){from, 0, G[from].size()-1, 0, 0}); } int get_flow(int from, int to){ //untried rep(i,G[from].size()){ if(G[from][i].to == to){ return G[from][i].flow; } } return -1; } int max_flow(int s, int t){ int flow = 0; while(true){ max_flow_bfs(s); if(level[t]<0) return flow; fill(iter.begin(), iter.end(), 0); int f; while((f = max_flow_dfs(s, t, INF))>0){ flow += f; } } } int min_cut(int s, int t, vector& S, vector& T){ S.clear(); T.clear(); int maxf = max_flow(s, t); for(int i=0; i= 0) S.push_back(i); else T.push_back(i); } return maxf; } }; int main(){ ios::sync_with_stdio(false); string S; cin >> S; Dinic dinic(S.length()*5 + 2); int s = S.length()*5; int t = S.length()*5+1; rep(i,S.length()){ if(S[i] == 'K' || S[i] == '?'){ dinic.add_edge(s, i*5, 1); REP(j,i+1,S.length()){ if(S[j] == 'U' || S[j] == '?') dinic.add_edge(i*5, j*5+1, 1); } } if(S[i] == 'U' || S[i] == '?'){ REP(j,i+1,S.length()){ if(S[j] == 'R' || S[j] == '?') dinic.add_edge(i*5+1, j*5+2, 1); } } if(S[i] == 'R' || S[i] == '?'){ REP(j,i+1,S.length()){ if(S[j] == 'O' || S[j] == '?') dinic.add_edge(i*5+2, j*5+3, 1); } } if(S[i] == 'O' || S[i] == '?'){ REP(j,i+1,S.length()){ if(S[j] == 'I' || S[j] == '?') dinic.add_edge(i*5+3, j*5+4, 1); } } if(S[i] == 'I' || S[i] == '?'){ dinic.add_edge(i*5+4, t, 1); } } cout << dinic.max_flow(s,t) << endl; return 0; }