#P15606. [ICPC 2021 Jakarta R] Uniform Maker

[ICPC 2021 Jakarta R] Uniform Maker

Problem Description

The International Costumes and Props Company (ICPC) received an order from a client to produce NN pennants each containing the same word. However, due to some miscommunication between the account manager and the client, not all the produced pennants have the same word although all of them have a word of the same length. Reproducing those pennants is very costly as the ICPC only uses a certain type of rare fabric in their production.

Fortunately, the client didn't specify the word that they want to be in the pennants. In fact, the client will be satisfied if and only if all the pennants have the same word.

The ICPC has a special technique to change one character in a word into some other character. It is expensive, albeit not as expensive as reproducing a new pennant. Therefore, the ICPC has to minimize the number of times they have to use such a technique. Your task in this problem is to help the ICPC to determine the minimum total number of characters that need to be changed so that the client will be satisfied.

For example, let there be N=6N = 6 pennants with the following words: calf, palm, book, icpc, ball, and room. The total number of characters that need to be changed can be minimized if all the words are changed into balm.

  • calf → 2 characters: b**m
  • palm → 1 characters: b***
  • book → 3 characters: *alm
  • icpc → 4 characters: balm
  • ball → 1 characters: ***m
  • room → 3 characters: bal*

The symbol * represents an unchanged character. There are a total of 1414 characters that need to be changed in this example.

Input Format

Input begins with a line containing two integers NN MM (2N1002 \leq N \leq 100; 1M1001 \leq M \leq 100) representing the number of pennants and the length of each word in the pennant, respectively. The next NN line each contains a string SiS_i (Si=M|S_i| = M) representing the word on the ithi^{th} pennant. Each string only contains lowercase alphabetical characters.

Output Format

Output contains an integer in a line representing the minimum total number of characters that need to be changed so that the client will be satisfied.

6 4
calf
palm
book
icpc
ball
room
14
3 11
goodluckfor
icpcjakarta
contestants

19
5 14
helpiamtrapped
inanincfactory
forthreemonths
withoutfoodand
drinkandshower
49