Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
n = int(input())
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append((b - 1, i))
    edges[b - 1].append((a - 1, i))
l = [0 for i in range(n)]
def dfs(cur, x):
    res = 1
    for i in edges[cur]:
        if i[1] != x:
            res += dfs(i[0], i[1])
    l[x] = res
    return res
dfs(0, -1)
l2 = [1]
i2 = pow(2, mod - 2, mod)
for i in range(n):
    l2.append(l2[-1] * i2 % mod)
cnt = 0
for i in l:
    cnt += (1 - l2[i]) * (1 - l2[n - i])
print((-n * i2 - l2[-1] + cnt + 1) % mod)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append((b - 1, i))
    edges[b - 1].append((a - 1, i))
l = [0 for i in range(n)]
def dfs(cur, x):
    res = 1
    for i in edges[cur]:
        if i[1] != x:
            res += dfs(i[0], i[1])
    l[x] = res
    return res
dfs(0, -1)
l2 = [1]
i2 = pow(2, mod - 2, mod)
for i in range(n):
    l2.append(l2[-1] * i2 % mod)
cnt = 0
for i in l:
    cnt += (1 - l2[i]) * (1 - l2[n - i])
print((-n * i2 - l2[-1] + cnt + 1) % mod)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
n = int(input())
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append((b - 1, i))
    edges[b - 1].append((a - 1, i))
l = [0 for i in range(n)]
def dfs(cur, x):
    res = 1
    for i in edges[cur]:
        if i[1] != x:
            res += dfs(i[0], i[1])
    l[x] = res
    return res
dfs(0, -1)
l2 = [1]
i2 = pow(2, mod - 2, mod)
for i in range(n):
    l2.append(l2[-1] * i2 % mod)
cnt = 0
for i in l:
    cnt += (1 - l2[i]) * (1 - l2[n - i])
print((-n * i2 - l2[-1] + cnt + 1) % mod)
Problem p02923 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
cnt = 0
l = []
for i in range(n - 1):
    if h[i] < h[i + 1]:
        l.append(cnt)
        cnt = 0
    else:
        cnt += 1
l.append(cnt)
print(max(l))

Buggy submission (verdict: Runtime Error):
def search(i, cnt):
    if i <= n - 2 and h[i] >= h[i + 1]:
        search(i + 1, cnt + 1)
    else:
        li.append(cnt)
n = int(input())
h = list(map(int, input().split()))
li = []
for j in range(n):
    search(j, 0)
print(max(li))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
edges = [[] for i in range(n)]
counter = [0] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
def dfs(now, prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next, now)
dfs(0, -1)
print(*counter)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
edges = [[] for i in range(n)]
counter = [0] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
def dfs(now, prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next, now)
dfs(0, -1)
print(*counter)

Buggy submission (verdict: Runtime Error):
def dfs(current, prev):
    for next in g[current]:
        if next != prev:
            if visited[next]:
                ki = False
            else:
                visited[next] = True
                dfs(next, now)


n, m = map(int, input().split())
g = [[] * n for i in range(n)]
ans = 0
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
visited = [False for i in range(n)]
for i in range(n):
    if not visited[i]:
        ki = True
        dfs(i, -1)
        if ki:
            ans += 1
print(ans)
Problem p02943 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
rev_s = s + s[::-1]
mido = "z" * n
for i in range(n + 1):
    if mido > rev_s[i:i + n]:
        mido = rev_s[i:i + n]
ind = float("inf")
for i in range(n):
    if mido[i] != mido[0]:
        if i < ind:
            ind = i
ans = ind * (2 ** min(k - 1, 20))
print((mido[0] * ans + mido[ind:ind + n - ans])[:n])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
rev_s = s + s[::-1]
mido = "z" * n
for i in range(n + 1):
    if mido > rev_s[i:i + n]:
        mido = rev_s[i:i + n]
ind = float("inf")
for i in range(n):
    if mido[i] != mido[0]:
        if i < ind:
            ind = i
ans = ind * (2 ** min(k - 1, 100))
print((mido[0] * ans + mido[ind:ind + n - ans])[:n])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
rev_s = s + s[::-1]
mido = "z" * n
for i in range(n + 1):
    if mido > rev_s[i:i + n]:
        mido = rev_s[i:i + n]
ind = float("inf")
for i in range(n):
    if mido[i] != mido[0]:
        if i > ind:
            ind = i
ans = ind * (2 ** (k - 1))
print((mido[0] * ans + mido[ind:ind + n - ans])[:n])
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(a)))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(set(a))))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)
Problem p02988 (python)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
i = 1
cnt = 0
while i < len(p) - 1:
  l = sorted([p[i - 1], p[i], p[i + 1]])
  if l[1] == p[i]:
    cnt += 1
  i += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
  p = int(input())
else:
  p = list(map(input().split()))
i = 1
cnt = 0
while i < len(p):
  if p[i] > p[i - 1] and p[i] < p[i + 1] :
    cnt += 1
  i += 1

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(input().split()))
i = 1
cnt = 0
while i < len(p):
  if p[i] > p[i - 1] and p[i] < p[i + 1] :
    cnt += 1
  i += 1
Problem p03039 (python)

Fixed submission:
mod = 10 ** 9 + 7
class nCr():
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
n, m, k = map(int, input().split())
ans = 0
c = nCr(n * m)
for i in range(n):
    ans += i * (n - i) * m * m
    ans %= mod
for i in range(m):
    ans += i * (m - i) * n * n
    ans %= mod
print(ans * c.comb(n * m - 2, k - 2) % mod)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
class nCr():
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
n, m, k = map(int, input().split())
ans = 0
c = nCr(n + m)
for i in range(n):
    ans += i * (n - i) * m * m
    ans %= mod
for i in range(m):
    ans += i * (m - i) * n * n
    ans %= mod
print(ans * c.comb(n * m - 2, k - 2) % mod)
Problem p03044 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)
n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
d = [-1 for i in range(n)]
edge = [[] for i in range(n)]
for u, v, w in uvw:
    edge[u - 1].append((v - 1, w))
    edge[v - 1].append((u - 1, w))
def dfs(now, D):
    d[now] = D
    for i, j in edge[now]:
        if d[i] == -1:
            dfs(i, D + j)
dfs(0, 0)
for i in d:
    print(i % 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
d = [-1 for i in range(n)]
edge = [[] for i in range(n)]
for u, v, w in uvw:
    edge[u - 1].append((v - 1, w))
    edge[v - 1].append((u - 1, w))
def dfs(now, D):
    d[now] = D
    for i, j in edge[now]:
        if d[i] == -1:
            dfs(i, D + j)
dfs(0, 0)
for i in d:
    print(i % 2)
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
b = 0
w = s.count(".")
l = [w]
for i in range(1, n + 1):
    if s[i - 1] == "#":
        b += 1
    if s[i - 1] == ".":
        w -= 1
    l.append(b + w)
print(min(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
l = []
b = 0
w = s.count(".")
for i in range(1, n - 1):
    if s[i - 1] == "#":
        b += 1
    elif s[i + 1] == ".":
        w -= 1
    l.append(b + w)
print(min(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
l = []
b = 0
w = s.count(".")
for i in range(n):
    if s[i] == "#":
        b += 1
    elif s[i] == ".":
        w -= 1
        l.append(b + w)
print(min(l))
Problem p03074 (python)

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 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)
Problem p03079 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a == b == c:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int, nput().split())
print("Yes"if a==b==c else"No")
Problem p03086 (python)

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 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))
Problem p03089 (python)

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 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")
Problem p03111 (python)

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 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)
Problem p03157 (python)

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 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)
Problem p03200 (python)

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 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)
Problem p03229 (python)

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 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)
Problem p03293 (python)

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 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")

Buggy 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")

Buggy 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")
Problem p03294 (python)

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 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)
Problem p03296 (python)

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 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)
Problem p03331 (python)

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 submission (verdict: Runtime Error):
N = list(int(input()))
if N.count(0) == len(N) - 1:
  print(10)
else:
  sum(N)
Problem p03333 (python)

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 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)
Problem p03351 (python)

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 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")

Buggy 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")
Problem p03352 (python)

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 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))
Problem p03359 (python)

Fixed submission:
a,b = map(int, input().split())
if a > b:
  print(a - 1)
else:
  print(a)

Buggy submission (verdict: Runtime Error):
l = list(map(int, input().split()))
l2 = set(l)
print(l2[0])
Problem p03361 (python)

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 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")
Problem p03407 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
50 100 120
Problem p03411 (python)

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 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))))
Problem p03436 (python)

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 submission (verdict: Runtime Error):
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................
Problem p03437 (python)

Fixed submission:
x, y = map(int, input().split())
i = 1
if x % y == 0:
    print(-1)
else:
    print(x * y - x)

Buggy 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")
Problem p03463 (python)

Fixed submission:
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
    print("Alice")
else:
    print("Borys")

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input())
if (b - a) % 2 == 0:
    print("Alice")
else:
    print("Borys")
Problem p03472 (python)

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 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))
Problem p03493 (python)

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 submission (verdict: Runtime Error):
print(input()%9)
Problem p03497 (python)

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 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)
Problem p03524 (python)

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")

Buggy 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")