package main import ( "fmt" ) func main() { var a int fmt.Scan(&a) for i := 0; i < a; i++ { solve() } } // diff() var diff_p [1000000]int var diff_g [1000000]int // diff_p[] の値のi~ の最小値 var diff_pp [1000000]int func solve() { var s string fmt.Scanln(&s) s_len := len(s) cost := 100 p_cost := 0 diff_pp[s_len-6] = 100 for j := s_len-7; j >= 0; j-- { // diff_p[j] = diff(s[j:j+7], "problem") diff_p[j] = diff_problem(s[j:j+7]) // diff_g[j] = diff(s[j:j+4], "good") diff_g[j] = diff_good(s[j:j+4]) diff_pp[j] = min(diff_p[j], diff_pp[j+1]) } for j := 0; j < s_len-10; j++ { if j >= 7 { if diff_p[j-7] == 0 { p_cost++ } } cost = min(cost, diff_g[j]+diff_pp[j+4]+p_cost) } fmt.Println(cost) return } func min(x, y int) int { if x > y { return y } return x } func diff(s1, s2 string) int { c := 0 for i := 0; i < len(s1); i++ { if s1[i] != s2[i] { c++ } } return c } func diff_problem(s string) int{ c := 0 for i:=0; i<7; i++{ if s[i] != "problem"[i]{ c++ } } return c } func diff_good(s string) int{ c := 0 for i:=0; i<4; i++{ if s[i] != "good"[i]{ c++ } } return c }