George Takei is busy writing a new screenplay. He wishes to finish it in time for April 20, a very significant day for him. While he has finished the rough draft, it is too full of errors to use. Help him correct it before the deadline! George knows that you can't fix everything, but you can at least help him trim his draft a little.
The only words the script should contain are variations on the phrase ohmy
. Some letters may be duplicated, but this is okay as long as they are still in order (George needs to have good inflection, after all), so the phrases ooohhhhmmmyyyy
and oooooooooooooooooooohmy
, for example, are also valid ohmy
phrases. Your task is to remove the minimum possible amount of letters needed to produce a screenplay with the maximum possible number of ohmy
phrases. Additionally, every character in the screenplay must be a valid part of one of these phrases.
Input Specification
The first line of input is , the number of characters in the screenplay. The second line of input contains the text of the screenplay in lowercase. There are no spaces.
Output Specification
An ohmy
phrase, where the number of h
's is the maximum possible number of ohmy
phrases in the screenplay, and the number of y
's is the minimum number of characters that must be removed. Note that an ohmy
phrase must have a positive integer for the number of each letter. If 0 deletions are needed or there are 0 ohmy
phrases in the screenplay, omit the corresponding letter in your output, but know that your output is not an actual ohmy
phrase.
Sample Input 1
25
ohmyohhhhhmyyyhohmyohqqmy
Sample Output 1
ohhhhmyyy
Explanation of Sample Output 1
The sample input contains three errors:
ohmyohhhhhmyyyhohmyohqqmy
With these errors removed, the phrase becomes:
ohmyohhhhhmyyyohmyohmy
Which separates into four ohmy
phrases:
ohmy-ohhhhhmyyy-ohmy-ohmy
Sample Input 2
22
ohhhhhhhhhohmymyohmymy
Sample Output 2
ohhmyyy
Explanation of Sample Output 2
The maximum number of ohmy
phrases this screenplay could contain is two, so two h
's are outputted. The best way to create a valid screenplay is by deleting three characters:
ohhhhhhhhhohmymyohmymy
Leaving:
ohhhhhhhhhhmyyohmmy
Which separates into two ohmy
phrases:
ohhhhhhhhhhmyy-ohmmy
Comments
The test cases have been updated. Good thing the contest wasn't rated. Thanks for the heads up Fatal
I noticed someone's code had a comment,
Actually, the opposite is true. The number of ohmys must be maximized first.
Should I remove 3 characters to get 1 phrase, or 8 characters to get 2 phrases?
Should the answer be "ohhmyyy"? (max phrases + min characters removed)
Maximize the number of phrases, then find minimal deletions to get to that maximum phrase.