eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Ancient Scrolls

Ancient Scrolls

You bought \textbf{3} ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure. However, he also said, they were copied so many times by hand, so the string will contain some errors, though the length seems correct. Your job is to recover the original string from these strings. When nding the original string, you decided to use the following assumption. \begin{itemize} \item The copied string will contain at most \textbf{d} errors. In other words, the Hamming distance of the original string and the copied string is at most \textbf{d}. \item If there exist many candidates, the lexicographically minimum string is the original string. \end{itemize} Can you nd the orignal string? \InputFile The input contains a series of datasets. Each dataset has the following format: \textbf{l d} \textbf{str_1} \textbf{str_2} \textbf{str_3} The fi rst line contains two integers \textbf{l} (\textbf{1} ≤ \textbf{l} ≤ \textbf{100000}) and \textbf{d} (\textbf{0} ≤ \textbf{d} ≤ \textbf{5000}.) \textbf{l} describes the length of \textbf{3} given strings and \textbf{d} describes acceptable maximal Hamming distance. The following \textbf{3} lines have given strings, whose lengths are \textbf{l}. These \textbf{3} strings consist of only lower and upper case alphabets. The input ends with a line containing two zeros, which should not be processed. \OutputFile Print the lexicographically minimum satisfying the condition in a line. If there do not exist such strings, print "\textbf{-1}".
Ліміт часу 20 секунд
Ліміт використання пам'яті 256 MiB
Вхідні дані #1
3 1
ACM
IBM
ICM
5 2
iwzwz
iziwi
zwizi
1 0
A
B
C
10 5
jLRNlNyGWx
yyLnlyyGDA
yLRnvyyGDA
0 0
Вихідні дані #1
ICM
iwiwi
-1
AARAlNyGDA
Джерело JAG Practice Contest for ACM-ICPC Asia Regional 2012, AtCoder, 2012/11/04