Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
An = [int(_) for _ in input().split()]
An.sort()

old_val = 0
ans = 0
same_flag = False
# 割り切れるものの数を数える
def dfs(An):
    global ans, old_val, same_flag
    if(len(An) == 0):
        return
    val = An.pop(-1)
    # 同じ数に対してのループの場合
    if(val == old_val):
        same_flag = True
    if((same_flag == True) and (val != old_val or len(An) == 1)):
        ans += 1
        same_flag = False
    for i in An:
        # 割り切れる場合はansに数を足して今のループを抜ける
        if(val % i == 0):
            ans += 1
            break
    old_val = val
    # どの数でも割り切れなかった場合は一度抜ける
    dfs(An)

dfs(An)
print(N - ans)

Fixed submission:
"""
考え方のポイント
・自分以外では割り切れないような数の個数を求める
　→ 数列の各項に対して〇（割り切れない）×がついていって、〇の個数を数える
・[2, 2]みたいな入力は、他の数で割り切れるようになるので、同じ数が入っていると絶対に×になる。

まずは入力が全部異なる前提で進める。
範囲内の整数からなる全て配列dを用意する。
→ 入力の数列を約数としてもつ数にチェックをしていく（Anに2が含まれていれば、2の倍数全てにチェック（+1)する）
→ チェック後にd[i]をみたとき、d[i]の約数がan中に何個存在するかが示されていることになる。（2∈Aiならd[5](=6)の値は必ず1以上になってる)
"""
N = int(input())
An = [int(i) for i in input().split()]
An.sort()
max_val = 10**6+1
d = [0] * max_val


# O(N) = O(2*10^5)
# d[i]のうち、配列の値の位置を+1しとく。
for i in An:
    d[i] += 1
    # O(MlogM) = 6*10^6
    # 始めてその倍数がきたときだけ
    if(d[i] == 1):
        # [2, 2]などの重複がない場合（既にカウントされているものではない場合)
        # 倍数の位置にも2としておいて以降はみないようにする
        for val in range(i*2, max_val, i):
            d[val] = 2

print(d.count(1))

Buggy python submission (verdict: Runtime Error):
N = int(input())
An = [int(_) for _ in input().split()]
An.sort()
An = list(set(An))
N = len(An)

ans = 0

# 割り切れるものの数を数える
def dfs(An):
    global ans
    if(len(An) == 0):
        return
    val = An.pop(-1)
    for i in An:
        # 割り切れる場合はansに数を足して今のループを抜ける
        if(val % i == 0):
            ans += 1
            break
    # どの数でも割り切れなかった場合は一度抜ける
    dfs(An)

dfs(An)
if(N == 1):
    last_ans = 0
else:
    last_ans = N - ans

print(last_ans)

Fixed submission:
"""
考え方のポイント
・自分以外では割り切れないような数の個数を求める
　→ 数列の各項に対して〇（割り切れない）×がついていって、〇の個数を数える
・[2, 2]みたいな入力は、他の数で割り切れるようになるので、同じ数が入っていると絶対に×になる。

まずは入力が全部異なる前提で進める。
範囲内の整数からなる全て配列dを用意する。
→ 入力の数列を約数としてもつ数にチェックをしていく（Anに2が含まれていれば、2の倍数全てにチェック（+1)する）
→ チェック後にd[i]をみたとき、d[i]の約数がan中に何個存在するかが示されていることになる。（2∈Aiならd[5](=6)の値は必ず1以上になってる)
"""
N = int(input())
An = [int(i) for i in input().split()]
An.sort()
max_val = 10**6+1
d = [0] * max_val


# O(N) = O(2*10^5)
# d[i]のうち、配列の値の位置を+1しとく。
for i in An:
    d[i] += 1
    # O(MlogM) = 6*10^6
    # 始めてその倍数がきたときだけ
    if(d[i] == 1):
        # [2, 2]などの重複がない場合（既にカウントされているものではない場合)
        # 倍数の位置にも2としておいて以降はみないようにする
        for val in range(i*2, max_val, i):
            d[val] = 2

print(d.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
An = [int(x) for x in input().split()]

for i in range(1, N+1):
    print(An.count(i))

Fixed submission:
N = int(input())
An = [int(x) for x in input().split()]

mylist = [0] * N

for i in An:
    mylist[i-1] = mylist[i-1] + 1

for i in mylist:
    print(i)
Buggy python submission (verdict: Runtime Error):
X = input()
uresisa_500yen = (X // 500) * 1000
mod = (X % 500)
uresisa_5yen = (mod // 5) * 5

uresisa_total = uresisa_500yen + uresisa_5yen
print(uresisa_total)

Fixed submission:
X = int(input(""))

happy_1 = (X // 500) * 1000
happy_2 = ((X % 500) // 5) * 5

val = happy_1 + happy_2

print(val)
Buggy python submission (verdict: Runtime Error):
K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, K - An_list[N-1])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

Fixed submission:
import numpy as np

K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, (K - An_list[-1])+An_list[0])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

Buggy python submission (verdict: Runtime Error):
#入出力
K,N = map(int, input("K,N:").split())
An_list = np.array(input("An:").split(), dtype=int)

# ここの距離を求める
An_delta_list = np.array([], dtype=int)

# 差のリストをつくる
for i in range(len(An_list)-1):
    An_delta_list = np.append(An_delta_list, An_list[i+1] -An_list[i])
An_delta_list = np.append(An_delta_list, K - An_list[-1])

# 差が最大の部分を見つける
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max


print(result)

Fixed submission:
import numpy as np

K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, (K - An_list[-1])+An_list[0])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

Buggy python submission (verdict: Runtime Error):
#入出力
K,N = map(int, input("K,N:").split())
An_list = np.array(input("An:").split(), dtype=int)


"""
# 入出力
K = 20
N = 3
An_list = np.array([0, 5, 15], dtype=int)
"""


# ここの距離を求める
An_delta_list = np.array([], dtype=int)

# 差のリストをつくる
for i in range(len(An_list)-1):
    An_delta_list = np.append(An_delta_list, An_list[i+1] -An_list[i])
An_delta_list = np.append(An_delta_list, K - An_list[-1])

# 差が最大の部分を見つける
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

"""
print("全リスト：", An_delta_list)
print("差の最大の値：", An_delta_max)
print("結果：", result)
"""

Fixed submission:
import numpy as np

K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, (K - An_list[-1])+An_list[0])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)
Buggy python submission (verdict: Runtime Error):
# coding: UTF-8

S = input()
T = input()

res = set()
for ss, tt in zip(S, T):
    if ss != tt:
        set[ss] = 1

print(len(res))

Fixed submission:
# coding: UTF-8

S = input()
T = input()

res = 0
for ss, tt in zip(S, T):
    if ss != tt:
        res += 1

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

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
R_A = deque()
R_A.append(0)
i = 0
while i < N:
  R_A.append(R_A[-1]+A[i])
  i += 1 
B = list(map(int, input().split()))
R_B = deque()
R_B.append(0)
i = 0
while i < M:
  R_B.append(R_B[-1]+B[i])
  i += 1 
R_B = list(R_B)
ans = 0
i = 0
while i <= N:
  m = K - R_A[i]
  if m < 0:
    break
  idx = bisect(R_B, m)
  ans = max(ans, i+idx-1)
  R_B = R_B[:idx+1]
  i += 1
print(ans)



Fixed submission:
from bisect import bisect

N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i <= N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 and idx >= N or P[idx] != x:
        print(x)
        break
    i += 1



Fixed submission:
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 or idx >= N or P[idx] != x:
        print(x)
        break
    i += 1
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect, bisect_left
N = int(input())
A = list(map(int, input().split()))
A_ = sorted(list(set(A)))
A = sorted(A)
ans = 0
i = 0
while i < len(A_):
  a = A_[i]
  j = bisect_left(A_, a*2)
  while j < len(A_):
    if A_[j] % a == 0:
      A_.pop(j)
    else:
      j += 1
  if bisect(A, a)-bisect_left(A, a) > 1:
    ans -= 1
  i += 1
print(ans+len(A_))



Fixed submission:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
memo = [0]*(M+1)
i = 0
while i < N:
  a = A[i]
  memo[a] += 1
  x = a+a
  while x <= M:
    memo[x] += 2
    x += a
  i += 1
print(sum([1 if m == 1 else 0 for m in memo]))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect, bisect_left
N = int(input())
A = list(map(int, input().split()))
A_ = sorted(list(set(A)))
A = sorted(A)
ans = 0
i = 0
while i < len(A_):
  a = A_[i]
  j = i+1
  while j < len(A_):
    if A_[j] % a == 0:
      A_.pop(j)
    else:
      j += 1
  if bisect(A, a)-bisect_left(A, a) > 1:
    ans -= 1
  i += 1
print(ans+len(A_))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
memo = [0]*(M+1)
i = 0
while i < N:
  a = A[i]
  memo[a] += 1
  x = a+a
  while x <= M:
    memo[x] += 2
    x += a
  i += 1
print(sum([1 if m == 1 else 0 for m in memo]))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect, bisect_left
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
i = 0
while i < N:
  j = 0
  isOK = True
  while A[j]*2 <= A[i] and isOK:
    if A[i]%A[j] == 0:
      isOK = False
      break
    j += 1
  if bisect(A, A[i])-bisect_left(A, A[i]) == 1 and isOK:
    ans += 1
  i += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
memo = [0]*(M+1)
i = 0
while i < N:
  a = A[i]
  memo[a] += 1
  x = a+a
  while x <= M:
    memo[x] += 2
    x += a
  i += 1
print(sum([1 if m == 1 else 0 for m in memo]))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
N = int(input())
A = reduce(lambda x, y:x*y if x*y <= 10**18 else -1, map(int, input().split()))
print(A)


Fixed submission:
from math import log
from functools import reduce
N = int(input())
A = sorted(list(map(int, input().split())))
if A[0] == 0:
  print(0)
else:
  ans = 1
  for a in reversed(A):
    ans *= a
    if ans > 10**18:
      ans = -1
      break
  print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
isOK = True
B = [0]*(N+1)
B[0] = 1-A[0]
M = 1
i = 1
while i <= N:
  B[i] = B[i-1]*2-A[i]
  i += 1
if B[i] < 0 or N > 0 and A[-1] == 0:
  isOK = False
B[-1] = A[-1]
i = N-1
while i >= 0:
  if B[i] < 1 or i > 0 and B[i] > B[i-1]*2:
    isOK = False
    break
  else:
    B[i] = min(B[i], B[i+1])+A[i]
  i -= 1
print(-1 if not isOK else sum(B))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
isOK = True
B = [0]*(N+1)
B[0] = 1-A[0]
M = 1
i = 1
while i <= N:
  B[i] = B[i-1]*2-A[i]
  i += 1
if B[-1] < 0 or N > 0 and A[-1] == 0:
  isOK = False
B[-1] = A[-1]
i = N-1
while i >= 0:
  if B[i] < 1 or i > 0 and B[i] > B[i-1]*2:
    isOK = False
    break
  else:
    B[i] = min(B[i], B[i+1])+A[i]
  i -= 1
print(-1 if not isOK else sum(B))
Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 998244353

def C(a, b, m):
  return 1 if b == 0 else reduce(lambda x, y:(x*y)%m, range(a-b+1, a+1))*pow(reduce(lambda x,y:(x*y)%m, range(1, b+1)), m-2, m)
  
N, M, K = map(int, input().split())
ans = (M*pow(M-1, (N-k-1), mod))%mod
k = 1
while k <= K and k < N:
  a = ((C(N, k, mod)-1)*M*pow(M-1, (N-k-1), mod))%mod
  ans += a
  k += 1
print(ans)


Fixed submission:
from functools import reduce
mod = 998244353

N, M, K = map(int, input().split())
C = 1
ans = (M*pow(M-1, (N-1), mod))%mod
k = 1
while k <= K and k < N:
  C *= (N-k)*pow(k, mod-2, mod)
  C %= mod
  a = (C*M*pow(M-1, (N-k-1), mod))%mod
  ans = (ans+a)%mod
  k += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
i = 0
while i < N-1:
  j = A[i]+i+1
  while j <N:
    ans += 1 if j-i == A[i]+A[j] else 0
    j += 1
  i += 1
print(ans)


Fixed submission:
from bisect import bisect, bisect_left

N = int(input())
A = list(map(int, input().split()))
I = [0]*N
J = [0]*N
i = 0
while i < N:
  I[i] = A[i]+i
  J[i] = i-A[i]
  i += 1
I.sort()
ans = 0
for j in J:
  ans += bisect(I, j)-bisect_left(I, j)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(map(int, input()))
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x += s*(10**i)
    d[x%2019] += 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)



Fixed submission:
S, W = map(int, input().split())
print( "unsafe" if S <= W else "safe" )
Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, input()))
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x += s*(10**i)
    d[x%2019] += 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)



Fixed submission:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x += int(s)*(10**i)
    d[x%2019] += 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)



Fixed submission:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))

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

S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  d = [0]*2019
  d[0] = 1
  i = N-1
  while i >= 0:
    d[int(S[i:])%2019] += 1
    i -= 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)



Fixed submission:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))

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

S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  ans = 0
  for i in range(N):
    cnt = 0
    for j in range(i+4, N+1):
      ans += 1 if int(S[i:j])%2019 == 0 else 0
  print(ans)



Fixed submission:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))

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

S = input()
if len(S) < 4:
  print(0)
else:
  ans = 0
  d = [deque() for _ in range(3)]
  x = 0
  d[x].append(0)
  for i, s in enumerate(S):
    x = (x+int(s))%3
    d[x].append(i+1)
  for m in range(3):
    for s in d[m]:
      eidx = bisect(d[m], s+4)
      while eidx < len(d[m]):
        e = d[m][eidx]
        ans += 1 if int(S[s:e])%2019 == 0 else 0
        eidx += 1
print(ans)


Fixed submission:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))
Buggy python submission (verdict: Runtime Error):
from collections import deque
X, Y, A, B, C = map(int, input().split())
P = deque(sorted(list(map(int, input().split())), reverse=True))
Q = deque(sorted(list(map(int, input().split())), reverse=True))
R = deque(sorted(list(map(int, input().split())), reverse=True))
ans = 0
p_cnt = 0
while p_cnt < X:
  if P[0] < R[0]:
    r = R.popleft()
  else:
    r = P.popleft()
  ans += r
  p_cnt += 1
q_cnt = 0
while q_cnt < Y:
  if Q[0] < R[0]:
    g = R.popleft()
  else:
    g = Q.popleft()
  ans += g
  q_cnt += 1
print(ans)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)[:X]
Q = sorted(list(map(int, input().split())), reverse=True)[:Y]
R = sorted(list(map(int, input().split())), reverse=True)
print(sum(sorted(P+Q+R, reverse=True)[:X+Y]))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
memo = [10**10]*(H+1)
memo[0] = 0
i = 0
while i <= H:
  for a, b in AB:
    memo[i] = min(memo[i], b+memo[max(0, i-a)])
  i += 1
print(memo[H])

Fixed submission:
H, A = map(int, input().split())
print(H//A + (0 if H%A == 0 else 1))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)
def GCD(a, b):
  a, b = max(a,b), min(a, b)
  if a%b == 0:
    return b
  else:
    return GCD(b, a%b)
N = int(input())
A = list(map(int, input().split()))
L = 1
for i in range(N):
  g = GCD(A[i], L)
  L = A[i]*L//g
ans = 0
for i in range(N):
  ans += L//A[i]
print(ans%(7+10**9))

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
L = 1
for i in range(N):
  g = fractions.gcd(A[i], L)
  L = A[i]*L//g
ans = 0
for i in range(N):
  ans += L//A[i]
print(ans%(7+10**9))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)
def GCD(a, b):
  a, b = max(a,b), min(a, b)
  if a%b == 0:
    return b
  else:
    return GCD(b, a%b)
N = int(input())
A = list(map(int, input().split()))
L = 1
for a in A:
  g = GCD(a, L)
  L = a*L//g
ans = 0
for a in A:
  ans += L//a
print(ans%(7+10**9))

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
L = 1
for i in range(N):
  g = fractions.gcd(A[i], L)
  L = A[i]*L//g
ans = 0
for i in range(N):
  ans += L//A[i]
print(ans%(7+10**9))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)
def GCD(a, b):
  a, b = max(a,b), min(a, b)
  if a%b == 0:
    return b
  else:
    return GCD(b, a%b)
N = int(input())
A = list(map(int, input().split()))
L = 1
for a in A:
  g = GCD(a, L)
  L = a*L//g
ans = 0
for a in A:
  ans += L//a
print(ans%(7+10**9))

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
L = 1
for i in range(N):
  g = fractions.gcd(A[i], L)
  L = A[i]*L//g
ans = 0
for i in range(N):
  ans += L//A[i]
print(ans%(7+10**9))
Buggy python submission (verdict: Runtime Error):
from collections import deque
import copy
def solve(maze, start, end):
  memo = []
  q = deque()
  q.append([start,[]])
  ans = 0
  while q:
    cur, path = q.popleft()
    if cur == end:
      ans = path
      break
    elif cur in memo:
      continue
    else:
      memo.append(cur)
      for y, x in zip((0,0,1,-1),(1,-1,0,0)):
        if maze[cur[0]+y][cur[1]+x] == ".":
          q.append([[cur[0]+y,cur[1]+x],copy.deepcopy(path)+[cur]])
  return ans


H, W = map(int, input().split())
Maze = [["#"]*(W+2)]+[["#"]+list(input())+["#"] for _ in range(H)] + [["#"]*(W+2)]
Ans = 0
for sy in range(1, H+1):
  for sx in range(1, W+1):
    if Maze[sy][sx] == "#":
      continue
    memo = [[False]*(W+2) for _ in range(H+2)]
    for ey in range(H+1, sy,-1):
      for ex in range(1, W+1):
        if Maze[ey][ex] == "#" or memo[ey][ex]:
          continue
        P = solve(Maze, [sy, sx], [ey,ex])
        Ans = max(Ans, len(P))
        for p in P:
          memo[p[0]][p[1]] = True
print(Ans)

Fixed submission:
alphabet = list("abcdefghijklmnopqrstuvwxyz")
s = input()
print(alphabet[alphabet.index(s)+1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
ans = 0
if N > 3:
  for i in range(N-3):
  	if S[i:i+3] == "ABC":
    	ans += 1
else:
  ans = 1 if S == "ABC" else 0
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
if N > 3:
  for i in range(N-2):
    if S[i:i+3] == "ABC":
      ans += 1
else:
  ans = 1 if S == "ABC" else 0
print(ans)
Buggy python submission (verdict: Runtime Error):
def isPrime(x):
  i = 2
  while i*i <= x:
    if x % i == 0:
      return True
  return False

X = int(input())
ans = X
while not isPrime(x):
  ans += 1
print(ans)


Fixed submission:
prime_table = [True]*(2*(10**5)+1)
prime_table[0], prime_table[1] = False, False
i = 2
while i * i <= 2*(10**5):
  if prime_table[i]:
    j = i*i
    while j <= 2*(10**5):
      prime_table[j] = False
      j += i
  i += 1
x = int(input())
ans = x
while not prime_table[ans]:
  ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N = input()
S = list(input())
ans = ""
for s in S:
  i = (a.index(s)+N)%26
  ans += a[i]
print(ans)


Fixed submission:
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N = int(input())
S = list(input())
ans = ""
for s in S:
  i = (a.index(s)+N)%26
  ans += a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return 1 if n == 0 else P(n, n)

X, Y = map(int, input().split())
L, S = max(X, Y), min(Y, X)
if (S-(L-S))%3 != 0:
  print(0)
else:
  s = (S-(L-S))//3
  l = (S-(L-S))//3+(L-S)
  bunshi = factorial(s+l)
  bunbo = (factorial(s)*factorial(l))%mod
  print((bunshi*pow(bunbo,mod-2, mod))%mod)
  
  

Fixed submission:
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

def C(n, k):
  k = min(k, n-k)
  if k == 0:
    return 1
  else:
    return (P(n, k)*pow(factorial(k), mod-2, mod))%mod

X, Y = map(int, input().split())
if (X+Y)%3 == 0:
  n = Y-(X+Y)//3
  m = X-(X+Y)//3
  if n < 0 or m < 0:
    print(0)
  else:
    print(C(n+m, n))
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

X, Y = map(int, input().split())
L, S = max(X, Y), min(Y, X)
if (S-(L-S))%3 != 0 or S-(L-S) < 0:
  print(0)
else:
  s = (S-(L-S))//3
  l = (S-(L-S))//3+(L-S)
  bunshi = factorial(s+l)
  bunbo = (factorial(s)*factorial(l))%mod
  print((bunshi*pow(bunbo,mod-2, mod))%mod)
  
  

Fixed submission:
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

def C(n, k):
  k = min(k, n-k)
  if k == 0:
    return 1
  else:
    return (P(n, k)*pow(factorial(k), mod-2, mod))%mod

X, Y = map(int, input().split())
if (X+Y)%3 == 0:
  n = Y-(X+Y)//3
  m = X-(X+Y)//3
  if n < 0 or m < 0:
    print(0)
  else:
    print(C(n+m, n))
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

X, Y = map(int, input().split())
L, S = max(X, Y), min(Y, X)
if (S-(L-S))%3 != 0:
  print(0)
else:
  s = (S-(L-S))//3
  l = (S-(L-S))//3+(L-S)
  bunshi = factorial(s+l)
  bunbo = (factorial(s)*factorial(l))%mod
  print((bunshi*pow(bunbo,mod-2, mod))%mod)
  
  

Fixed submission:
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

def C(n, k):
  k = min(k, n-k)
  if k == 0:
    return 1
  else:
    return (P(n, k)*pow(factorial(k), mod-2, mod))%mod

X, Y = map(int, input().split())
if (X+Y)%3 == 0:
  n = Y-(X+Y)//3
  m = X-(X+Y)//3
  if n < 0 or m < 0:
    print(0)
  else:
    print(C(n+m, n))
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
M = int(math.sqrt(N))
i = 1
j = 1
for x in reversed(range(M)):
  if N % x == 0:
    i = x
    j = N // x
    break
print(i+j-2)


Fixed submission:
import math
N = int(input())
M = int(math.sqrt(N))
i = 1
j = 1
for x in reversed(range(M+1)):
  if N % x == 0:
    i = x
    j = N // x
    break
print(i+j-2)