Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as c
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
W,V = [],[]
for i in range(N):
    w,v = map(int,input().split())
    W.append(w),V.append(v)

ans = 0
for i in range(1,N+1):
    for a,b in zip(c(V,i),c(W,i)):
        if sum(b) > M:
            continue
        ans = max(ans,sum(a))
print(ans)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as c
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
W,V = [],[]
for i in range(N):
    w,v = map(int,input().split())
    W.append(w),V.append(v)

ans = 0
for i in range(1,N+1):
    for a,b in zip(c(V,i),c(W,i)):
        if sum(b) > M:
            continue
        ans = max(ans,sum(a))
print(ans)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
H = [int(input()) for _ in range(N)]
ans = 0
H.sort()
for i in range(N-K+1):
    a = H[i:i+K]
    b = max(a)-min(a)
    if i == 0:
        ans = b
    elif ans > b:
        ans = b
print(ans)

Fixed submission:
N,K = map(int,input().split())
H = [int(input()) for _ in range(N)]
ans = 10**10
H.sort()
for i in range(N-K+1):
    ans = min(ans,H[i+K-1]-H[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())

A = [1]
P = [1]
for i in range(n):
	A.append(A[i]*2+3)
	P.append(P[i]*2+1)
print(A,P)

def func(n,x):
	elif x == 1:
		return 0 if n != 0 else 1
	elif x <= 1+A[n-1]:
		return func(n-1,x-1)
	elif x == 2+A[n-1]:
		return P[n-1]+1
	elif x <= 2+2*A[n-1]:
		return P[n-1]+1+func(n-1,x-2-A[n-1])
	else:
		return 2*P[n-1]+1

print(func(n,x))

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

A = [1]
P = [1]
for i in range(n):
	A.append(A[i]*2+3)
	P.append(P[i]*2+1)
# print(A,P)

def func(n,x):
	if x == 1:
		return 0 if n != 0 else 1
	elif x <= 1+A[n-1]:
		return func(n-1,x-1)
	elif x == 2+A[n-1]:
		return P[n-1]+1
	elif x <= 2+2*A[n-1]:
		return P[n-1]+1+func(n-1,x-2-A[n-1])
	else:
		return 2*P[n-1]+1

print(func(n,x))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*max(N,M)
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)

Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)

Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*M
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)

Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)
Buggy python submission (verdict: Runtime Error):
from collections import Counter as c

e,o = 0,0
ans = 0
E,O = [],[]
for v,i in zip(V,range(N)):
    if i%2 == 0:
        E.append(v)
    else:
        O.append(v)
EC = c(E).most_common()
OC = c(O).most_common()
n = N//2

EC01=EC[0][1]

OC01=OC[0][1]

if len(EC) == 1:
    EC11 = 0
else:
    EC11=EC[1][1]
if len(OC) == 1:
    OC11 = 0
else:
    OC11=OC[1][1]
if len(EC) == 1 and len(OC) == 1 and EC[0][0]==OC[0][0]:
    ans = EC01
elif EC01+OC11 > EC11+OC01:
    ans += n - EC01
    ans += n - OC11
elif EC01+OC11 < EC11+OC01:
    ans += n - EC11
    ans += n - OC01
elif EC01 == OC01:
    ans = 0
print(ans)

Fixed submission:
from collections import Counter as c

N = int(input())
V = list(map(int,input().split()))
ev = c(V[::2]).most_common(2)
od = c(V[1::2]).most_common(2)

if ev[0][0] == od[0][0]:
    if len(ev) == 1 and len(od) == 1:
        print(N//2)
    else:
        print(N-max(ev[0][1]+od[1][1],ev[1][1]+od[0][1]))
else:
    print(N-ev[0][1]-od[0][1])

Buggy python submission (verdict: Runtime Error):
from collections import Counter as c

e,o = 0,0
ans = 0
E,O = [],[]
for v,i in zip(V,range(N)):
    if i%2 == 0:
        E.append(v)
    else:
        O.append(v)
EC = c(E).most_common()
OC = c(O).most_common()
n = N//2

EC01=EC[0][1]

OC01=OC[0][1]

if len(EC) == 1:
    EC11 = 0
else:
    EC11=EC[1][1]
if len(OC) == 1:
    OC11 = 0
else:
    OC11=OC[1][1]
if len(EC) == 1 and len(OC) == 1 and EC[0][0]==OC[0][0]:
    ans = EC01
elif EC01+OC11 > EC11+OC01:
    ans += n - EC01
    ans += n - OC11
elif EC01+OC11 < EC11+OC01:
    ans += n - EC11
    ans += n - OC01
elif EC01 == OC01:
    ans = 0
print(EC01,EC11,OC01,OC11)
print(ans)

Fixed submission:
from collections import Counter as c

N = int(input())
V = list(map(int,input().split()))
ev = c(V[::2]).most_common(2)
od = c(V[1::2]).most_common(2)

if ev[0][0] == od[0][0]:
    if len(ev) == 1 and len(od) == 1:
        print(N//2)
    else:
        print(N-max(ev[0][1]+od[1][1],ev[1][1]+od[0][1]))
else:
    print(N-ev[0][1]-od[0][1])
Buggy python submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = Y[0]%Y[1]
for y in Y:
    for i in range(y-1,0,-1):
        if y%i == 0:
            ans = max(ans,i)
            break
print(ans)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = max(Y)
for y in Y:
    ans = gcd(y,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
import math
minY = min(Y)
ans = 0
for i in range(len(Y)):
    ans = max(ans,math.gcd(minY,Y[i]))
print(ans)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = max(Y)
for y in Y:
    ans = gcd(y,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
X = list(map(int,input().split()))

ans = 10**9
for i in range(N-(K-1)):
	x = X[i:i+K]
	if (x[0] <= 0 and x[K-1] <= 0) or (x[0] >= 0 and x[K-1] >= 0):
		res = max(abs(x[0]),x[K-1])
	else:
		res = min(abs(x[0])*2 + x[K-1], x[K-1]*2 + abs(x[0]))
	ans = min(ans,res)
print(ans)

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

ans = 10**9
for i in range(N-K+1):
    ans = min(ans,X[i+K-1]-X[i]+min(abs(X[i]),abs(X[i+K-1])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
X = list(map(int,input().split()))
ans = 10**9
for i in range(N-K+1):
    #print(X[i:i+K])
    if min(X[i:i+K]) >= 0:
        #print('a')
        ans = min(ans,max(X[i:i+K]))
    elif max(X[i:i+K]) <= 0:
        #print('b')
        ans = min(ans,abs(min(X[i:i+K])))
    else:
        #print('c')
        ans = min(ans,abs(min(X[i:i+K])*2)+max(X[i:i+K]))
print(ans)

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

ans = 10**9
for i in range(N-K+1):
    ans = min(ans,X[i+K-1]-X[i]+min(abs(X[i]),abs(X[i+K-1])))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)
print(s[ans_idx])

Fixed submission:
s = list(input())
k = int(input())-1
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)

print(s[ans_idx])

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

if int(s[0]) > 1:
    print(int(s[0]))
else:
    print(int(s[1]))

Fixed submission:
s = list(input())
k = int(input())-1
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)

print(s[ans_idx])
Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = map(int,input().split())
A = list(map(int,input().split()))
B = []
res = 0

for a in A:
    res += a
    B.append(res)
B = np.array(B)

ans = 0
for i in range(n):
    b = B[i:]
    # print(b)
    ans += np.count_nonzero(b%m == 0)
    B -= B[i]

print(ans)

Fixed submission:
from collections import Counter

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

B = [0]
res = 0
for a in A:
	res += a
	B.append(res%m)

C = Counter(B)
ans = 0
for c in C.values():
	ans += c*(c-1)//2

print(ans)

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

n,m = map(int,input().split())
A = list(map(int,input().split()))
B = []
res = 0

for a in A:
    res += a
    B.append(res)
B = np.array(B)

ans = 0
for i in range(n):
    b = B[i:]
    # print(b)
    ans += np.count_nonzero(b%m == 0)
    B -= B[i]

print(ans)

Fixed submission:
from collections import Counter

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

B = [0]
res = 0
for a in A:
	res += a
	B.append(res%m)

C = Counter(B)
ans = 0
for c in C.values():
	ans += c*(c-1)//2

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
def mod(m):
    if m == 0:
        return 0
    ans = 0
    for l in L:
        ans += m%l
    return max(ans,mod(m-1))
print(mod(max(L)*2))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
print(sum(A)-N)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A  = list(map(int,input().split()))
l,r=0,0
ans = 0
for i in range(N):
    if A[i] == min(A):
        ans += len(A[l:i])
        l = i+1
if A[-1] != min(A):
    ans += len(A[l:])
print(ans//(K-1) if ans%(K-1)==0 else ans//(K-1)+1)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
n = N-K
ans += n//(K-1)
ans += 1 if n%(K-1) != 0 else 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))

Fixed submission:
N = int(input())

def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))

Buggy python submission (verdict: Runtime Error):
%%timeit
def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))

Fixed submission:
N = int(input())

def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))

Buggy python submission (verdict: Time Limit Exceeded):
list6 = [6, 36, 216, 1296, 7776, 46656, 279936]
list9 = [9, 81, 729, 6561, 59049, 531441]

def f(N,ans):
    if N < 6:
        return ans + N
    if N < 9:
        return ans + (N-6)+1
 
    max6 = max(y for y in list6 if N >= y)
    max9 = max(y for y in list9 if N >= y)
    return min(f(N-max6,ans+1),f(N-max9,ans+1))

print(f(int(input()),0))

Fixed submission:
N = int(input())

def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list6,list9 = [6],[9]
i = 2
while list6[-1] <= 100000:
    list6.append(6**i)
    i += 1
i = 2
while list9[-1] <= 100000:
    list9.append(9**i)
    i += 1
ans = 0
def f(N,ans):
    if N < 6:
        return ans + N
    if N < 9:
        return ans + (N-6)+1
 
    max6 = max(y for y in list6 if N >= y)
    max9 = max(z for z in list9 if N >= z)
 
    a6 = N-max6
    a9 = N-max9
    return min(f(a6,ans+1),f(a9,ans+1))
print(f(N,0))

Fixed submission:
N = int(input())

def f9(a,i):
    if a < 9**i:
        return i-1
    return f9(a,i+1)

def f6(a,i):
    if a < 6**i:
        return i-1
    return f6(a,i+1)

def func(a,ans):
    if a < 6:
        return ans+a
    elif a < 9:
        return ans+1+(a-6)
    return min(func(a-6**f6(a,0),ans+1),func(a-9**f9(a,0),ans+1))

print(func(N,0))
Buggy python submission (verdict: Runtime Error):
def f(i):
    if i > len(S)-2:
        return 10**6
    ans = S[:i].count('W')+S[i+1:].count('E')
    return min(ans,f(i+1))

n=input()
S = input()+'_'

print(f(0))

Fixed submission:
input()
S = input()

def f():
    ans,total = 0,0
    for s in S:
        if s == 'W':
            total += 1
        elif total:
            total -= 1
            ans += 1
        else:
            pass
    return ans

print(f())

Buggy python submission (verdict: Runtime Error):
def f(i):
    if i > len(S)-2:
        return 10**6
    ans = S[:i].count('W')+S[i:].count('E')
    return min(ans,f(i+1))

input()
S = input()+'_'

print(f(0))

Fixed submission:
input()
S = input()

def f():
    ans,total = 0,0
    for s in S:
        if s == 'W':
            total += 1
        elif total:
            total -= 1
            ans += 1
        else:
            pass
    return ans

print(f())
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

S = []
for len_i in range(1,len(s)+1):
	for left_j in range(len(s)-len_i+1):
		cur_s = s[left_j:left_j+len_i]
		if cur_s not in S:
			S.append(s[left_j:left_j+len_i])
S.sort()
# print(S)
print(S[k-1])

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

S = []
for len_i in range(1,k+1):
	for left_j in range(len(s)-len_i+1):
		cur_s = s[left_j:left_j+len_i]
		if cur_s not in S:
			S.append(s[left_j:left_j+len_i])
S.sort()
# print(S)
print(S[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

Y = X.copy()
Y.sort()

for x in X:
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Fixed submission:
from copy import deepcopy

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

Y = X.copy()
Y.sort()

for x in X:
    if x <= Y[N//2-1]:
        print(Y[N//2])
    else:
        print(Y[N//2-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()

for x in X:
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Fixed submission:
from copy import deepcopy

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

Y = X.copy()
Y.sort()

for x in X:
    if x <= Y[N//2-1]:
        print(Y[N//2])
    else:
        print(Y[N//2-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()

for i in range(N):
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Fixed submission:
from copy import deepcopy

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

Y = X.copy()
Y.sort()

for x in X:
    if x <= Y[N//2-1]:
        print(Y[N//2])
    else:
        print(Y[N//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
ans = set()
n = [i for i in range(a,b+1)]
[ans.add(i) for i in n[:k]]
[ans.add(i) for i in n[-k:]]
ans = list(ans)
ans.sort()
[print(a) for a in ans]

Fixed submission:
a,b,k = map(int,input().split())
k -= 1
aa = min(a+k,b)
bb = max(b-k,a)
if aa < bb:
	[print(i) for i in range(a,aa+1)]
	[print(i) for i in range(bb,b+1)]
else:
	[print(i) for i in range(a,b+1)]
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def abX():
    ans = 0
    for a,b in AB:
        for c,d in CD:
            if a<c and b<d:
                ans+=1
                CD.remove([c,d])
                break
    return ans

def abY():
    ans = 0
    for a,b in ab:
        for c,d in cd:
            if a<c and b<d:
                ans+=1
                cd.remove([c,d])
                break
    return ans

print(max(abX(),abY()))

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=1,key=lambda x:x[1])
CD.sort()
ans = 0
for c,d in CD:
    for a,b in AB:
        if a<c and b<d:
            ans+=1
            AB.remove([a,b])
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i == 1 or i == n:
        continue
    ans += abs(m-2)
if n == 1:
    if m == 1:
        ans = 1
    else:
        ans = m-2
print(ans)

Fixed submission:
n,m = map(int,input().split())
if n == m == 1:
    ans = 1
elif n == 1 or m == 1:
    ans = n*m-2
elif n == 2 or m == 2:
    ans = 0
else:
    ans = (n-2)*(m-2)
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
stack = [[0,0]]
S[0][0] = 0

total_dot = 0
for sss in S:
    for s in sss:
        if s == ".":
            total_dot += 1

move = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 1
while stack:
    cur_stack = stack
    stack = []
    for si,sj in cur_stack:
        for mi,mj in move:
            i,j = si+mi,sj+mj
            if 0 > i or i >= h or 0 > j or j >= w:
                continue
            next_mass = S[i][j]
            if next_mass == "#":
                continue
            elif next_mass == ".":
                S[i][j] = cnt
                stack.append([i,j])
    cnt += 1
# [print(s) for s in S]
print(total_dot-S[-1][-1])

Fixed submission:
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
stack = [[0,0]]
S[0][0] = 0

total_dot = 0
for sss in S:
    for s in sss:
        if s == ".":
            total_dot += 1

move = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 1
while stack:
    cur_stack = stack
    stack = []
    for si,sj in cur_stack:
        for mi,mj in move:
            i,j = si+mi,sj+mj
            if 0 > i or i >= h or 0 > j or j >= w:
                continue
            next_mass = S[i][j]
            if next_mass == "#":
                continue
            elif next_mass == ".":
                S[i][j] = cnt
                stack.append([i,j])
    cnt += 1
# [print(s) for s in S]
print(total_dot-S[-1][-1]) if S[-1][-1] != "." else print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Y = map(int,input().split())
flag = 0
for a in range(0,N+1):
    if flag == 1:break
    for b in range(0,N+1):
        if flag == 1:break
        for c in range(0,N+1):
            if flag == 1:break
            if a+b+c == N and a*10000+b*5000+c*1000 == Y:
                print(a,b,c)
                flag = 1
                break
if flag == 0:
    print(-1,-1,-1)

Fixed submission:
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)

Buggy python submission (verdict: Runtime Error):
flag = 0
for a in range(0,N+1):
    if flag == 1:break
    for b in range(0,N+1):
        if flag == 1:break
        for c in range(0,N+1):
            if flag == 1:break
            if a+b+c == N and a*10000+b*5000+c*1000 == Y:
                print(a,b,c)
                flag = 1
                break
if flag == 0:
    print(-1,-1,-1)

Fixed submission:
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,Y = map(int,input().split())
satu = [10000,5000,1000]
flag = 0
for a in range(N+1):
    for b in range(N+1):
        for c in range(N+1):
            if a+b+c == N:
                if satu[0]*a+satu[1]*b+satu[2]*c == Y:
                    print(a,b,c)
                    flag = 1
                    sys.exit()
if flag == 0:print(-1,-1,-1)

Fixed submission:
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)