問題一覧 > 通常問題

No.252 "Good Problem" (I Didn't Say It Was a Good Problem (2)

レベル : / AI推定難易度 : 1425 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 54
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 387 / 自分の提出
問題文最終更新日: 2026-06-25 04:14:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder 1周年記念 復習コンテスト R1 (順位表) の他の問題:

Problem Statement

When searching a string $S$ from the beginning, the string $S$ is called a good problem if the substring $\verb|good|$ and the substring $\verb|problem|$ are both found, and the position of the first $\verb|good|$ found is before the position of the first $\verb|problem|$ found.
You repeatedly perform the operation of rewriting $1$ character at any position in the string $S$ to one of $\verb|a|$ to $\verb|z|$.
Output the minimum number of operations required to make the string $S$ a good problem.
(Note: this problem may be easier to understand if you have solved the real good problem.)

Input

The $1$st line contains the number of test cases $T$.
$T$ test cases follow. Each test case consists of $1$ line containing the string $S$.

$|S| \geq 11$.
The string $S$ consists only of lowercase letters.
The sum of the lengths of the string $S$ over all test cases does not exceed $1000000 = 10^6$.

Output

Output the answer for each test case.

Sample

Sample 1
Input
3
veryverygoodproblem
goodexcellentproblems
problemgood
Output
0
0
10
Sample 2
Input
2
goodproblem
agdddekproblemsdl
Output
0
2
Sample 3
Input
9
geodaaaproblem
goodproblen
badendlessprobrem
podpdpprrobleem
problemgoodprobremgood
smallproblem
proproprefurohobbyhobby
gooeproblemd
itisproblemcoolgoodproblem
Output
1
1
4
5
2
4
8
1
1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。