Score: 100 points
Problem Statement:
Kyoto University Programming Contest (KUPC) is organized by students. The committee has to divide N proposed problems into KUPCs, each containing K problems. Each problem can appear only once, and the first letters of the problem names in one KUPC must be different. Find the maximum number of KUPCs that can be held this year.
Constraints:
1 ≤ N ≤ 10^4
1 ≤ K ≤ 26
1 ≤ |P_i| ≤ 10
All characters in P_i are capital letters.
Input:
The input is given in the format: N K P_1 ... P_N
Output:
Print the maximum number of KUPCs that can be held.
Sample Input 1:
9 3
APPLE
ANT
ATCODER
BLOCK
BULL
BOSS
CAT
DOG
EGG
Sample Output 1:
3
Sample Input 2:
3 2
KU
KYOUDAI
KYOTOUNIV
Sample Output 2:
0

# Buggy version:
import collections 
n,k=map(int,input().split())
p=[str(input()) for _ in range(n)]
for i in range(n):
    p[i]=p[i][0:1]
#print(p)
c=collections.Counter(p)
#print(c)
a=[]
for v in c.values():
    a.append(v)
#print(a)
a.sort(reverse=True)
ans=0


#print(a)
while True:
    a.sort(reverse=True)
    if k<=len(a):
        ans+=1
        for i in range(k):
            a[i]-=1
        for i in range(k-1,-1,-1):
            print(a[i])
            if a[i]==0:
                a.pop(i)
        #print(a)
    else:
        break

print(ans)


# Fixed version:
import collections 
n,k=map(int,input().split())
p=[str(input()) for _ in range(n)]
for i in range(n):
    p[i]=p[i][0:1]
#print(p)
c=collections.Counter(p)
#print(c)
a=[]
for v in c.values():
    a.append(v)
#print(a)
a.sort(reverse=True)
ans=0


#print(a)
while True:
    a.sort(reverse=True)
    if k<=len(a):
        ans+=1
        for i in range(k):
            a[i]-=1
        for i in range(k-1,-1,-1):
            #print(a[i])
            if a[i]==0:
                a.pop(i)
        #print(a)
    else:
        break

print(ans)

# Buggy version:
n,k = map(int,input().split())
p = [input()[0] for i in range(n)]
from collections import Counter
c = Counter(p)
v = sorted(list(c.values()),reverse=True)
ans = 0
while len(v)>=k:
    for i in range(k):
        v[i] -= 1
        if v[i]<0:
            print(ans)
            exit()
    ans += 1
    v = sorted(v,reverse=True)

# Fixed version:
n,k = map(int,input().split())
p = [input()[0] for i in range(n)]
from collections import Counter
c = Counter(p)
v = sorted(list(c.values()),reverse=True)
ans = 0
while len(v)>=k:
    for i in range(k):
        v[i] -= 1
        if v[i]<0:
            print(ans)
            exit()
    ans += 1
    v = sorted(v,reverse=True)
print(ans)

# Buggy version:
n,K=[int(x) for x in input().split()]
ans=0
from collections import defaultdict
d=defaultdict(int)
for i in [0]*n:
    d[input()[0]]+=1
while True:
    for j,_ in zip(sorted(d.items(),key=lambda x:x[1],reverse=True),[0]*K):
        k,v=j
        if v==0 or len(d)<K:
            print(ans//K)
            import sys
            sys.exit()
        print(k,v)
        ans+=1
        d[k]-=1


# Fixed version:
n,K=[int(x) for x in input().split()]
ans=0
from collections import defaultdict
d=defaultdict(int)
for i in [0]*n:
    d[input()[0]]+=1
while True:
    for j,_ in zip(sorted(d.items(),key=lambda x:x[1],reverse=True),[0]*K):
        k,v=j
        if v==0 or len(d)<K:
            print(ans//K)
            import sys
            sys.exit()
        ans+=1
        d[k]-=1

# Buggy version:
afrom collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)

# Fixed version:
from collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)