Problem:


Score : 100 points

Problem Statement

		                Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students.
		                This contest is abbreviated as Kyoto University Programming Contest and called KUPC.
                    

		                source: Kyoto University Programming Contest Information

		            The problem-preparing committee met to hold this year's KUPC and N problems were proposed there.
		            The problems are numbered from 1 to N and the name of i-th problem is P_i.
		            However, since they proposed too many problems, they decided to divide them into some sets for several contests.
                

		            They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions.
                    

 One KUPC provides K problems. 

 Each problem appears at most once among all the KUPCs. 

 All the first letters of the problem names in one KUPC must be different. 

		            You, one of the committee members, want to hold as many KUPCs as possible.
		            Write a program to find the maximum number of KUPCs that can be held this year.
                

Constraints

 1 \leq N \leq 10^4

 1 \leq K \leq 26

 1 \leq |P_i| \leq 10

 All characters in P_i are capital letters.

		            Note that, for each i and j (1 \leq i < j \leq N),
                    P_i \neq P_j are not necessarily satisfied.
                

Input

The input is given from Standard Input in the following format:

N K
P_1
:
P_N

Output

		                Print the maximum number of KUPCs that can be held on one line.
                    

Sample Input 1

9 3
APPLE
ANT
ATCODER
BLOCK
BULL
BOSS
CAT
DOG
EGG

For example, three KUPCs can be held by dividing the problems as follows. 

 First: APPLE, BLOCK, CAT

 Second: ANT, BULL, DOG

 Third: ATCODER, BOSS, EGG

Sample Output 1

3

Sample Input 2

3 2
KU
KYOUDAI
KYOTOUNIV

Sample Output 2

0

No KUPC can be held.



Sample input:
9 3
APPLE
ANT
ATCODER
BLOCK
BULL
BOSS
CAT
DOG
EGG


Sample output:
3

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())

D={}
for i in range(N):
    s=input()
    D[s]=1

if K==1:
    print(len(D))
    exit()

d={}
for k,v in D.items():
    if k[0] not in d:
        d[k[0]]=1
    else:
        d[k[0]]+=1

MAX=0
for k,v in d.items():
    if MAX<v:
        MAX=v

NMAX=N-MAX
print(min(MAX,NMAX//(K-1)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
dic = {}
for _ in range(n):
  p = input()[0]
  if p in dic:
    dic[p] += 1
  else:
    dic[p] = 1

ans = 0
for _ in range(1000):
  cnt = 0
  for p in dic:
    if dic[p] > 0:
      dic[p] -= 1
      cnt += 1
      if cnt == k:
        ans += 1
        break
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
nPs = {}
for i in range(N):
  P = input()
  c = P[0]
  if c not in nPs:
    nPs[c] = 0
  nPs[c] += 1
#print(nPs)
r = N//K
for c in nPs:
  nPs[c] = min(r, nPs[c])
r = sum(nPs.values())//K
print(r)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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
while 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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
p = [input()[0] for i in range(n)]
from collections import Counter
c = Counter(p)
v = list(c.values())
ans = 0
while len(v)>=k:
    ans += 1
    c = 0
    i=0
    while c<k and len(v)>=k:
        v[i] -= 1
        if v[c]==0:v.pop(c)
        else:i+=1
        c+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
p = [input()[0] for i in range(n)]
from collections import Counter
c = Counter(p)
v = list(c.values())
ans = 0
while len(v)>=k:
    ans += 1
    c = 0
    while c<k and len(v)>=k:
        v[c] -= 1
        if v[c]==0:v.pop(c)
        c+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
p = [input()[0] for i in range(n)]
from collections import Counter
c = Counter(p)
v = list(c.values())
ans = 0
while len(v)>=k:
    c = 0
    while c<k and len(v)>=k:
        if v[c]==0:
            v.pop(c)
        else:
            v[c] -= 1
            c+=1
    if c==k:ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))

N, K = inpl()
S = [0]*26
for _ in range(N):
    S[ord(input()[0]) - 65] += 1

ans = 0
while True:
    S = sorted(S, reverse=True)
    s = S[K-1]
    if s == 0:
        break
    ans += s
    for i in range(K):
        S[i] -= s
print(ans)

Submission status: Wrong Answer

Solution code:
n,k= (int(i) for i in input().split())
q = [input() for i in range(n)]
#s = list(set(a)) # 重複チェック
query = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
tmp = [0]*26
j = -1
for i in q:
  j+= 1
  tmp[(ord(i[0])-65)] += 1

ct = 0
while ct <10**15:
 tmp = sorted(tmp,reverse =True)
 a = min(tmp[0:k])
# print(tmp)
# print(a)
 if a > 0:
  for l in range(k):
   tmp[l] -=a
  ct += a
  continue
 else:
  break
print(ct)

Submission status: Wrong Answer

Solution code:
n,k= (int(i) for i in input().split())
a = [input() for i in range(n)]
#s = list(set(a)) # 重複チェック
query = 'abcdefghijklmnopqrstuvwxyz'
tmp = [0]*26
j = -1
for i in a:
  j+= 1
  tmp[(ord(i[0])-65)] += 1

ct = 0
while ct <10**15:
 tmp = sorted(tmp,reverse =True)
 a = min(tmp[0:k])
# print(tmp)
# print(a)
 if a > 0:
  for l in range(k):
   tmp[l] -=a
  ct += a
  continue
 else:
  break
print(ct)

Submission status: Wrong Answer

Solution code:
n,k= (int(i) for i in input().split())
a = [input() for i in range(n)]
#s = list(set(a)) # 重複チェック
query = 'abcdefghijklmnopqrstuvwxyz'
tmp = [0]*26
j = -1
for i in a:
  j+= 1
  tmp[(ord(i[0])-65)] += 1

ct = 0
while ct <20000:
 tmp = sorted(tmp,reverse =True)
 a = min(tmp[0:k])
# print(tmp)
# print(a)
 if a > 0:
  for l in range(k):
   tmp[l] -=a
  ct += a
  continue
 else:
  break
print(ct)

Submission status: Wrong Answer

Solution code:
n,k= (int(i) for i in input().split())
a = [input() for i in range(n)]
s = list(set(a)) # 重複チェック
query = 'abcdefghijklmnopqrstuvwxyz'
tmp = [0]*26
j = -1
for i in a:
  j+= 1
  tmp[(ord(i[0])-65)] += 1

ct = 0
while ct <20000:
 tmp = sorted(tmp,reverse =True)
 a = min(tmp[0:k])
# print(tmp)
# print(a)
 if a > 0:
  for l in range(k):
   tmp[l] -=a
  ct += a
  continue
 else:
  break
print(ct)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
p = [input() for _ in range(n)]
p_ini = [0]*26
for _p in p:
    p_ini[ord(_p[0])-ord('A')] += 1
res = 0
while p_ini.count(0)<=26-k:
    tmp = 0
    for i in range(26):
        if p_ini[i]!=0:
            p_ini[i] -= 1
            tmp += 1
        if tmp==k:
            break
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys

N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
p = list(d.values())
if len(p) < K:
    print(0)
    sys.exit()

h = []
for i in p:
    heappush(h, i)

while(len(h) > K):
    k = heappop(h) + heappop(h)
    heappush(h, k)

print(min(h))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys

N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
p = list(d.values())
if len(p) < K:
    print(0)
    sys.exit()

h = []
for i in p:
    heappush(h, i)

#while(len(h) > K):
for _ in range(len(h) - K):
    k = heappop(h) + heappop(h)
    heappush(h, k)

print(min(h))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys

N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
p = list(d.values())
if len(p) < K:
    print(0)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys

N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
p = list(d.values())

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys

N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

Submission status: Wrong Answer

Solution code:
print('test')

Submission status: Wrong Answer

Solution code:
import sys
n, k = [int(x) for x in sys.stdin.readline().split()]
p = [x.strip()[0] for x in sys.stdin.read().split()]
if len(set(p)) < k:
	print 0
	exit()
dic = {}
for x in p:
	dic[x] = dic.get(x, 0) + 1
loop, count = True, 0
while(loop):
	ctr = k
	for x, _ in sorted(dic.items(), key=lambda x: x[1], reverse=True):
		if ctr == 0:
			count += 1
			break
		if dic[x] <= 0:
			loop = False
			break
		else:
			dic[x] -= 1
		ctr -= 1
	if ctr != 0:
		loop = False
print count

Submission status: Wrong Answer

Solution code:
import collections

def exit0():
    print('0')
    exit(0)

def getP():
    tmp = input()
    return tmp[0]

N,K = map(int, input().split())
Ps = [getP() for _ in range(N)]

if(len(Ps)%K != 0):
    exit0()

Alpha1 = collections.Counter(Ps)
print(Alpha1.most_common(1)[0][1])

if(K<Alpha1.most_common(1)[0][1]):
    exit0()
else:
    print(Alpha1.most_common(1)[0][1])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
p = [0]*26
for _ in range(n):
    s = input()
    p[ord(s[0])-ord('A')] += 1
p = [min(n//k, x) for x in reversed(sorted(p))]
t=[0]*k
for v in p:
    t = list(sorted(t))
    t[0] += v
print(min(t))

Submission status: Wrong Answer

Solution code:
def main():
    n, k = [int(x) for x in input().split()]
    letters = []
    for _ in range(n):
        letters.append(input()[0])
    alphabet = [0 for _ in range(26)]
    for letter in letters:
        alphabet[ord(letter) - 65] += 1
    alphabet.sort()
    alphabet.reverse()
    num_contests = 0
    picked = 0
    idx = 0
    while idx < 26:
        if alphabet[idx] > 0:
            picked += 1
            alphabet[idx] -= 1
        if picked == k:
            num_contests += 1
            picked = 0
            idx = -1
        idx += 1
    print(num_contests)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, k = [int(x) for x in input().split()]
    letters = []
    for _ in range(n):
        letters.append(input()[0])
    alphabet = [0 for _ in range(26)]
    for letter in letters:
        alphabet[ord(letter) - 65] += 1
    num_contests = 0
    picked = 0
    idx = 0
    while idx < 26:
        if alphabet[idx] > 0:
            picked += 1
            alphabet[idx] -= 1
        if picked == k:
            num_contests += 1
            picked = 0
            idx = -1
        idx += 1
    print(num_contests)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import string
N, K = map(int, input().split())
letters = string.ascii_uppercase
L = [0 for i in range(len(letters))]
for i in range(N):
    p = input()
    L[ord(p[0]) - ord("A")] += 1
ans = 0
while True:
    maxv = [0 for k in range(K)]
    argmax = [-1 for k in range(K)]
    cnt = 0
    for n in range(N):
        minimum = min(maxv)
        if L[n] > minimum:
            for k in range(K):
                if maxv[k] == minimum:
                    argmax[k] = n
                    maxv[k] = L[n]
                    break
    # print(argmax)
    if 0 in maxv:
        print(ans)
        break
    else:
        for k in range(K):
            L[argmax[k]] -= 1
        ans += 1

Submission status: Wrong Answer

Solution code:
import string
N, K = map(int, input().split())
letters = string.ascii_uppercase
L = [0 for i in range(len(letters))]
for i in range(N):
    p = input()
    L[ord(p[0]) - ord("A")] += 1
ans = 0
while True:
    maxv = [0 for k in range(K)]
    argmax = [-1 for k in range(K)]
    cnt = 0
    for n in range(N):
        minimum = min(maxv)
        if L[n] > minimum:
            for k in range(K):
                if maxv[k] == minimum:
                    argmax[k] = n
                    maxv[k] = L[n]
                    break
    # print(argmax)
    if maxv[0] == 0:
        print(ans)
        break
    else:
        for k in range(K):
            L[argmax[k]] -= 1
        ans += 1

Submission status: Wrong Answer

Solution code:
r=raw_input
n,k=map(int,r().split())
c=[0]*200
for i in[0]*n:c[ord(r()[0])]+=1
for e in sorted(c)[::-1]:
 for i in range(k-1,0,-1):v=min(e,c[i]);c[i]-=v;c[i+1]+=v;e-=v
 c[1]+=e
print c[k]

Submission status: Wrong Answer

Solution code:
r=raw_input
n,k=map(int,r().split())
c=[0]*200
for i in[0]*n:c[ord(r()[0])]+=1
for e in c:
 for i in range(k-1,0,-1):v=min(e,c[i]);c[i]-=v;c[i+1]+=v;e-=v
 c[1]+=e
print c[k]

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import heapq
n, k = map(int, raw_input().split())
d = defaultdict(int)
c = 0
for i in xrange(n):
    p = raw_input()
    d[p[0]] +=1

# print d
dv = d.values()
dv = map(lambda x: -x,dv)
heapq.heapify(dv)
try:
    while True:
        vl = []
        for i in xrange(k):
            vl.append(- heapq.heappop(dv))
        m = min(vl)
        c += m
        for i in xrange(k):
            vl[i] -= m
            if not vl[i] == 0:
                heapq.heappush(dv, -vl[i])
except Exception, e:
    pass
print c

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
a=[0]*25
b=[]
count=0
for i in range(n):
	b.append(raw_input())
b=list(set(b))
for i in b:
	a[ord(i[0])-65]+=1
for i in a:
	if i>0:
		count+=i
if len(set(a))==2:
	print 0
else:
    print count/k

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
from collections import defaultdict
from heapq import *
import sys
d=defaultdict(int)
n,k=map(int,sys.stdin.readline().split())
for _ in range(n):
	s=sys.stdin.readline().strip()
	d[s[0]]-=1
if len(d)<k:
	print(0)
else:
	q=[]
	for khi in d:
		heappush(q,[d[khi],khi])
	r=0
	print(r)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
from collections import defaultdict
from heapq import *
import sys
d=defaultdict(int)
n,k=map(int,sys.stdin.readline().split())
for _ in range(n):
	s=sys.stdin.readline().strip()
	d[s[0]]-=1
if len(d)<k:
	print(0)
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int, raw_input().split())
C = sorted(Counter(raw_input()[0] for _ in xrange(N)).values())
a = C.pop()
b = sum(C)
for i in xrange(a, 0, -1):
    if b/i >= K-1:
        print i
        break
else:
    print 0

Submission status: Wrong Answer

Solution code:
N,K = map(int, raw_input().split())
dic = {}
for _ in xrange(N):
  p = raw_input()
  if p[0] in dic:
    dic[p[0]] += 1
  else:
    dic[p[0]] = 1

counter = 0
while True:
  dic = dict(sorted(dic.items(), key=lambda x:x[1], reverse=True))
  if len(dic) < K: break
  keys = dic.keys()
  for i in xrange(K):
    dic[keys[i]] -= 1
    if dic[keys[i]] == 0:
      del dic[keys[i]]
  counter += 1

print counter

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int, raw_input().split())
C = sorted(Counter(raw_input()[0] for _ in xrange(N)).values())
a = C.pop()
b = sum(C)
for i in xrange(a+1, 0, -1):
    if b/i >= K-1:
        print i
        break
else:
    print 0

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n,k = list(map(int, input().split()))
    r = 0
    a = [0] * 26
    for _ in range(n):
        t = ord(input()[0]) - ord('A')
        a[t] += 1
    a.sort()
    a.reverse()
    if a[k-1] == 0:
        return 0
    b = a[:n]
    b.sort()
    c = sum(a[n:])
    for _ in range(c):
        b[0] += 1
        b.sort()

    return b[0]

print(f())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n,k = list(map(int, input().split()))
    r = 0
    a = [0] * 26
    for _ in range(n):
        t = ord(input()[0]) - ord('A')
        a[t] += 1
    a.sort()
    a.reverse()
    if a[k-1] == 0:
        return 0
    b = a[:n]
    c = sum(a[n:])
    for _ in range(c):
        b[0] += 1
        b.sort()

    return b[0]

print(f())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def no_more():
    dic = defaultdict(bool)
    for prob in p:
        dic[prob[0]] = True
    num = sum([1 for x in dic.values() if x == True])
    return num < k

def can_be_added(prob, temp):
    letter = prob[0]
    for p in temp:
        if p[0] == letter:
            return False
    return True


if __name__ == '__main__':
    n, k = [int(x) for x in input().split()]
    p = []
    ans = 0
    stop = False
    for i in range(n):
        p.append(str(input()))
    while True:
        temp = []
        for prob in p:
            if prob not in temp and can_be_added(prob, temp):
                temp.append(prob)
                if len(temp) == k:
                    ans += 1
                    for prob in temp:
                        p.remove(prob)
                    if len(p) == 0 or no_more():
                        stop = True
        if len(temp) < k:
            break
        if stop:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input(). split())
cnt = 0
s_t = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
t = [0 for i in range(26)]

for i in range(n):
    p = input()
    for j in range(26):
        if p[0] == s_t[j]:
            t[j] += 1
            break

while True:
    erase = 0
    pa = True
    for i in range(26):
        if t[i] - 1 >= 0:
            t[i] -= 1
            erase += 1
        if erase == k:
            cnt += 1
            break
        if i == 25 and erase != k:
            pa = False
            break
    if pa == False:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
def calc(ls, k):
    cnt = 0
    while ls[0] > 0:
        ls.sort(reverse=True)
        for i in range(k):
            ls[i] -= 1
            if ls[i] < 0:
                return cnt
        #print(ls)
        cnt += 1
    return cnt

n, k = map(int, input().split())
ls = [0 for i in range(26)]
for i in range(n):
    word = input()
    inx = ord(word[0]) - ord('A')
    ls[inx] += 1
ls.sort(reverse=True)
ans = calc(ls, k)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
P_li = []
for i in range(N):
    P_li.append(raw_input()[0])
P_li.sort()

# mk
cnt = 0
while len(P_li)!=0 or len(P_li)<K:
    k_li = list(set(P_li))
    if len(k_li)<K:
        break
    else:
        cnt +=1
    #del
    for k in k_li[:3]:
        P_li.remove(k)

print cnt

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, K = map(int, input().split())

p = [input()[0] for i in range(N)]

if N % K == 0:
    c = Counter(p)
    max_c = c.most_common(1)
    if max_c[0][1] <= N / K:
        print(N // K)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, K = map(int, input().split())

p = [input()[0] for i in range(N)]

if N % K == 0:
    c = Counter(p)
    max_c = c.most_common(1)
    if max_c[0][1] <= N / K:
        print(N // K)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def solve():
	N,K = map(int,raw_input().split())
	P = [0]*26
	for i in xrange(N):
		P[ord(raw_input()[0])-65] += 1
	P.sort(reverse = True)
	ans = 0
	for i in xrange(N):
		pos = 0
		cnt = K
		while pos < 26:
			if cnt == 0:
				ans += 1
				break
			if P[pos] > 0:
				P[pos] -= 1
				cnt -= 1
			pos += 1
		else:
			return ans
	return ans
print solve()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
P = set([raw_input() for i in xrange(N)])

cnt = [0]*26
for p in P:
    cnt[ord(p[0]) - ord("A")] += 1

ans = 0
while 1:
    k = 0
    for i in xrange(26):
        if cnt[i] > 0:
            k += 1
            cnt[i] -= 1
        if k == K:
            ans += 1
            break
    else:
        break
print ans

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
p=[raw_input() for _ in xrange(n)]
cnt=0
pr=[0]*26

for i in xrange(n):
    pr[ord(p[i][0])-ord('A')]+=1

for i in xrange(26):
    if pr[i]>0:
        cnt+=1
if k>cnt:
    print(0)
else:
    ans=0
    pr.sort()
    pr.reverse()
    while pr!=[0]*26:
        tmp=k
        for i in xrange(26):
            if tmp==0:
                ans+=1
                break
            if pr[i]>0:
                tmp-=1
                pr[i]-=1
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
P = [raw_input() for i in xrange(N)]

cnt = [0]*26
for p in P:
    cnt[ord(p[0]) - ord("A")] += 1

ans = 0
while N:
    k = 0
    for i in xrange(26):
        if cnt[i] > 0:
            k += 1
            cnt[i] -= 1
            N -= 1
        if k == K:
            ans += 1
            break
    else:
        break
print ans

Submission status: Time Limit Exceeded

Solution code:
import collections
N, K = map(int, raw_input().split())
P_list = list()
for i in range(N):
    P_list.append(raw_input()[0])
    C_list = collections.Counter(P_list).values()
 
# clean
C_list = [c for c in C_list if c > 0]
C_list.sort(reverse=True)
 
res = 0
while True:
    if len(C_list) >= K:
        for i in range(K):
            C_list[i] -= 1
        res += 1
        C_list = [c for c in C_list if c > 0]
        C_list.sort(reverse=True)
    else:
        break
print res

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections
N, K = map(int, raw_input().split())
P_list = list()
for i in range(N):
    P_list.append(raw_input()[0])
    C_list = collections.Counter(P_list).values()

# clean
C_vec = np.array(C_list)

while True:
    m = int(C_vec.sum() / K)
    C_vec = np.minimum(C_vec, m)
    m_next = int(C_vec.sum() / K)
    if m_next == m:
        break
    else:
        m = m_next

print m

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections
N, K = map(int, raw_input().split())
P_list = list()
for i in range(N):
    P_list.append(raw_input()[0])
    C_list = collections.Counter(P_list).values()

# clean
C_vec = np.array(C_list)
C_vec.sort()
C_vec = C_vec[::-1]

res = 0
while True:
    if len(C_list) >= K:
        d = C_vec[K-1]
        C_vec[0:K] -= d
        res += d
        C_vec = C_vec[C_vec > 0]
        C_vec.sort()
        C_vec = C_vec[::-1]
    else:
        break
print res

Submission status: Time Limit Exceeded

Solution code:
import collections
N, K = map(int, raw_input().split())
P_list = list()
for i in range(N):
    P_list.append(raw_input()[0])
    C_list = collections.Counter(P_list).values()

# clean
C_list = [c for c in C_list if c > 0]
C_list.sort(reverse=True)

res = 0
while True:
    if len(C_list) >= K:
        d = C_list[K-1]
        for i in range(K):
            C_list[i] -= d
        res += d
        C_list = [c for c in C_list if c > 0]
        C_list.sort(reverse=True)
    else:
        break
print res

Submission status: Time Limit Exceeded

Solution code:
import collections
N, K = map(int, raw_input().split())
P_list = list()
for i in range(N):
    P_list.append(raw_input()[0])
    C_list = collections.Counter(P_list).values()

# clean
C_list = [c for c in C_list if c > 0]
C_list.sort(reverse=True)

res = 0
while True:
    if len(C_list) >= K:
        for i in range(K):
            C_list[i] -= 1
        res += 1
        C_list = [c for c in C_list if c > 0]
        C_list.sort(reverse=True)
    else:
        break
print res

Submission status: Accepted

Solution code:
from collections import Counter

N,K=map(int,input().split())
P = [input() for _ in range(N)]

c = Counter([P[i][0] for i in range(N)])

ans = 0
while True:
  mc = c.most_common()
  if len(mc)<K:break
  if mc[K-1][1] == 0: break
  mc = mc[:K]
  for k,v in mc:
    c[k] -= 1
  ans += 1
  
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
word = [0 for i in range(26)]
ans = 0
for i in range(n):
    q = input()
    word[ord(q[0]) - ord('A')] += 1
word.sort(reverse=True)
for i in range(n//k):
    for j in range(k):
        word[j] -= 1
        if word[j] < 0:
            print(ans)
            exit()
    ans += 1
    word.sort(reverse=True)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
P = [input()[0] for _ in range(n)]
CP = Counter(P)

P = list(CP.values())
ans = 0
while len(P) >= k:
  P.sort(reverse=True)
  for i in range(k):
    P[i] -= 1
  P = [i for i in P if i > 0]
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
N,K = list(map(int, input().split(' ')))
d = {}
for i in range(N):
    S = str(input())[0]
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
p = list(d.values())
if len(p) < K:
    print(0)
    sys.exit()
c = 0
while(len(p) >= K):
    c += 1
    sq = sorted(p, reverse=True)
    for i in range(K):
        sq[i] = sq[i] - 1
    p = [i for i in sq if i != 0]
print(c)

Submission status: Accepted

Solution code:
from heapq import *
n,k=map(int,input().split())
s=[0]*26
for i in range(n):
    s[ord(input()[0])-65]-=1
s=[i for i in s if i<0]
d=0
while len(s)>=k:
    t=[]
    for i in range(k):
        a=heappop(s)
        if a+1!=0:
            t.append(a+1)
    for j in t:
        heappush(s,j)
    d+=1
print(d)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import Counter
import numpy as np

N,K = map(int,input().split())
P = [input().rstrip()[0] for _ in range(N)]

counter = np.array(tuple(Counter(P).values()))

answer = 0
while True:
    counter.sort()
    counter = counter[::-1]
    counter = counter[counter>0]
    if len(counter) < K:
        break
    counter[:K] -= 1
    answer += 1

print(answer)

Submission status: Accepted

Solution code:

from collections import defaultdict

def main():
    num, k = map(int, input().split())
    data = [input() for i in range(num)]
    initial_dic = defaultdict(int)
    for i in range(num):
        initial_dic[data[i][0]] += 1

    aaa = list(initial_dic.values())
    aaa.sort(reverse=True)
    ans = 0
    if len(aaa) < k:
        pass
    else:
        while 1:
            if aaa[k - 1] == 0:
                break
            for i in range(k):
                aaa[i] -= 1
            ans += 1
            aaa.sort(reverse=True)

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))

N, K = inpl()
S = [0]*26
for _ in range(N):
    S[ord(input()[0]) - 65] += 1

ans = 0
while True:
    S = sorted(S, reverse=True)
    s = S[K-1]
    if s == 0:
        break
    ans += 1
    for i in range(K):
        S[i] -= 1
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = [input() for _ in range(n)]
p_ini = [0]*26
for _p in p:
    p_ini[ord(_p[0])-ord('A')] += 1
res = 0
while p_ini.count(0)<=26-k:
    p_ini = sorted(p_ini)[::-1]
    for i in range(k):
        if p_ini[i]!=0:
            p_ini[i] -= 1
    res += 1
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
from heapq import heappop,heappush
n,k = (int(i) for i in input().split())
p = [input()[0] for i in range(n)]
c,h,ans = Counter(p),[],0
for i,j in c.most_common(): heappush(h,-j)
while len(h)>=k:
	x,ans = [],ans+1
	for i in range(k):
		m = heappop(h)
		if m+1<0: x.append(m+1)
	for i in x: heappush(h,i)
print(ans)

Submission status: Accepted

Solution code:
import heapq
N,K = map(int,input().split())
hist = [0] * 26

def ctoi(c):
    return ord(c) - ord('A')

for i in range(N):
    c = input()[0]
    hist[ctoi(c)] -= 1

if K == 1:
    print(N)
    exit()
if K == 26:
    print(min(hist))
    exit()

heapq.heapify(hist)
ans = 0
while True:
    used = []
    for i in range(K):
        a = heapq.heappop(hist)
        if a == 0:
            print(ans)
            exit()
        used.append(a+1)
    ans += 1
    for u in used:
        heapq.heappush(hist, u)