fun main(arr:Array) { val inputCount = readLine()!!.toInt() (1..inputCount).forEach { println(getAns(readLine()!!)) } } fun getAns(input:String):Int { val listGood = mutableListOf() val listProbrem = mutableListOf() for(i in (0..input.length - 11)) { listGood.add(convCount("good", input.substring((i until i + 4)))) listProbrem.add(convCount("problem", input.substring(i + 4 until i + 11))) } for(i in (1..listGood.lastIndex)) { listGood[i] = Math.min(listGood[i], listGood[i - 1]) } for(i in (0..listProbrem.lastIndex - 1).reversed()) { listProbrem[i] = Math.min(listProbrem[i], listProbrem[i + 1]) } return listGood.indices.map { listGood[it] + listProbrem[it] }.min()!! } fun convCount(original:String, require:String):Int { val ans = original.withIndex().map { if(it.value == require[it.index]) 0 else 1 }.sum() return ans }