package main import ( "fmt" ) func main() { var a int fmt.Scan(&a) for i := 0; i < a; i++ { solve() } } var diff_p [1000000]int var diff_g [1000000]int var diff_pp [1000000]int func solve() { var s string fmt.Scanln(&s) s_len := len(s) cost := 100 p_cost := 0 // diff()を計算しておく // diff_p := make([]int, s_len) // diff_g := make([]int, s_len) // diff_p[] の値のi~ の最小値 // diff_pp := make([]int, s_len) diff_pp[s_len-6] = 100 for j := s_len-7; j >= 0; j-- { diff_p[j] = diff(s[j:j+7], "problem") diff_g[j] = diff(s[j:j+4], "good") diff_pp[j] = min(diff_p[j], diff_pp[j+1]) } // diff_p[]の値をi~の最小値に書き換える // for i := s_len - 8; i >= 0; i-- { // diff_p[i] = min(diff_p[i], diff_p[i+1]) // } for j := 0; j < s_len-10; j++ { if j >= 7 { //if s[j-7:j] == "problem" { if diff_p[j-7] == 0 { p_cost++ } } cost = min(cost, diff_g[j]+diff_pp[j+4]+p_cost) } fmt.Println(cost) // fmt.Println(diff_g) // fmt.Println(diff_p) // fmt.Println(diff_pp) 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 }