Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
S = sorted(S)
c = 0
for i in range(n - 1):
  j = i + 1
  while S[i] == S[j] and j < n:
    c += 1
    j += 1
    if j == n:
      break
print(c)

Fixed submission:
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
S = sorted(S)
c = 0
i = 0
while i < n - 1:
  j = i + 1
  while j < n:
    if S[i] == S[j]:
      j += 1
    else:
      break
  c += (j-i) * (j-i-1) // 2
  i = j  
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
c = 0
for i in range(n):
  for j in range(i+1,n):
    if S[i] == S[j]:
      c += 1
print(c)

Fixed submission:
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
S = sorted(S)
c = 0
i = 0
while i < n - 1:
  j = i + 1
  while j < n:
    if S[i] == S[j]:
      j += 1
    else:
      break
  c += (j-i) * (j-i-1) // 2
  i = j  
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [input() for i in range(n)]
c = 0
for i in range(n):
  for j in range(n):
    if i < j and sorted(S[i]) == sorted(S[j]):
      c += 1
print(c)

Fixed submission:
n = int(input())
S = [input() for i in range(n)]
for i in range(n):
  S[i] = sorted(S[i])
S = sorted(S)
c = 0
i = 0
while i < n - 1:
  j = i + 1
  while j < n:
    if S[i] == S[j]:
      j += 1
    else:
      break
  c += (j-i) * (j-i-1) // 2
  i = j  
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
P = int(input())
A = list(map(int, input().split()))

Q = [1 for _ in range(P)]

for i in range(P):
    if A[i]:
        for k in range(P):
            if i == k:
                continue
            Q[i] *= pow(i - k, P - 2, P)
            Q[i] %= P
    else:
        Q[i] = 0

F = [0 for _ in range(P + 1)]
F[0] = 1

for i in range(P):
    tmp = [0 for _ in range(P + 1)]
    for j in range(1, P + 1):
        tmp[j] += F[j - 1]
        tmp[j] %= P
    for j in range(P + 1):
        tmp[j] += F[j] * (-i)
        tmp[j] %= P
    F = tmp

res = [0 for _ in range(P)]

for i in range(P):
    G = [0 for _ in range(P)]
    G[P - 1] = F[P]
    res[P - 1] += Q[i] * G[P - 1]
    res[P - 1] %= P
    for j in range(P - 1)[::-1]:
        G[j] = F[j + 1] + i * G[j + 1]
        G[j] %= P
        res[j] += Q[i] * G[j]
        res[j] %= P

print(*res)

Fixed submission:
P = int(input())
A = list(map(int, input().split()))

Q = [1 for _ in range(P)]

for i in range(P):
    if A[i]:
        for k in range(P):
            if i == k:
                continue
            Q[i] *= (i - k)
            Q[i] %= P
        Q[i] = pow(Q[i], P - 2, P)
    else:
        Q[i] = 0

F = [0 for _ in range(P + 1)]
F[0] = 1

for i in range(P):
    tmp = [0 for _ in range(P + 1)]
    for j in range(1, P + 1):
        tmp[j] += F[j - 1]
        tmp[j] %= P
    for j in range(P + 1):
        tmp[j] += F[j] * (-i)
        tmp[j] %= P
    F = tmp

res = [0 for _ in range(P)]

for i in range(P):
    G = [0 for _ in range(P)]
    G[P - 1] = F[P]
    res[P - 1] += Q[i] * G[P - 1]
    res[P - 1] %= P
    for j in range(P - 1)[::-1]:
        G[j] = F[j + 1] + i * G[j + 1]
        G[j] %= P
        res[j] += Q[i] * G[j]
        res[j] %= P

print(*res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
H = list(map(int, input().split()))
for i in range(n - 1):
  if max(H[:i+1]) <= H[i+1] + 1:
    continue
  else:
    print('No')
    exit()
print('Yes')

Fixed submission:
n = int(input())
H = list(map(int, input().split()))
m = H[0]
for i in range(n - 1):
  if max(m, H[i]) <= H[i+1] + 1:
    m = max(m, H[i])
  else:
    print('No')
    exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)
a,b,c,d = map(int, input().split())
p = b//c + (-a//c) +1
q = b//d + (-a//d) +1
r = b*gcd(c,d)//(c*d) + (-a*gcd(c,d)//(c*d)) +1
print(b-a+1-p-q+r)

Fixed submission:
s = input()
for i in range(0,3):
  if s[i] == s[i+1]:
    print('Bad')
    exit()
print('Good')
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int, input().split())
p = 0
for i in range(a,b+1):
  if i % c != 0 and i % d != 0:
    p += 1
print(p)

Fixed submission:
import fractions
a,b,c,d = map(int, input().split())
p = b//c + (-a//c) +1
q = b//d + (-a//d) +1
r = b*fractions.gcd(c,d)//(c*d) + (-a*fractions.gcd(c,d)//(c*d)) +1
print(b-a+1-p-q+r)
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
S = [(input()+'#') for i in range(h)]+['#'*(w+1)]
Rows = []
Columns = []
for i in range(h):
    Row = []
    row = 0
    for j in range(w+1):
        if S[i][j] == '.':
            row += 1
        else:
            if row > 0:
                Row += [row]
            row = 0
            Row += [row]
    Rows += [Row]
for j in range(w):
    Column = []
    column = 0
    for i in range(h+1):
        if S[i][j] == '.':
            column += 1
        else:
            if column > 0:
                Column += [column]
            column = 0
            Column += [column]
    Columns += [Column]
mRows = []
mColumns = []
for i in range(h):
  mRow= []
  for j in range(len(Rows[i])):
    mRow += [Rows[i][j]]*max(1,Rows[i][j])
  mRows += [mRow]
for i in range(w):
  mColumn= []
  for j in range(len(Columns[i])):
    mColumn += [Columns[i][j]]*max(1,Columns[i][j])
  mColumns += [mColumn]
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,mRows[i][j]+mColumns[j][i]-1)
print(ans)

Fixed submission:
h,w = map(int,input().split())
S = [(input()+'#') for i in range(h)]+['#'*(w+1)]
Rows = []
Columns = []
for i in range(h):
    Row = []
    row = 0
    for j in range(w+1):
        if S[i][j] == '.':
            row += 1
        else:
            if row > 0:
                Row += [row]
            row = 0
            Row += [row]
    Rows += [Row]
for j in range(w):
    Column = []
    column = 0
    for i in range(h+1):
        if S[i][j] == '.':
            column += 1
        else:
            if column > 0:
                Column += [column]
            column = 0
            Column += [column]
    Columns += [Column]
mRows = []
mColumns = []
for i in range(h):
  mRow= []
  for j in range(len(Rows[i])):
    mRow += [Rows[i][j]]*max(1,Rows[i][j])
  mRows += [mRow]
for i in range(w):
  mColumn= []
  for j in range(len(Columns[i])):
    mColumn += [Columns[i][j]]*max(1,Columns[i][j])
  mColumns += [mColumn]
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,mRows[i][j]+mColumns[j][i]-1)
print(ans)
Buggy python 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')

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 python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
D=[list(map(int,input().split())) for i in range(m)]

I=set(i for i in range(1,n+1))

for i in range(m):
  I &= set(i for i in range(D[i][0],D[i][1]+1))
print(len(I))  

Fixed submission:
n,m=map(int,input().split())
D=[list(map(int,input().split())) for i in range(m)]
maxI=n
minI=1
for i in range(m):
  maxI=min(maxI,D[i][1])
  minI=max(minI,D[i][0])
print(max(maxI-minI+1,0))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
I = [list(map(int,input().split())) for i in range(q)]
AC = []
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        AC += [i]
for i in range(q):
    AC_q = [j for j in AC if I[i][0]-1 <= j <= I[i][1]-2]
    print(len(AC_q))

Fixed submission:
n,q = map(int,input().split())
s = input()
I = [list(map(int,input().split())) for i in range(q)]
AC = []
ac = 0
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac += 1
        AC += [ac]
    else:
        AC += [ac]
AC = [0] + AC + [ac]
for i in range(q):
    ac_q =  AC[I[i][1]-1]-AC[I[i][0]-1]
    print(ac_q)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

INF = 10**18

A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(input())
    si = bisect_left(S,x)
    ti = bisect_left(T,x)
    res = INF
    res = min(res, max(S[si] - x, T[ti] - x))
    res = min(res, max(x - S[si - 1], x - T[ti - 1]))
    res = min(res, x + T[ti] - 2 * S[si - 1])
    res = min(res, -x + 2 * T[ti] - S[si - 1])
    res = min(res, x + S[si] - 2 * T[ti - 1])
    res = min(res, -x + 2 * S[si] - T[ti - 1])
    print(res)

Fixed submission:
import bisect

A,B,Q = map(int,input().split())
shrine = [-float('inf')]+[int(input()) for _ in range(A)]+[float('inf')]
temple = [-float('inf')]+[int(input()) for _ in range(B)]+[float('inf')]
query = [int(input()) for _ in range(Q)]

for q in query:
  s = bisect.bisect(shrine,q)
  t = bisect.bisect(temple,q)
  print(
      min(
        max(shrine[s],temple[t])-q, 
        q - min(shrine[s-1],temple[t-1]),
        (shrine[s]-q)*2+(q-temple[t-1]),
        (temple[t]-q)*2+(q-shrine[s-1]),
        (shrine[s]-q)+(q-temple[t-1])*2,
        (temple[t]-q)+(q-shrine[s-1])*2,
        )
        )
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

cost = [0,2,5,5,4,5,6,3,7,6]

dp = [0 for _ in range(N + 1)] #dp[i] i本のマッチを使って作れる最大の桁数

for i in range(1, N + 1):
    for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1)

ans = ''

i = N
for k in range(dp[N]):
    for a in A:
        if dp[i - cost[a]] == dp[i] - 1:
            if k == dp[N] - 1 and i != cost[a]:
                continue
            ans += str(a)
            i -= cost[a]
            break

print(ans)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

cost = [0,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 1)] #dp[i] i本のマッチを使って作れる最大の桁数
dp[0] = 0

for i in range(1, N + 1):
    for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1)

ans = ''

i = N
for k in range(dp[N]):
    for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  count = 0  
  while count < n-1:
    Dif_X[Dif_X.index(max(Dif_X))] = 0
    count += 1
  print(sum(Dif_X))

Fixed submission:
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  Sum_Dif_X = sum(Dif_X)  
  Sorted_Dif_X = sorted(Dif_X, reverse = True)
  count = 0  
  while count < n-1:
    Sum_Dif_X -= Sorted_Dif_X[count]
    count += 1
  print(Sum_Dif_X)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  while Dif_X.count(0)<n-1:
    Dif_X[Dif_X.index(max(Dif_X))] = 0
  print(sum(Dif_X))

Fixed submission:
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  Sum_Dif_X = sum(Dif_X)  
  Sorted_Dif_X = sorted(Dif_X, reverse = True)
  count = 0  
  while count < n-1:
    Sum_Dif_X -= Sorted_Dif_X[count]
    count += 1
  print(Sum_Dif_X)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  while Dif_X.count(0)<n-1:
    Dif_X[Dif_X.index(max(Dif_X))] = 0
  print(sum(Dif_X))

Fixed submission:
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  Sum_Dif_X = sum(Dif_X)  
  Sorted_Dif_X = sorted(Dif_X, reverse = True)
  count = 0  
  while count < n-1:
    Sum_Dif_X -= Sorted_Dif_X[count]
    count += 1
  print(Sum_Dif_X)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**18

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

dp = [INF for _ in range(N)]
dp[0] = 0

for i in range(1, N):
    for k in range(1, K + 1):
        if i - k < 0:
            break
        dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))

print(dp[N - 1])

Fixed submission:
n,k = map(int,input().split())
H = list(map(int,input().split()))

if k >= n-1:
    print(abs(H[0]-H[n-1]))

else:
    dp = [0 for i in range(n)]
    for i in range(k+1):
        dp[i] = abs(H[0]-H[i])

    for i in range(k+1,n):
        mincost = 10**9
        for j in range(1,k+1):
            mincost = min(mincost,dp[i-j]+abs(H[i]-H[i-j]))
        dp[i] = mincost

    print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
H = list(map(int,input().split()))

if k >= n-1:
    print(abs(H[0]-H[n-1]))

else:
    dp = [0 for i in range(n)]
    for i in range(k+1):
        dp[i] = abs(H[0]-H[i])

    for i in range(k+1,n):
        mincost = 10**9
        for j in range(1,k+1):
            mincost = min(mincost,dp[i-j]+abs(H[i]-H[i-j]))
        dp[i] = mincost

    print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
H = list(map(int,input().split()))

if k >= n-1:
    print(abs(H[0]-H[n-1]))

else:
    dp = [0 for i in range(n)]
    for i in range(k+1):
        dp[i] = abs(H[0]-H[i])

    for i in range(k+1,n):
        mincost = 10**9
        for j in range(1,k+1):
            mincost = min(mincost,dp[i-j]+abs(H[i]-H[i-j]))
        dp[i] = mincost

    print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w = map(int,input().split())
item = [list(map(int,input().split())) for i in range(n)]

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 item[i-1][0] <= j:
      dp[i][j] = max(dp[i-1][j-item[i-1][0]]+item[i-1][1],dp[i-1][j])
    else:
      dp[i][j] = dp[i-1][j]
print(dp[n][w])


Fixed submission:
n,w = map(int,input().split())
item = [list(map(int,input().split())) for i in range(n)]

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 item[i-1][0] <= j:
      dp[i][j] = max(dp[i-1][j-item[i-1][0]]+item[i-1][1],dp[i-1][j])
    else:
      dp[i][j] = dp[i-1][j]
print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

dp = [[[0 for k in range(N+1)] for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(a+b+c-k-j+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])

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

dp = [[[0.0 for k in range(N+1)] for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(a+b+c-k-j+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])

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

dp = [[[0 for k in range(N+2)] for j in range(N+2)] for i in range(N+2)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])

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

dp = [[[0.0 for k in range(N+1)] for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 0

a,b,c = 0,0,0
for i in range(N):
    if A[i] == 1:
        a += 1
    elif A[i] == 2:
        b += 1
    else:
        c += 1

for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(a+b+c-k-j+1):
            if i==j==k==0:
                continue
            temp = N
            if i!=0:
                temp += dp[i-1][j][k]*i
            if j!=0:
                temp += dp[i+1][j-1][k]*j
            if k!=0:
                temp += dp[i][j+1][k-1]*k
            dp[i][j][k] = temp/(i+j+k)

print(dp[a][b][c])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007

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

dp = [[0 for j in range(K+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    cum = [0 for j in range(K+2)]
    cum[0] = 0
    for j in range(1,K+2):
        cum[j] = cum[j-1]+dp[i-1][j-1]
        cum[j] %= MOD
    for j in range(K+1):
        dp[i][j] = cum[j+1]-cum[max(0,j-A[i-1])]
        dp[i][j] %= MOD

print(dp[N][K])

Fixed submission:
MOD = 1000000007

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

dp = [[0 for j in range(K+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    cum = [0 for j in range(K+2)]
    cum[0] = 0
    for j in range(1,K+2):
        cum[j] = cum[j-1]+dp[i-1][j-1]
        cum[j] %= MOD
    for j in range(K+1):
        dp[i][j] = cum[j+1]-cum[max(0,j-A[i-1])]
        dp[i][j] %= MOD

print(dp[N][K])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
for i in reversed(range(m//n)):
  if m % (i+1) == 0:
    print(i+1)
    break

Fixed submission:
n,m = map(int,input().split())
Div = []
for i in range(1,int(m**0.5)+1):
  if m%i == 0:
    Div += [i]
    if i != m//i:
      Div += [m//i]
Div.sort(reverse=True)
for div in Div:
  if div <= m//n:
    print(div)
    break
Buggy python 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)

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 python submission (verdict: Runtime Error):
S = input()
W = int(input())
res = ''
for i in range((len(S) + W - 1) // W):
    res = ''.join((res, S[3 * i]))
print(res)

Fixed submission:
S = input()
W = int(input())
res = ''
for i in range((len(S) + W - 1) // W):
    res = ''.join((res, S[W * i]))
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())
D = [tuple(map(int, input().split())) for _ in range(C)]
color = [tuple(map(int, input().split())) for _ in range(N)]

wrongness = [[0, 0, 0] for _ in range(C)]

for c in range(C):
    for i in range(N):
        for j in range(N):
            wrongness[c][(i + j) % 3] += D[color[i][j] - 1][c]

ans = 10**18

for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            if c1 == c2 or c2 == c3 or c3 == c1:
                continue
            ans = min(ans, wrongness[c1][0] + wrongness[c2][1] + wrongness[c3][2])

print(ans)

Fixed submission:
n,c = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(c)]
C = [list(map(int,input().split())) for _ in range(n)]

color_count = [[0]*c for i in range(3)]
for i in range(n):
    for j in range(n):
        color_count[(i+j)%3][C[i][j]-1] += 1

min_wrongness = 10**9

for i in range(c):
    for j in range(c):
        for k in range(c):
            if i!=j and j!=k and k!=i:
                wrongness = 0
                for l in range(3):
                    for m in range(c):
                        if l == 0:
                            wrongness += D[m][i]*color_count[l][m]
                        elif l == 1:
                            wrongness += D[m][j]*color_count[l][m]
                        else:
                            wrongness += D[m][k]*color_count[l][m]
                min_wrongness = min(min_wrongness,wrongness)
                
print(min_wrongness)