Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())

c -= a
d -= b

c = abs(c)
d = abs(d)

k = d/c
co = 0
kkk = 0
for i in range(1,c+1):
	if i * d / c == i * d // c:
		kk = i * d // c
		co += kk - kkk
		kkk = kk
	else:
		kk = i * d // c + 1
		co += kk - kkk
		kkk = kk - 1

print(co)


Fixed submission:
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


a,b,c,d = map(int,input().split())

c -= a
d -= b

c = abs(c)
d = abs(d)

ll = gcd(c,d)



k = d/c
co = 0
kkk = 0


print((c//ll + d//ll - 1)*ll)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())

c -= a
d -= b

c = abs(c)
d = abs(d)

k = d/c
co = 0
kkk = 0
for i in range(1,c+1):
	if i * d / c == i * d // c:
		kk = i * d // c
		co += kk - kkk
		kkk = kk
	else:
		kk = i * d // c + 1
		co += kk - kkk
		kkk = kk - 1

print(co)


Fixed submission:
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


a,b,c,d = map(int,input().split())

c -= a
d -= b

c = abs(c)
d = abs(d)

ll = gcd(c,d)



k = d/c
co = 0
kkk = 0


print((c//ll + d//ll - 1)*ll)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

b = mean(a)//1

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

b = sum(a)//n

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)
Buggy python submission (verdict: Runtime Error):
da = list(map(int,input(),split()))
a = 0
k = 0
for i in range(3):
  if  da[i] == 5:
    a += 1
  elif da[i] == 7:
    k += 1

if a == 2 and k == 1:
  print("YES")
else:
  print("NO")

Fixed submission:
da = list(map(int,input().split()))
a = 0
k = 0
for i in range(3):
  if  da[i] == 5:
    a += 1
  elif da[i] == 7:
    k += 1
 
if a == 2 and k == 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    c += 1
print(c)

Fixed submission:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)

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

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in c:
        if i in s: f = 0
    if f : break
    c += 1
print(c)

Fixed submission:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)

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

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in s:
        if i in c: f = 0
    if f : break
    c += 1
print(c)

Fixed submission:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)

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

c = input().split()

while 1:
    f = 1
    s = str(c)
    for i in c:
        if i in c: f = 0
    if f : break
    c += 1
print(c)

Fixed submission:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)
Buggy python submission (verdict: Runtime Error):
a = int(input())

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

b.sorted()

su = 0

for i in range(a-1):
  su += b[2*i]

Fixed submission:
a = int(input())

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

b.sort()

su = 0

for i in range(a):
  su += b[2*i]
print(su)

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

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

b.sorted()

su = 0

for i in range(a):
  su += b[2*i]

Fixed submission:
a = int(input())

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

b.sort()

su = 0

for i in range(a):
  su += b[2*i]
print(su)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
ans = 0
mod = 10**9 + 7
ans = sum(a[i]*a[j] for i in range(n) for j in range(i+1, n))
print(ans % mod)

Fixed submission:
from itertools import accumulate
n = int(input())
*a, = map(int, input().split())
cumsum = [0] + list(accumulate(a))
ans = sum(a[i]*cumsum[i] for i in range(n))
mod = 10**9 + 7
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
ans = 0
mod = 10**9 + 7
for i in range(n):
    ans += a[i]*sum(a[i+1:])
print(ans % mod)

Fixed submission:
from itertools import accumulate
n = int(input())
*a, = map(int, input().split())
cumsum = [0] + list(accumulate(a))
ans = sum(a[i]*cumsum[i] for i in range(n))
mod = 10**9 + 7
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
ans = 0
mod = 10**9 + 7
for i in range(n):
    for j in range(i+1, n):
        ans += a[i]*a[j]
print(ans % mod)

Fixed submission:
from itertools import accumulate
n = int(input())
*a, = map(int, input().split())
cumsum = [0] + list(accumulate(a))
ans = sum(a[i]*cumsum[i] for i in range(n))
mod = 10**9 + 7
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
*a, = map(int, input().split())
tmp = 1
for i in range(k):
    tmp *= a[i]
ans = [tmp]
for i in range(k, n):
    tmp //= a[i - k]
    tmp *= a[i]
    ans += [tmp]
for i, j in zip(ans, ans[1:]):
    print('Yes' if i < j else 'No')

Fixed submission:
n, k = map(int, input().split())
*a, = map(int, input().split())
for i, j in zip(a, a[k:]):
    print('Yes' if i < j else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from math import *
def f(n):
    ans = 0
    r = range(1, int(sqrt(n))+1)
    return sum(x**2 + y**2 + z**2 + x*y + y*z + z*x == n for x in r for y in r for z in r)

n = int(input())
for i in range(1, n+1):
    print(f(i))

Fixed submission:
n = int(input())
ans = [0]*(n+1)
r = range(1, int(n**0.5)+1)
for x in r:
    for y in r:
        for z in r:
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if a<=n:
                ans[a] += 1
for i in ans[1:]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
q = int(input())
d = [0]*(10**5+1)
for i in a:
    d[i] += 1
for _ in [0]*q:
    b, c = map(int, input().split())
    d[c] += d[b]
    d[b] = 0
    print(sum(i*j for i, j in enumerate(d)))

Fixed submission:
n = int(input())
*a, = map(int, input().split())
q = int(input())
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
ans = sum(a)
for _ in [0]*q:
    b, c = map(int, input().split())
    if b in d:
        if c in d:
            d[c] += d[b]
        else:
            d[c] = d[b]
        ans += (c-b)*d[b]
        d[b] = 0
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
q = int(input())
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for _ in [0]*q:
    b, c = map(int, input().split())
    if b in d:
        if c in d:
            d[c] += d[b]
        else:
            d[c] = d[b]
        d[b] = 0
    print(sum(i*j for i, j in d.items()))

Fixed submission:
n = int(input())
*a, = map(int, input().split())
q = int(input())
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
ans = sum(a)
for _ in [0]*q:
    b, c = map(int, input().split())
    if b in d:
        if c in d:
            d[c] += d[b]
        else:
            d[c] = d[b]
        ans += (c-b)*d[b]
        d[b] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
input()
*a, = map(int, input().split())
ans = 1
for i in a: ans *= i
print(ans if ans<=10**18 else -1)

Fixed submission:
input()
*a, = map(int, input().split())
if 0 in a:
    print(0)
    exit()
ans = 1
a = sorted(a)[::-1]
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())
def f(n):
    return math.floor(a*n/b) - a*math.floor(n/b)
ans = f(n)
for x in range(b-1, n+1, b):
    ans = max(ans, f(x))
print(ans)

Fixed submission:
from math import floor
a, b, n = map(int, input().split())
def f(x):
    return floor(a*x/b) - a*floor(x/b)
print(f(min(n, b-1)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())
ans = 0
for x in range(n, -1, -1):
    ans = max(ans, math.floor(a*x/b) - a*math.floor(x/b))
print(ans)

Fixed submission:
from math import floor
a, b, n = map(int, input().split())
def f(x):
    return floor(a*x/b) - a*floor(x/b)
print(f(min(n, b-1)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
for i in range(n):
    print(a.count(i+1))

Fixed submission:
n = int(input())
*a, = map(int, input().split())
d = {}
for i in range(1, -~n): d[i] = 0
for i in a:
    if i not in d: d[i] = 1
    else: d[i] += 1
for i in d.values():
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
def _gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

def gcd(a, b, c):
    return _gcd(_gcd(a, b), c)

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)
print(ans)

Fixed submission:
def _gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

def gcd(a, b, c):
    return _gcd(_gcd(a, b), c)

n = int(input())
ans = 0
for i in range(1, n+1):
    ans += gcd(i, i, i)
for i in range(1, n+1):
    for j in range(i+1, n+1):
        ans += gcd(i, j, j)*6
for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            ans += gcd(i, j, k)*6
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    b = a[:i] + a[i+1:]
    # print(b)
    c = list(set(b))
    # print(c)
    tmp = 0
    for i in c:
        n = b.count(i)
        tmp += n * (n-1) // 2
    print(tmp)

Fixed submission:
from collections import Counter
n = int(input())
*a, = map(int, input().split())
c = Counter(a)
s = sum(i*(i-1)//2 for i in c.values())
for k in range(n):
    print(s-c[a[k]]+1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    query = input()
    if query[0] == '1':
        s = s[::-1]
    else:
        _, f, c = query.split()
        if f == '1':
            s = c + s
        else:
            s = s + c
print(s)

Fixed submission:
from collections import deque
s = input()
q = int(input())
inv = False
pr, su = deque(), deque()
for _ in range(q):
    query = input()
    if query[0] == '1':
        inv = not inv
    else:
        _, f, c = query.split()
        if inv:
            if f == '1': su.append(c)
            else: pr.append(c)
        else:
            if f == '1': pr.append(c)
            else: su.append(c)
ans = ''.join(pr)[::-1] + s + ''.join(su)
print(ans[::-1] if inv else ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for _ in [0]*n]
s = sorted(s, key=s.count)
ans = []
for i in set(s):
    if s.count(i) == s.count(s[-1]):
        ans += [i]
print('\n'.join(sorted(ans)))

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

d = {}
cnt = 0
for i in range(n):
	if s[i] in d: d[s[i]] += 1
	else: d[s[i]] = 1
	cnt = max(cnt, d[s[i]])

l = []
for i in range(n):
	if d[s[i]] == cnt:
		l.append(s[i])

l = list(set(l))
l.sort()
for i in range(len(l)):
	print(l[i])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		sum = n * (n+1) / 2
		d[n] = sum / n
		return d[n]

idx = 0
mx = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	if mx < sum(pp):
		mx = sum(pp)
		idx = i

ans = 0
for i in p[idx:idx+k]:
	ans += kitaichi(i)

print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		sum = n * (n+1) / 2
		d[n] = sum / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		sum = 0
		for i in range(n+1):
			sum += i
		sum = n * (n+1) / 2
		d[n] = sum / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		ret = 0
		for i in range(n+1):
			ret += i
		d[n] = ret / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))

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

def kitaichi(n):
	ret = 0
	for i in range(n+1):
		ret += i
	return ret / n

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
print(min(abs(sum(a[:i]) - sum(a[i:])) for i in range(1, n)))

Fixed submission:
n = int(input())
*a, = map(int, input().split())
s = sum(a)
ans = s
tmp = 0
for i in a[:-1]:
    tmp += i
    ans = min(ans, abs(tmp*2 - s))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
print(*[a.index(i)+1 for i in range(1, n+1)])

Fixed submission:
n = int(input())
*a, = map(int, input().split())
b = [(j, i) for i, j in enumerate(a)]
b.sort()
print(*[j+1 for i, j in b])
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
b = [k]*n
for i in a:
    b = [b[j] if i-1==j else b[j]-1 for j in range(n)]
for i in b:
    print('Yes' if i>0 else 'No')

Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
b = [k]*n
for i in a: b[i-1] += 1
for i in b: print('Yes' if i>q else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum(i%(i+1) for i in range(1, n)))

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
r = range(1, n+1)
p = deque(r)
p.rotate(-1)
print(sum(i%p[i-1] for i in r))

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
print(sum(s[i]==s[j] for i in range(n) for j in range(i+1, n)))

Fixed submission:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
ans = 0
d = {}
for i in s:
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    print(max(a[:i]+a[i+1:]))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
idx = a.index(max(a))
a.sort()
for i in range(n):
    if i==idx:
        print(a[-2])
    else:
        print(a[-1])
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, n = map(int, input().split())
ans = 0
r = 0
while r*R <= n:
    g = 0
    while r*R + g*G <= n:
        b = (n - r*R - g*G) // B
        if (r*R + g*G + b*B == n) and (b >= 0):
            ans += 1
        g += 1
    r += 1
print(ans)


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

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, n = map(int, input().split())
ans = 0
for r in range(n+1):
    for g in range(n+1):
        v = r*R + g*G
        if n >= v and (n-v) % B == 0:
            ans += 1
print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(0, n+1, r):
    for j in range(i, n+1, g):
        if (n-j) % b == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
while True:
    if '01' in s: i = s.index('01')
    elif '10' in s: i = s.index('10')
    else: break
    s = s[:i] + s[i+2:]
    ans += 2
print(ans)

Fixed submission:
from collections import deque
s = input()
ans = 0
d = deque(s[0])
for i in s[1:]:
    if len(d) != 0 and d[-1] != i:
        ans += 2
        d.pop()
    else:
        d.append(i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
while True:
    for i in range(len(s)-1):
        if s[i]+s[i+1]=='BW':
            s[i], s[i+1] = s[i+1], s[i]
            ans += 1
            break
    else: break
    continue
print(ans)

Fixed submission:
s = input()
b = 0
ans = 0
for i in s:
    if i=='B':
        b += 1
    else:
        ans += b
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, s = map(int, input().split())
x = [abs(i-s) for i in map(int, input().split())]
for i in range(min(x), -1, -1):
    if all(j%i==0 for j in x):
        print(i)
        exit()

Fixed submission:
from fractions import *
from math import *
from functools import reduce

def gcds(*xs):
    return reduce(gcd, xs)

n, s = map(int, input().split())
x = [abs(i-s) for i in map(int, input().split())]
print(gcds(*x))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*x, = map(int, input().split())
for i in range(n):
    y = sorted(x[:i]+x[i+1:])
    print(y[(n-1)//2])

Fixed submission:
n = int(input())
*x, = map(int, input().split())
y = sorted(x)
for i in x:
    if i < y[n//2]:
        print(y[n//2])
    else:
        print(y[n//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for i in range(a, b+1):
    if i-a+1 <= k or b-i+1 <= k:
        print(i)

Fixed submission:
a, b, k = map(int, input().split())
ans = []
for i in range(a, a+k):
    ans += [i]*(i<=b)
for i in range(b, b-k, -1):
    ans += [i]*(a<=i)
print(*(sorted(set(ans))), sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
*a, = map(int, input().split())
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
a.sort(key=lambda x: d[x])
b = sorted(set(a), key=a.index)
cnt = len(b)
ans = 0
for i in b:
    if cnt <= k:
        break
    ans += d[i]
    cnt -= 1
print(ans)

Fixed submission:
n, k = map(int, input().split())
*a, = map(int, input().split())
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
cnt = len(d)
ans = 0
for _, i in sorted(d.items(), key=lambda x: x[1]):
    if cnt <= k:
        break
    ans += i
    cnt -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
*a, = map(int, input().split())
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
a.sort(key=lambda x: d[x])
b = sorted(set(a), key=a.index)
cnt = len(b)
ans = 0
for i in b:
    if cnt <= k:
        break
    ans += a.count(i)
    cnt -= 1
print(ans)

Fixed submission:
n, k = map(int, input().split())
*a, = map(int, input().split())
d = {}
for i in a:
    d[i] = d.get(i, 0)+1
cnt = len(d)
ans = 0
for _, i in sorted(d.items(), key=lambda x: x[1]):
    if cnt <= k:
        break
    ans += i
    cnt -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0]+[int(input()) for _ in [0]*n]
used = [False, True]+[False]*(n-1)
ans = 0
now = 1
while now!=2:
    b = a[now]
    if not used[b]:
        now = a[now]
        ans += 1
    else:
        print(-1)
        break
else:
    print(ans)

Fixed submission:
n = int(input())
a = [0]+[int(input()) for _ in [0]*n]
ans = 0
now = 1
while now!=2:
    now = a[now]
    ans += 1
    if ans > n:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = {}
def f(n):
    if n not in d:
        d[n] = 1
    else:
        d[n] += 1
for _ in [0]*m:
    a, b = map(int, input().split())
    f(a)
    f(b)
for i in range(1, n+1):
    print(d[i])

Fixed submission:
n, m = map(int, input().split())
d = {}
for i in range(1, n+1): d[i] = 0
for _ in [0]*m:
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1
for i in d.values():
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())
a.sort()
ans = 0
while n:
    a.pop(0)
    a.pop()
    ans += a.pop()
    n -= 1
print(ans)

Fixed submission:
import collections
n = int(input())
*a, = map(int, input().split())
a.sort()
a = collections.deque(a)
ans = 0
while n:
    a.popleft()
    a.pop()
    ans += a.pop()
    n -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += nums[i] * nums[j]
print(ans%(10**9+7))

Fixed submission:
n = int(input())
nums = list(map(int, input().split()))
total = sum(nums[1:])
ans = 0
for i in range(n-1):
    ans += nums[i] * total
    total -= nums[i+1]
print(ans%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
string = input()
count = []
for i in range(n+1):
    left = string[:i]
    right = string[i:]
    tmp_max = max(left.count("W"), right.count("R"))
    count.append(tmp_max)
print(min(count))

Fixed submission:
n = int(input())
string = input()

left = string[:0]
right = string[0:]
w, r = left.count("W"), right.count("R")
count = max(w,r)

for i in range(1,n+1):
    next_str = string[i-1]
    if next_str == "W":
        w +=1
    else:
        r -= 1
    tmp = max(w,r)
    if tmp < count:
        count = tmp
        
print(count)