Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a.popleft())
    else:
        b.appendleft(a.popleft())
    
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

Fixed submission:
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0,a[i])
    
if n%2==0:
    print(*b)
else:
    print(*b[::-1])

Fixed submission:
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)

Buggy python submission (verdict: Runtime Error):
        b.insert(0,a[i])


Fixed submission:
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
    b.append(a[i])
    b=b[::-1]

print(*b)

Fixed submission:
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)
Buggy python submission (verdict: Runtime Error):
import sys
def BellmanFord(edges,num_v,source):
    #グラフの初期化
    inf=float("inf")
    dist=[inf for i in range(num_v)]
    dist[source-1]=0

    #辺の緩和
    for i in range(num_v):
        for edge in edges:
            #print(dist)
            if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                if i==num_v-1: 
                	print("inf")
                    sys.exit()

    return dist

n,m=map(int,input().split())
es=[]
for _ in range(m):
    a,b,c=map(int,input().split())
    es.append((a,b,-c))
    
res=BellmanFord(es,n,1)
print(-res[-1])

Fixed submission:
def BellmanFord(s,N,Edge):
    INF=float("inf")
    dist=[INF]*N
    neg=[False]*N
    dist[s]=0
    for i in range(N-1):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=min(dist[t],dist[f]+c)
    for i in range(N):
        for f,t,c in Edge:
            if dist[t]>dist[f]+c and dist[f]!=INF:
                dist[t]=dist[f]+c
                neg[t]=True
            if neg[f]:
                neg[t]=True
    return dist,neg

n,m=map(int,input().split())
es=[]
for _ in range(m):
    a,b,c=map(int,input().split())
    es.append((a-1,b-1,-c))
    
res, neg =BellmanFord(0,n,es)
if not neg[-1]:
    print(-res[-1])
else:
    print("inf")
Buggy python submission (verdict: Runtime Error):
g

Fixed submission:
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table
N=int(input())
_, table = sieve(N)
d={}
for p in table:
    sum_=0
    calc=p
    while calc <= N:
        sum_ += N//calc
        calc *= p
    d[p] = sum_
    
lim = 10**9+7
ans=1
for i in d.values():
    ans = (ans * (i+1)) % lim
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
lim=10**9+7
import numpy as np
def seachPrimeNum(N):
    max_ = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max_:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

ans = 1
l=seachPrimeNum(N)
#print(l)
for p in l:
    temp=0
    k=1
    while True:
        if p**k>N:
            break
        temp += N//(p**k)
        k+=1
    ans = (ans * (temp + 1)) % lim
    #print(N//p + 1)
print(ans)

Fixed submission:
import sys
N=int(input())
if N == 1:
    print(1)
    sys.exit()
lim=10**9+7
import numpy as np
def seachPrimeNum(N):
    max_ = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max_:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

ans = 1
l=seachPrimeNum(N)
#print(l)
for p in l:
    temp=0
    k=1
    while True:
        if p**k>N:
            break
        temp += N//(p**k)
        k+=1
    ans = (ans * (temp + 1)) % lim
    #print(N//p + 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
for i in range(1,100000)[::-1]:
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Fixed submission:
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
for i in range(1,10)[::-1]:
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Fixed submission:
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
for i in range(1,10):
    s = "S"*i +"T"*i
    while s in S:
        S=S.replace(s,"")
print(len(S))

Fixed submission:
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
while "SSTT" in S:
    S=S.replace("SSTT","")
while "ST" in S:
    S=S.replace("ST","")
print(len(S))

Fixed submission:
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
while "ST" in S:
    S=S.replace("ST","")
print(len(S))

Fixed submission:
from collections import deque
S=list(map(lambda x: 1 if x=="T" else 0,input()))

q=deque()

for i in S:

    if i:
        if (not q) or q[-1]!=0:
            q.append(i)
        elif q and q[-1]==0:
            q.pop()
    else:
        q.append(i)
print(len(q))
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
a=len(A)
b=len(B)
c=len(C)

if (a or b or c == 5) and (a or b or c ==7) and (a*b*c ==5*7*5):
  print('YES')
else:
  print('NO')

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


if (a or b or c == 5) and (a or b or c ==7) and (a*b*c ==5*7*5):
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_ = list(map(int, input().split()))
A = []
mod = 10 ** 9 + 7
for a_ in A_:
    a = a_ % mod
    A.append(a)

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j] % mod
        ans %= mod

print(ans)

Fixed submission:
N = int(input())
A_ = list(map(int, input().split()))
A = []
mod = 10 ** 9 + 7
for i, a_ in enumerate(A_[::-1]):
    if i == 0:
        A.append(a_ % mod)
    else:
        a = (a_ + A[-1]) % mod
        A.append(a)
A = A[::-1]
A = A[1:]
ans = 0
for i, a in enumerate(A_[:-1]):
    ans += A[i] * a % mod
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int, input().split())

Items = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    Items[r][c] = v


DP = [[[-float('inf')] * 4 for _ in range(C + 1)] for __ in range(R + 1)]

for y in range(R+1):
    for x in range(C+1):
        if y == 0:
            DP[y][x][0] = 0
            continue
        if x == 0:
            DP[y][x][0] = 0
            continue
        if Items[y][x] == 0:
            for k in range(4):
                DP[y][x][0] = max(DP[y][x][0], DP[y - 1][x][k])
                if k != 0:
                    DP[y][x][k] = DP[y][x-1][k]
            DP[y][x][0] = max(DP[y][x][0], DP[y][x-1][0])
        else:
            for k in range(4):
                DP[y][x][0] = max(DP[y][x][0], DP[y - 1][x][k])
            DP[y][x][0] = max(DP[y][x][0], DP[y][x - 1][0])
            for k in range(1, 4):
                DP[y][x][k] = max(DP[y][x-1][k-1] + Items[y][x], DP[y][x-1][k])
                if k == 1:
                    DP[y][x][k] = max(DP[y][x][k], max(DP[y-1][x]) + Items[y][x])

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int, input().split())

Items = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    Items[r][c] = v


DP = [[0] * 4 for _ in range(R + 1)]

for x in range(1, C+1):
    for y in range(1, R+1):
        v = Items[y][x]
        if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1]))

print(max(DP[R]))
Buggy python submission (verdict: Time Limit Exceeded):
import decimal

N = int(input())
A = [int(decimal.Decimal(input()) * 10 ** 9) for _ in range(N)]
B = []
for a in A:
    cnt = 0
    while a % 10 == 0:
        cnt += 1
        a //= 10
    B.append((a, cnt))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        x, cnt1 = B[i]
        y, cnt2 = B[j]
        if cnt1 + cnt2 >= 18:
            ans += 1
            continue
        z = x * y
        cnt3 = 0
        while z % 10 == 0:
            cnt3 += 1
            z //= 10
        if cnt1 + cnt2 + cnt3 >= 18:
            ans += 1

print(ans)

Fixed submission:
import decimal

N = int(input())
A = [int(decimal.Decimal(input()) * 10 ** 9) for _ in range(N)]
B = [[0] * 19 for _ in range(19)]
for a in A:
    cnt2 = 0
    while a % 2 == 0:
        cnt2 += 1
        a //= 2
    cnt5 = 0
    while a % 5 == 0:
        cnt5 += 1
        a //= 5
    B[min(cnt2, 18)][min(cnt5, 18)] += 1
ans = 0
for i in range(361):
    a, r = divmod(i, 19)
    if a >= 9 and r >= 9:
        ans -= B[a][r]
    for j in range(361):
        b, s = divmod(j, 19)
        if a + b >= 18 and r + s >= 18:
            ans += B[a][r] * B[b][s]

ans //= 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

for i in range(1,10 ** 6):
    x = int('7' * i)
    if x % K == 0:
        print(i)
        exit()
print(-1)

Fixed submission:
K = int(input())
mod = K
num = 0
for i in range(10 ** 6):
    num += 7 * pow(10, i, mod)
    num %= mod
    if num == 0:
        print(i + 1)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    if A == [N] * N:
        break
    B = [0] * (N+1)
    for i, a in enumerate(A):
        start = max(0, i - a)
        end = min(N-1, i + a) + 1
        B[start] += 1
        B[end] -= 1
        A = list(accumulate(B))[:-1]
print(' '.join(map(str, A)))



Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    if A == [N] * N:
        break
    B = [0] * (N+1)
    for i, a in enumerate(A):
        start = max(0, i - a)
        end = min(N-1, i + a) + 1
        B[start] += 1
        B[end] -= 1
    A = list(accumulate(B))[:-1]
print(' '.join(map(str, A)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod))


for i in range(min(N, K)+1):
    ans += (M%mod) * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)


Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod) % mod)


for i in range(K+1):
    ans += M * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N):
    nCi.append(nCi[i-1]*(N-i)//i)


for i in range(min(N, K)+1):
    ans += ((M%mod) * pow(M - 1, N-1-i, mod) * (nCi[i]%mod)) % mod
    ans %= mod

print(ans)

Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod) % mod)


for i in range(K+1):
    ans += M * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(1000000000)


N, M, K = map(int, input().split())
mod = 998244353

DP = [[-1] * (K+1) for _ in range(N+1)]


def dpdp(n, k):
    if DP[n][k] != -1:
        return DP[n][k]
    if n-1 <= k:
        DP[n][k] = pow(M, n-1, mod)
        return pow(M, n-1, mod)
    if k == 0:
        DP[n][k] = pow(M-1, n-1, mod)
        return pow(M-1, n-1, mod)
    if n == 1:
        DP[n][k] = M % mod
        return M % mod

    return (dpdp(n-1, k-1) % mod + (M-1) * dpdp(n-1, k) % mod) % mod


print(dpdp(N, K) * M % mod)


Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod) % mod)


for i in range(K+1):
    ans += M * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
K = [0 for i in range(N)]

for i in range(N-1):
    for j in range(i+1, N):
        a = abs(j - i)
        b = abs(X - i) + 1 + abs(j - Y)
        c = abs(Y - i) + 1 + abs(j - X)
        K[min(a, b, c)] += 1

for i in range(1, N):
    print(K[i])


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
K = [0] * N

for i in range(N-1):
    for j in range(i+1, N):
        a = abs(j - i)
        b = abs(X - i) + 1 + abs(j - Y)
        c = abs(Y - i) + 1 + abs(j - X)
        K[min(a, b, c)] += 1

for i in range(1, N):
    print(K[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

Q = deque()
N, X, Y = map(int, input().split())
K = [0 for i in range(N)]

edge = [[]for i in range(N+1)]
for i in range(1, N):
    edge[i].append(i + 1)
    edge[i+1].append(i)
edge[X].append(Y)
edge[Y].append(X)

for i in range(1, N):
    Done = [-1 for j in range(N+1)]
    Q.append(i)
    Done[0] = 0
    Done[i] = 0
    while len(Q) > 0:
        x = Q.popleft()
        for y in edge[x]:
            if Done[y] >= 0:
                continue
            else:
                Done[y] = Done[x] + 1
                Q.append(y)
                if y > i:
                    K[Done[y]] += 1

for z in K[1:]:
    print(z)


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
K = [0] * N

for i in range(N-1):
    for j in range(i+1, N):
        a = abs(j - i)
        b = abs(X - i) + 1 + abs(j - Y)
        c = abs(Y - i) + 1 + abs(j - X)
        K[min(a, b, c)] += 1

for i in range(1, N):
    print(K[i])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count:
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)


Fixed submission:
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(1, N+1):
    num = A.count(i)
    ans += num * (num - 1) // 2
for k in range(1, N+1):
    n = A.count(A[k-1])
    ans_ = ans - (n - 1)
    print(ans_)


Fixed submission:
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Z = []
for i in range(N):
    a = A.copy()
    answeri = 0
    del a[i]
    for k in range(0, len(a)):
        for j in range(k + 1, len(a)):
            if a[k] == 0:
                continue
            elif a[k] == a[j]:
                answeri += 1
    Z.append(answeri)
for x in Z:
    print(x)

Fixed submission:
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]

Q = deque()
f = 0
if Maze[0][0]:
    f += 1
Q.append((0, 0, f))
ans = 0
while Q:
    x, y, f = Q.popleft()
    if x == W - 1 and y == H - 1:
        ans = f
        break
    for d in range(2):
        nx = x + (0, 1)[d]
        ny = y + (1, 0)[d]
        if nx >= W or ny >= H:
            continue
        if Maze[y][x] == 0 and Maze[ny][nx] == 1:
            Q.append((nx, ny, f + 1))
        else:
            Q.appendleft((nx, ny, f))


print(ans)

Fixed submission:
H, W = map(int, input().split())
Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]

DP = [[float('inf')] * W for _ in range(H)]

if Maze[0][0] == 1:
    DP[0][0] = 1
else:
    DP[0][0] = 0

for i in range(H):
    for j in range(W):
        if Maze[i][j] == 1:
            if i + 1 < H:
                DP[i+1][j] = DP[i][j]
            if j + 1 < W:
                DP[i][j+1] = min(DP[i][j+1], DP[i][j])
        if Maze[i][j] == 0:
            if i + 1 < H:
                if Maze[i+1][j] != 1:
                    DP[i + 1][j] = DP[i][j]
                else:
                    DP[i + 1][j] = DP[i][j] + 1
            if j + 1 < W:
                if Maze[i][j + 1] != 1:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j])
                else:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]+1)

print(DP[H-1][W-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
Maze = [input() for _ in range(H)]

Q = deque()
f = 0
if Maze[0][0] == '#':
    f += 1
Q.append((0, 0, f))
ans = 0
while Q:
    x, y, f = Q.popleft()
    if x == W - 1 and y == H - 1:
        ans = f
        break
    for d in range(2):
        nx = x + (0, 1)[d]
        ny = y + (1, 0)[d]
        if nx >= W or ny >= H:
            continue
        if Maze[y][x] == '.' and Maze[ny][nx] == '#':
            Q.append((nx, ny, f + 1))
        else:
            Q.appendleft((nx, ny, f))


print(ans)

Fixed submission:
H, W = map(int, input().split())
Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]

DP = [[float('inf')] * W for _ in range(H)]

if Maze[0][0] == 1:
    DP[0][0] = 1
else:
    DP[0][0] = 0

for i in range(H):
    for j in range(W):
        if Maze[i][j] == 1:
            if i + 1 < H:
                DP[i+1][j] = DP[i][j]
            if j + 1 < W:
                DP[i][j+1] = min(DP[i][j+1], DP[i][j])
        if Maze[i][j] == 0:
            if i + 1 < H:
                if Maze[i+1][j] != 1:
                    DP[i + 1][j] = DP[i][j]
                else:
                    DP[i + 1][j] = DP[i][j] + 1
            if j + 1 < W:
                if Maze[i][j + 1] != 1:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j])
                else:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]+1)

print(DP[H-1][W-1])
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())

Ball = ''

while len(Ball) < N:
    Ball += "B" * A + "R" * B

print(Ball[:N].count("B"))


Fixed submission:
N, A, B = map(int, input().split())
num = N // (A + B) + 1
zan = num * (A + B) - N

if zan <= B:
    print(num * A)
else:
    print(num * A + B - zan)

Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
color = ''
while True:
    if len(color) < N:
        color = color + 'b' * A + 'r' * B
    else:
        break
num = color[:N].count('b')
print(num)

Fixed submission:
N, A, B = map(int, input().split())
num = N // (A + B) + 1
zan = num * (A + B) - N

if zan <= B:
    print(num * A)
else:
    print(num * A + B - zan)

Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
color = ''
while True:
    if len(color) < N:
        color = color + 'b' * A + 'r' * B
    else:
        break
num = color[:N].count('b')
print(num)

Fixed submission:
N, A, B = map(int, input().split())
num = N // (A + B) + 1
zan = num * (A + B) - N

if zan <= B:
    print(num * A)
else:
    print(num * A + B - zan)