cswork / OAOpen practice workspace

AmazonOA #203

Get Maximum Information Gain

Estimated MediumJudge-ready

Topics (AI-labelled)HashingStrings

Choose two different indices among n lowercase strings. Their number of common features is the number of common characters counted with multiplicity, i.e. the sum over letters of the smaller frequency; for aa and aaa it is 2. A pair is valid when its number of common features is ≤K; maximize the absolute difference of the two string lengths. The original text did not define the return value when no valid pair exists; this site adds that −1 is output in that case, and 0 is output when a valid pair exists but the lengths are equal.

Input

The first line contains n K, followed by n lines of lowercase strings. 2≤n≤1000, 1≤string length≤1000, 1≤K≤1000.

Output

Output a single integer, the answer.

Example 1

Input:

3 1
abc
bcd
zzzz

Output:

1

Example 2

Input:

2 1
aa
aaa

Output:

-1

Example 3

Input:

2 1
abc
xyz

Output:

0

Example notes

The answers are 1, −1 and 0; in the second example the common characters count as 2, not as 1 distinct letter.

Editorial

Loading solution…