This page is still under construction.

Parts of this page are still being built. What you see may change.

(ℓ, d) pattern

Time limit2sMemory limit512 MB

Summary
Find the unique length-l lowercase string within Hamming distance d of some substring in every given string.
Level

Medium6 of 10

Topics
Brute force, String matching
Solved
No attempts yet

Problem

You are given kk strings S1,S2,…,SkS_1, S_2, \dots, S_k. Every character in them is a space or one of the 26 lowercase letters a to z.

For two constants ℓ\ell and dd, compute an (ℓ,d)(\ell, d)-pattern of this set of strings. An (ℓ,d)(\ell, d)-pattern is a string W=W[1]W[2]⋯W[ℓ]W = W[1]W[2] \cdots W[\ell] of length ℓ\ell that satisfies the following property.

  • For every i=1,2,…,ki = 1, 2, \dots, k, the string SiS_i contains at least one substring X=X[1]X[2]⋯X[ℓ]X = X[1]X[2] \cdots X[\ell] of length ℓ\ell whose Hamming distance from WW is at most dd.

The Hamming distance between XX and WW is the number of positions jj with X[j]≠W[j]X[j] \neq W[j]. A substring is ℓ\ell consecutive characters, and it may contain a space.

WW consists of lowercase letters only. The input is always such that exactly one (ℓ,d)(\ell, d)-pattern exists.

Input

The first line contains two integers ℓ\ell and dd separated by a space. (1≤ℓ≤101 \le \ell \le 10, 0≤d≤20 \le d \le 2)

The second line contains the number of strings kk. (1≤k≤301 \le k \le 30)

Each of the next kk lines contains one string, in the order S1,S2,…,SkS_1, S_2, \dots, S_k. Each string has length at most 50 and uses only spaces and lowercase letters. A pattern exists, so every string has length at least ℓ\ell.

Output

Print the (ℓ,d)(\ell, d)-pattern WW on the first line.

Examples2

  1. Example 1

    Input
    5 1
    4
    you have two applas
    i am an ppple
    we are acples
    adples are good for health
    
    Expected output
    apple
    
  2. Example 2

    Input
    3 0
    3
    oil is expensive
    we have three oilers
    be more oily
    
    Expected output
    oil