PivotOJ

Garage Door Code

시간 제한: 4000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2024-2025BOJ 32669

문제

There have been an increasing number of laptop thefts in your area lately. After yours was recently stolen, too, you decided that you had enough and are 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 have decided to keep an eye on it to try to figure out how to get in. Over the course of the afternoon, you have seen a handful of people come, enter the garage, and then leave.

There's a security keypad on the door. As you have watched carefully, you have observed different people putting in the code, but they enter different numbers of digits. You figure out that some, maybe all, of them are pretending to intersperse additional key presses just to confuse anyone who might be watching them. You look up the keypad manufacturer's webpage and find that the keypad was designed to use codes with a predetermined length of KK digits. Given the set of observations you've made of different individuals "entering" elongated variations of the code (each does contain the correct code), can you determine what the correct code might be? %Or, instead of unique yes/no, what are possible codes (or how many are there) that would be consistent with your set of observations? It is guaranteed that there will always be at least one correct code that matches all observations. There may be multiple codes that match; you must find all matching codes.

입력

The first line of input contains two integers KK (3K63 \leq K \leq 6), the number of digits specified by the manufacturer for a correct code, and NN (2N202 \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.

출력

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, having sorted them in increasing lexicographic order.

예제

예제 1

입력
4 3
21302749
5230248
21076724
출력
1
2024

예제 2

입력
5 7
0812734225
162334559
7512334755
1002394561
9321423495
81237425
47126345119
출력
1
12345

예제 3

입력
3 3
1234
012345
11223344
출력
4
123
124
134
234
코드를 제출하려면 로그인하세요.