Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int, input().split())

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if (n - i*r - j*g) >= 0 and (n -i*r -j*g)%b == 0:
            ans += 1
            
print(ans)

Fixed submission:
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        sum = N - i * R - j * G
        if sum >= 0 and sum % B == 0:
            cnt += 1

print(cnt)

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

cnt = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        sum = N - i * R - j * G
        if sum >= 0 and sum % B == 0:
            cnt += 1

print(cnt)

Fixed submission:
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        sum = N - i * R - j * G
        if sum >= 0 and sum % B == 0:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
 
g1 = []
g2 = []
g3 = []
 
cnt = 0
 
for i in range(n):
    s = input()
    cnt += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        g3.append(s)
    elif s[0] == "B":
        g1.append(s)
    elif s[-1] == "A":
        g2.append(s)
        
a = len(g1)
b = len(g2)
c = len(g3)
 
if a == b:
    if a == c:
        cnt += c * 2
    elif a > c:
        cnt += c
        cnt += a
    elif a < c:
        if a == 0:
            cnt += c - 1
        else]:
            cnt += a
            cnt += c
elif a > b:
    cnt += b
    cnt += c
elif b > a:
    cnt += a
    cnt += c
 
print(cnt)

Fixed submission:
n = int(input())
 
g1 = []
g2 = []
g3 = []
 
cnt = 0
 
for i in range(n):
    s = input()
    cnt += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        g3.append(s)
    elif s[0] == "B":
        g1.append(s)
    elif s[-1] == "A":
        g2.append(s)
        
a = len(g1)
b = len(g2)
c = len(g3)
 
if a == b:
    if a == c:
        cnt += c * 2
    elif a > c:
        cnt += c
        cnt += a
    elif a < c:
        if a == 0:
            cnt += c - 1
        else:
            cnt += a
            cnt += c
elif a > b:
    cnt += b
    cnt += c
elif b > a:
    cnt += a
    cnt += c
 
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = 0
t = 0
sum1 = 0

for i in range(n):
    s = n // (i+1)
    t = n % (i+1)
    if s == t:
        sum1 += i+1
        
print(sum1)
        

Fixed submission:
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    # divisors.sort()
    return divisors

s = make_divisors(n)
sum = 0

for i in s:
    if i > 1:
        if n // (i - 1) == n % (i - 1):
            sum += i - 1

print(sum)
Buggy python submission (verdict: Runtime Error):
import functools
import fractions
import copy

N = int(input())
A_list = list(map(int, input().split()))
vlaues = []
values_list = []

for i in range(N):
    values = copy.copy(A_list)
    del values[i]
    gcd = functools.reduce(fractions.gcd, values)
    values_list.append(gcd)

print(max(values_list))



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

s = (T + 0.5) // A

ans = int(s * B)

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

n = int(input())
a = list(map(int, input().split()))
 
 
def gcd(x,y):
    while y:
        x,y = y, x % y
    return x
    
gcd_left = [0]
gcd_rigth = [0]
gcd_list = []

for i in range(n):
    s = gcd(gcd_left[i], a[i])
    gcd_left.append(s)
    
for i in range(n):
    t = gcd(gcd_rigth[i], a[-i-1])
    gcd_rigth.append(t)

for i in range(n):
    u = copy.copy(a)
    del u[i]
    v = gcd(gcd_left[i], gcd_rigth[n-1-i])
    gcd_list.append(v)

print(max(gcd_list))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
 
def gcd(x,y):
    while y:
        x,y = y, x % y
    return x
    
gcd_left = [0]
gcd_rigth = [0]
gcd_list = []

for i in range(n):
    s = gcd(gcd_left[i], a[i])
    gcd_left.append(s)
    
for i in range(n):
    t = gcd(gcd_rigth[i], a[-i-1])
    gcd_rigth.append(t)

for i in range(n):
    v = gcd(gcd_left[i], gcd_rigth[n-1-i])
    gcd_list.append(v)

print(max(gcd_list))

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import fractions
import copy
 
N = int(input())
A_list = list(map(int, input().split()))
values = []
values_list = []
 
for i in range(N):
    values = copy.copy(A_list)
    del values[i]
    gcd = functools.reduce(fractions.gcd, values)
    values_list.append(gcd)
 
print(max(values_list))
 

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
 
def gcd(x,y):
    while y:
        x,y = y, x % y
    return x
    
gcd_left = [0]
gcd_rigth = [0]
gcd_list = []

for i in range(n):
    s = gcd(gcd_left[i], a[i])
    gcd_left.append(s)
    
for i in range(n):
    t = gcd(gcd_rigth[i], a[-i-1])
    gcd_rigth.append(t)

for i in range(n):
    v = gcd(gcd_left[i], gcd_rigth[n-1-i])
    gcd_list.append(v)

print(max(gcd_list))

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import fractions
import copy

N = int(input())
A_list = list(map(int, input().split()))
vlaues = []
values_list = []

for i in range(N):
    values = copy.copy(A_list)
    del values[i]
    gcd = functools.reduce(fractions.gcd, values)
    values_list.append(gcd)

print(max(values_list))



Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
 
def gcd(x,y):
    while y:
        x,y = y, x % y
    return x
    
gcd_left = [0]
gcd_rigth = [0]
gcd_list = []

for i in range(n):
    s = gcd(gcd_left[i], a[i])
    gcd_left.append(s)
    
for i in range(n):
    t = gcd(gcd_rigth[i], a[-i-1])
    gcd_rigth.append(t)

for i in range(n):
    v = gcd(gcd_left[i], gcd_rigth[n-1-i])
    gcd_list.append(v)

print(max(gcd_list))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
s = list(s)

count = 0
white_count = 0
white_count2 = 0
black_count = 0
black_No = 0

for i in range(n):
    if s[i] == "#":
        black_No = i
        break

for i in range(n - black_No):
    if s[i + black_No] == ".":
        white_No = i + black_No
        break

while True:
    try:
        if s[white_No + count] == ".":
            count += 1
        else:
            break
    except:
        break

for i in range(n - black_No):
    if s[i + black_No] == ".":
        white_count += 1

if count > white_No - black_No:
    t = n - white_No - count
    for i in range(t):
        if s[i + white_No + count] == ".":
            white_count2 += 1
    for j in range(n - t):
        if s[j] == "#":
            black_count += 1
    result = black_count + white_count2
else:
    result = white_count

print(result)


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

count_black = 0
count_white = 0
a = n + 1
cnt_white = [0] * a
cnt_black = [0] * a
result = []

for i in range(n):
    if s[i] == ".":
        count_white += 1

cnt_white[0] = count_white

for i in range(n):
    if s[i] == "#":
        count_black += 1
    else:
        count_white -= 1
    cnt_white[i+1] = count_white
    cnt_black[i+1] = count_black

for i in range(n+1):
    result.append(cnt_black[i] + cnt_white[i])

ans = min(result)

print(ans)

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

count = 0
white_count = 0
white_count2 = 0

for i in range(n):
    if s[i] == ".":
        white = i
        break

while True:
    try:
        if s[white + count] == ".":
            count += 1
        else:
            break
    except:
        count -= 1
        break

for i in range(n):
    if s[i] == ".":
        white_count += 1

if count > white:
    n = n -white - white_count
    for i in range(n):
        if s[i + white + white_count] == ".":
            white_count2 += 1
    result = white + white_count2
else:
    result = white_count

print(result)


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

count_black = 0
count_white = 0
a = n + 1
cnt_white = [0] * a
cnt_black = [0] * a
result = []

for i in range(n):
    if s[i] == ".":
        count_white += 1

cnt_white[0] = count_white

for i in range(n):
    if s[i] == "#":
        count_black += 1
    else:
        count_white -= 1
    cnt_white[i+1] = count_white
    cnt_black[i+1] = count_black

for i in range(n+1):
    result.append(cnt_black[i] + cnt_white[i])

ans = min(result)

print(ans)
Buggy python submission (verdict: Runtime Error):
li = [int(input()) for _ in range(5)]

temp = 10
for i in range(5):
    if li[i]%10 != 0 and li[i]%10 < temp:
        temp = li[i]%10
        s = i
else:
    t = li.pop(s)
    
ans = 0

for i in li:
    if i%10 == 0:
        ans += i//10
    else:
        ans += 1 + i//10
        
print(ans * 10 + t)

Fixed submission:
li = [int(input()) for _ in range(5)]
 
s = 0
temp = 10
for i in range(5):
    if li[i]%10 != 0 and li[i]%10 < temp:
        temp = li[i]%10
        s = i
else:
    t = li.pop(s)
    
ans = 0

for i in li:
    if i%10 == 0:
        ans += i//10
    else:
        ans += 1 + i//10
        
print(ans * 10 + t)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

li = []

for i in range(n-1):
    if s[i:i+2] == "AC":
        li.append(i)

for i in range(q):
    ans = 0
    a,b = map(int, input().split())
    data1 = list(filter(lambda x: a-1 <= x <=b-2, li))
    print(len(data1))

Fixed submission:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

li = []

for i in range(n-1):
    if s[i:i+2] == "AC":
        li.append(i)

for i in range(q):
    ans = 0
    a,b = map(int, input().split())
    data1 = list(filter(lambda x: a-1 <= x <=b-2, li))
    print(len(data1))

Fixed submission:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

for i in range(q):
    x,y = map(int, input().split())
    
    print(s[x-1:y].count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()

for i in range(q):
    x,y = map(int, input().split())
    
    print(s[x-1:y].count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

p = len(s)
cnt = 0
temp = 0

while True:
    s = s.replace("01","")
    s = s.replace("10","")
    
    cnt = len(s)
    
    if temp == cnt:
        break
    temp = cnt
    
print(p - cnt)

Fixed submission:
s = input()

c0 = s.count("0")
c1 = s.count("1")

print(min(c0,c1)*2)

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

cnt = 0
temp = 0

while True:
    cnt += s.count("01") * 2
    s = s.replace("01","")
    
    cnt += s.count("10") * 2
    s = s.replace("10","")
    
    if temp == cnt:
        break
    temp = cnt
    
print(cnt)

Fixed submission:
s = input()

c0 = s.count("0")
c1 = s.count("1")

print(min(c0,c1)*2)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
li = list(map(int,input().split()))
ans = li[0]

for i in range(1,n):
    ans = math.gcd(ans,li[i])

print(ans)
    


Fixed submission:
n = int(input())
li = list(map(int,input().split()))
ans = li[0]

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

for i in range(1,n):
    ans = gcd(ans,li[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input().split()
s = [int(c) for c in s]
Sum = 0

Max = max(s)

for i in range(n):
    Sum += s[n]
    
if Max < Sum - Max:
    print("Yes")
else:
    print("No")

Fixed submission:
n = int(input())
s = input().split()
s = [int(c) for c in s]
Sum = 0

Max = max(s)

for i in range(n):
    Sum += s[i]
    
if Max < Sum - Max:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

dp = [10**18] * n

def rec(i):
    if dp[i] < 10**18:
        return dp[i]
    
    if i == 0:
        return 0
        
    res = rec(i-1) + abs(h[i] - h[i-1])
    if i > 1:
        res = min(res, rec(i-2) + abs(h[i] - h[i-2]))
    dp[i] = res
    return res

print(rec(n-1))


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

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(li[i] - li[i-1])
    else:
        dp[i] = min(abs(li[i] - li[i-1]) + dp[i-1], abs(li[i] - li[i-2]) + dp[i-2])

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
li = [int(x) for x in input().split()]

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i < k-1:
        temp = []
        for j in range(i):
            s = abs(li[i] - li[i-j-1]) + dp[i-j-1]
            temp.append(s)
        else:
            dp[i] = min(temp)
    elif i >= k-1:
        temp = []
        for j in range(k):
            s = abs(li[i] - li[i-j-1]) + dp[i-j-1]
            temp.append(s)
        else:
            dp[i] = min(temp)
            
print(dp[-1])


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

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(li[i] - li[i-1])
    else:
        dp[i] = min(abs(li[i] - li[i-1]) + dp[i-1], abs(li[i] - li[i-2]) + dp[i-2])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np

n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

city = [[] for _ in range(n+1)]
arr = []

for i in range(m):
    s,t = map(int,input().split())
    city[s].append(t)
    arr.append((s,t))

for i in range(1,n+1):
    city[i].sort()
    
for i in range(m):
    x = str(arr[i][0])
    y = str(city[int(x)].index(arr[i][1]) + 1)
    print(x.rjust(6, "0") + y.rjust(6,"0"))

Fixed submission:
import collections
import bisect

n,m = map(int,input().split())
 
city = [[] for _ in range(n+1)]
arr = []
 
for i in range(m):
    s,t = map(int,input().split())
    arr.append((s,t))
 
city =collections.defaultdict(list)

for x,y in sorted(arr):
    city[x] += [y]
for x,y in arr:
    z=str(bisect.bisect(city[x],y))
    print(str(x).rjust(6, "0") + z.rjust(6,"0"))
Buggy python submission (verdict: Time Limit Exceeded):
n,x = map(int,input().split())
li = list(map(int,input().split()))

res = []

s = 10**10

for i in range(n):
    s = abs(li[i] - x)
    res.append(s)
    
s = min(res)
    
while True:
    for i in range(n):
        if res[i]%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

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

res_abs = []
res = []

s = 10**10

for i in range(n):
    s = abs(li[i] - x)
    res_abs.append(s)
    
    s = li[i] - x
    res.append(s)
    
res.sort()

temp = 10**10

for i in range(n-1):
    temp = min(temp, res[i+1] - res[i])

    
s = min(min(res_abs), temp)
    
while True:
    for i in range(n):
        if res_abs[i]%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

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

s = 10**10

for i in range(n):
    s = min(s, abs(li[i] - x))
    
while True:
    for i in range(n):
        if abs(li[i]-x)%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1

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

res_abs = []
res = []

s = 10**10

for i in range(n):
    s = abs(li[i] - x)
    res_abs.append(s)
    
    s = li[i] - x
    res.append(s)
    
res.sort()

temp = 10**10

for i in range(n-1):
    temp = min(temp, res[i+1] - res[i])

    
s = min(min(res_abs), temp)
    
while True:
    for i in range(n):
        if res_abs[i]%s != 0:
            break
    else:
        print(s)
        exit()
        
    s -= 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int,input().split()))

cnt = 0
s = 0

while True:
    for i in range(n):
        if s == 0:
            if li[i] % 2 == 0:
                li[i] //= 2
                s = 1
            else:
                li[i] *= 3
        else:
            li[i] *= 3
    else:
        if s == 0:
            break
        s = 0
        cnt += 1
        
print(cnt)

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

cnt = 0
t = 0

while True:
    for i in range(t,n):
        if li[i] % 2 == 0:
            li[i] //= 2
            t = i
            cnt += 1
            break
    else:
        break

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

ans = max(x,y)*2*c
s = max(x,y)

while True:
    tmp = 0
    tmp -= c*2
    s -= 1
    if x > s:
        tmp += a
    if y > s:
        tmp += b
    if tmp > 0:
        print(ans)
        exit()
    else:
        ans += tmp

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

ans = 0

if a+b > c*2:
    ans += c*min(x,y)*2
    if x>y:
        ans += min(a*(x-y), c*(x-y)*2)
    else:
        ans += min(b*(y-x), c*(y-x)*2)
        
else:
    ans += a*x + b*y
    
print(ans)

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

if (a+b)//2 <= c　and x != 0 and y != 0:
    print(x*a + y*b)
    exit()
    
ans = 0

ans += min(x,y) * c * 2

if x >= y:
    ans += min((x-y)*a, (x-y)*2*c)
else:
    ans += min((y-x)*b, (y-x)*2*c)
    
print(ans)

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

ans = 0

if a+b > c*2:
    ans += c*min(x,y)*2
    if x>y:
        ans += min(a*(x-y), c*(x-y)*2)
    else:
        ans += min(b*(y-x), c*(y-x)*2)
        
else:
    ans += a*x + b*y
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = str(input())

li_n = list(map(int,n))

s = li_n[-1] + 1

ans = int(n) - s

ans2 = list(map(int,str(ans)))

print(sum(ans2))

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

if len(n) == 1:
    print(n[0])
    exit()

if n[1:].count(9) == len(n) -1:
    print(n[0] + (len(n)-1)*9)
else:
    print(n[0]-1 + (len(n)-1)*9)
Buggy python submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())
Map = [['#'] * (w+2)]
Map += [['#'] + list(input()) + ['#'] for _ in range(h)]
Map += [['#'] * (w+2)]

cnt = 0

for i in range(h+2):
    for j in range(w+2):
        if Map[i][j] == '.':
            cnt += 1
            
stack = deque([(1,1)])
Map[1][1] = 1
moved = [[0,1], [0,-1], [1,0], [-1,0]]

while stack:
    x, y = stack.popleft()
    for s, t in moved:
        if Map[x+s][y+t] == '.':
            stack.append((x+s, y+t))
            Map[x+s][y+t] = Map[x][y] + 1
            
goal = Map[-2][-2]

print(cnt - goal)

Fixed submission:
from collections import deque

h, w = map(int, input().split())
Map = [['#'] * (w+2)]
Map += [['#'] + list(input()) + ['#'] for _ in range(h)]
Map += [['#'] * (w+2)]

cnt = 0

for i in range(h+2):
    for j in range(w+2):
        if Map[i][j] == '.':
            cnt += 1
            
stack = deque([(1,1)])
Map[1][1] = 1
moved = [[0,1], [0,-1], [1,0], [-1,0]]

while stack:
    x, y = stack.popleft()
    for s, t in moved:
        if Map[x+s][y+t] == '.':
            stack.append((x+s, y+t))
            Map[x+s][y+t] = Map[x][y] + 1

goal = Map[-2][-2]
if goal == '.':
    print(-1)
else:
    print(cnt - goal)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

n,k = map(int,input().split())
a_li = list(map(int,input().split()))

d = defaultdict(int)

for key in a_li:
    d[key] += 1
d = sorted(d.items(), key=lambda x:x[1])

if k >= len(d):
    print(0)
    eixt()
    
s = len(d) - k
ans = 0

for i in range(s):
    ans += d[i][1]
    
print(ans)

Fixed submission:
from collections import defaultdict

n,k = map(int,input().split())
a_li = list(map(int,input().split()))

d = defaultdict(int)

for key in a_li:
    d[key] += 1
d = sorted(d.items(), key=lambda x:x[1])
    
s = len(d) - k
ans = 0

for i in range(s):
    ans += d[i][1]
    
print(ans)