atcoder#ABC249C. [ABC249C] Just K

[ABC249C] Just K

Score : 300300 points

Problem Statement

You are given NN strings S1,S2,,SNS_1,S_2,\dots,S_N consisting of lowercase English alphabets.

Consider choosing some number of strings from S1,S2,,SNS_1,S_2,\dots,S_N.

Find the maximum number of distinct alphabets that satisfy the following condition: "the alphabet is contained in exactly KK of the chosen strings."

Constraints

  • 1N151 \le N \le 15
  • 1KN1 \le K \le N
  • NN and KK are integers.
  • SiS_i is a non-empty string consisting of lowercase English alphabets.
  • For each integer ii such that 1iN1 \le i \le N, SiS_i does not contain two or more same alphabets.
  • If iji \neq j, then SiSjS_i \neq S_j.

Input

Input is given from Standard Input in the following format:

NN KK

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer.

4 2
abi
aef
bc
acg
3

When S1,S3S_1,S_3, and S4S_4 are chosen, a,b, and c occur in exactly two of the strings.

There is no way to choose strings so that 44 or more alphabets occur in exactly 22 of the strings, so the answer is 33.

2 2
a
b
0

You cannot choose the same string more than once.

5 2
abpqxyz
az
pq
bc
cy
7