#include #include const std::string G = "good", P = "problem"; std::string S; int L; int cost(int index, int offset, const std::string& s){ if(index+offset < 0 || index+offset+s.size() > L){return 1001001001;} int res = 0; for(int i=0;i= L){return 1001001001;} int res = cost(index, -(P.size()+1), P); for(int i=index;i= index){ // printf("%d, %d, %d: %d\n", index, i, j, cost(i, -j, P)); res = std::min(res, cost(i, -j, P)); } } } return res; } int solve(int index){ int res; if(S[index] == 'g'){ res = cost(index, 0, G) + solve2(index + 4); }else if(S[index] == 'o'){ res = std::min(cost(index, -1, G) + solve2(index + 3), cost(index, -2, G) + solve2(index + 2)); // printf("%d: %d, %d\n", index, solve2(index + 3), solve2(index + 2)); }else if(S[index] == 'd'){ res = cost(index, -3, G) + solve2(index + 1); }else{ res = cost(index, -3, G) + solve2(index + 1); } return res; } int main(){ int N; std::cin >> N; while(N--){ std::cin >> S; L = S.size(); int res = 1001001001; for(int i=0;i