#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' }; int main() { cin >> s; vector p[6]; for (i = 0; i < 20; i++) { p[0].push_back(0); } i = 0; for (auto &x : s) { for (j = 4; j >= 0; j--) { if (!p[j].empty()&&x==ta[j]) { x = ' '; p[j].pop_back(); p[j + 1].push_back(i); break; } } i++; } i = 0; for (auto x : s) { if (x == '?') { for (j = 4; j >= 0; j--) { auto it = p[j].begin(); for (auto y : p[j]) { if (i < y) break; it++; } if (it!=p[j].begin()) { it--; p[j].erase(it); auto it2 = p[j + 1].begin(); for (auto y : p[j+1]) { if (i < y) break; it2++; } p[j + 1].insert(it2,i); break; } } } for (j = 4; j >= 0; j--) { if (!p[j].empty() && x == ta[j]) { p[j].pop_back(); p[j + 1].push_back(i); break; } } i++; } cout << p[5].size() << endl; }