import sys sys.setrecursionlimit(10 ** 6) from bisect import * from collections import * from heapq import * int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline()[:-1] def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] def main(): inf = 10 ** 9 n = II() for _ in range(n): s = SI() n = len(s) # 各位置でのproblemとの変更回数を求める cntp = [inf] * n for i in range(n - 6): ch = 0 for c0, c1 in zip("problem", s[i:i + 7]): if c0 != c1: ch += 1 cntp[i] = ch #print(cntp) # 左から何個のproblemがあるか数えておく zero = 0 cnt_zero = [0] * n for i in range(n): if cntp[i] == 0: zero += 1 cnt_zero[i] = zero #print(cnt_zero) # ある位置から右を見たときのproblemの変更最小値 for i in range(n - 1, 0, -1): if cntp[i] < cntp[i - 1]: cntp[i - 1] = cntp[i] #print(cntp) # 各位置にgoodの先頭を持って行ったときの変更回数を求め、最小値を求める ans=inf for i in range(n - 10): ch = 0 for c0, c1 in zip("good", s[i:i + 4]): if c0 != c1: ch += 1 cur=ch+cntp[i+4]+(cnt_zero[i-7] if i>=7 else 0) if cur