問題一覧 > 通常問題

No.1542 Pon Pon Pon, Pon Pon Pon Pon, Pon Pon Pon

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 21
作問者 : ゅゅ / テスター : 57tggx そすうぽよ logx 👑 qand Re_menal2 とりゐ pepper_aobuta
お気に入りにしたユーザー ProblemId : 6504 / 自分の提出
問題文最終更新日: 2021-06-06 18:54:56
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
ゅゅちゃんお誕生日コンテスト (順位表) の他の問題:

Problem Statement

There is a string $S$, which is initially ponpon. The following operation, choosing one of the 2 options below, was repeated 0 or more times on $S$.

  1. Insert pon.
  2. Insert any 1 character among p, o, n.
Here, "insert" also includes adding to the beginning or the end.

Given $S$ after the operations, find the maximum possible number of times operation 1. was performed.

However, if $S$ cannot be obtained by repeating operations 1. and 2., print -1.

Input

$N$
$S$

  • $1 \leqq N \leqq 500$
  • The length of the string $S$ is $N$
  • The string $S$ is guaranteed to consist only of the 3 kinds of characters p, o, n.

Output

Print a newline at the end.

Sample

Sample 1
Input
9
ponpponon
Output
1

pon is inserted once after the p at the 4th character.

Sample 2
Input
9
pponoponn
Output
0

Only operation 2. was performed.

Sample 3
Input
12
pppoponnonon
Output
-1

If the string cannot be obtained by performing operations 1. and 2. on ponpon, print -1.

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