Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
l = [0]
for i in range(n - 1):
    if s[i] != s[i + 1]:
        l.append(i + 1)
l += [n]
le = len(l)
ans = 0
for i in range(le - 1):
    if s[l[i]] == "0":
        ans = max(ans, l[min(le, k * 2 + i)] - l[i])
    else:
        ans = max(ans, l[min(le, k * 2 + i + 1)] - l[i])
print(ans)

Fixed submission:
n, k = map(int, input().split())
s = input()
l = [0]
for i in range(n - 1):
    if s[i] != s[i + 1]:
        l.append(i + 1)
l += [n]
le = len(l)
ans = 0
for i in range(le - 1):
    if s[l[i]] == "0":
        ans = max(ans, l[min(le - 1, k * 2 + i)] - l[i])
    else:
        ans = max(ans, l[min(le - 1, k * 2 + i + 1)] - l[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
for i in a:
    for j in b:
        l.append(i + j)
c.sort(reverse=True)
l.sort(reverse=True)
l2 = []
for i in c:
    for j in l:
        l2.append(i + j)
l2.sort(reverse=True)
print(*l2[:k], sep="\n")

Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
for i in a:
    for j in b:
        l.append(i + j)
c.sort(reverse=True)
l.sort(reverse=True)
l = l[:k]
l2 = []
for i in c:
    for j in l:
        l2.append(i + j)
l2.sort(reverse=True)
print(*l2[:k], sep="\n")
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int, nput().split())
print("Yes"if a==b==c else"No")

Fixed submission:
a, b, c = map(int, input().split())
if a == b == c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = list(input())
l = ["A", "C", "G", "T"]
l2 = []
cnt = 0
for i in range(len(s)):
    if s[i] in l:
        cnt += 1
    else:
        l2.append(cnt)
        cnt = 0
print(max(l2))

Fixed submission:
s = list(input())
l = ["A", "C", "G", "T"]
l2 = []
cnt = 0
for i in range(len(s)):
    if s[i] in l:
        cnt += 1
    else:
        l2.append(cnt)
        cnt = 0
l2.append(cnt)
print(max(l2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
l = [""]
for i in b:
    l.insert(i - 1, i)
for i in range(n):
    if l[i] > i + 1:
        exit(print(-1))
print(*l, sep="\n")

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
l = [""]
for i in b:
    l.insert(i - 1, i)
print(*l[-1] and [-1] or l, sep="\n")
Buggy python submission (verdict: Runtime Error):
n,a,b,c=map(int,input().split())
l=[int(input())for i in range(n)]
def dfs(i,x,y,z):
 if i==n:return abs(a-x)+abs(b-y)+abs(c-z)-30if a+b+c>=3else 10**9+7
 A,B,C,D=dfs(i+1,x,y,z),dfs(i+1,x+l[i],y,z)+10,dfs(i+1,x,y+l[i],z)+10,dfs(i+1,x,y,z+l[i])+10
 return min(A,B,C,D)
print(dfs(0,0,0,0)

Fixed submission:
n,a,b,c=map(int,input().split())
l=[int(input())for _ in range(n)]
def dfs(i,x,y,z):
 if i==n:return abs(a-x)+abs(b-y)+abs(c-z)-30if min(x,y,z)>0else 10**9
 return min(dfs(i+1,x,y,z),dfs(i+1,x+l[i],y,z)+10,dfs(i+1,x,y+l[i],z)+10,dfs(i+1,x,y,z+l[i])+10)
print(dfs(0,0,0,0))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
x = list(map(int, input().split()))
l = []
if n >= m:
    print(0)
    exit()
else:
    x.sort()
    for i in range(m - 1):
        l.append(x[i + 1] - x[i])
    for j in range(n - 1):
        l.remove(max(l))
    print(sum(l))

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
l = []
if n >= m:
    print(0)
else:
    x = set(x)
    x = list(x)
    x.sort()
    for i in range(m - 1):
        l.append(x[i + 1] - x[i])
    l.sort()
    l.reverse()
    del l[0:n - 1]
    print(sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y = 0, 0
ans = 1
if len(set(a)) < n or len(set(b)) < m:
    exit(print(0))
for i in range(n * m, 0, -1):
    if i in a and i in b:
        x += 1
        y += 1
    elif i in a:
        ans *= x
        y += 1
    elif i in b:
        ans *= y
        x += 1
    else:
        ans *= x * y - n * m + i
    ans %= 10 ** 9 + 7
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y = 0, 0
ans = 1
if len(set(a)) < n or len(set(b)) < m:
    exit(print(0))
for i in range(n * m, 0, -1):
    if i in a and i in b:
        x += 1
        y += 1
    elif i in a:
        ans *= x
        y += 1
    elif i in b:
        ans *= y
        x += 1
    else:
        ans *= x * y - n * m + i
    ans %= 10 ** 9 + 7
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for i in range(h)]
t = [[None] * w for i in range(h)]
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
def dfs(i, j, bw):
    global h, w
    if not (0 <= i < h and 0 <= j < w) or s[i][j] == bw or t[i][j]:
        return 0, 0
    t[i][j] = True
    W, b = 0, 0
    if s[i][j] == "#":
        b += 1
    else:
        W += 1
    for k in d:
        n, m = dfs(i + k[0], j + k[1], s[i][j])
        W += n
        b += m
    return W, b
ans = 0
for i in range(h):
    for j in range(w):
        X, Y = dfs(i, j, "u shi ta pu ni chi a ku n wara")
        ans += X * Y
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
h, w = map(int, input().split())
s = [input() for i in range(h)]
t = [[None] * w for i in range(h)]
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
def dfs(i, j, bw):
    global h, w
    if not (0 <= i < h and 0 <= j < w) or s[i][j] == bw or t[i][j]:
        return 0, 0
    t[i][j] = True
    W, b = 0, 0
    if s[i][j] == "#":
        b += 1
    else:
        W += 1
    for k in d:
        n, m = dfs(i + k[0], j + k[1], s[i][j])
        W += n
        b += m
    return W, b
ans = 0
for i in range(h):
    for j in range(w):
        X, Y = dfs(i, j, "u shi ta pu ni chi a ku n wara")
        ans += X * Y
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    l = []
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i- k), i))
print(dp[n - 1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    l = []
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i- k), i))
print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])

Fixed submission:
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])

Buggy python submission (verdict: Time Limit Exceeded):
def rec(i, j):
    if dp[i][j]:
        return dp[i][j]
    if i == n:
        res = 0
    elif j < w[i]:
        res = rec(i + 1, j)
    else:
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])
    dp[i][j] = res
    return res
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)
dp = [[0] * (W + 1) for i in range(n + 1)]
print(rec(0, W))

Fixed submission:
n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = list(s)
cnt = 0
for i in range(len(l)):
    if l[i] == "W":
        cnt += l[:i].count("B")
print(cnt)

Fixed submission:
s=input()
b=0
cnt=0
for i in range(len(s)):
  if s[i]=="B":
    b+=1
    cnt+=i
print(int((len(s)*2-b-1)*b*(1/2)-cnt))

Buggy python submission (verdict: Runtime Error):
def ans():
    global cnt, s, l
    if s.count("BW") == 0:
        return None
    for i in range(s.count("BW")):
        print(s)
        cnt += 1
        l.pop(s.index("BW") + 1)
        l[s.index("BW"):s.index("BW") + 1] = ["W", "B"]
        s = "".join(l)
    ans()
s = input()
l = list(s)
cnt = 0
ans()
print(cnt)

Fixed submission:
s=input()
b=0
cnt=0
for i in range(len(s)):
  if s[i]=="B":
    b+=1
    cnt+=i
print(int((len(s)*2-b-1)*b*(1/2)-cnt))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n, p = map(int, input().split())
c = Counter(prime_factorize(p))
ans = 1
for i in c.most_common():
    ans *= i[0] ** (i[1] // n)
print(ans)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
ans = -2 * sum(a[:n // 2])
if n % 2 == 0:
    ans += 2 * sum(a[n // 2:]) + a[n // 2 - 1] - a[n // 2]
else:
    ans += 2 * sum(a[n // 2 + 1:]) + max(a[n // 2 - 1] - a[n // 2], a[n // 2] - a[n // 2 + 1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
g = n * m // gcd(n, m)
gc = gcd(n, m)
l = ["" for i in range(g)]
for i in range(0, g, g // n):
    l[i] = s[i * gc // m]
for i in range(0, g, g // m):
    if l[i] != "":
        if l[i] != t[i * gc // n]:
            print(-1)
            exit()
print(g)

Fixed submission:
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
gcm = gcd(n, m)
lcm = n * m // gcm
for i in range(gcm):
    if s[(n // gcm) * i] != t[(m // gcm) * i]:
        print(-1)
        exit()
print(lcm)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
g = n * m // gcd(n, m)
gc = gcd(n, m)
l = ["" for i in range(g)]
for i in range(0, g, g // n):
    l[i] = s[i * gc // m]
for i in range(0, g, g // m):
    if l[i] != "":
        if l[i] != t[i * gc // n]:
            print(-1)
            exit()
print(g)

Fixed submission:
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
gcm = gcd(n, m)
lcm = n * m // gcm
for i in range(gcm):
    if s[(n // gcm) * i] != t[(m // gcm) * i]:
        print(-1)
        exit()
print(lcm)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
for i in range(len(s)):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
print("No")

Fixed submission:
s = list(input())
t = list(input())
for i in range(len(s)):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
for i in range(s):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
print("No")

Fixed submission:
s = list(input())
t = list(input())
for i in range(len(s)):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
for i in range(s):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
print("No")

Fixed submission:
s = list(input())
t = list(input())
for i in range(len(s)):
    s.insert(0, s.pop(-1))
    if s == t:
        print("Yes")
        exit()
print("No")
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
x = a[0]
ans = 0
for i in range(1, len(a)):
    x = (x * a[i]) // gcd(x, a[i])
for j in a:
    ans += (x - 1) % j
print(ans)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
x = a[0]
ans = 0
for i in range(1, len(a)):
    x = (x * a[i]) // gcd(x, a[i])
for j in a:
    ans += (x - 1) % j
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 0
while i < n - 1:
    if a[i] == a[i + 1] == a[i + 2]:
        cnt += 1
        i += 1
    elif a[i] == a[i + 1]:
        cnt += 1
    i += 1
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 0
while i < n - 1:
    if i < n - 2 and a[i] == a[i + 1] == a[i + 2]:
        cnt += 1
        i += 1
    elif a[i] == a[i + 1]:
        cnt += 1
    i += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = list(int(input()))
if N.count(0) == len(N) - 1:
  print(10)
else:
  sum(N)


Fixed submission:
N = list(input())
list1 = [int(x) for x in N]
if N.count("0") == len(N) - 1 and N[0] == "1" and len(N) != 1:
  print(10)
else:
  print(sum(list1))
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n,a,b,k=map(int,input().split())
A=0
m=998244353
for i in range(n+1):
 if (k-i*a)%b==0:A+=comb(n,i,exact=True)*comb(n,(k-i*a)//b,exact=True)%m
print(A%m)

Fixed submission:
mod = 998244353
n, a, b, k = map(int, input().split())
ans = 0
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
for i in range(n + 1):
    x = k - a * i
    if x >= 0 and x % b == 0:
        j = x // b
        if j <= n:
            ans += comb(n, i) * comb(n, j)
            ans %= mod
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb
n,a,b,k=map(int,input().split())
A=0
m=998244353
for i in range(n+1):
 if (k-i*a)%b==0:A+=comb(n,i,exact=True)*comb(n,(k-i*a)//b,exact=True)%m
print(A%m)

Fixed submission:
mod = 998244353
n, a, b, k = map(int, input().split())
ans = 0
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
for i in range(n + 1):
    x = k - a * i
    if x >= 0 and x % b == 0:
        j = x // b
        if j <= n:
            ans += comb(n, i) * comb(n, j)
            ans %= mod
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
I,i,R=input,int,range
n,L,R,A,C=i(I()),[],[],0,0
for _ in R(n):l,r=map(i,I().split());L+=[l];R+=[r]
L=sorted(l)[::-1];R.sort()
for j in R(n):C+=(L[j]-R[j])*2;A=max(A,C)
print(A)

Fixed submission:
I,i,H=input,int,range
n,L,R,A,C=i(I()),[0],[0],0,0
for _ in H(n):l,r=map(i,I().split());L+=[l];R+=[r]
L=sorted(L)[::-1];R.sort()
for j in H(n//2+1):C+=(L[j]-R[j])*2;A=max(A,C)
print(A)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if (abs(b - a) <= 3 and abs(c - b) <= 3) or abs(a - c) <= 3:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c, d = map(int, input().split())
if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if abs(a - c) <= d:
    print("Yes")
elif abs(a - c) <= d * 2 and ((a <= b and b <= c) or (a >= b and b >= c):
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c, d = map(int, input().split())
if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from math import sqrt
x = int(input())
cnt = 0
l = []
for i in range(1, x + 1):
    for j in range(1, int(sqrt(i)) +1):
        for k in range(2, i):
            if j ** k == i:
                l.append(i)
print(max(l))

Fixed submission:
from math import sqrt
x = int(input())
cnt = 0
l = []
for i in range(1, x + 1):
    for j in range(1, int(sqrt(i)) +1):
        for k in range(2, 10):
            if j ** k == i:
                l.append(i)
print(max(l))
Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split()))
l2 = set(l)
print(l2[0])

Fixed submission:
a,b = map(int, input().split())
if a > b:
  print(a - 1)
else:
  print(a)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#" and s[i - 1][j] != "#" and s[i][j - 1] != "#" and s[i + 1][j] != "#" and s[i][j + 1] != "#":
            print("No")
            exit()
print("Yes")

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
ans = "Yes"
for i in range(1, h - 1):
    for j in range(1, w - 1):
        if s[i][j] == "#" and s[i-1][j] == "." and s[i][j-1] == "." and s[i+1][j] == "." and s[i][j+1] == ".":
            ans = "No"
print(ans)
Buggy python submission (verdict: Runtime Error):
50 100 120

Fixed submission:
a, b, c = map(int, input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
l=list(s)
for i in range(len(s)):
 if 26-(ord(s[i])-ord("a"))<=k:k-=26-(ord(s[i])-ord("a"));l[i]="a"
print("".join(l[:-1]+list(chr((ord(l[-1])-97+k)%26+97))))

Fixed submission:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab.sort()
cd.sort()
ans = 0
for i in cd:
    c, d = i
    flag = False
    cur = 0
    difference = float("inf")
    for i in range(n):
        a, b = ab[i]
        if a < c and b < d:
            if difference > d - b:
                difference = min(difference, d - b)
                flag = True
                cur = i
    if flag:
        ab[cur] = [float("inf"), float("inf")]
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
n, k = map(int, input().split())
fa = [1] * (k + 1)
fi = [1] * (k + 1)
for i in range(1, k + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(k - n + 1):
    ans += comb(k - 1, n + i - 1)
    ans %= mod
print(ans)

Fixed submission:
mod = 998244353
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
n, k = map(int, input().split())
fa = [1] * (k + 1)
fi = [1] * (k + 1)
for i in range(1, k + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(k - n + 1):
    ans += comb(k - 1, n + i - 1)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................

Fixed submission:
from collections import deque
def bfs():
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    if d[gy][gx] != float("inf"):
        return d[gy][gx]
    else:
        return -1
h, w = map(int, input().split())
sy, sx = 0, 0
gy, gx = h - 1, w - 1
s = [list(input()) for i in range(h)]
black = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            black += 1
if bfs() == -1:
    print(-1)
else:
    print(h * w - bfs() - black - 1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
abig = 0
bbig = 0
for i in range(n):
    if a[i] > b[i]:
        abig += 1
    elif a[i] < b[i]:
        bbig += 1
if abig % 2 == bbig % 2:
    print("Yes")
else:
    print("No")

Fixed submission:
x, y = map(int, input().split())
i = 1
if x % y == 0:
    print(-1)
else:
    print(x * y - x)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input())
if (b - a) % 2 == 0:
    print("Alice")
else:
    print("Borys")

Fixed submission:
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
    print("Alice")
else:
    print("Borys")
Buggy python submission (verdict: Runtime Error):
import math as m1
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
b = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        if h - i <= 0:
            print(ans + 1)
            exit()
        h -= i
        ans += 1
    if 
print(ans + m1.ceil(h / m))

Fixed submission:
import math as m1
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
b = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        if h - i <= 0:
            print(ans + 1)
            exit()
        h -= i
        ans += 1
print(ans + m1.ceil(h / m))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = set(a)
ans = 0
for i in s:
    c = a.count(i)
    if c >= i:
        ans += c - i
    else:
        ans += c
print(ans)

Fixed submission:
import collections
n=int(input())
c=collections.Counter(list(map(int,input().split()))).most_common()
a=0
for i in c:
 if i[0]>i[1]:a+=i[1]
 else:a+=i[1]-i[0]
print(a)
Buggy python submission (verdict: Runtime Error):
print(input()%9)

Fixed submission:
input_number = int(input())
hundred = int(input_number / 100)
ten = int((input_number - hundred * 100) / 10)
one = int((input_number -(hundred * 100 + ten * 10) /1))
print(hundred + ten + one)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
print(n * 2 - 1)
ma, mi = max(a), min(a)
ima, imi = a.index(ma), a.index(mi)
if abs(ma) > abs(mi):
    for i in range(1, n + 1):
        print(ima + 1, i)
    for i in range(1, n):
        print(i, i + 1)
else:
    for i in range(1, n + 1):
        print(imi + 1, i)
    for i in range(1, n):
        print(i + 1, i) 

Fixed submission:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
c.sort(key=lambda x:x[1])
for i in range(len(set(a)) - k):
    ans += c[i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
a,b,c=s.count("a"),s.count("b"),s.count("c")
print("NO"ifabs(a-b)>1 or abs(a-c)>1 or abs(b-c)>1else"YES")

Fixed submission:
s = list(input())
a, b, c = s.count("a"), s.count("b"), s.count("c")
if abs(a - b) > 1 or abs(a - c) > 1 or abs(b - c) > 1:
    print("NO")
else:
    print("YES")