No.996 Phnom Penh
タグ : / 解いたユーザー数 34
作問者 :
ganmodokix
/ テスター :
monkukui2
Problem Statement
You are given a string $S$. You may perform the following operations on this string any number of times, in any order.
- Operation 1: Choose one occurrence of "phnom" contained in $S$ as a contiguous substring, and replace it with "penh".
- Operation 2: Erase all "h" contained in $S$, and then replace all "e" with "h".
However, if the string would not change between before and after an operation, that operation cannot be performed.
Find the maximum number of operations you can perform on the string $S$.
Input
$S$
The input also satisfies the following constraints.
- $S$ is a string consisting only of lowercase English letters
- $1 \le |S| \le 2 \times 10^5$
Output
Print the maximum number of operations, followed by a newline.
Sample
Sample 1
Input
phnompenh
Output
3
The maximum number of operations, $3$, can be achieved by operating as follows.
- Operation 1. "phnompenh"$\to$"penhpenh"
- Operation 2. "penhpenh"$\to$"phnphn"
- Operation 2. "phnphn"$\to$"pnpn"
Sample 2
Input
phnomom
Output
5
The maximum number of operations, $5$, can be achieved by operating as follows.
- Operation 1. "phnomom"$\to$"penhom"
- Operation 2. "penhom"$\to$"phnom"
- Operation 1. "phnom"$\to$"penh"
- Operation 2. "penh"$\to$"phn"
- Operation 2. "phn"$\to$"pn"
Sample 3
Input
pepenhomom
Output
6
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。