Buggy python submission (verdict: Time Limit Exceeded):
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()

    setA = list(set(A))
    if len(setA) <= k:
        print(0)
        exit()

    sLen = len(setA)
    # ここを何とかしよう
    kosu = [0] * sLen
    i = 0
    while i < sLen:
        kosu[i] = A.count(setA[i])
        i += 1
    #print(*kosu)
    # -----------------
    kosu = sorted(kosu)
    ans = 0
    #print(*ALL)
    for i in range(sLen-k):
        ans += kosu[i]
    print(ans)
if __name__ == '__main__':
  main()


Fixed submission:
import collections
#aa = collections.Counter(a) # list to list

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()

    setA = list(set(A))
    if len(setA) <= k:
        print(0)
        exit()

    sLen = len(setA)
    # ここを何とかしよう
    kosu = [0] * sLen
    i = 0
    while i < sLen:
        kosu[i] = A.count(setA[i])
        i += 1
    #print(*kosu)
    # -----------------
    kosu = sorted(kosu)
    ans = 0
    #print(*ALL)
    for i in range(sLen-k):
        ans += kosu[i]
    print(ans)
if __name__ == '__main__':
  main()


Fixed submission:
import collections
#aa = collections.Counter(a) # list to list

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()

    setA = list(set(A))
    if len(setA) <= k:
        print(0)
        exit()

    ALL = []
    for i in setA:
        ALL.append(A.count(i))
    ALL = sorted(ALL)
    ans = 0
    sLen = len(setA)
    #print(*ALL)
    for i in range(sLen-k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()


Fixed submission:
import collections
#aa = collections.Counter(a) # list to list

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()

    setA = list(set(A))
    if len(setA) <= k:
        print(0)
        exit()

    ALL = []
    for i in setA:
        ALL.append(A.count(i))
    ALL = sorted(ALL)
    ans = 0
    sLen = len(setA)
    #print(*ALL)
    for i in range(sLen-k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()


Fixed submission:
import collections
#aa = collections.Counter(a) # list to list

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()