Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02788 (python)

Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

def main():
    N, D, A = map(int, input().split())
    B = []

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    S = [0] * (N + 1)
    for i in range(N):
        if S[i] < H[i]:
            cnt = (H[i] - S[i]) // A if (H[i] - S[i]) % A == 0 else (H[i] - S[i]) // A + 1
            ans += cnt
            search_max = bisect_right(X, X[i] + 2 * D)
            S[i] += cnt * A
            S[search_max] -= cnt * A
        
        S[i+1] += S[i]

    print(ans)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right
import sys
input = sys.stdin.readline

class BIT:
    '''
    区間加算BIT(区間加算・区間合計取得) 
    '''
    def __init__(self, N):
        # 添え字0は使えないので1-indexとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N

    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k

    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        # 区間[l,r)に値xを追加

        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, -x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def query(self, l, r):
        # 区間[l,r)の和を取得
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
            - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

def main():
    N, D, A = map(int, input().split())
    B = []

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]

    bit = BIT(N)
    for i in range(N):
        H[i] -= bit.query(i, i+1)
        if H[i] <= 0:
            continue
        cnt = H[i] // A if H[i] % A == 0 else H[i] // A + 1
        index = bisect_right(X, X[i] + 2 * D)
        bit.add(i, index+1, cnt * A)
        ans += cnt

    print(ans)



if __name__ == "__main__":
    main()
Problem p02850 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(4100000)

def main():
    N = int(input())
    d = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        d[a].append((b,i))
        d[b].append((a,i))

    ans = [0] * (N - 1) 

    def dfs(v, c, p):
        k = 1
        for i in range(len(d[v])):
            u = d[v][i][0]
            ei = d[v][i][1]
            if u == p:
                continue
            if k == c:
                k += 1
            ans[ei] = k
            k += 1
            dfs(u,ans[ei],v)
    
    dfs(0,-1,-1)
    print(max(ans))
    for a in ans:
        print(a)

        

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque

def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append([b,i])
        edge[b].append([a,i])
    color = [0] * (N-1)
    def dfs(s,p,c):
        tmp_c = 1
        for v, num in edge[s]:
            if v == p:
                continue
            if tmp_c == c:
                tmp_c += 1
            color[num] = tmp_c
            dfs(v,s,tmp_c)
            tmp_c += 1
    dfs(0,-1,0)
    print(max(color))
    for c in color:
        print(c)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

def main():
    N = int(input())
    visited = [False] * N
    d = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        d[a].append((b,i))
        d[b].append((a,i))

    ans = [0] * (N - 1) 

    def dfs(v, c, p):
        k = 1
        for i in range(len(d[v])):
            u = d[v][i][0]
            ei = d[v][i][1]
            if u == p:
                continue
            if k == c:
                k += 1
            ans[ei] = k
            k += 1
            dfs(u,ans[ei],v)
    
    dfs(0,-1,-1)
    print(max(ans))
    for a in ans:
        print(a)

        

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    visited = [False] * N
    d = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        d[a].append((b,i))
        d[b].append((a,i))

    ans = [0] * (N - 1) 

    def dfs(v, c, p):
        k = 1
        for i in range(len(d[v])):
            u = d[v][i][0]
            ei = d[v][i][1]
            if u == p:
                continue
            if k == c:
                k += 1
            ans[ei] = k
            k += 1
            dfs(u,ans[ei],v)
    
    dfs(0,-1,-1)
    print(max(ans))
    for a in ans:
        print(a)

        

if __name__ == "__main__":
    main()
Problem p02882 (python)

Fixed submission:
from decimal import *
import math

def main():
    a, b, x = map(int, input().split())
    if a * a * b == x:
        print(0)
        exit()
    if Decimal(a) * Decimal(b) / Decimal(2) >= Decimal(x) / Decimal(a):
        tmp = Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(b))
        c = math.atan(Decimal(tmp) / Decimal(b))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))
    else:
        d = (Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(a))) - Decimal(b)
        c = math.atan(Decimal(a) / (Decimal(b) - Decimal(d)))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math
from decimal import *

def main():
    a, b, x = map(int, input().split())
    c = decimal(b) * decimal(b) * decimal(a)
    ans = math.degrees(math.atan(decimal(c)/decimal(x)))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from decimal import *
import math

def main():
    a, b, x = map(int, input().split())
    if Decimal(a) * Decimal(b) / Decimal(2) >= Decimal(x) / Decimal(a):
        tmp = Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(b))
        c = math.atan(Decimal(tmp) / Decimal(b))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))
    else:
        d = (Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(a))) - Decimal(b)
        c = math.atan(Decimal(a) / (Decimal(b) - Decimal(d)))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))


if __name__ == "__main__":
    main()
Problem p02960 (python)

Fixed submission:
def main():
    S = list(input())

    dp = [0] * 13
    dp[0] = 1
    mod = 10**9 + 7
    digit = 1
    for i in range(len(S)-1,-1,-1):
        nextdp = [0] * 13
        if S[i] == '?':
            for j in range(10):
                for k in range(13):
                    nextdp[(j * digit + k) % 13] += dp[k]
                    # あらかじめ10*9 + 7で割って余りを出しておく
                    nextdp[(j * digit + k) % 13] %= mod
        else:
            j = int(S[i])
            for k in range(13):
                nextdp[(j * digit + k) % 13] += dp[k]
                # あらかじめ10*9 + 7で割って余りを出しておく
                nextdp[(j * digit + k) % 13] %= mod
        
        digit *= 10
        # A * 桁数の13で割ったあまりは (A % 13) * (桁数 % 13)のため、桁数を13で割っておく
        digit %= 13
        dp = nextdp
    
    print(dp[5])

main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()
    N = len(S)
    MOD = 10 ** 9 + 7
    dp = [[0] * 12 for _ in range(N + 5)]
    dp[0][0] = 1

    for i in range(N):
        if S[i] != '?':
            for j in range(13):
                dp[i+1][(j * 10 + int(S[i]))%13] += dp[i][j]
                dp[i+1][(j * 10 + int(S[i]))%13] %= MOD
        else:
            for k in range(10):
                for j in range(13):
                    dp[i+1][(j * 10 + k)%13] += dp[i][j]
                    dp[i+1][(j * 10 + k)%13] %= MOD

    print(dp[N][5])

    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()

def main():
    S = input()
    S = S[::-1]

    dp = [[0] * 15 for _ in range(len(S) + 5)]
    MOD = 10**9 + 7

    dp[0][0] = 1

    for i in range(len(S)):
        for j in range(13):
            if S[i] != '?':
                k = int(S[i])
                dp[i+1][(j+k*10**i)%13] += dp[i][j]
                dp[i+1][(j+k*10**i)%13] %= MOD
            else:
                for k in range(10):
                    dp[i+1][(j+k*10**i)%13] += dp[i][j]
                    dp[i+1][(j+k*10**i)%13] %= MOD


    print(dp[len(S)][5])



main()
Problem p02972 (python)

Fixed submission:
def main():
    N = int(input())
    a = [0] + list(map(int, input().split()))

    b = [0] * (N + 1) 

    for i in range(N,0,-1):
        sum = 0
        for j in range(2*i, N+1, i):
            sum += b[j]
        if sum % 2 != a[i] % 2:
            b[i] = 1
    
    ans = []
    for i in range(1,N+1):
        if b[i] == 1:
            ans.append(i)
    
    print(len(ans))
    print(*ans)

main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = [0] * N
    for i, a in enumerate(reversed(A)):
        tmp = N - i 
        cnt = 1
        tmp_sum = 0
        if tmp == 1:
            if a % 2 == sum(ans) % 2:
                break
            else:
                ans[tmp-1] = 1
                break
        while tmp <= N:
            tmp_sum += ans[tmp-1]
            cnt = cnt + 1
            tmp = tmp * cnt
        
        if a % 2 == tmp_sum % 2:
            continue
        else:
            ans[tmp-1] = 1
    if ans.count(0) == len(ans):
        print(0)
    else:
        print(len(ans))
        print(*ans)
main()
Problem p02985 (python)

Fixed submission:
import sys
from math import factorial
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(10 ** 5 + 5)
MOD = 10 ** 9 + 7

def permutations_count(n, r):
    return (comb(n,r) * factorial(r)) % MOD

def main():
    N, K = map(int, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append(b)
        edge[b].append(a)

    ans = 1
    q = deque([])
    q.append((0,-1))
    while q:
        s, p = q.popleft()
        for v in edge[s]:
            if p == v:
                continue
            q.append((v,s))
        nk = K if p == -1 else K - 2
        c = len(edge[s]) + 1 if p == -1 else len(edge[s]) - 1
        ans *= permutations_count(nk,c)
        ans %= MOD

    

    print(ans)


    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from math import factorial
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

ans = 1

def permutations_count(n, r):
    if n < 0:
        return 0
    return factorial(n) // factorial(n - r)

def main():
    N, K = map(int, input().split())
    edge = [[] for _ in range(N)]
    MOD = 10 ** 9 + 7
    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append(b)
        edge[b].append(a)


    def dfs(s,p):
        global ans
        for u in edge[s]:
            if p == u:
                continue
            dfs(u,s)
        k = K if p == -1 else K-2
        # edge[u]には親が含まれているため-1する必要がある
        nc = len(edge[s]) + 1 if p == -1 else len(edge[s]) - 1
        ans *= permutations_count(k, nc)
        ans %= MOD
    
    dfs(0,-1)
    

    print(ans)


    
if __name__ == "__main__":
    main()
Problem p03032 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K+1-l):
            if l + r > N:
                continue
            D = K - l - r
            S = []
            now = 0
            for i in range(l):
                now += V[i]
                S.append(V[i])
            for j in range(N-r,N):
                now += V[j]
                S.append(V[j])

            sort_S = sorted(S)
            for d in range(min(D,len(S))):
                if sort_S[d] < 0:
                    now += abs(sort_S[d])

            ans = max(ans, now)

    print(ans)
            

main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K+1-l):
            if l + r > K:
                continue
            D = K - l - r
            S = []
            now = 0
            for i in range(l):
                now += V[i]
                S.append(V[i])
            for j in range(N-1, N-1-r, -1):
                now += V[j]
                S.append(V[j])

            sort_S = sorted(S)
            for d in range(min(D,len(S))):
                if sort_S[d] < 0:
                    now += abs(sort_S[d])

            ans = max(ans, now)

    print(ans)
            

main()
Problem p03044 (python)

Fixed submission:
import heapq
import sys

input = sys.stdin.readline

def dijkstra_heap(s,edge,N):
    d = [float('inf')] * N
    used = [True] * N
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist, a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

def main():
    N = int(input())
    edge = [[] for i in range(N)]

    for i in range(N-1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        edge[u].append([w,v])
        edge[v].append([w,u])

    D = dijkstra_heap(0,edge,N)
    first = D[0]
    for d in D:
        if abs(d - first) % 2 == 0:
            print(0)
        else:
            print(1)

main()

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

X = [0] * M
Y = [0] * M
Z = [0] * M
for i in range(M):
    X[i], Y[i], Z[i] = map(int, input().split())

X1 = list(set(X))

print(N-len(X1))
Problem p03148 (python)

Fixed submission:
import heapq

def main():
    N, K = map(int, input().split())
    sushi_list = []
    for _ in range(N):
        t, d = map(int, input().split())
        sushi_list.append((d,t))
    sushi_list = sorted(sushi_list, reverse=True)

    # 各種類(最大でK種類目まで)でおいしさが最大のものを保存
    keep = []
    # 取り替えるようのheapq
    exchange = []
    # keepに入っている種類
    types = set()
    for i in range(K):
        d, t = sushi_list[i]
        if t not in types:
            keep.append(d)
            types.add(t)
        else:
            heapq.heappush(exchange, d)

    base_point1 = sum(keep)
    base_point2 = sum(exchange)
    bonus_point = len(types)

    ans = base_point1 + base_point2 + bonus_point ** 2
    
    # K～N番目までをみて、選んでいない種類で最大のものを交換していく
    for i in range(K, N):
        if len(exchange) == 0:
            break

        d, t = sushi_list[i]
        # すでに選んだ種類のものはスキップする
        if t in types:
            continue 
        types.add(t)
        # 選んでいない種類で最大のものを追加する
        base_point1 += d
        # 選んだ種類で最小のものを削除する
        base_point2 -= heapq.heappop(exchange)
        bonus_point += 1
        ans = max(ans, base_point1 + base_point2 + bonus_point ** 2)

    print(ans)


    

main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    d = defaultdict(list)
    for _ in range(N):
        t, v = map(int, input().split())
        d[t].append(v)

    other = []
    vmax = []
    for nums in d.values():
        vmax.append(max(nums))
        for j in nums:
            if j != max(nums):
                other.append(j)

    vmax.sort(reverse=True)
    other.sort(reverse=True)
    sum_v = list(accumulate(vmax))
    sum_o = list(accumulate(other))
    ans = 0
    for i in range(min(len(d), K)):
        tmp = (i + 1) * (i + 1) + sum_v[i]
        if K - (i + 1) > 0:
            tmp += sum_o[min(K-(i+1),len(sum_o))-1]
        ans = max(ans, tmp)

    print(ans)

    
    




if __name__ == "__main__":
    main()
Problem p03193 (python)

Fixed submission:
N, H, W = map(int, input().split(" "))
count = 0
for i in range(N):
        A, B = map(int, input().split(" "))
        if A // H > 0 and B // W > 0:
                count += 1

print(count)

Buggy submission (verdict: Runtime Error):
10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268
Problem p03263 (python)

Fixed submission:
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(list(map(int, input().split())))

    ope = []

    for i in range(H-1):
        for j in range(W):
            if A[i][j] % 2 == 1:
                A[i][j] -= 1
                A[i+1][j] += 1
                ope.append([i+1,j+1,i+2,j+1])
    for j in range(W-1):
        if A[H-1][j] % 2 == 1:
            A[H-1][j] -= 1
            A[H-1][j+1] += 1
            ope.append([H,j+1,H,j+2])
            

    print(len(ope))
    for o in ope:
        print(*o) 

main()

Buggy submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    ans = []
    for h in range(H):
        for w in range(W-1):
            if A[h][w] % 2 == 1:
                A[h][w] -= 1
                A[h][w+1] += 1
                ans.append([h+1,w+1,h+1,w+2])

    for h in range(H-1):
        if A[h][W-1] % 2 == 1:
            A[h][W-1] -= 1
            A[h+1][W-1] += 1
            ans.append([h+1,w+1,h+2,w+1])

    print(len(ans))
    for a in ans:
        print(*a)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(list(map(int, input().split())))

    ope = []

    for i in range(H):
        if i % 2 == 0:
            for j in range(W):
                if A[i][j] % 2 == 1:
                    if j != W - 1:
                        A[i][j] -= 1
                        A[i][j+1] += 1
                        ope.append([i+1,j+1,i+1,j+2])
                    elif i == H - 1 and j == W - 1:
                        continue
                    elif j == W - 1:
                        A[i][j] -= 1
                        A[i+1][j] += 1
                        ope.append([i+1,j+1,i+2,j+1])
        else:
            for j in range(W-1,-1,-1):
                if A[i][j] % 2 == 1:
                    if j != 0:
                        A[i][j] -= 1
                        A[i][j-1] += 1
                        ope.append([i+1,j+1,i+1,j])
                    elif i == 0 and j == 0:
                        continue    
                    elif j == 0:
                        A[i][j] -= 1
                        A[i+1][j] += 1
                        ope.append([i+1,j+1,i+2,j+1])

    print(len(ope))
    for o in ope:
        print(*o) 

main()
Problem p03309 (python)

Fixed submission:
from statistics import median

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N

    for i in range(N):
        B[i] = A[i] - i - 1

    b = int(median(B))
    sumB = 0
    for i in range(N):
        sumB += abs(B[i] - b)

    print(sumB)


main()

Buggy submission (verdict: Runtime Error):
from statistics import median

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N

    for i in range(N):
        B[i] = A[i] - i - 1

    b = int(median(B))
    sumB = 0
    for i in range(N):
        sumB += abs(B[i] - b)

    print(sumB)


main()
Problem p03436 (python)

Fixed submission:
from collections import deque

H,W = map(int, input().split())
s = [input() for _ in range(H)]

cnt = 0
for i in range(H):
    cnt += s[i].count('.')

dx = [1,0,-1,0]
dy = [0,1,0,-1]

visited = [[float('inf')] * W for i in range(H)]

def bfs():
    queue = deque([[0,0]])
    visited[0][0] = 1

    while queue:
        y,x = queue.popleft()

        if y == H - 1 and x == W - 1:
            return visited[y][x]
        
        for i in range(4):
            nx = x + dy[i]
            ny = y + dx[i]

            if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != '#' and visited[ny][nx] == float('inf'):
                queue.append([ny,nx])
                visited[ny][nx] = visited[y][x] + 1
    
    return -1

num = bfs()

if num == -1:
    print(num)
else:
    print(cnt - num)

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W = map(int, input().split())
s = [input() for _ in range(H)]

cnt = 0
for i in range(H):
    cnt += s[i].count('.')

dx = [1,0,-1,0]
dy = [0,1,0,-1]

visited = [[float('inf')] * W for i in range(H)]

def bfs():
    queue = deque([[0,0]])
    visited[0][0] = 1

    while queue:
        y,x = queue.popleft()

        if y == H - 1 and x == W - 1:
            return visited[y][x]
        
        for i in range(4):
            nx = x + dy[i]
            ny = y + dx[i]

            if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != '#' and visited[ny][nx] == float('inf'):
                queue.append([ny,nx])
                visited[ny][nx] = visited[y][x] + 1

print(cnt - bfs())
Problem p03495 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0])

n = sum( x > 0 for x in filter_TMP)

cnt = 0
ans = 0
while n > K:
    ans += filter_TMP[cnt]
    del filter_TMP[cnt]
    cnt += 1
    n -= 1

print(ans)