Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math

def cal(N):
    num=math.ceil(N**0.5)
    num=int(num)
    for i in range(num,N+1):
       if N%i==0:
           x=len(str(i))
           break
    return x

print(cal(int(input())))

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))

Buggy python submission (verdict: Time Limit Exceeded):
import math

def cal(N):
    num=math.ceil(N**0.5)
    num=int(num)
    for i in range(num,N+1):
       if N%i==0:
           x=str(i)
           break
    return x

x=cal(int(input()))
print(len(x))

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))

Buggy python submission (verdict: Time Limit Exceeded):
import math

N=int(input())
num=math.ceil(N**0.5)
num=int(num)
for i in range(num,N+1):
    if N%i==0:
        x=str(i)
        break
print(len(x))

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))

Buggy python submission (verdict: Time Limit Exceeded):
import math

N=int(input())
num=math.ceil(N**0.5)
num=int(num)
for i in range(num,N+1):
    if N%i==0:
        x=str(i)
        break
print(len(x))

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))

Buggy python submission (verdict: Runtime Error):
import math

N=int(input())
num=(N**0.5)//1+1
num=int(num)
for i in range(num,N+1):
    if N%i==0:
        x=i
        break

ans=int((math.log(x,10)+1)//1)
print(ans)

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))

Buggy python submission (verdict: Runtime Error):
def cal1(n):
    num=(n**0.5)//1+1
    for i in range(num,n+1):
        if n//i==0:
            num=i
            break
    return num

import math

N=int(input())
num=cal1(N)
print(int((math.log(num,10)+1)//1))

Fixed submission:
def cal(N):
    num=(N**0.5)//1
    num=int(num)
    for i in range(num,0,-1):
       if N%i==0:
           k=int(N/i)
           x=len(str(k))
           break
    return x

print(cal(int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
X=input()

for i in range(int(len(X)/2)):
    s=X.find('ST')
    if s==-1:
        break
    else:
        X=X[:s]+X[s+2:]

print(len(X))

Fixed submission:
X=input()

ans=0
for i in range(len(X)):
    if X[i]=='S':
        ans+=1
    else:
        if ans==0:
            ans=0
        else:
            ans-=1
print(ans*2)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = []
for l, r in LR:
    tmp = [x for x in range(l, r+1)]
    dic += tmp
dic.sort()
dp = [0]*(N+1)
dp[1] = 1
n = len(dic)
cnt = 0
t = []
for i in range(2, N+1):
    tmp = i-1
    while cnt < n:
        if dic[cnt] <= tmp:
            t.append(dic[cnt])
            cnt += 1
        else:
            break
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])


Fixed submission:
def main():
    N, K = map(int, input().split())

    LR = [list(map(int, input().split())) for _ in range(K)]
    MOD = 998244353

    dp = [0]*(N+1)
    S = [0]*(N+1)
    dp[1] = 1
    S[1] = 1

    for i in range(2, N+1):
        for l, r in LR:
            if i-l < 0:
                continue
            else:
                dp[i] += S[i-l] - S[max(i-r-1, 0)]
        dp[i] %= MOD
        S[i] = S[i-1] + dp[i]
    print(dp[-1]%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = set()
for l, r in LR:
    for i in range(l, r+1):
        dic.add(i)
dic = list(dic)
dic.sort()
dp = [0]*(N+1)
dp[1] = 1

n = len(dic)
cnt = 0
t = []
for i in range(2, N+1):
    tmp = i-1
    while cnt < n:
        if dic[cnt] <= tmp:
            t.append(dic[cnt])
            cnt += 1
        else:
            break
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])


Fixed submission:
def main():
    N, K = map(int, input().split())

    LR = [list(map(int, input().split())) for _ in range(K)]
    MOD = 998244353

    dp = [0]*(N+1)
    S = [0]*(N+1)
    dp[1] = 1
    S[1] = 1

    for i in range(2, N+1):
        for l, r in LR:
            if i-l < 0:
                continue
            else:
                dp[i] += S[i-l] - S[max(i-r-1, 0)]
        dp[i] %= MOD
        S[i] = S[i-1] + dp[i]
    print(dp[-1]%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = set()
for l, r in LR:
    for i in range(l, r+1):
        dic.add(i)
dic = list(dic)
dp = [0]*(N+1)
dp[1] = 1

for i in range(2, N+1):
    tmp = i-1
    t = [x for x in dic if x <= tmp]
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])


Fixed submission:
def main():
    N, K = map(int, input().split())

    LR = [list(map(int, input().split())) for _ in range(K)]
    MOD = 998244353

    dp = [0]*(N+1)
    S = [0]*(N+1)
    dp[1] = 1
    S[1] = 1

    for i in range(2, N+1):
        for l, r in LR:
            if i-l < 0:
                continue
            else:
                dp[i] += S[i-l] - S[max(i-r-1, 0)]
        dp[i] %= MOD
        S[i] = S[i-1] + dp[i]
    print(dp[-1]%MOD)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
h, w, k = gets.chomp.split(" ").map(&:to_i)
map = Array.new(h)
h.times do |i|
  map[i]=gets.chomp.split("")
end

cnt = 0
ans = 0
(1<<h).times do |i|
  (1<<w).times do |j|
    cnt = 0
    h.times do |h_shift|
      w.times do |w_shift|
        next if i>>h_shift&1==1 or j>>w_shift&1==1
        if map[h_shift][w_shift] == "#"
          cnt += 1
        end
      end
    end
    if k==cnt
      ans += 1
    end
  end
end
puts ans


Fixed submission:
H, W, K = map(int, input().split())

origin = [list(input()) for _ in range(H)]
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h_shift in range(H):
            for w_shift in range(W):
                if i >> h_shift & 1 == 1 or j >> w_shift & 1: #赤で塗られるマス
                    continue
                if origin[h_shift][w_shift] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
T = input()
ans = []
if T[0]=='?':
    T[0]='D'

for i in range(len(T)-1):
    flg = 1
    if T[i+1]!='?':
        if T[i] != '?':
            ans.append(T[i])
            continue
        else:
            tmp = ans[i-1]
            flg = 0

    if flg:
        tmp = ans[i-1]
    if tmp=='P':
        ans.append('D')
    else:
        ans.append('P')



if T[-1]=='?':
    if ans[-1]=='P':
        ans.append('D')
    else:
        ans.append('P')
else:
    ans.append(T[-1])
print(''.join(ans))


Fixed submission:
T = str(input())

ans = []
for i in T:
    if i == '?':
        ans.append('D')
    else:
        ans.append(i)

print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
import sys
N, K = map(int, input().split()) #N: 町の数, K: ちょうどこの回数でたどり着く町

visited = [False for _ in range(N)]

A = list(map(lambda n: int(n)-1, input().split()))
tmp = 0 #次に訪れる番号
visited[0] = True
#cnt = 0 #テレポートの回数
log = [0] #テレポートの記録

for i in range(1, K+1):
    tmp = A[tmp]
    if visited[tmp]:
        start = log.index(tmp)
        break

    visited[tmp] = True
    log.append(tmp)

if i == K:
    print(log[K])
else:
    loop = log[start:i+1]
    period = len(loop)
    remain = K - i
    print(loop[remain%period] + 1)   

Fixed submission:
import sys
N, K = map(int, input().split()) #N: 町の数, K: ちょうどこの回数でたどり着く町

visited = [False for _ in range(N)]

A = list(map(lambda n: int(n)-1, input().split()))
tmp = 0 #次に訪れる番号
visited[0] = True
#cnt = 0 #テレポートの回数
log = [0] #テレポートの記録

for i in range(1, K+1):
    tmp = A[tmp]
    if visited[tmp]:
        start = log.index(tmp)
        break

    visited[tmp] = True
    log.append(tmp)

if i == K:
    print(tmp+1)
else:
    loop = log[start:i+1]
    period = len(loop)
    remain = K - i
    print(loop[remain%period] + 1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

check = [0] * N

for i in range(K):
    d_i = int(input())
    A_i = map(int, input().split())
    for j in A_i:
        check[j] = 1

print(sum(1 for x in check if x == 0))


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

check = [0] * N

for i in range(K):
    d_i = int(input())
    A_i = map(int, input().split())
    for j in A_i:
        check[j-1] = 1

print(sum(1 for x in check if x == 0))
Buggy python submission (verdict: Runtime Error):
import math
R = int(input())

pi = math.pi

print(2*R*pis)


Fixed submission:
import math
R = int(input())

pi = math.pi

print(2*R*pi)
Buggy python submission (verdict: Runtime Error):
s = input()

if s[1]=='7':
    print('Yes')
elif s[2]=='7':
    print('Yes')
elif s[3]=='7':
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()

if s[0]=='7':
    print('Yes')
elif s[1]=='7':
    print('Yes')
elif s[2]=='7':
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
K = int(input())

import math

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        a = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(a,k)

print(ans)



Fixed submission:
K = int(input())

import math

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        a = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(a,k)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i,j,k)

print(ans)


Fixed submission:
K = int(input())

import math

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        a = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(a,k)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input()) #N: ボールの個数

A = list(map(int, input().split()))
count_A = [0]*(N+1)
count_pattern = [0]*(N+1)

for i in A:
    if count_A[i]==0:
        a = A.count(i)
        count_A[i] = a
        count_pattern[i] = (a*(a-1)//2)

max = sum(count_pattern)

for i in range(N):
    a = A[i]
    b = count_A[a]
    print(max - (b-1))


Fixed submission:
N = int(input()) #N: ボールの個数

A = list(map(int, input().split()))

from collections import defaultdict

d = defaultdict(int)
for i in A:
    d[i] += 1
max = sum([d[i]*(d[i]-1)//2 for i in range(1,N+1)])
ans = [max - d[i] + 1 for i in A]

for x in ans:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())

friends = [set() for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x: int(x)-1, input().split())
    friends[a].add(b)
    friends[b].add(a)

blocks = [set() for _ in range(N)]
for _ in range(K):
    c,d = map(lambda x: int(x)-1, input().split())
    blocks[c].add(d)
    blocks[d].add(c)

ans = [0]*N
visited = [False]*N
for i in range(N):
    if visited[i]: 
        continue
    d = [i]
    check = {i} 
    while len(d):
        tmp = d.pop()
        for k in friends[tmp]:
            if visited[k]:
                continue
            d.append(k) 
        visited[tmp] = True
        check.add(tmp)
    for j in check:
        ans[j] += len(check) - len(friends[j]&check) - len(blocks[j]&check) - 1
print(*ans)


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

friends = [set() for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x: int(x)-1, input().split())
    friends[a].add(b)
    friends[b].add(a)

blocks = [set() for _ in range(N)]
for _ in range(K):
    c,d = map(lambda x: int(x)-1, input().split())
    blocks[c].add(d)
    blocks[d].add(c)

ans = [0]*N
visited = [False]*N
for i in range(N):
    if visited[i]:
        continue
    visited[i] = True
    d = [i]
    check = {i} 
    while len(d):
        tmp = d.pop()
        for k in friends[tmp]:
            if visited[k]:
                continue
            d.append(k)
            visited[k] = True
            check.add(k)
    for j in check:
        ans[j] += len(check) - len(friends[j]&check) - len(blocks[j]&check) - 1
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int,input().split()))
check = [0]*1001
tmp_p = []
for p in P:
    if check[p]!=0:
        tmp_p.append(check[p])
    else:
        tmp = ((1+p)*p/2)/p
        tmp_p.append(tmp)
ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(tmp_p[i:k+i]))
print(ans)


Fixed submission:
n, k = map(int, input().split())
P = list(map(int,input().split()))
check = [0]*1001
tmp_p = []
for p in P:
    if check[p]!=0:
        tmp_p.append(check[p])
    else:
        tmp = ((1+p)*p/2)/p #期待値の計算
        tmp_p.append(tmp)
ans = sum(tmp_p[0:k])
tmp_ans = ans
for i in range(n-k):
    tmp_ans += (tmp_p[k+i]-tmp_p[i])
    ans = max(ans, tmp_ans)
print(ans)

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

tmp_p = []
for p in P:
    tmp = ((1+p)*p/2)/p
    tmp_p.append(tmp)
ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(tmp_p[i:k+i]))
print(ans)


Fixed submission:
n, k = map(int, input().split())
P = list(map(int,input().split()))
check = [0]*1001
tmp_p = []
for p in P:
    if check[p]!=0:
        tmp_p.append(check[p])
    else:
        tmp = ((1+p)*p/2)/p #期待値の計算
        tmp_p.append(tmp)
ans = sum(tmp_p[0:k])
tmp_ans = ans
for i in range(n-k):
    tmp_ans += (tmp_p[k+i]-tmp_p[i])
    ans = max(ans, tmp_ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())

print((a*b)//math.gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

print((a*b)//gcd(a,b))

Buggy python submission (verdict: Runtime Error):
from math import gcd
a, b = map(int, input().split())

print((a*b)//gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

print((a*b)//gcd(a,b))

Buggy python submission (verdict: Runtime Error):
from math import gcd
a, b = map(int, input().split())

print(a*b//gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

print((a*b)//gcd(a,b))

Buggy python submission (verdict: Runtime Error):
from math import gcd
a, b = map(int, input().split())

print(a*b//gcd(a,b))


Fixed submission:
a, b = map(int, input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

print((a*b)//gcd(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = list(map(int, input().split()))

for i in range(1, N+1):
    print(A.index(i)+1, end=" ")
print()


Fixed submission:
N = int(input())

A = list(map(int, input().split()))
ans = [0]*N
for i in range(N):
    ans[A[i]-1] = i+1

print(*ans)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a) 

X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [0]*N

def dfs(u, parent):
    ans[u] = ans[parent] + X[u]
    for v in graph[u]:
        if v != parent:
            dfs(v, u)
dfs(0, 0)
print(*ans)


Fixed submission:
from collections import deque
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a].append(b)
    graph[b].append(a)

ans = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

que = deque([0])
parent = [-1]*N
while que:
    node = que.pop()
    for v in graph[node]:
        if v == parent[node]:
            continue
        parent[v] = node
        que.append(v)
        ans[v] += ans[node] 

print(*ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = tuple(map(int, input().split()))

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])


Fixed submission:
N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = tuple(map(int, input(),split()))

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])


Fixed submission:
N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = tuple(map(int, input(),split()))

dp = [0, abs(H[1]-H[0])]

if N > 2:
    for i in range(2, N):
        dp[2] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])


Fixed submission:
N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())

H = list(map(int, input().split()))

dp = [0]*(N+1)
dp[2] = abs(H[0] - H[1])
if len(H) > 2:
    cnt = 3
    while dp[N] == 0:
        dp[cnt] = min((dp[cnt-1] + abs(H[cnt-1] - H[cnt-2])), dp[cnt-2] + abs(H[cnt-1] - H[cnt-3]))
        cnt += 1
else:
    dp[N] = abs(H[0] - H[1])

print(dp[N])


Fixed submission:
N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

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

dp = np.zeros(W+1)

for i, (w, v) in enumerate(items):
    tmp = np.zeros(W+1)
    tmp[w:] = dp[:W-w+1] + v
    dp[w:] = np.fmax(tmp[w:], dp[w:])

print(int(dp[-1]))


Fixed submission:
import numpy as np
N, W = map(int, input().split())

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

dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0

for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

print(np.max(np.where(dp <= W)))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

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

dp = np.zeros(W+1)

for i, (w, v) in enumerate(items):
    tmp = np.zeros(W+1)
    tmp[w:] = dp[:-w] + v
    dp[w:] = np.fmax(tmp[w:], dp[w:])

print(int(dp[-1]))


Fixed submission:
import numpy as np
N, W = map(int, input().split())

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

dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0

for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

print(np.max(np.where(dp <= W)))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N, K = map(int, input().split())
A = list(map(int ,input().split()))

d = Counter(A)
d.most_common()
n =len(d)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)

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

d = defaultdict(int)
for i in A:
    d[i] += 1

d_ = sorted(d.items(), key=lambda x:x[1], reverse=True)
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d_[i][1]
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N, K = map(int, input().split())
A = list(map(int ,input().split()))

d = Counter(A)
d.most_common()
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)

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

d = defaultdict(int)
for i in A:
    d[i] += 1

d_ = sorted(d.items(), key=lambda x:x[1], reverse=True)
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d_[i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
n = len(s)

ans = 7

for bit in range(2**(n-1)):
    tmp = s[0]
    for i in range(n-1):
        if (1<<i)&bit:
            tmp += '+'
        else:
            total += '-'
        tmp += s[i+1]
    total = eval(tmp)
    if total == ans:
        print(tmp + '=7')
        sys.exit()


Fixed submission:
import sys
s = input()
n = len(s)

ans = 7

for bit in range(2**(n-1)):
    tmp = s[0]
    for i in range(n-1):
        if (1<<i)&bit:
            tmp += '+'
        else:
            tmp += '-'
        tmp += s[i+1]
    total = eval(tmp)
    if total == ans:
        print(tmp + '=7')
        sys.exit()
Buggy python submission (verdict: Runtime Error):
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

tmp_b = 0
tmp_c = 0
max_b = B[-1]
max_c = C[-1]
ans = 0
for i in range(N):
    flg = False
    tmp = A[i]
    if tmp >= max_b:
        break
    while True:
        if B[tmp_b] > tmp:
            tmp = B[tmp_b]
            break
        else:
            tmp_b += 1
    while True:
        if C[tmp_c] > tmp:
            break
        else:
            tmp_c += 1
    k = tmp_c
    for j in range(tmp_b, N):
        if B[j] >= max_c or flg:
            break
        else:
            while True:
                if B[j] < C[k]:
                    ans += N-k
                    break
                else:
                    k += 1
                    if k == N:
                        flg = True
                        break

print(ans)


Fixed submission:
import bisect
N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a*(N-c)
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools

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

D = list(map(int, input().split()))
dic = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    dic.remove(i)

dict = map(str, dic)
n = len(str(N)) #何桁か

ans = []
for i in range(2):
    for v in itertools.permutations(dict, n+i):
        if int(''.join(v)) >= N:
            ans.append(int(''.join(v)))
print(min(ans))

Fixed submission:
N, K = map(int, input().split())
D = set(input().split())

for i in range(N, 10**5):
    if not set(str(i)) & D:
        print(i)
        break