#Lutece0554. Video Game Combos

Video Game Combos

Migrated from Lutece 554 Video Game Combos

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Bessie is playing a video game! In the game, the three letters A, B, and C are the only valid buttons. Bessie may press the buttons in any order she likes; however, there are only NN distinct combos possible (1N201 \leq N \leq 20). Combo ii is represented as a string SiS_i which has a length between 11 and 1515 and contains only the letters A, B, and C.

Whenever Bessie presses a combination of letters that matches with a combo, she gets one point for the combo. Combos may overlap with each other or even finish at the same time! For example if N=3N = 3 and the three possible combos are ABA, CB, and ABACB, and Bessie presses ABACB, she will end with 33 points. Bessie may score points for a single combo more than once.

Bessie of course wants to earn points as quickly as possible. If she presses exactly KK buttons (1K1,0001 \leq K \leq 1,000), what is the maximum number of points she can earn?

Input

  • Line 11: Two space-separated integers: NN and KK.
  • Lines 2N+12\cdots N+1: Line i+1i+1 contains only the string SiS_i, representing combo ii.

Output

  • Line 11: A single integer, the maximum number of points Bessie can obtain.

Samples

3 7
ABA
CB
ABACB
4

Note

The optimal sequence of buttons in this case is ABACBCB, which gives 44 points--11 from ABA, 11 from ABACB, and 22 from CB.

Resources

USACO Jan 2012