Patterns P94030


Statement
 

pdf   zip

thehtml

In this problem, we will say that a pattern is a string made up of lowercase letters and symbols ‘?’, such as “??me”. Each instance of ‘?’ must be replaced by exactly one lowercase letter. We say that a string matches a pattern if we can transform the pattern into the string by replacing the question marks by the appropriate letters. For instance, “same”, “some” and “home” all match the pattern “??me”.

Given several words, can you find a pattern matched by all the words? This pattern should contain the minimum number of ‘?’.

Input

Input consists of several cases. Each case starts with n, followed by n words, all of the same length, which will be between 1 and 1000. You can assume 1 ≤ n ≤ 1000, and that the words only consist of lowercase letters.

Output

For every case, print a pattern with the least amount of ‘?’ which is matched by all the words. If there is more than one answer, print “I should rethink this problem.”.

Public test cases
  • Input

    3 same some home
    2 cat gas
    2 hello hello
    2 xyz abc
    

    Output

    ??me
    ?a?
    hello
    ???
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++