P8243 [COCI 2013/2014 #3] REČENICE

Description

A long time ago, in a distant country where only math students lived, Iva and Vedran were discussing a special kind of sentence. In these sentences, exactly one word represents a number, and that number equals the total number of letters in the sentence. For example, `This sentence has thirtyone letters.` and `Blah Blah seventeen`. Jurica accidentally overheard his friends’ conversation and decided to impress them with the many special sentences he had memorized. He hurried home and wrote a program that, given a sentence, finds the smallest number that can be inserted to make the sentence special. Unfortunately, his computer broke, and now he needs your help. Write a program to help Jurica! Here are some additional notes: - The sentence has the form: $\textit{word}_1~\textit{word}_2~\textit{word}_3~\cdots~\textit{word}_{n-1}~\textit{word}_n$. Among these $n$ words, exactly one is `$`, which marks the place where the number word should be filled in. For example, `this sentence has thirtyone letters` would become `this sentence has $ letters`. - The words used to represent numbers follow these rules: - For all integers from $1$ to $19$, the words representing them in increasing order are `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight`, `nine`, `ten`, `eleven`, `twelve`, `thirteen`, `fourteen`, `fifteen`, `sixteen`, `seventeen`, `eighteen`, and `nineteen`. - For all multiples of ten from $20$ to $90$, the words representing them in increasing order are `twenty`, `thirty`, `forty`, `fifty`, `sixty`, `seventy`, `eighty`, `ninety`. - For all multiples of one hundred from $100$ to $900$, the words representing them in increasing order are `onehundred`, `twohundred`, `threehundred`, `fourhundred`, `fivehundred`, `sixhundred`, `sevenhundred`, `eighthundred`, `ninehundred`. - For all other two-digit numbers, first put the word for the largest multiple of ten not exceeding the number, then concatenate the word for the units digit. For example, the word for the integer $68$ is `sixtyeight`. - For all other three-digit numbers, first put the word for the largest multiple of one hundred not exceeding the number, then concatenate the word for the last two digits (following the previous rules). For example, the words for the integers $319,530,971$ are `threehundrednineteen`, `fivehundredthirty`, and `ninehundredseventyone`.

Input Format

The first line contains an integer $n$, the number of words in the sentence. Then follow $n$ lines, each containing a string, representing all the words of the sentence. It is guaranteed that `$` appears exactly once among them.

Output Format

Output one line with $n$ strings, representing the sentence after replacing `$` with the word for the smallest number that makes the sentence special.

Explanation/Hint

**[Explanation of Sample 2]** Fill `$` with the word `thirty`, which represents the integer $30$. Then the total number of letters in all words is $6+2+3+6+2+7+4=30$. **[Explanation of Sample 3]** Note that the sentence in this problem may not satisfy English grammar rules. **[Constraints]** **This problem uses bundled testdata**. The score and special limits of each subtask are as follows: - Subtask 1 (40 pts): the number represented by the word filled into `$` does not exceed $50$. - Subtask 2 (60 pts): no special limits. For all testdata, $1\leqslant n\leqslant 20$, and the number represented by the word filled into `$` is less than $1000$. **[Source]** This problem is from **_[COCI 2013-2014](https://hsin.hr/coci/archive/2013_2014/) [CONTEST 3](https://hsin.hr/coci/archive/2013_2014/contest3_tasks.pdf) T3 REČENICE_**, using the original data configuration, with a full score of $100$ points. Translated and organized by [Eason_AC](https://www.luogu.com.cn/user/112917). Translated by ChatGPT 5