Password Name Finder

Time limit1sMemory limit128 MB

Summary
Find the minimum set of 2 to 5 distinct girl names of length 3 to 8 whose pairwise concatenations reconstruct all given passwords.
Level

Medium6 of 10

Topics
String, Backtracking, Brute force
Solved
No attempts yet

Problem

Charlie is a skilled Internet user, and he proves it with the many email addresses he uses regularly. Each address is protected by a password. Because Charlie does not have a good memory, he invented a simple rule for making passwords that are easy to remember: each password is made by concatenating the names of two girls he secretly admires.

Charlie secretly admires at least two and at most five girls. Their names are all different, and each name consists of 3 to 8 lowercase English letters. Lucy knows Charlie's password rule and has found all of his passwords. Write a program that helps Lucy find the smallest possible set of names used to make the passwords.

Input

The first line contains an integer N, the number of passwords (1 ≤ N ≤ 100).

Each of the next N lines contains one password. A password is a string of at most 16 lowercase English letters from a to z.

Output

Print S, the minimum number of names that the passwords are made from, on the first line.

Then print the S names, one per line, in ascending lexicographic order.

The input is chosen so that the answer is unique.

Examples3

  1. Example 1

    Input
    2
    ivaana
    anaiva
    
    Expected output
    2
    ana
    iva
    
  2. Example 2

    Input
    3
    ananana
    nanahana
    hanaana
    
    Expected output
    3
    ana
    hana
    nana
    
  3. Example 3

    Input
    3
    nemikirk
    daglaskirk
    kirkdaglas
    
    Expected output
    3
    daglas
    kirk
    nemi