Under construction

Still being built. Things may change

Garage Door Code

Interview

Time limit4sMemory limit1024 MB

Summary
Find every K-digit code that appears as a subsequence of each observed keypad entry, and print them in sorted order.
Level

Easy3 of 10

Topics
Brute force, String matching, Implementation
Solved
No attempts yet

Problem

There have been an increasing number of laptop thefts in your area lately. After yours was recently stolen too, you decided you had had enough and were going to do something about it. After asking around, you heard some rumors about where the stolen laptops have been hidden, and you want to get your laptop back.

The rumors led you to a particular garage, and you decided to keep an eye on it to figure out how to get in. Over the course of the afternoon, you saw a handful of people come, enter the garage, and then leave.

There is a security keypad on the door. As you watched carefully, you noticed different people entering different numbers of digits. Some, maybe all, of them seem to be pretending to intersperse extra key presses just to confuse anyone watching them. The keypad manufacturer's webpage says the keypad was designed to use codes with a predetermined length of KK digits. Given NN observations of different individuals entering elongated variations of the code (each one contains the correct code), can you determine what the correct code is? It is guaranteed that at least one correct code matches all observations. There may be more than one matching code, and you must find all of them.

Input

The first line of input contains two integers KK (3≤K≤63 \leq K \leq 6), the number of digits specified by the manufacturer for a correct code, and NN (2≤N≤202 \leq N \leq 20), the number of elongated entry code sequences that you observed.

Each of the next NN lines contains a string of at least KK and at most 12 digits (0-9). These are the elongated entry code sequences that you have observed.

Output

Determine all KK-digit codes that match the full set of elongated observations.

On the first line, output MM, the number of codes that match the set of elongated observations. Then output MM lines, each containing one of these matching codes, sorted in increasing lexicographic order.

Examples3

  1. Example 1

    Input
    4 3
    21302749
    5230248
    21076724
    
    Expected output
    1
    2024
    
  2. Example 2

    Input
    5 7
    0812734225
    162334559
    7512334755
    1002394561
    9321423495
    81237425
    47126345119
    
    Expected output
    1
    12345
    
  3. Example 3

    Input
    3 3
    1234
    012345
    11223344
    
    Expected output
    4
    123
    124
    134
    234