#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define D int #define U unsigned using namespace std; D n, m,a, b, d, e; D i, j, k; char c,f; bool g, h; string s; D ans; char ta[] = { 'K','U','R','O','I' }; struct Ku { int n; int m; bool operator<(const Ku &obj)const { return m < obj.m; } }; int main() { Ku t; vector kuroi; auto it = kuroi.begin(); cin >> s; for (i = 0; i < s.size();i++) { auto x = s[i]; if (x == ta[0]) { t.n = i+1; t.m = 1; kuroi.push_back(t); x = ' '; } for (it = kuroi.begin(); it != kuroi.end(); it++) { if (ta[it->m]==x) { x = ' '; it->n = i+1; it->m++; if (it->m == 5) { ans++; kuroi.erase(it); } break; } } } sort(kuroi.begin(), kuroi.end()); reverse(kuroi.begin(), kuroi.end()); for (i = 0; i < s.size(); i++) { auto x = s[i]; if (x == '?') { g = false; for (it = kuroi.begin(); it != kuroi.end(); it++) { if (i>=it->n) { it->m++; if (it->m == 5) { ans++; kuroi.erase(it); } g = true; break; } } if (g == false) { t.n = 0; t.m = 1; kuroi.push_back(t); } } for (it = kuroi.begin(); it != kuroi.end(); it++) { if (ta[it->m] == x) { x = ' '; it->n = i + 1; it->m++; if (it->m == 5) { ans++; kuroi.erase(it); } break; } } } cout << ans << endl; }