P6758 [BalticOI 2013] Vim

Description

Given a string $S$ of length $N$, Victor’s goal is to delete all `e` characters in it, without deleting any other character. At the beginning, the cursor is at the first character. Victor uses `Vim` to solve this problem. However, Victor is not familiar with `Vim`. He only knows the following three commands: - `x`: Delete the character under the cursor. The cursor position does not change. This command cannot be used when the cursor is at the last character. - `h`: Move the cursor one position to the left. If the cursor is at the first position, it does not move. - `f`: Followed by a character $c$, it moves the cursor to the first character $c$ to its right, where $c\not =$ `e`. Compute the minimum number of **keystrokes** needed to delete all `e` characters, without deleting any other character.

Input Format

The first line contains an integer $N$. The next line contains a string $S$.

Output Format

Output a single integer, the minimum number of **keystrokes** needed to delete all `e` characters, without deleting any other character.

Explanation/Hint

#### Sample Explanation `fdhxhhxffhxfahxhhhxhhhxfdhxfghxfahhx` is an optimal solution. #### Constraints - For $50$ points, it is guaranteed that $N\le 500$. - For another $10$ points, it is guaranteed that $N\le 5\times 10^3$. - For $100\%$ of the testdata, it is guaranteed that $1\le N\le 7\times 10^4$, $S_i\in\{$ `a` $\sim$ `j` $\}$, $S_1,S_N\not=$ `e`. **Translator’s note: I really cannot figure out how it was set up, so I used Luogu’s default settings.** #### Notes This problem is translated from [Baltic Olympiad in Informatics 2013](https://boi.cses.fi/tasks.php) [Day 2](https://boi.cses.fi/files/boi2013_day2.pdf) T3 Vim. Translated by ChatGPT 5