#define _CRT_SECURE_NO_WARNINGS // #define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; // #define int ll typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) begin(c), end(c) #define range(i,a,b) for(ll i=a; i ostream & operator << (ostream &os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, tuple const &t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator << (ostream &os, tuple const &t){ _ot<0>(os, t); return os; } template ostream & operator<<(ostream &os, pair const &p){ return os << "(" << p.first << ", " << p.second << ") "; } template ostream & operator<<(ostream &os, vector const &v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \ << " [" << __LINE__ << "]" << endl) #else #define dump(...) #endif void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); // #define endl '\n' } template size_t uniq(vector &v){ sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v.size(); } template size_t uniq(T *l, size_t n){ sort(l,l+n); return unique(l,l+n) - l; } #define mems(arr,val) memset(arr,val,sizeof(arr)); int const inf = numeric_limits::max()/8; char dp[21][21][21][21][21][101]; int n; string s; int rec(int k, int u, int r, int o, int i, int pos){ char c = s[pos]; dump(k,u,r,o,i, pos, s[pos]); dump((c == 'k' || c == '?')); char & res = dp[k][u][r][o][i][pos]; if(res != -1) return res; if(pos == n){ return res = 0; } dump("koko"); res = 0; if((c == 'k' || c == '?') && k != 0){ res = max(res, rec(k-1,u+1,r,o,i,pos+1)); } if((c == 'u' || c == '?') && u != 0){ res = max(res, rec(k,u-1,r+1,o,i,pos+1)); } if((c == 'r' || c == '?') && r != 0){ res = max(res, rec(k,u,r-1,o+1,i,pos+1)); } if((c == 'o' || c == '?') && o != 0){ res = max(res, rec(k,u,r,o-1,i+1,pos+1)); } if((c == 'i' || c == '?') && i != 0){ res = max(res, rec(k,u,r,o,i-1,pos+1)+1); } dump(k,u,r,o,i, pos); res = max(res, rec(k,u,r,o,i,pos+1)); return res; } int solve(){ memset(dp,-1,sizeof(dp)); string t; for(char c : s){ c = tolower(c); if(string("kuroi?").find(c) == string::npos) continue; t += c; } s = t; n = s.size(); int ans = rec(s.size()/5,0,0,0,0,0); return ans; } int main(){ while(cin >> s && s != "~") cout << solve() << endl; }