#include #include #include #include #include int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); std::string s; std::cin >> s; std::stack wposStack; int minLen = std::numeric_limits::max(); for (std::string::size_type i = s.length() - 1; i != static_cast(-1); i--) { switch (s[i]) { case 'c': if (wposStack.size() > 1) { wposStack.pop(); minLen = std::min(minLen, static_cast(wposStack.top() - i + 1)); wposStack.pop(); } break; case 'w': wposStack.push(i); break; } } std::cout << (minLen == std::numeric_limits::max() ? -1 : minLen) << std::endl; return EXIT_SUCCESS; }