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

Fixed submission:
N=int(input())
A=[int(i) for i in input().split()]
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]%P
Q=[0 for i in range(N)]
I=[inv(i) for i in range(1,N+2)]
U=[0 for i in range(N+2)]
Fact=[0 for i in range(N+1)]
Fact[0]=1
for i in range(N):
    Fact[i+1]=((i+1)*Fact[i])%P
for i in range(N+1):
    U[i+1]=(U[i]+I[i])%P
for j in range(N):
    Q[j]=(U[j+1]+U[N-j]-1)%P
ans=0
for j in range(N):
    ans+=A[j]*Q[j]
    ans=ans%P
print((ans*Fact[N])%P)

Buggy submission (verdict: Runtime Error):
def E(i,y):
    if i==1:
        return 5*y
    else:
        return (2*i+1)*y

N,X=map(int,input().split())
x=[int(i) for i in input().split()]
a=[0]
for i in range(N):
    a.append(a[-1]+x[i])
ans=10**50
for k in range(1,N+1):
    tmp=(N+k)*X
    for i in range(N//k):
        tmp+=E(i+1,a[N-i*k]-a[N-i*k-k])
        #print(k,i,tmp)
    if N%k!=0:
        tmp+=E(N//k+1,a[N-(N//k)*k])
    #print(tmp)
    if ans>tmp:
        ans=tmp
print(ans)
Problem p03326 (python)

Fixed submission:
import itertools
N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
w=[[0 for i in range(N)] for i in range(8)]
S=list(itertools.product([-1,1],repeat=3))
def num(inp):
    res=0
    for i in range(3):
        res+=2**i*(inp[i]+1)//2
    return res
for sg in S:
    for i in range(N):
        w[num(sg)][i]=x[i]*sg[0]+y[i]*sg[1]+z[i]*sg[2]
tmp=[0 for i in range(8)]
for sg in S:
    w[num(sg)].sort(reverse=True)
    for i in range(M):
        tmp[num(sg)]+=w[num(sg)][i]
print(max(tmp))

Buggy submission (verdict: Runtime Error):
import itertools
N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
w=[[0 for i in range(N)] for i in range(8)]
S=list(itertools.product([-1,1],repeat=3))
def num(inp):
    res=0
    for i in range(3):
        res+=2*i(inp[i]+1)//2
    return res
for sg in S:
    for i in range(N):
        w[num(sg)][i]=x[i]sg[0]+y[i]sg[1]+z[i]*sg[2]
tmp=[0 for i in range(8)]
for sg in S:
    w[num(sg)].sort(reverse=True)
    for i in range(M):
        tmp[num(sg)]+=w[num(sg)][i]
print(max(tmp))
Problem p03634 (python)

Fixed submission:
import queue
N=int(input())
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
c=[0 for i in range(N-1)]
VL=[dict() for i in range(N)]
for i in range(N-1):
    a[i],b[i],c[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    VL[a[i]][b[i]]=c[i]
    VL[b[i]][a[i]]=c[i]
Q,K=map(int,input().split())
K-=1
x=[0 for i in range(Q)]
y=[0 for i in range(Q)]
for i in range(Q):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
reached=[False for i in range(N)]
dist=[0 for i in range(N)]
q=queue.Queue()
q.put(K)
reached[K]=True
while(not(q.empty())):
    r=q.get()
    for v in VL[r]:
        if not(reached[v]):
            q.put(v)
            dist[v]=VL[r][v]+dist[r]
            reached[v]=True
for i in range(Q):
    print(dist[x[i]]+dist[y[i]])

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
c=[0 for i in range(N-1)]
VL=[dict() for i in range(N)]
for i in range(N-1):
    a[i],b[i],c[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    VL[a[i]][b[i]]=c[i]
    VL[b[i]][a[i]]=c[i]
Q,K=map(int,input().split())
K-=1
x=[0 for i in range(Q)]
y=[0 for i in range(Q)]
for i in range(Q):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
reached=[False for i in range(N)]
dist=[0 for i in range(N)]
def dfs(v):
    reached[v]=True
    for u in VL[v]:
        if not(reached[u]):
            dist[u]=dist[v]+VL[v][u]
            dfs(u)
dfs(K)
for i in range(Q):
    print(dist[x[i]]+dist[y[i]])

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
c=[0 for i in range(N-1)]
VL=[dict() for i in range(N)]
for i in range(N-1):
    a[i],b[i],c[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    VL[a[i]][b[i]]=c[i]
    VL[b[i]][a[i]]=c[i]
Q,K=map(int,input().split())
K-=1
x=[0 for i in range(Q)]
y=[0 for i in range(Q)]
for i in range(Q):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
reached=[False for i in range(N)]
dist=[0 for i in range(N)]
def dfs(v):
    reached[v]=True
    for u in VL[v]:
        if not(reached[u]):
            dist[u]=dist[v]+VL[u][v]
            dfs(u)
dfs(K)
for i in range(Q):
    print(dist[x[i]]+dist[y[i]])
Problem p03724 (python)

Fixed submission:
N,M=map(int,input().split())
a=[0 for i in range(M)]
b=[0 for i in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
X=[0 for i in range(N)]
for i in range(M):
    X[a[i]]+=1
    X[b[i]]+=1
for i in range(N):
    if X[i]%2==1:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
X=[0 for i in range(N)]
for i in range(M):
    X[a[i]]+=1
    X[b[i]]+=1
for i in range(N):
    if X[i]%2==1:
        print("NO")
        exit()
print("YES")
Problem p03745 (python)

Fixed submission:
N=int(input())
A=[int(i) for i in input().split()]
if N==1:
    print(1)
    exit()
T=[[A[0],A[1]]]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        continue
    if not((T[k][0]>=A[i-2]>=A[i-1]>=A[i]) or (T[k][0]<=A[i-2]<=A[i-1]<=A[i])):
        k+=1
        T.append([A[i]])
    else:
        T[k].append(A[i])
print(len(T))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
T=[[A[0],A[1]]]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        continue
    if not((T[k][0]>=A[i-2]>=A[i-1]>=A[i]) or (T[k][0]<=A[i-2]<=A[i-1]<=A[i])):
        k+=1
        T.append([A[i]])
    else:
        T[k].append(A[i])
print(len(T))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
T=[[A[0],A[1]]]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        continue
    if not((T[k][0]>=A[i-2]>=A[i-1]>=A[i]) or (T[k][0]<=A[i-2]<=A[i-1]<=A[i])):
        k+=1
        T.append([])
        T[k].append(A[i])
    else:
        T[k].append(A[i])
print(k+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
T=[[A[0],A[1]]]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        #continue
    if not((T[k][0]>=A[i-2]>=A[i-1]>=A[i]) or (T[k][0]<=A[i-2]<=A[i-1]<=A[i])):
        k+=1
        T.append([])
        T[k].append(A[i])
    else:
        T[k].append(A[i])
print(len(T))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
T=[[A[0],A[1]]]
B=[0]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        continue
    if not(T[k][0]>=A[i-2]>=A[i-1]>=A[i] or T[k][0]<=A[i-2]<=A[i-1]<=A[i]):
        k+=1
        T.append([])
        T[k].append(A[i])
    else:
        T[k].append(A[i])
print(len(T))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
T=[[A[0],A[1]]]
k=0
for i in range(2,N):
    if len(T[k])<=1:
        T[k].append(A[i])
        continue
    if not(A[i-2]>=A[i-1]>=A[i] or A[i-2]<=A[i-1]<=A[i]):
        k+=1
        T.append([])
        T[k].append(A[i])
    else:
        T[k].append(A[i])
print(len(T))
Problem p03803 (python)

Fixed submission:
A,B=map(int,input().split())
if ((A-2)%13)<((B-2)%13):
  print("Bob")
elif ((A-2)%13)>((B-2)%13):
  print("Alice")
else:
  print("Draw")

Buggy submission (verdict: Runtime Error):
N,Ma,Mb=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
M=401
dp=[[[10**4 for cb in range(M)]for ca in range(M)]for i in range(N+1)]
for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())
dp[0][0][0]=0
for i in range(N):
    for ca in range(M):
        for cb in range(M):
            if dp[i][ca][cb]==10**4:
                continue
            dp[i+1][ca][cb]=min([dp[i+1][ca][cb],dp[i][ca][cb]])
            dp[i+1][ca+a[i]][cb+b[i]]=min([dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]])
ans=10**4
for i in range(1,M):
    for j in range(1,M):
        if i*Mb==j*Ma:
            if dp[N][i][j]<ans:
                ans=dp[N][i][j]
if ans!=10**4:
    print(ans)
else:
    print(-1)
Problem p03822 (python)

Fixed submission:
import sys
import heapq
sys.setrecursionlimit(2*10**5)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    q=[]
    for j in G[i]:
        heapq.heappush(q,-dp(j))
    k=1
    res=0
    while(q):
        x=-heapq.heappop(q)
        res=max(res,x+k)
        k+=1
    return res
print(dp(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(114514)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(11514)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(102030)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100030)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if len(G[i])==0:
        return 0
    X=sorted([dp(j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5+10)
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[-1]+[int(input())-1 for i in range(1,N)]
DP=[-1 for i in range(N)]
G=[[] for i in range(N)]
for i in range(1,N):
    G[a[i]].append(i)
def dp(i):
    if DP[i]!=-1:
        return DP[i]
    if len(G[i])==0:
        DP[i]=0
        return 0
    X=sorted([(dp(j),j) for j in G[i]],reverse=True)
    K=len(X)
    Y=[X[i][0]+i+1 for i in range(K)]
    return max(Y)
print(dp(0))
Problem p03803 (python)

Fixed submission:
a, b = (int(i) for i in input().split())

if a==1:
    a=14

if b==1:
    b=14

if a==b:
    print("Draw")
elif a>b:
    print("Alice")
else:
    print("Bob")

Buggy submission (verdict: Runtime Error):
a,b = int(input().split)

if a ==b :
    print("Draw")
elif a == 1 or a>b:
    print("Alice")
else:
    print("Bob")
Problem p02757 (python)

Fixed submission:
from collections import Counter

N, P = map(int, input().split())
S = input()

ans = 0

if P == 2 or P == 5:
    for i in range(N):
        if int(S[-1 - i]) % P == 0:
            ans += N - i
else:
    M = []
    cum = [0]

    for i in range(N):
        M.append(pow(10, i, P) * int(S[-1 - i]) % P)

    for i in range(N):
        cum.append((cum[-1] + M[i]) % P)

    C = Counter(cum)

    for v in C.values():
        ans += v * (v - 1) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
if sys.platform == 'ios' or 'darwin':
    sys.stdin = open('input_file.txt')

N, P = map(int, input().split())
S = input()

ans = 0

if P == 2 or P == 5:
    for i in range(N):
        if int(S[-1 - i]) % 2 == 0:
            ans += N - i
else:
    M = []
    cum = [0]

    for i in range(N):
        M.append(pow(10, i, P) * int(S[-1 - i]) % P)

    for i in range(N):
        cum.append((cum[-1] + M[i]) % P)

    C = Counter(cum)

    for v in C.values():
        ans += v * (v - 1) // 2

print(ans)
Problem p02815 (python)

Fixed submission:
MOD = 1000000007

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

C.sort(reverse=True)

ans = 0

if N > 1:
    for i in range(N):
        ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
        ans %= MOD
else:
    ans = 2*C[0]%MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007

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

C.sort(reverse=True)

ans = 0

for i in range(N):
    ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
    ans %= MOD

print(ans)
Problem p02964 (python)

Fixed submission:
from collections import defaultdict

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

D = defaultdict(list)

for i in range(N):
    D[A[i]].append(i)

next = [None for _ in range(N)]
dist = [None for _ in range(N)]

for v in D.values():
    l = len(v)
    for i in range(l):
        next[v[i]] = (v[(i + 1) % l] + 1) % N
        dist[v[i]] = (v[(i + 1) % l] - v[i] + N - 1) % N + 2

period = 0
node = 0

while node or not period:
    period += dist[node]
    node = next[node]

rem = N * K % period
count = 0
node = 0

while count + dist[node] <= rem:
    count += dist[node]
    node = next[node]

s = []
used = [0 for _ in range(10**6)]

for i in range(rem - count):
    j = (node + i) % N
    if not used[A[j] - 1]:
        used[A[j] - 1] = 1
        s.append(A[j])
    else:
        while True:
            p = s.pop()
            used[p - 1] = 0
            if p == A[j]:
                break

print(*s)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

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

D = defaultdict(list)

for i in range(N):
    D[A[i]].append(i)

next = [None for _ in range(N)]
dist = [None for _ in range(N)]

for v in D.values():
    l = len(v)
    for i in range(l):
        next[v[i]] = (v[(i + 1) % l] + 1) % N
        dist[v[i]] = (v[(i + 1) % l] - v[i] + N - 1) % N + 2

period = 0
node = 0

while node or not period:
    period += dist[node]
    node = next[node]

rem = N * K % period
count = 0
node = 0

while count + dist[node] <= rem:
    count += dist[node]
    node = next[node]

s = []
used = [0 for _ in range(max(A))]

for i in range(rem - count):
    j = (node + i) % N
    if not used[A[j] - 1]:
        used[A[j] - 1] = 1
        s.append(A[j])
    else:
        used[A[j] - 1] = 0
        while True:
            p = s.pop()
            if p == A[j]:
                break

print(*s)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

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

D = defaultdict(list)

for i in range(N):
    D[A[i]].append(i)

next = [None for _ in range(N)]
dist = [None for _ in range(N)]

for v in D.values():
    l = len(v)
    for i in range(l):
        next[v[i]] = (v[(i + 1) % l] + 1) % N
        dist[v[i]] = (v[(i + 1) % l] - v[i] + N - 1) % N + 2

period = 0
node = 0

while node or not period:
    period += dist[node]
    node = next[node]

rem = N * K % period
count = 0
node = 0

while count + dist[node] <= rem:
    count += dist[node]
    node = next[node]

s = []
used = [0 for _ in range(N)]

for i in range(rem - count):
    j = (node + i) % N
    if not used[A[j] - 1]:
        used[A[j] - 1] = 1
        s.append(A[j])
    else:
        used[A[j] - 1] = 0
        while True:
            p = s.pop()
            if p == A[j]:
                break

print(*s)
Problem p03017 (python)

Fixed submission:
n,a,b,c,d = map(int,input().split())
s = list(input())

if (b-a)*(d-c)>0 and max(a,b) < min(c,d):
  for i in range(min(a,b)-1,max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')

elif (b-a)*(d-c)>0 and max(a,b) > min(c,d):
  for i in range(a-1,c):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(b-1,d):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')
 
else:
  for i in range(min(a,b)-1,max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(max(a,b)-1,min(c,d)):
    if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
      print('Yes')
      exit()
  print('No')

Buggy submission (verdict: Runtime Error):
n,a,b,c,d = map(int,input().split())
s = list(input())

if (b-a)*(d-c)>0 and max(a,b) < min(c,d):
  for i in range(min(a,b),max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')

elif (b-a)*(d-c)>0 and max(a,b) > min(c,d):
  for i in range(a,c):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(b,d):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  print('Yes')
 
else:
  for i in range(min(a,b),max(c,d)):
    if s[i]=='#' and s[i+1]=='#':
      print('No')
      exit()
  for i in range(max(a,b),min(c,d)+1):
    if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
      print('Yes')
      exit()
  print('No')
Problem p03053 (python)

Fixed submission:
def main():
    from collections import deque

    h,w = map(int,input().split())
    A = []
    for i in range(h):
        A += list(input())

    queue = deque([])
    Distance = [-1]*(h*w)

    for i in range(h):
        for j in range(w):
            if A[i*w+j]=='#':
                queue.append([i,j])
                Distance[i*w+j] = 0

    ans = 0

    while queue:
        x,y = queue.popleft()
        d = Distance[x*w+y]
        if x!=0 and Distance[(x-1)*w+y] == -1:
                queue.append([x-1,y])
                ans = Distance[(x-1)*w+y] = d+1
        if x!=h-1 and Distance[(x+1)*w+y] == -1:
                queue.append([x+1,y])
                ans = Distance[(x+1)*w+y] = d+1
        if y!=0 and Distance[x*w+y-1] == -1:
                queue.append([x,y-1])
                ans = Distance[x*w+y-1] = d+1
        if y!=w-1 and Distance[x*w+y+1] == -1:
                queue.append([x,y+1])
                ans = Distance[x*w+y+1] = d+1

    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque

h,w = map(int,input().split())
A = [input() for i in range(h)]

queue = deque([])
Distance = [[-1 for i in range(w)]for j in range(h)]

for i in range(h):
  for j in range(w):
    if A[i][j]=='#':
      queue.append([i,j])
      Distance[i][j] = 0

while queue:
    x,y = queue.popleft()
    if x!=0:
        if A[x-1][y] == '.' and Distance[x-1][y] == -1:
            queue.append([x-1,y])
            ans = Distance[x-1][y] = Distance[x][y] + 1
    if x!=h-1:
        if A[x+1][y] == '.' and Distance[x+1][y] == -1:
            queue.append([x+1,y])
            ans = Distance[x+1][y] = Distance[x][y] + 1
    if y!=0:
        if A[x][y-1] == '.' and Distance[x][y-1] == -1:
            queue.append([x,y-1])
            ans = Distance[x][y-1] = Distance[x][y] + 1
    if y!=w-1:
        if A[x][y+1] == '.' and Distance[x][y+1] == -1:
            queue.append([x,y+1])
            ans = Distance[x][y+1] = Distance[x][y] + 1

print(ans)
Problem p03253 (python)

Fixed submission:
from operator import mul
from functools import reduce

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under 
    
n,m = map(int,input().split())

f = factorization(m)
c = 1

for i in range(len(f)):
  c *= cmb(n+f[i][1]-1,f[i][1])%1000000007

if m != 1:
  print(c%1000000007)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
class Factorial():
    def __init__(self,n,mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n+1)]
        self.inv = [0 for _ in range(n+1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i+1] = self.factorial[i]*(i+1)%mod
        self.inv[n] = pow(self.factorial[n],mod-2,mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i+1]*(i+1)%mod
            
    def comb(self,m,k):
        return self.factorial[m]*self.inv[k]*self.inv[m-k]%self.mod

def factorization(n):
    if n == 1: return [1]
    res = []
    x = n
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1: res.append(x)
    return res

from collections import Counter

MOD = 1000000007
N,M = map(int,input().split())

ans = 1

if M > 1:

    F = factorization(M)
    C = Counter(F)

    fact = Factorial(2*N,MOD)
    
    for v in C.values():
        ans *= fact.comb(N+v-1,v)
        ans %= MOD

print(ans)