LCC '23 Contest 1 J3 - Candy Counting

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

After coming back from trick-or-treating, Jayden now has N candies that he can eat over the next M days.

Jayden's mom allows him to eat as many candies as he wants for M days, but on the condition that he does not touch anything sweet for the rest of the year.

Jayden has a severe case of OCD (Obsessive Compulsive Disorder), and he forces himself to perfectly portion his candies, meaning that he will only eat a candy if he can eat the same amount of that brand of candy every day over the M days. In order to achieve this, he will even give out some candy to his friends if he can't portion it evenly for the next M days.

How many candies will Jayden need to give out?

Constraints

1\le N \le 1\times 10^6

1\le M \le 364

Input Specification

The first line of input will contain two space-separated integers, N and M.

The next N lines of input will contain the brand of the i^{th} candy (The brand names will all be lowercase characters).

Output Specification

Output one integer, the number of candies that Jayden will need to give away.

Sample Input

10 3
kitkat
kitkat
smarties
kitkat
kitkat
aeros
snickers
smarties
aeros
aeros

Sample Output

4

Sample Output Explanation

Jayden can eat 1 aeros and 1 kitkat per day. He will have 1 kitkat, 2 smarties, and 1 snickers left over, which he can't evenly portion over 3 days, so he must give them away.


Comments

There are no comments at the moment.