Type printer#274

Type printer

4 seconds
64 megabytes
Medium

You need to print words on a movable type printer. Movable type printers are those old printers that require you to place small metal pieces (each containing a letter) in order to form words. A piece of paper is then pressed against them to print the word. The printer you have allows you to do any of the following operations:

  1. Add a letter to the end of the word currently in the printer.

  2. Remove the last letter from the end of the word currently in the printer. You are only allowed to do this if there is at least one letter currently in the printer.

  3. Print the word currently in the printer.

Initially, the printer is empty; it contains no metal pieces with letters. At the end of printing, you are allowed to leave some letters in the printer. Also, you are allowed to print the words in any order you like. As every operation requires time, you want to minimize the total number of operations. You must write a program that, given the words you want to print, finds the minimum number of operations needed to print all the words in any order, and outputs one such sequence of operations. 1 \leq N \leq 25000 (number of words to print).

Input

Your program must read from the standard input the following data:

  1. The first line contains the integer , the number of words to print.

  2. Each of the next lines contains a word. Each word consists only of lowercase Latin letters ( – ) and its length is from to characters, inclusive.

All words are distinct.

Output

Your program must write to the standard output the following data:

  1. The first line must contain an integer , representing the minimum number of operations required to print all words.

  2. Each of the next lines must contain one character, describing the sequence of performed operations. Each operation is described as follows:

    1. Adding a letter is represented by the lowercase letter itself.

    2. Removing the last letter is represented by the character (minus, ASCII code ).

    3. Printing the current word is represented by the character (uppercase Latin letter ).

Examples

Example 1

Loading
Loading