#P6758. [BalticOI 2013] Vim

[BalticOI 2013] Vim

Problem Description

Given a string SS of length NN, 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 cc, it moves the cursor to the first character cc to its right, where cc\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 NN.

The next line contains a string SS.

Output Format

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

35
chefeddiefedjeffeachbigagedegghehad
36

Hint

Sample Explanation

fdhxhhxffhxfahxhhhxhhhxfdhxfghxfahhx is an optimal solution.

Constraints

  • For 5050 points, it is guaranteed that N500N\le 500.
  • For another 1010 points, it is guaranteed that N5×103N\le 5\times 10^3.
  • For 100%100\% of the testdata, it is guaranteed that 1N7×1041\le N\le 7\times 10^4, Si{S_i\in\{ a \sim j }\}, S1,SNS_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 Day 2 T3 Vim.

Translated by ChatGPT 5