Multidimensional Hangman

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

The Multidimensional Hangman Game has very peculiar rules. In a way, it is like you are playing several games of the traditional Hangman game at the same time, with the difference that the words don’t have to exist in the dictionary. If you’ve never played Hangman, don’t worry: all the information you need is below.

In the multidimensional version of the game, there are several words on a board, initially unknown, all of the same length. At each turn in the game, you discover some characters from certain word positions (how these characters were discovered is not important for this problem). At a certain point, when only one unknown character remains in each word on the board, the game goes into the all or nothing phase. At this point, you must choose a word that maximizes the number of compatibilities with the words on the board. For a chosen word PP, we say it is compatible with a word TT on the board if all known letters in TT occur in exactly the same positions in PP.

Given the known information about the words on the board, you must determine which word to choose for all or nothing phase, which maximizes the number of compatibilities. If there is more than one solution, print the lexicographically smallest. We say that a word PP is lexicographically smaller than a word QQ if P_i<Q_iP\_i < Q\_i where P_iP\_i is the ii-th character of PP, Q_iQ\_i is the ii-th character of QQ and ii is the smallest index such that P_iQ_iP\_i \ne Q\_i.

입력

The first line of the input contains two integers NN and CC satisfying 1N1041 ≤ N ≤ 10^4 and 1C121 ≤ C ≤ 12, indicating the number of words on the board and the length of the words it contains. Each of the next NN lines contains a word of length CC composed only of characters from “a” to “z” except for one of its positions, which will contain a character “*” , indicating that the character at that position is still unknown.

출력

Print a single line, containing, in order, a word TT, of length CC, and an integer MM, such that MM is the greatest number of compatibilities a word might have with the input words and TT is the lexicographically smallest amongst the words with compatibility MM.