|
|||
Cellphone TypingA research team is developing a new technology to save time when typing text messages in mobile devices. They are working on a new model that has a complete keyboard, so users can type any single letter by pressing the corresponding key. In this way, a user needs P keystrokes to type a word of length P. However, this is not fast enough. The team is going to put together a dictionary of the common words that a user may type. The goal is to reduce the average number of keystrokes needed to type words that are in the dictionary. During the typing of a word, whenever the following letter is uniquely determined, the cellphone system will input it automatically, without the need for a keystroke. To be more precise, the behavior of the cellphone system will be determined by the following rules:
For instance, if the dictionary is composed of the words “ Your task is, given a dictionary, to calculate the average number of keystrokes needed to type a word in the dictionary with the new cellphone system. Input SpecificationThe input contains several test cases. Each test case is described using several lines. The first line contains an integer N, representing the number of words in the dictionary (1 ≤ N ≤ 105). Each of the next N lines contains a nonempty string of at most 80 lowercase letters from the English alphabet, representing a word in the dictionary. Within each test case, all words are different, and the sum of the lengths of all words is at most 106. Output SpecificationFor each test case, output a line with a rational number representing the average number of keystrokes needed to type a word in the dictionary. The result must be output as a rational number with exactly two digits after the decimal point, rounded if necessary. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |