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

Fixed submission:
N, T = map(int, input().split())
C = []
for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    C.append(c)
if len(C) >= 1:
  C.sort()
  print(C[0])
else:
  print('TLE')

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
C = []
for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    C.append(c)
C.sort()
print(C[0])
Problem p03303 (python)

Fixed submission:
S = input()
w = int(input())
s = ''
if w == 1:
  print(S)
else:
  if len(S) % w == 0:
    for i in range(len(S) // w):
      s += S[i * w]
    print(s)
  else:
    for i in range((len(S) // w) + 1):
      s += S[i * w]
    print(s)

Buggy submission (verdict: Runtime Error):
S = input()
w = int(input())
s = ''
if w == 1:
  print(S)
else:
  for i in range((len(S) // w) + 1):
    s += S[i * w]
  print(s)

Buggy submission (verdict: Runtime Error):
S = input()
w = int(input())
s = ''
if w == 1:
  print(S)
else:
  for i in range((len(S) // w) + 1):
    s += S[i * w]
print(s)

Buggy submission (verdict: Runtime Error):
S = input()
w = int(input())
s = ''
for i in range((len(S) // w) + 1):
  s += S[i * w]
print(s)
Problem p03352 (python)

Fixed submission:
X = int(input())
l = []
if X < 4:
  print(1)
else:
  for i in range(2, int(X ** 0.5) + 1):
    j = 2
    while i ** j <= X:
      l.append(i ** j)
      j += 1
  l.sort()
  print(l[-1])

Buggy submission (verdict: Runtime Error):
X = int(input())
l = []
for i in range(2, int(X ** 0.5) + 1):
  j = 2
  while i ** j <= X:
    j += 1
  l.append(i ** j)
l.sort()
print(l[-1])
Problem p03363 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dic = {}
dic[0] = 1
total = 0
for i in range(n):
  total += a[i]
  if total in dic:
    dic[total] += 1
  else:
    dic[total] = 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
dic = {}
dic[0] = 1
total = 0
for i in range(n):
  total += a[i]
  dic[total] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)
Problem p03408 (python)

Fixed submission:
N = int(input())
s = {}
for i in range(N):
  a = input()
  if a in s:
    s[a] += 1
  else:
    s[a] = 1
M = int(input())
t = {}
for i in range(M):
  b = input()
  if b in t:
    t[b] += 1
  else:
    t[b] = 1
ans = 0
for p in s:
  if p in t:
    m = s[p] - t[p]
  else:
    m = s[p]
  if m > ans:
    ans = m
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = {}
for i in range(N):
  a = input()
  if a in s:
    s[a] += 1
  else:
    s[a] = 1
M = int(input())
t = {}
for i in range(M):
  b = input()
  if b in t:
    t[b] += 1
  else:
    t[b] = 1
ans = 0
for p in s:
  if p in t:
    m = s[p] - t[p]
  else:
    m = s[p]
  if m > n:
    ans = m
print(ans)
Problem p03434 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()
s = 0
for i in range(1, N + 1):
  if i % 2 == 1:
    s += a[-i]
  else:
    s -= a[-i]
print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, N + 1):
  if i % 2 == 1:
    s += a[-i]
  else:
    s -= a[-i]
print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(N):
  if i % 2 == 1:
    s += a[-i]
  else:
    s -= a[-i]
print(s)
Problem p03437 (python)

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

Buggy submission (verdict: Runtime Error):
x, y = int(input())
if x % y == 0:
  print(-1)
else:
  print(x)
Problem p03547 (python)

Fixed submission:
X, Y = input().split()
dic = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
if dic[X] > dic[Y]:
  print('>')
elif dic[X] == dic[Y]:
  print('=')
else:
  print('<')

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
dic = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
if dic[X] > dic[Y]:
  print('>')
elif dic[X] == dic[Y]:
  print('=')
else:
  print('<')
Problem p03694 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input()))
A.sort()
print(A[-1] - A[0])
Problem p03720 (python)

Fixed submission:
N, M = map(int, input().split())
dic = {}
for i in range(M):
  a, b = map(int, input().split())
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
  if b in dic:
    dic[b] += 1
  else:
    dic[b] = 1
for i in range(1, N + 1):
  if i not in dic:
    print(0)
  else:
    print(dic[i])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dic = {}
for i in range(M):
  a, b = map(int, input().split())
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
  if b in dic:
    dic[b] += 1
  else:
    dic[b] = 1
for i in range(1, N + 1):
  print(dic[i])
Problem p03729 (python)

Fixed submission:
A, B, C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A[-1] == B[0] and B[-1] == C[0]:
  print('YES')
else:
  print('NO')
Problem p03761 (python)

Fixed submission:
n = int(input())
list_1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dic = {}
for al in list_1:
  dic[al] = 100
for i in range(n):
  s = input()
  for al in list_1:
    count = 0
    for t in s:
      if al == t:
        count += 1
    if dic[al] > count:
      dic[al] = count
ans = ''
for al in list_1:
  if dic[al] > 0:
    for i in range(dic[al]):
      ans += al
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
list_1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dic = {}
for al in list_1:
  dic[al] = 100
for i in range(n):
  s = input()
  for al in list_1:
    count
    for t in s:
      if al == t:
        count += 1
    if dic[al] > count:
      dic[al] = count
ans = ''
for al in list_1:
  if dic[al] > 0:
    for i in range(dic[al]):
      ans += al
print(ans)
Problem p03814 (python)

Fixed submission:
S = input()
list_A = []
list_Z = []
for i in range(len(S)):
  if S[i] == 'A':
    list_A.append(i)
  if S[i] == 'Z':
    list_Z.append(i)
a = list_A[0]
z = list_Z[-1]
print(z - a + 1)

Buggy submission (verdict: Runtime Error):
S = input()
list_A = []
list_Z = []
for i in range(len(S)):
  if s[i] == 'A':
    list_A.append(i)
  if s[i] == 'Z':
    list_Z.append(i)
a = list_A[0]
z = list_Z[-1]
print(z - a + 1)
Problem p03828 (python)

Fixed submission:
def prim(p):
  if p == 2:
    return True
  else:
    flg = False
    count = 0
    for i in range(1, int(p ** 0.5) + 1):
      if p % i == 0:
        count += 1
    if count == 1:
      flg = True
    return flg
N = int(input())
if N == 1:
  print(1)
else:
  p_list = []
  for j in range(2, N + 1):
    if prim(j):
      p_list.append(j)
  l = []
  for p in p_list:
    k = 1
    add = 0
    while N // (p ** k):
      add += N // (p ** k)
      k += 1
    l.append(add + 1)
  ans = 1
  for r in l:
    ans *= r
    ans = ans % (10 ** 9 + 7)
  print(ans)

Buggy submission (verdict: Runtime Error):
def prime(p):
  if p == 2:
    return True
  else:
    flg = False
    count = 0
    for i in range(1, int(p ** 0.5)):
      if p % i == 0:
        count += 1
    if count == 1:
      flg = True
    return flg
N = int(input())
if N == 1:
  print(1)
else:
  p_list = []
  for j in range(2, N + 1):
    if prime(j):
      p_list.append(j)
  l = []
  for p in p_list:
    k = 1
    add = 0
    while N // (p ** k):
      add += N // (p ** k)
      k += 1
    l.append(add + 1)
  for r in l:
    ans *= r % (10 ** 9 + 7)
  print(ans)

Buggy submission (verdict: Runtime Error):
def prime(p):
  if p == 2:
    return True
  else:
    count = 0
    for i in range(1, int(p ** 0.5), 2):
      if p % i == 0:
        count += 1
    if count == 1:
      return True
    else:
      return False
N = int(input())
if N == 1:
  print(1)
else:
  p_list = []
  for j in range(2, N + 1):
    if prime(j):
      p_list.append(j)
  l = []
  for p in p_list:
    k = 1
    add = 0
    while N // (p ** k):
      add += N // (p ** k)
      k += 1
    l.append(add + 1)
  for r in l:
    ans *= r % (10 ** 9 + 7)
  print(ans)
Problem p03853 (python)

Fixed submission:
H, W = map(int, input().split())
for i in range(H):
  c = input()
  print(c)
  print(c)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
for i in range(N):
  c = input()
  print(c)
  print(c)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input())
for i in range(N):
  c = input()
  print(c)
  print(c)
Problem p03862 (python)

Fixed submission:
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
  s = A[i] + A[i + 1] - x
  ans += max(0, s)
  if s > 0:
    if s <= A[i + 1]:
      A[i + 1] -= s
    else:
      A[i + 1] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
A = list(map(int, input().split()))
s = 0
for i in range(N - 1):
  s = A[i] + A[i + 1] - x
  ans += max(0, s)
  if s > 0:
    if s <= A[i + 1]:
      A[i + 1] -= s
    else:
      A[i + 1] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - 1):
  s = A[i] + A[i + 1] - x
  ans += max(0, s)
  if s > 0:
    if s <= A[i + 1]:
      A[i + 1] -= s
    else:
      A[i + 1] = 0
print(ans)
Problem p03909 (python)

Fixed submission:
alpha = {1:'A', 2:'B', 3:'C', 4:'D', 5:'E', 6:'F', 7:'G', 8:'H', 9:'I', 10:'J', 11:'K', 12:'L', 13:'M', 14:'N', 15:'O', 16:'P', 17:'Q', 18:'R', 19:'S', 20:'T', 21:'U', 22:'V', 23:'W', 24:'X', 25:'Y', 26:'Z'}
h, w = map(int, input().split())
for i in range(h):
  a = list(input().split())
  for j in range(w):
    if a[j] == 'snuke':
      ans = alpha[j+1] + str(i+1)
      break
print(ans)

Buggy submission (verdict: Runtime Error):
alpha = {1:'A', 2:'B', 3:'C', 4:'D', 5:'E', 6:'F', 7:'G', 8:'H', 9:'I', 10:'J', 11:'K', 12:'L', 13:'M', 14:'N', 15:'O', 16:'P', 17:'Q', 18:'R', 19:'S', 20:'T', 21:'U', 22:'V', 23:'W', 24:'X', 25:'Y', 26:'Z'}
h, w = map(int, input().split())
for i in range(h):
  a = list(map(int, input().split()))
  for j in range(w):
    if a[j] == 'snuke':
      ans = alpha[j+1] + str(i+1)
      break
print(ans)
Problem p03943 (python)

Fixed submission:
A = list(map(int, input().split()))
A.sort()
if A[2] == A[1] + A[0]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
A = map(int, input().split())
A.sort()
if A[2] == A[1] + A[0]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
A.sort()
if A[2] = A[1] + A[0]:
  print('Yes')
else:
  print('No')
Problem p03951 (python)

Fixed submission:
n = int(input())
s = input()
t = input()
for i in range(n):
  cnt = 0
  for j in range(i, n):
    if s[j] != t[j-i]:
      break
    cnt += 1
  if cnt == n-i:
    ans = n+i
    break
if cnt == 0:
  ans = 2*n
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
t = input()
for i in range(n):
  cnt = 0
  for j in range(i, n):
    if s[j] != t[j-i]:
      break
    cnt += 1
  if cnt == n-i:
    ans = n+i
    break
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
t = input()
for i in range(n):
  if s[i:] == t[:n-i]:
    ans = n + i
    break
print(ans)
Problem p03958 (python)

Fixed submission:
k, t = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
double_cnt = 0
total = 0
for i in range(t):
  b = a[i] - double_cnt
  c = total - (double_cnt + 1) + 2
  double_cnt = max(0, b-c)
  total += a[i]
print(double_cnt)

Buggy submission (verdict: Runtime Error):
k, t = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
double_cnt = 0
total = 0
for i in range(t):
  b = a[i] - bouble_cnt
  c = total - (bouble_cnt + 1) + 2
  bouble_cnt = max(0, b-c)
  total += a[i]
print(bouble_cnt)
Problem p03959 (python)

Fixed submission:
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
t_max = max(t)
for i in range(n):
  if t[i] == t_max:
    max_ind = i
    break
if t[max_ind] != a[max_ind] or t[-1] != a[0]:
  print(0)
else:
  idx = []
  before = 0
  for i in range(n):
    if before == t[i]:
      idx .append(i)
    before = t[i]
  if len(idx) == 0:
    print(1)
  else:
    new_idx = []
    for j in idx:
      if j < n-1 and a[j] == a[j+1]:
        new_idx.append(j)
    if len(new_idx) == 0:
      print(1)
    else:
      ans = 1
      for k in new_idx:
        ans *= min(t[k], a[k])
        ans %= MOD
      print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
t_max = max(t)
for i in range(n):
  if a[i] == t_max:
    max_ind = i
    break
if t[max_ind] != a[max_ind] or t[-1] != a[0]:
  print(0)
else:
  idx = []
  before = 0
  for i in range(n):
    if before == t[i]:
      idx .append(i)
    before = t[i]
  if len(idx) == 0:
    print(1)
  else:
    new_idx = []
    for j in idx:
      if j < n-1 and a[j] == a[j+1]:
        new_idx.append(j)
    if len(new_idx) == 0:
      print(0)
    else:
      ans = 1
      for k in new_idx:
        ans *= min(t[k], a[k])
        ans %= MOD
      print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
if t[0] != a[-1]:
  print(0)
else:
  idx = []
  before = 0
  for i in range(n):
    if before == t[i]:
      idx.append(i)
    before = t[i]
  new_index = []
  for j in idx:
    if j < n-1:
      if a[j] == a[j+1]:
        new_index.append(j)
  if len(new_index) > 0:
    print(1)
  else:
    ans = 1
    for k in new_index:
      ans *= min(t[k], a[k])
      ans %= MOD
  print(ans)
Problem p04030 (python)

Fixed submission:
s = input()
l = []
for t in s:
  if t == '0' or t == '1':
    l.append(t)
  elif t == 'B':
    if l != []:
      l.pop()
for r in l:
  print(r, end='')

Buggy submission (verdict: Runtime Error):
s = input()
l = []
for t in s:
  if t == '0' or t == '1':
    l.append(t)
  elif t == 'B':
    l.pop()
for r in l:
  print(r, end='')

Buggy submission (verdict: Runtime Error):
s = input()
c = ''
for t in s:
  if t == '0' or t == '1':
    c += t
  if t == 'B' and c != '':
    c -= c[-1]
print(c)

Buggy submission (verdict: Runtime Error):
s = input()
c = ''
for t in s:
  if t == '0' or t == '1':
    c += t
  elif t == 'B':
    if c != '':
      k = c[-1]
      c -= k
print(c)

Buggy submission (verdict: Runtime Error):
s = input()
c = ''
for t in s:
  if t == '0' or t == '1':
    c += t
  elif t == 'B':
    if c != '':
      c = c - c[-1]
print(c)
Problem p03044 (python)

Fixed submission:
from collections import deque

N = int(input())
e = [[] for i in range(N)]
for i in range(1, N):
    u, v, w = map(int, input().split())
    e[u-1].append((v-1, w))
    e[v-1].append((u-1, w))
l = [-1 for i in range(N)]

q = deque()
l[0] = 0
q.append(0)
while (q):
    u = q.pop()
    for v, w in e[u]:
        if l[v] >= 0:
            continue
        if w % 2 == 0:
            l[v] = l[u]
        else:
            l[v] = 1 - l[u]
        q.append(v)

for col in l:
    print(col)

Buggy submission (verdict: Runtime Error):
N = int(input())
e = [[] for i in range(N)]
for i in range(1, N):
    u, v, w = map(int, input().split())
    e[u-1].append((v-1, w))
    e[v-1].append((u-1, w))
l = [-1 for i in range(N)]
def dfs(u, p, col):
    l[u] = col
    for v, w in e[u]:
        if v == p:
            continue
        if w % 2 == 0:
            dfs(v, u, col)
        else:
            dfs(v, u, 1-col)
    
dfs(0, -1, 0)
for col in l:
    print(col)

Buggy submission (verdict: Runtime Error):
N = int(input())
e = [[] for i in range(N)]
for i in range(1, N):
    u, v, w = map(int, input().split())
    e[u-1].append(v-1)
    e[v-1].append(u-1)
l = [-1 for i in range(N)]
def dfs(u, p, col):
    l[u] = col
    for v in e[u]:
        if v != p:
            dfs(v, u, 1 - col)
    
dfs(0, -1, 0)
for col in l:
    print(col)
Problem p02553 (python)

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

aa = int(a)*int(c)
bb = int(a)*int(d)
cc = int(b)*int(c)
dd = int(b)*int(d)

li = [aa,bb,cc,dd]

print(max(li))

Buggy submission (verdict: Runtime Error):
import sys

args = sys.argv
a = args[1]
b = args[2]
c = args[3]
d = args[4]

aa = int(a)*int(c)
bb = int(a)*int(d)
cc = int(b)*int(c)
dd = int(b)*int(d)

li = [aa,bb,cc,dd]

print(max(li))

Buggy submission (verdict: Runtime Error):
import sys

args = sys.argv
a = args[1]
b = args[2]
c = args[3]
d = args[4]

aa = int(a)*int(c)
bb = int(a)*int(d)
cc = int(b)*int(c)
dd = int(b)*int(d)

li = [aa,bb,cc,dd]

print(max(li))
Problem p02576 (python)

Fixed submission:
n,x,t = input().split()

b = -(-int(n)//int(x))
a = b*int(t)

print(a)

Buggy submission (verdict: Runtime Error):
import math

N/x=math.ceil(a)
a*T=aa

print(aa)
Problem p02732 (python)

Fixed submission:
n=(int)(input())
a=input().split()
for i in range(n):
  a[i]=(int)(a[i])
  
dic={}
sum=0
for i in range(n):
  if not a[i] in dic:
    dic[a[i]]=1
  else:
    dic[a[i]]+=1
    sum+=dic[a[i]]-1

for i in a:
  print(sum-dic[i]+1)

Buggy submission (verdict: Runtime Error):
n=(int)(nput())
a=input().split()
for i in range(n):
  a[i]=(int)(a[i])
  
dic={}
sum=0
for i in range(n):
  if not a[i] in dic:
    dic[a[i]]=1
  else:
    dic[a[i]]+=1
    sum+=dic[a[i]]-1

for i in a:
  print(sum-dic[i]+1)
Problem p02658 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 1

for i in a:
    ans *= i
    if ans > 10 ** 18:
        print(-1)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 1

for i in a:
    ans *= i

  if ans > 10 ** 18:
      print(-1)

print(ans)
Problem p02579 (python)

Fixed submission:
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [input() for _ in range(H)]

Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

grid = [[0 for _ in range(W)] for _ in range(H)]
grid[Ch][Cw] = 1

stack1 = [(Ch, Cw)]
stack2 = []

answer = 1

#print(grid)

while 1:
    while stack1:
        sh, sw = stack1.pop()
    
        stack2.append((sh, sw))
    
        for i, j in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            nh, nw = sh + i, sw + j
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                if nh == Dh and nw == Dw:
                    print(answer - 1)
                    exit()
                grid[nh][nw] = answer
                stack1.append((nh, nw))
    #print(grid)
    
    if len(stack2) == 0:
        break
    
    answer += 1
    while stack2:
        sh, sw = stack2.pop()
        for i in range(-2, 3):
            for j in range(-2, 3):
                nh, nw = sh + i, sw + j
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                    if nh == Dh and nw == Dw:
                        print(answer - 1)
                        exit()
                    grid[nh][nw] = answer
                    stack1.append((nh, nw))
    #print(grid)

print(-1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
S = [input() for _ in range(H)]

grid = [[0 for _ in range(W)] for _ in range(H)]
grid[Ch][Cw] = 1

stack1 = [(Ch, Cw)]
stack2 = []

answer = 0

while 1:
    while stack1:
        sh, sw = stack1.pop()
        stack2.append((sh, sw))
        for i, j in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            nh, nw = sh + i, sw + j
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                if nh == Dh and nw == Dw:
                    print(answer)
                    exit()
                grid[nh][nw] = 1
                stack1.append((nh, nw))
    answer += 1

    while stack2:
        sh, sw = stack2.pop()
        for i in range(-2, 3):
            for j in range(-2, 3):
                nh, nw = sh + i, sw + j
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] != "#" and grid[nh][nw] == 0:
                    if nh == Dh and nw == Dw:
                        print(answer)
                        exit()
                    grid[nh][nw] = 1
                    stack1.append((nh, nw))
    if !stack1:
        print(-1)
        exit()
Problem p02642 (python)

Fixed submission:
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

cnt = [0] * (10 ** 6 + 1)
for a in A:
    cnt[a] += 1

if cnt[1] >= 2:
    print(0)
    exit()

if cnt[1] == 1:
    print(1)
    exit()

answer = 0
for i in range(2, 10 ** 6 + 1):
    if cnt[i] == 1:
        answer += 1
    if cnt[i] == 0:
        continue
    k = 2
    while i * k <= 10 ** 6:
        cnt[i * k] = 0
        k += 1

print(answer)

Buggy submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#N, M = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

cnt = [0] * (2 * 10 ** 5 + 1)
for a in A:
    cnt[a] += 1

if cnt[1] >= 2:
    print(0)
    exit()

if cnt[1] == 1:
    print(1)
    exit()

answer = 0
for i in range(2, 2 * 10 ** 5 + 1):
    if cnt[i] == 1:
        answer += 1
    if cnt[i] == 0:
        continue
    k = 2
    while i * k <= 2 * 10 ** 5:
        cnt[i * k] = 0
        k += 1

print(answer)