Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
def g():
    m_l = [0] * (n+1)

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    
    while True:
        mm = min(i for i in m_l if i > 0)

        for i in range(n+1):
            if mm == m_l[i]:
                mn += mm
                r -= 1
                m_l[i] = 0

                if r <= k: return mn
        
print(g())


Fixed submission:
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
import numpy as np

def g():
    m_l = np.array([0]*(n+1))

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    while True:
        ma = np.ma.masked_equal(m_l, 0, copy=False)
        a = np.where(m_l == ma.min())[0]

        for i in a:
            mn += m_l[i]
            r -= 1
            m_l[i] = 0

            if r <= k: return mn
        
print(g())

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
def g():
    m_l = [0] * (n+1)

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    
    while True:
        mm = min(i for i in m_l if i > 0)

        for i in range(n+1):
            if mm == m_l[i]:
                mn += mm
                r -= 1
                m_l[i] = 0

                if r <= k: return mn
        
print(g())


Fixed submission:
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
import numpy as np

def g():
    m_l = np.array([0]*(n+1))

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    while True:
        ma = np.ma.masked_equal(m_l, 0, copy=False)
        a = np.where(m_l == ma.min())[0]

        for i in a:
            mn += m_l[i]
            r -= 1
            m_l[i] = 0

            if r <= k: return mn
        
print(g())

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a_l = list(map(int, input().split())
)
import sys
def g():
    m_l = [0] * (n+1)

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    
    while True:
        mm = min(i for i in m_l if i > 0)

        for i in range(n+1):
            if mm == m_l[i]:
                mn += mm
                r -= 1
                m_l[i] = 0

                if r <= k: return mn
        
print(g())


Fixed submission:
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
import numpy as np

def g():
    m_l = np.array([0]*(n+1))

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    while True:
        ma = np.ma.masked_equal(m_l, 0, copy=False)
        a = np.where(m_l == ma.min())[0]

        for i in a:
            mn += m_l[i]
            r -= 1
            m_l[i] = 0

            if r <= k: return mn
        
print(g())

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a_l = list(map(int, input().split()))

import sys
def g():
    m_l = [0] * (n+1)

    for a in a_l:
        m_l[a] += 1

    r = 0
    for m in m_l:
        if m != 0: r+= 1


    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    
    while True:
        mm = min(i for i in m_l if i > 0)

        for i in range(n+1):
            if mm == m_l[i]:
                mn += mm
                r -= 1
                m_l[i] = 0

                if r <= k: return mn
        
print(g())


Fixed submission:
n, k = map(int, input().split())
a_l = list(map(int, input().split()))
           
import sys
import numpy as np

def g():
    m_l = np.array([0]*(n+1))

    r = 0
    for a in a_l:
        if m_l[a] == 0: r += 1
        m_l[a] += 1

    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    while True:
        ma = np.ma.masked_equal(m_l, 0, copy=False)
        a = np.where(m_l == ma.min())[0]

        for i in a:
            mn += m_l[i]
            r -= 1
            m_l[i] = 0

            if r <= k: return mn
        
print(g())