Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(x) for x in input().split()]
s = input()
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(s[l-1:r].count("AC"))

Fixed submission:
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

c_lst = [x for x in range(n) if s[x] == "C" and s[x-1] == "A"]

cnt = 0
for i in range(q):
    for x in c_lst:
        if x+1 <= lst[i][0]:
            pass
        elif x+1 <= lst[i][1]:
            cnt += 1
        else:
            break
    print(cnt)
    cnt = 0


Fixed submission:
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

a_lst = [x for x in range(n) if s[x] == "A"]
cnt = 0
for i in range(q):
    for x in a_lst:
        if lst[i][0]-1 <= x and lst[i][1] > x+1:
            if s[x+1] == "C":
                cnt += 1
    print(cnt)
    cnt = 0

Fixed submission:
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

cnt = 0
for i in range(q):
    for x in range(lst[i][0]-1, lst[i][1]):
        if s[x] == "A" and s[x+1] == "C":
            if x+1 < lst[i][1]:
                cnt += 1
    print(cnt)
    cnt = 0

Fixed submission:
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

for i in range(q):
    print(s[lst[i][0]-1:lst[i][1]].count("AC"))

Fixed submission:
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

n = int(input())
a = [int(x) for x in input().split()]

def f(n,l):
    return sum([n % x for x in l])

def lcm(x,y):
    return x*y / gcd(x,y)

def lcm_m(l):
    return int(reduce(lcm, l, 1))

num = lcm_m(a) - 1
print(f(num, a))


Fixed submission:
from fractions import gcd
from functools import reduce

n = int(input())
a = [int(x) for x in input().split()]

def f(n,l):
    return sum([n % x for x in l])

m = 1
for x in a:
    m *= x
print(f(m-1, a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 10 ** 6

for i in range(n):
    a = s[:i].count("W")
    b = s[i:].count("E")
    ans = min(ans,a+b)
print(ans)



Fixed submission:
n = int(input())
s = list(input())

tmp = s[1:].count("E")
ans = tmp
for i in range(n-1):
    if s[i] == "W":
        tmp += 1
    if s[i+1] == "E":
        tmp -= 1
    ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
k = int(input())

l = []
for i in range(len(s)):
    for y in range(i+1,len(s)+1):
        #print(''.join(s[i:y]))
        if not ''.join(s[i:y]) in l:
            l.append(''.join(s[i:y]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])


Fixed submission:
s = list(input())
k = int(input())

l = []
for i in range(len(s)):
    for y in range(k):
#        print(''.join(s[i:i+y+1]))
        if not ''.join(s[i:i+y+1]) in l:
            l.append(''.join(s[i:i+y+1]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])

Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())

l = []
for i in range(len(s)-1):
    for y in range(i+1,len(s)+1):
        if not ''.join(s[i:y]) in l:
            l.append(''.join(s[i:y]))

l.sort()
if len(s) == 1:
    print(s[0])
else:
    print(l[k-1])


Fixed submission:
s = list(input())
k = int(input())

l = []
for i in range(len(s)):
    for y in range(k):
#        print(''.join(s[i:i+y+1]))
        if not ''.join(s[i:i+y+1]) in l:
            l.append(''.join(s[i:i+y+1]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])

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

l = []
for i in range(len(s)-1):
    for y in range(i+1,len(s)+1):
        if not str(s[i:y]) in l:
            l.append(str(s[i:y]))

l.sort()
if len(s) == 1:
    print(s)
else:
    print(l[k-1])


Fixed submission:
s = list(input())
k = int(input())

l = []
for i in range(len(s)):
    for y in range(k):
#        print(''.join(s[i:i+y+1]))
        if not ''.join(s[i:i+y+1]) in l:
            l.append(''.join(s[i:i+y+1]))

l.sort()
if not l:
    print(s[0])
else:
    print(l[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
import statistics
n = int(input())
x = [int(x) for x in input().split()]

#m = (n // 2) - 1
for i in range(n):
    l = x[:i] + x[i+1:]
#    l.sort()
    print(statistics.median(l))
    #print(l[m])

Fixed submission:
n = int(input())
x = [int(x) for x in input().split()]

s = sorted(x)

for i in range(n):
    if x[i] <= s[n//2 - 1]:
        print(s[n//2])
    else:
        print(s[n//2 - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = [int(x) for x in input().split()]

m = (n // 2) - 1
for i in range(n):
    l = x[:i] + x[i+1:]
    l.sort()
    print(l[m])

Fixed submission:
n = int(input())
x = [int(x) for x in input().split()]

s = sorted(x)

for i in range(n):
    if x[i] <= s[n//2 - 1]:
        print(s[n//2])
    else:
        print(s[n//2 - 1])
Buggy python submission (verdict: Runtime Error):
import itertools

n = int(input())
a = [int(x) for x in input().split()]


base = max(a)
ans = 0
ans_set = []
for x in a:
    if x == base:
        pass
    elif len(list(itertools.combinations(range(base), x))) > ans:
        ans = len(list(itertools.combinations(range(base), x)))
        ans_set = [base, x]
print(*ans_set)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

base = max(a)
tmp = 10**9
tmp_i = 0
for x in a:
    if x == base:
        pass
    elif abs(base - 2*x) < tmp:
        tmp = abs(base - 2*x)
        tmp_i = x

print(base, tmp_i)

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

n = int(input())
a = [int(x) for x in input().split()]


base = max(a)
ans = 0
ans_set = []
for x in a:
    if x == base:
        pass
    elif len(list(itertools.combinations(range(1, base+1), x))) > ans:
        ans = len(list(itertools.combinations(range(1, base+1), x)))
        ans_set = [base, x]
print(*ans_set)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

base = max(a)
tmp = 10**9
tmp_i = 0
for x in a:
    if x == base:
        pass
    elif abs(base - 2*x) < tmp:
        tmp = abs(base - 2*x)
        tmp_i = x

print(base, tmp_i)
Buggy python submission (verdict: Runtime Error):
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    print(c)
    #for i in range(len(s)):
    #    if a[i] != s[i]:
    #        ans = s[:i-1] + chr(ord(s[i-1])+1)
    #        break
    #print(ans)

Fixed submission:
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    end = False
    for i in range(25)[::-1]:
        if end:
            break
        for j in range(i+1,26)[::-1]:
            if s[i] < s[j]:
                print(s[:i]+s[j])
                end = True
                break

Buggy python submission (verdict: Runtime Error):
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    for i in range(len(s)):
        if a[i] != s[i]:
            ans = s[:i-1] + chr(ord(s[i-1])+1)
            break
    print(ans)

Fixed submission:
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    end = False
    for i in range(25)[::-1]:
        if end:
            break
        for j in range(i+1,26)[::-1]:
            if s[i] < s[j]:
                print(s[:i]+s[j])
                end = True
                break

Buggy python submission (verdict: Runtime Error):
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    for i in range(26):
        if a[i] != s[i]:
            ans = s[:i-1] + chr(ord(s[i-1])+1)
            break
    print(ans)

Fixed submission:
s = input()

a = list('abcdefghijklmnopqrstuvwxyz')

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
elif len(s) < 26:
    for x in a:
        if s.count(x) == 0:
            print(s + x)
            break
else:
    end = False
    for i in range(25)[::-1]:
        if end:
            break
        for j in range(i+1,26)[::-1]:
            if s[i] < s[j]:
                print(s[:i]+s[j])
                end = True
                break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

a.append(0)
tmp = 0
ans = 0

for i in range(n):
    for y in range(n+1):
        if i == y:
            pass
        else:
            ans += abs(a[y] - tmp)
            tmp = a[y]
    print(ans)
    tmp = 0
    ans = 0

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

a.append(0)
a.insert(0,0)

ans = 0

for i in range(1,n+2):
    ans += abs(a[i-1]-a[i])

for i in range(1,n+1):
    print(ans + abs(a[i-1] - a[i+1]) - (abs(a[i] - a[i-1]) + abs(a[i] - a[i+1])))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

a.insert(0,0)
ans = 0
visited = []
i = 1

while True:
    if a[i] == 2:
        ans += 1
        break
    elif not i in visited:
        ans += 1
        visited.append(i)
        i = a[i]
    else:
        ans = -1
        break
print(ans)

Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

a.insert(0,0)
ans = 0
i = 1

for x in range(n+1):
    if a[i] == 2:
        ans += 1
        break
    elif x == n:
        ans = -1
        break
    else:
        ans += 1
        i = a[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a,b = [int(x) for x in input().split()]

r = range(a,b+1)
tmp = []
ans = 0

if a == b:
    print(1)
elif n == 1:
    print(0)
else:
    for v in itertools.combinations_with_replacement(r, n-2):
        if not sum(v) in tmp:
            ans += 1
            tmp.append(sum(v))

    print(ans)

Fixed submission:
n,a,b = [int(x) for x in input().split()]

if a > b:
    print(0)
elif n == 1:
    if a != b:
        print(0)
    else:
        print(1)
else:
    print((b-a)*(n-2)+1)

Buggy python submission (verdict: Runtime Error):
import itertools
n,a,b = [int(x) for x in input().split()]

r = range(a,b+1)
tmp = []
ans = 0

if a == b:
    print(1)
elif n == 1:
    print(0)
else:
    for v in itertools.combinations_with_replacement(r, n-2):
        if not sum(v) in tmp:
            ans += 1
            tmp.append(sum(v))

    print(ans)

Fixed submission:
n,a,b = [int(x) for x in input().split()]

if a > b:
    print(0)
elif n == 1:
    if a != b:
        print(0)
    else:
        print(1)
else:
    print((b-a)*(n-2)+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

if n == 1:
    print(1)
else:
    for x in range(1,n):
        tmp = (1+x)*x//2
        if tmp >= n:
            l = x
            break

    d = tmp - n
    for x in range(1,l+1):
        if x != d:
            print(x)

Fixed submission:
n = int(input())

if n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    for x in range(1,n):
        tmp = (1+x)*x//2
        if tmp >= n:
            l = x
            break

    d = tmp - n
    for x in range(1,l+1):
        if x != d:
            print(x)
Buggy python submission (verdict: Runtime Error):
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
N = 10 ** 6
fact = [1, 1] + [0] * (N-2)
factinv = [1, 1] + [0] * (N-2)
inv = [0, 1] + [0] * (N-2)

for i in range(2, N + 1):
    fact[i] = (fact[i-1] * i) % p
    inv[i] = (-inv[p % i] * (p // i)) % p
    factinv[i] = (factinv[i-1] * inv[i-1]) % p

n, m, k = [int(i) for i in input().split()]

ret = 0
for i in range(k+1):
  ret += ((cmb(n-1, i, p) * m % p) * (power_func(m-1, n-1-i, p))) % p
print(ret % p)


Fixed submission:
s = input()
t = input()
if s == t[:-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
import sys
import math

def main():
    # a = sys.stdin.readline().strip()
    a, b, c, d = [int(i) for i in sys.stdin.readline().strip().split()]
    # [[int(i) for i in sys.stdin.readline().strip().split()] for _ in range(2)]
    n = b - a + 1
    # print(n)
    if a % c == 0:
        mi_c = a // c
    else:
        mi_c = a // c + 1
    ma_c = b // c
    n -= (ma_c - mi_c + 1)
    # print(ma_c, mi_c, n)

    if a % d == 0:
        mi_d = a // d
    else:
        mi_d = a // d + 1
    ma_d = b // d
    n -= (ma_d - mi_d + 1)
    # print(ma_d, mi_d, n)

    cd = (c * d) // math.gcd(c, d)
    if a % cd == 0:
        mi_cd = a // cd
    else:
        mi_cd = a // cd + 1
    ma_cd = b // cd
    n += (ma_cd - mi_cd + 1)
    # print(ma_cd, mi_cd, n)
    print(n)
    
main()


Fixed submission:
import sys
import fractions

def main():
    # a = sys.stdin.readline().strip()
    a, b, c, d = [int(i) for i in sys.stdin.readline().strip().split()]
    # [[int(i) for i in sys.stdin.readline().strip().split()] for _ in range(2)]
    n = b - a + 1
    # print(n)
    if a % c == 0:
        mi_c = a // c
    else:
        mi_c = a // c + 1
    ma_c = b // c
    n -= (ma_c - mi_c + 1)
    # print(ma_c, mi_c, n)

    if a % d == 0:
        mi_d = a // d
    else:
        mi_d = a // d + 1
    ma_d = b // d
    n -= (ma_d - mi_d + 1)
    # print(ma_d, mi_d, n)

    cd = (c * d) // fractions.gcd(c, d)
    if a % cd == 0:
        mi_cd = a // cd
    else:
        mi_cd = a // cd + 1
    ma_cd = b // cd
    n += (ma_cd - mi_cd + 1)
    # print(ma_cd, mi_cd, n)
    print(n)
    
main()
Buggy python submission (verdict: Runtime Error):
import sys
import itertools

def main():
    n, k = [int(i) for i in sys.stdin.readline().strip().split()]
    max_k = (n-1) * (n-2) // 2
    if max_n < k:
        print('-1')
        return
    
    pairs = [(1, i) for i in range(2, n+1)]
    l = max_k
    for c in itertools.combinations(list(range(2, n+1)), 2):
        if l == k:
            break
        pairs.append(c)
        max_k -= 1
    print(len(pairs))
    for p in pairs:
        print(p[0], p[1])
    return


main()

Fixed submission:
import sys
import itertools

def main():
    n, k = [int(i) for i in sys.stdin.readline().strip().split()]
    max_k = (n-1) * (n-2) // 2
    if max_k < k:
        print('-1')
        return
    
    pairs = [(1, i) for i in range(2, n+1)]
    l = max_k
    for c in itertools.combinations(list(range(2, n+1)), 2):
        if l == k:
            break
        pairs.append(c)
        l -= 1
    print(len(pairs))
    for p in pairs:
        print(p[0], p[1])
    return


main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = []
ans = 0

for _ in range(N):
    S = input()
    if S not in D:
        D.append(S)
        ans += 1

print(ans)


Fixed submission:
N = int(input())
D = {}
ans = 0

for _ in range(N):
    S = input()
    if S not in D:
        D[S] = True
        ans += 1

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

B = [[i, a] for i, a in enumerate(A)]

C = sorted(B, key=lambda b: b[1], reverse=True)

l = 0
r = N - 1

ans = 0
queue = [[C, l, r, 0]]
while queue:
    D, l, r, total = queue.pop()

    total2 = total + abs(D[0][0] - l) * D[0][1]
    if len(D) == 1:
        ans = max(ans, total2)
        continue
    else:
        queue.append([D[1:], l+1, r, total2])

    total2 = total + abs(D[0][0] - r) * D[0][1]
    if len(D) == 1:
        ans = max(ans, total2)
        continue
    else:
        queue.append([D[1:], l, r-1, total2])

print(ans)


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

B = [[i, a] for i, a in enumerate(A)]

C = sorted(B, key=lambda b: b[1], reverse=True)

dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]

dp[1][0] = (C[0][0] - 0) * C[0][1]
dp[0][1] = ((N - 1) - C[0][0]) * C[0][1]

ans = 0
for i in range(2, N + 1):
    for j in range(0, i + 1):
        t1, t2 = 0, 0

        if j - 1 >= 0:
            t1 = dp[j - 1][i - j] + abs((C[i - 1][0] - (j - 1))) * C[i - 1][1]

        if i - j - 1 >= 0:
            t2 = dp[j][i - j - 1] + abs((C[i - 1][0] - (N - (i - j)))) * C[i - 1][1]

        dp[j][i - j] = max(t1, t2)

        if i == N:
            ans = max(ans, dp[j][i - j])

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


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

d2 = {}
for k in range(N):
    a = A[k]

    if a not in d2:
        d2[a] = 0
        for i, n in d.items():
            if a == i:
                d2[a] += comb(n - 1, 2)
            else:
                d2[a] += comb(n, 2)
    print(d2[a])


Fixed submission:
import math


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

b = 0
for n in d.values():
    b += comb(n, 2)

for k in range(N):
    a = A[k]
    print(b - d[a] + 1)

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


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

for k in range(N):
    ans = 0
    a = A[k]
    for i, n in d.items():
        if a == i:
            ans += comb(n-1, 2)
        else:
            ans += comb(n, 2)
    print(ans)


Fixed submission:
import math


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

b = 0
for n in d.values():
    b += comb(n, 2)

for k in range(N):
    a = A[k]
    print(b - d[a] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
rev = False
for _ in range(Q):
    Query = input().split()
    if Query[0] == '1':
        rev = not rev
    else:
        if rev:
            if Query[1] == '1':
                S = S + Query[2]
            else:
                S = Query[2] + S
        else:
            if Query[1] == '1':
                S = Query[2] + S
            else:
                S = S + Query[2]
if rev:
    S = S[::-1]
print(S)


Fixed submission:
S = input()
Q = int(input())
L = ''
R = ''
rev = False
for _ in range(Q):
    Query = input().split()
    if Query[0] == '1':
        rev = not rev
    else:
        if rev:
            if Query[1] == '1':
                R = R + Query[2]
            else:
                L = Query[2] + L
        else:
            if Query[1] == '1':
                L = Query[2] + L
            else:
                R = R + Query[2]
S = L + S + R
if rev:
    S = S[::-1]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
count_rmv = 0
count_int = sorted(collections.Counter(A).values())
num_int_type = len(count_int)

while num_int_type > K:
    count_rmv += count_int[0]
    del count_int[0]
    num_int_type -= 1

print(count_rmv)


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import collections

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

count_rmv = 0
count_int = collections.Counter(A).most_common()
num_int_type = len(count_int)

while num_int_type > K:
    num_int_type -= 1
    count_rmv += count_int[num_int_type][1]

print(count_rmv)
Buggy python submission (verdict: Runtime Error):
import math
a,b,h,m=map(int,input().split())
angle=abs(m*6-(h*30+m/60*30))
print(math.sqrt(a*a+b*b-2*a*b*math.cos(angle/180*pi)))


Fixed submission:
import math
a,b,h,m=map(int,input().split())
angle=abs(m*6-(h*30+m/60*30))
print(math.sqrt(a*a+b*b-2*a*b*math.cos(angle/180*math.pi)))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import numpy as np

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans+=np.gcd(i,np.gcd(j,k))
print(str(ans)+"\n")


Fixed submission:
from sys import stdin

A=input()
if A[0]=='7' or A[1]=='7' or A[2]=='7':
    print("Yes\n")
else:
    print("No\n")
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import numpy as np

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans+=np.gcd(i,np.gcd(j,k))
print(str(ans)+"\n")

Fixed submission:
from sys import stdin

def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

k=int(input())
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,gcd(j,k))
print(str(ans)+"\n")

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

k=int(input())
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,gcd(j,k))
print(str(ans)+"\n")

Fixed submission:
from sys import stdin

def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

k=int(input())
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,gcd(j,k))
print(str(ans)+"\n")