Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s =str(input())
n = len(s)
ls = [1]*n
if n % 2 != 0:
    k = n+1
else:
    k = n
for _ in range(k):
    new = [0]*n
    for i in range(n):
        if i == 0:
            if s[1] == "L":
                new[0] = ls[1]
        elif i == n-1:
            if s[n-2] == "R":
                new[n-1] = ls[n-2]
        else:
            if s[i-1] == "R":
                new[i] += ls[i-1]
            if s[i+1] == "L":
                new[i] += ls[i+1]
    ls = new
print(*ls)

Fixed submission:
s = str(input())
ls = [0]*len(s)
r = 0
l = 0
ind = 0
if s[0] == "R":
    r = 1
else:
    l = 1
for i in range(1,len(s)):
    if s[i-1] == "L" and s[i] == "R":
        ls[ind] = (l - l//2) + r//2
        if ind > 0:
            ls[ind-1] = (r - r//2) + l//2
        l = 0
        r = 1
    elif s[i-1] == "R" and s[i] == "L":
        ind = i
        l += 1
    else:
        if i == len(s)-1:
            if s[i] == "L":
                l += 1
                ls[ind] = (l - l//2) + r//2
                if ind > 0:
                    ls[ind-1] = (r - r//2) + l//2
                r = 0
                l = 0
            else:
                r += 1
                ls[-1] = r
                r = 0
        else:
            if s[i] == "R":
                r += 1
            else:
                l += 1
if r != 0 and l != 0:
    ls[ind] = (l - l//2) + r//2
    if ind > 0:
        ls[ind-1] = (r - r//2) + l//2
elif r != 0:
    ls[-1] = r
print(*ls)

Buggy python submission (verdict: Time Limit Exceeded):
s =str(input())
n = len(s)
ls = [1]*n
for _ in range(2*n):
    new = [0]*n
    for i in range(n):
        if i == 0:
            if s[1] == "L":
                new[0] = ls[1]
        elif i == n-1:
            if s[n-2] == "R":
                new[n-1] = ls[n-2]
        else:
            if s[i-1] == "R":
                new[i] += ls[i-1]
            if s[i+1] == "L":
                new[i] += ls[i+1]
    ls = new
print(*ls)

Fixed submission:
s = str(input())
ls = [0]*len(s)
r = 0
l = 0
ind = 0
if s[0] == "R":
    r = 1
else:
    l = 1
for i in range(1,len(s)):
    if s[i-1] == "L" and s[i] == "R":
        ls[ind] = (l - l//2) + r//2
        if ind > 0:
            ls[ind-1] = (r - r//2) + l//2
        l = 0
        r = 1
    elif s[i-1] == "R" and s[i] == "L":
        ind = i
        l += 1
    else:
        if i == len(s)-1:
            if s[i] == "L":
                l += 1
                ls[ind] = (l - l//2) + r//2
                if ind > 0:
                    ls[ind-1] = (r - r//2) + l//2
                r = 0
                l = 0
            else:
                r += 1
                ls[-1] = r
                r = 0
        else:
            if s[i] == "R":
                r += 1
            else:
                l += 1
if r != 0 and l != 0:
    ls[ind] = (l - l//2) + r//2
    if ind > 0:
        ls[ind-1] = (r - r//2) + l//2
elif r != 0:
    ls[-1] = r
print(*ls)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = [int(input()) for i in range(n)]
for j in range(n):
    a = ls[0:j] + ls[j+1:]
    print(max(a))

Fixed submission:
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = [int(input()) for i in range(n)]
for j in range(n):
    a = ls[0:j] + ls[j+1:]
    print(max(a))

Fixed submission:
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
ls = list(map(int,input().split()))
for k in range(2**n):
    a = [0]*n
    for l in range(n):
        if (k>>l)&1:
            a[l] += 1
    p = 0
    for i in range(n):
        di = a[i::i+1]
        m = sum(di)
        if m % 2 != ls[i]:
            p = 1
            break
    if p == 0:
        new = []
        for t in range(len(a)):
            if a[t] == 1:
                new.append(t+1)
        print(sum(a))
        if sum(a) != 0:
            print(*new)
        sys.exit()
print(-1)

Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
di = [100]*(n+1)
di[0] = 0
for i in range(n):
    N = n - i
    num = int(n/N)
    fi = []
    for j in range(num):
        fi.append(N*(j+1))
    p = 0
    for k in fi:
        p += di[k]
    if (p - 100)%2 == ls[fi[0]-1]:
        di[fi[0]] = 0
    else:
        di[fi[0]] = 1
print(sum(di))
for e in range(1,len(di)):
    if di[e] == 1:
        print(e,end=" ")
Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def combinations_count(n, r): #組み合わせ(nCr)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1,k+1):
    cnt = combinations_count(n-k+1,i)* combinations_count(k-1, i-1)
    print(cnt%mod)

Fixed submission:
from operator import mul
from functools import reduce
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under
for i in range(1,k+1):
    cnt = cmb(n-k+1,i)* cmb(k-1, i-1)
    print(cnt%mod)

Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def combinations_count(n, r): #組み合わせ(nCr)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1,k+1):
    cnt = combinations_count(n-k+1,i)* combinations_count(k-1, i-1)% mod
    print(cnt%mod)

Fixed submission:
from operator import mul
from functools import reduce
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under
for i in range(1,k+1):
    cnt = cmb(n-k+1,i)* cmb(k-1, i-1)
    print(cnt%mod)

Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def combinations_count(n, r): #組み合わせ(nCr)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1,k+1):
    cnt = combinations_count(n-k+1,i)* combinations_count(k-1, i-1)% mod
    print(cnt)

Fixed submission:
from operator import mul
from functools import reduce
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under
for i in range(1,k+1):
    cnt = cmb(n-k+1,i)* cmb(k-1, i-1)
    print(cnt%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m = map(int,input().split())
ls = [int(input()) for _ in range(m)]
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])
        if dp[i] >= 10**9+7:
            dp[i] %= 10**9+7 
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])

Fixed submission:
import sys
n,m = map(int,input().split())
ls = set(int(input()) for _ in range(m))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])
        if dp[i] >= 10**9+7:
            dp[i] %= 10**9+7 
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m = map(int,input().split())
ls = [int(input()) for _ in range(m)]
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])
        if dp[i] >= 10**9+7:
            dp[i] %= 10**9+7 
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])

Fixed submission:
import sys
n,m = map(int,input().split())
ls = set(int(input()) for _ in range(m))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])
        if dp[i] >= 10**9+7:
            dp[i] %= 10**9+7 
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m = map(int,input().split())
ls = [int(input()) for _ in range(m)]
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])%(10**9+7)
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])

Fixed submission:
import sys
n,m = map(int,input().split())
ls = set(int(input()) for _ in range(m))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    if i not in ls:
        dp[i] = (dp[i-1]+dp[i-2])
        if dp[i] >= 10**9+7:
            dp[i] %= 10**9+7 
    else:
        if i-1 in ls:
            print(0)
            sys.exit()
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())
ans = 0
cnt = 0
for i in range(n//r+1):
    ans = 0
    for j in range((n-i*r)//g+1):
        for k in range((n-i*r-j*g)//b+1):
            ans = i*r+j*g+k*b
            if ans == n:
                cnt += 1
print(cnt)

Fixed submission:
r,g,b,n = map(int,input().split())
ans = 0
cnt = 0
for i in range(n//r+1):
    ans = 0
    for j in range((n-i*r)//g+1):
        ans = i*r+j*g
        a = (n-ans)/b
        if a % 1 == 0:
            cnt +=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())
ls = [r,g,b]
z = ls[0]
y = ls[1]
x = ls[2]
ls.sort()
p = n
q = 0
X = n//x +1
Y = n//y +1
Z = n//z +1
for i in range(X):
    p = n
    for j in range(Y):
        p = n -i*x
        if p >= j*y:
            p = 0
        else:
            break
        for k in range(Z):
            p = n -i*x -j*y
            if p == k*z:
                q += 1
print(q)

Fixed submission:
r,g,b,n = map(int,input().split())
ans = 0
cnt = 0
for i in range(n//r+1):
    ans = 0
    for j in range((n-i*r)//g+1):
        ans = i*r+j*g
        a = (n-ans)/b
        if a % 1 == 0:
            cnt +=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a = [0]*(5)
for l in range(5):
    a[l] = str(input())
ls = [a[0],a[1],a[2],a[3],a[4]]
new = [0]*(5)
s = 0
for i in range(5):
    new[i] = int(a[i][-1])
ans = min([e for e in new if e !=0])
for p in ls:
    if int(p) % 10 ==0:
        s += int(p)
    else:
        s += ((int(p)//10) + 1) *10
print(s-10+ans)
        

Fixed submission:
a = [0]*(5)
for l in range(5):
    a[l] = str(input())
ls = [a[0],a[1],a[2],a[3],a[4]]
new = [0]*(5)
s = 0
for i in range(5):
    new[i] = int(a[i][-1])
for p in ls:
    if int(p) % 10 ==0:
        s += int(p)
    else:
        s += ((int(p)//10) + 1) *10
if sum(new) !=0:
    ans = min([e for e in new if e !=0])
    print(s-10+ans)
else:
    print(s)
Buggy python submission (verdict: Runtime Error):
s = str(input())
mx = 0
for i in range(n):
    for j in range(i+1,n+1):
        cnt = j-i-1
        p = 0
        for k in list(s[i:j]):
            if k in ["A","C","G","T"]:
                p += 1
        if p == cnt:
            if p > mx:
                mx = p
print(mx)

Fixed submission:
s = str(input())
mx = 0
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        cnt = j-i
        p = 0
        for k in list(s[i:j]):
            if k in ["A","C","G","T"]:
                p += 1
        if p == cnt:
            if p > mx:
                mx = p
print(mx)

Buggy python submission (verdict: Runtime Error):
s = str(input())
ls = ["A","G","T","C"]
di = []
for i in range(len(s)):
    k = 0
    for j in range(len(s)-i):
        if s[i+j] in ls:
            k += 1
        else:
            di.append(k)
            k = 0
print(max(di))
            

        
        

Fixed submission:
s = str(input())
mx = 0
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        cnt = j-i
        p = 0
        for k in list(s[i:j]):
            if k in ["A","C","G","T"]:
                p += 1
        if p == cnt:
            if p > mx:
                mx = p
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = str(input())
p = len(s)
new = []
if p == 1:
    print("0")
    sys.exit()
while True:
    for i in range(len(s)-1):
        if i == len(s) - 2:
            if s[i] != s[i+1]:
                s = s[:i] + s[i+2:]
                print(p-len(s))
                sys.exit()
            else:
                print(p-len(s))
                sys.exit()
        elif s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            break

        
        

Fixed submission:
s = str(input())
ze = 0
on = 0
for i in range(len(s)):
    if s[i] == "0":
        ze += 1
    else:
        on += 1
print(len(s)-max(ze,on)+min(ze,on))
Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    for p in range(w+1):
        if p >= ls[i][0]:
            dp[i+1][p] = max(dp[i][p],dp[i][p-ls[i][0]]+ls[i][1])
        else:
            dp[i+1][p] = dp[i][p]
print(dp[n][w])

Fixed submission:
n,w = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
inf = float("inf")
dp = [[inf]*(100000+1) for _ in range(n+1)]
dp[0][0] = 0
ans = 0
for i in range(n):
    for v in range(100001):
        if v - ls[i][1] >= 0:
            dp[i+1][v] = min(dp[i][v],dp[i][v-ls[i][1]]+ls[i][0])
        else:
            dp[i+1][v] = dp[i][v]
for j in range(100001):
    if dp[n][j] <= w:
        ans = j
print(ans)

Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
inf = float("inf")
dp = [[-inf]*(w+1) for _ in range(n+1)]
for j in range(w+1):
    dp[0][j] = 0
for i in range(n):
    s,t = map(int,input().split())
    for l in range(w+1):
        if l-s >=0:
            dp[i+1][l] = max(dp[i][l],dp[i][l-s]+t)
        else:
            dp[i+1][l] = dp[i][l]
print(dp[-1][w])        

Fixed submission:
n,w = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
inf = float("inf")
dp = [[inf]*(100000+1) for _ in range(n+1)]
dp[0][0] = 0
ans = 0
for i in range(n):
    for v in range(100001):
        if v - ls[i][1] >= 0:
            dp[i+1][v] = min(dp[i][v],dp[i][v-ls[i][1]]+ls[i][0])
        else:
            dp[i+1][v] = dp[i][v]
for j in range(100001):
    if dp[n][j] <= w:
        ans = j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
#素因数分解(素因数を並べたリスト)(ex:60→[2,2,3,5])
def factorization(n): 
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            for _ in range(cnt):
                arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr
ls = factorization(m)
fi = []
for k in range(2**len(ls)):
    a = 1
    for l in range(len(ls)):
        if (k>>l)&1:
            a *= ls[l]
    if a not in fi:
        fi.append(a)
di = []
for i in range(len(fi)):
    if m//fi[i] >= n:
        di.append(fi[i])
print(max(di))

Fixed submission:
n,m = map(int,input().split())
ls = []
for i in range(1,int(m**(1/2))+1):
    if m % i == 0:
        ls.append(i)
        ls.append(m//i)
ls = sorted(list(set(ls)),reverse=True)
for j in ls:
    if j*n <= m:
        print(j)
        break
Buggy python submission (verdict: Runtime Error):
from functions import gcd
n,x = map(int,input().split())
ls = list(map(int,input().split()))
new = [0]*n
for i in range(n):
    new[i] = abs(ls[i]-x)
ans = new[0]
for j in range(1,n):
    ans = functions.gcd(ans,new[j])
print(ans)

Fixed submission:
from fractions import gcd
n,x = map(int,input().split())
ls = list(map(int,input().split()))
new = [0]*n
for i in range(n):
    new[i] = abs(ls[i]-x)
ans = new[0]
for j in range(1,n):
    ans = gcd(ans,new[j])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math 
n,x = map(int,input().split())
ls = list(map(int,input().split()))
new = [0]*n
for i in range(n):
    new[i] = abs(ls[i]-x)
ans = new[0]
for j in range(1,n):
    ans = math.gcd(ans,new[j])
print(ans)

Fixed submission:
from fractions import gcd
n,x = map(int,input().split())
ls = list(map(int,input().split()))
new = [0]*n
for i in range(n):
    new[i] = abs(ls[i]-x)
ans = new[0]
for j in range(1,n):
    ans = gcd(ans,new[j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = str(input())
s = s.replace("W","1")
s = s.replace("E","0")
m = int(s[:])
box = [0]*(n)
p = 0
for i in range(1,n+1):
    box[i-1] = sum(list(map(int,s[:i])))
k = 0
full = box[n-1]
for j in range(n):
    if j == 0:
        p = n-full+box[0]
        if p > k:
            k = p
    elif j == n-1:
        p = (n-1)-full+int(s[n-1])
        if p > k:
            k = p
    else:
        p = j-box[j-1]+full-box[j]
        if p > k:
            k = p
print(n-k-1)

Fixed submission:
n = int(input())
s = str(input())
s = s.replace("W","1")
s = s.replace("E","0")
fl = sum(list(map(int,s)))
k = 0
p = 0
for i in range(n):
    if i == 0:
        p = fl - int(s[0])
        k = p
    elif i == n-1:
        p = n-1-fl+int(s[n-1])
        if p > k:
            k = p
    else:
        if (s[i-1] == "1" and s[i] == "1"):
            p -= 1
        elif (s[i-1] == "1" and s[i] == "0"):
            continue
        elif (s[i-1] == "0" and s[i] == "1"):
            continue
        else:
            p += 1
            if p > k:
                k = p
print(n-k-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
w = sorted(ls)
p = w[int(n/2)]
for i in l:
    if i < p:
        print(p)
    else:
        print(w[int(n/2)-1])


Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
new = sorted(ls)
for i in ls:
    if i < new[int(n/2)]:
        print(new[int(n/2)])
    else:
        print(new[int(n/2)-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
di[0] = abs(ls[0])
di[-1] = abs(ls[-1])
for i in range(1,n):
    di[i] = abs(ls[i] - ls[i-1])
for j in range(n):
    if j == 0:
        if (ls[j])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    elif j == n-1:
        if (ls[j]-ls[j-1])*(-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    else:
        if (ls[j]-ls[j-1])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))

Fixed submission:
n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
ls = [0] + ls + [0]
for i in range(n+1):
    di[i] = abs(ls[i+1] - ls[i])
mx = sum(di)
for j in range(1,n+1):
    print(mx-di[j-1]-di[j]+abs(ls[j+1]-ls[j-1]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
p = 0
for i in list(set(ls)):
    a = ls.count(i)
    if a > i:
        p += a-i
    elif a < i:
        p += a
print(p)

Fixed submission:
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
c = Counter(ls)
p = 0
for s,t in c.items():
    if s > t:
        p += t
    elif s < t:
        p += t - s
print(p)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ls = list(map(int,input().split()))
p = 0
for i in list(set(ls)):
    a = ls.count(i)
    if a > i:
        p += a-i
    elif a < i:
        p += a
print(p)


Fixed submission:
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
c = Counter(ls)
p = 0
for s,t in c.items():
    if s > t:
        p += t
    elif s < t:
        p += t - s
print(p)
Buggy python submission (verdict: Runtime Error):
import collections
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
if len(a) > k:
    di = [0]*(len(a))
    new = c.most_common()[::-1]
    for i in range(len(a)):
        di[i] = new[i][1]
    import numpy 
    new_ls = numpy.cumsum(numpy.array(di))
    for j in range(len(a)):
        if len(a) - k <=new_ls[j]:
            print(new_ls[j])
            sys.exit()
else:
    print(0)

Fixed submission:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
if len(a) > k:
    for i in range(len(a)-1):
        if len(a) - k - i > 0:
            p += c.most_common()[-1-i][1]
        else:
            print(p)
            sys.exit()
else:
    print(0)

Fixed submission:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
if len(a) > k:
    for i in range(len(a)-1):
        if len(a) - k - i > 0:
            p += c.most_common()[-1-i][1]
        elif len(a) - k - i == 0:
            print(p)
else:
    print(0)

Fixed submission:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
ls = [int(input()) for i in range(n)]
ls.sort()
c = collections.Counter(ls)
p = 0
for j in range(len(c)):
    if c.most_common()[j][1] % 2 ==0:
        continue
    else:
        p += 1
print(p)

Fixed submission:
import collections
n = int(input())
ls = [int(input()) for i in range(n)]
ls.sort()
c = collections.Counter(ls)
d = list(c)
p = 0
for j in range(len(c)):
    if c[d[j]] % 2 ==0:
        continue
    else:
        p += 1
print(p)