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

Fixed submission:
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if A[-1]%2 == 0:
        if abs(A[k-1]-M) <= abs(M-A[k]) and abs(A[k-1]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    else:
        if abs(A[k-1]-M) < abs(M-A[k]) and abs(A[k-1]-M) < abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if A[-1]%2 == 0:
        if abs(A[k-1]-M) <= abs(M-A[k]) and abs(A[k-1]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    else:
        if abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if N == 2:
        print(*reversed(A))
        exit()
    if abs(A[k-1]-M) < abs(M-A[k]) and abs(A[k-1]-M) < abs(A[k+1]-M):
        ans = [A[-1],A[k-1]]
    elif abs(A[k+1]-M) < abs(M-A[k]) and abs(A[k+1]-M) < abs(A[k-1]-M):
        ans = [A[-1],A[k+1]]
    elif abs(A[k-1]-M) > abs(M-A[k]) and abs(A[k]-M) < abs(A[k+1]-M):
        ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()
Problem p03408 (python)

Fixed submission:
from collections import defaultdict
def main():
    N = int(input())
    ans = 0
    s = defaultdict(int)
    for _ in range(N):
        a = input()
        s[a] += 1
    M = int(input())
    for _ in range(M):
        b = input()
        s[b] -= 1
    for v in s.items():
        ans = max(ans,v[1])
    print(ans)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def main():
    N = int(input())
    ans = 0
    s = defaultdict(int)
    for _ in range(N):
        a = input()
        s[a] += 1
    M = int(input())
    for _ in range(M):
        b = input()
        s[b] -= 1
    for v in s.items():
        ans = max(ans,v[1])
    print(ans)
if __name__ == a__main__":
    main()
Problem p03476 (python)

Fixed submission:
def sieve(N):#エラトステネスの篩
    prime = [0]*(N+1)
    isprime = [True]*(N+1)
    isprime[0]=isprime[1] = False
    num = 0
    for p in range(2,N+1):
        if isprime[p]:
            prime[num] = p
            num += 1
            for j in range(2*p,N+1,p):
                isprime[j] = False
    return prime
from bisect import bisect_left as bl
from bisect import bisect_right as br
lis = sieve(10**5)
prime = set(lis)-{0}
for i in range(len(lis)):
    if lis[i] != 0:
        if (lis[i]+1)//2 in prime:continue
        else:lis[i] = 0
    else:continue
Q = int(input())
lis = set(lis)-{0}
lis = sorted(tuple(lis))
for _ in range(Q):
    l,r = map(int,input().split())
    t = bl(lis,l)
    s = br(lis,r)
    tmp = s-t
    print(tmp)

Buggy submission (verdict: Runtime Error):
def sieve(N):#エラトステネスの篩
    prime = [0]*(N+1)
    isprime = [True]*(N+1)
    isprime[0]=isprime[1] = False
    num = 0
    for p in range(2,N+1):
        if isprime[p]:
            prime[num] = p
            num += 1
            for j in range(2*p,N+1,p):
                isprime[j] = False
    return prime
from bisect import bisect_left as bl
lis = sieve(10**5)
prime = set(lis)-{0}
for i in range(len(lis)):
    if lis[i] != 0:
        if (lis[i]+1)//2 in prime:continue
        else:lis[i] = 0
    else:continue
Q = int(input())
lis = set(lis)-{0}
lis = sorted(tuple(lis))
for _ in range(Q):
    l,r = map(int,input().split())
    t = bl(lis,l)
    tmp = 0
    if t == len(lis):print(tmp);continue
    while lis[t] <= r:
        tmp += 1
        t += 1
    print(tmp)

Buggy submission (verdict: Runtime Error):
def sieve(N):#エラトステネスの篩
    prime = [0]*(N+1)
    isprime = [True]*(N+1)
    isprime[0]=isprime[1] = False
    num = 0
    for p in range(2,N+1):
        if isprime[p]:
            prime[num] = p
            num += 1
            for j in range(2*p,N+1,p):
                isprime[j] = False
    return prime
from bisect import bisect_left as bl
lis = sieve(10**5)
prime = set(lis)-{0}
for i in range(len(lis)):
    if lis[i] != 0:
        if (lis[i]+1)//2 in prime:continue
        else:lis[i] = 0
    else:continue
Q = int(input())
lis = set(lis)-{0}
lis = sorted(tuple(lis))
for _ in range(Q):
    l,r = map(int,input().split())
    t = bl(lis,l)
    tmp = 0
    while lis[t] <= r:
        tmp += 1
        t += 1
    print(tmp)
Problem p02645 (python)

Fixed submission:
S = input()
print(S[0] + S[1] + S[2])

Buggy submission (verdict: Runtime Error):
import math
N ,K = map(int,input().split())
A = list(map(int, input().split()))
sum = [0] * N

for i in range(min(41,K)):
    for i in range(N):
        lo = max(0,i - A[i])
        up = min(N - 1,i+A[i])
        sum[lo] += 1
        if up + 1 < N:
            sum[up + 1] -= 1

    for i in range(1,N):
        sum[i] += sum[i-1]

    for i in range(N):
        A[i] = sum[i]
        sum[i] = 0

S = ""
for i in range(N):
    S += str(A[i])
    if i != N - 1 :
        S += " "

print(S)
Problem p03844 (python)

Fixed submission:
print(eval(str(input())))

Buggy submission (verdict: Runtime Error):
print(eval(input()))
Problem p02677 (python)

Fixed submission:
# coding: utf-8

import math

#ans^2 = A^2 +B^2 - 2ABconDiffを使用
line = input().split(" ")
A = int(line[0])
B = int(line[1])
H = int(line[2])
M = int(line[3])

ans = 0

#Aの刺す分
ang_a = H * 5 + M/12
#Bの刺す時間
ang_b = M

if ang_a == ang_b:
    ans = A - B

else:
    diff = abs(ang_a-ang_b)
    theta = (diff / 60) * 360
    ans_pow = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
    ans = ans_pow**0.5

print(ans)

Buggy submission (verdict: Runtime Error):
import math

#ans^2 = A^2 +B^2 - 2ABconDiffを使用
line = input().split(" ")
A = int(line[0])
B = int(line[1])
H = int(line[2])
M = int(line[3])

ans = 0

#Aの刺す分
ang_a = H * 5 + M/12
#Bの刺す時間
ang_b = M

if ang_a == ang_b:
    ans = A - B

else:
    diff = abs(ang_a-ang_b)
    theta = (diff / 60) * 360
    ans_pow = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
    ans = ans_pow**0.5

print(ans_pow)
print(ans)
Problem p03109 (python)

Fixed submission:
S=input()

S_l=S.split('/')

if int(S_l[1])>4:
       print('TBD')
else:
       print('Heisei')

Buggy submission (verdict: Runtime Error):
S=input()

S_l=S.split('/')

if int(S_l[1]>4:
       print('TBD')
else:
       print('Heisei')
Problem p03239 (python)

Fixed submission:
N, T=map(int, input().split())
 
c_list=[]
t_list=[]
ans_list=[]
for i in range(N):
  c,t=map(int, input().split())
  c_list.append(c)
  t_list.append(t)
 
ct_dict=dict(zip(c_list, t_list))  
  
if T<=min(t_list):
  print("TLE")
else:
  for k,v in ct_dict.items():
    if v<=T:
      ans_list.append(k)
 
  print(min(ans_list))

Buggy submission (verdict: Runtime Error):
N, T=map(int, input().split())
 
c_list=[]
t_list=[]
ans_list=[]
for i in range(N):
  c,t=map(int, input().split())
  c_list.append(c)
  t_list.append(t)
 
ct_dict=dict(zip(c_list, t_list))  
  
if T<=min(t_list):
  print("TLE")
else:
  for k,v in ct_dict.items():
    if v<=T:
      ans_list.append(k)
 
print(min(ans_list))

Buggy submission (verdict: Runtime Error):
N, T=map(int, input().split())

c_list=[]
t_list=[]
ans_list=[]
for i in N:
  c,t=map(int, input().split())
  c_list.append(c)
  t_list.append(t)

ct_dict=dict(zip(c_list, t_list))  
  
if T<=min(t_list):
  print("TLE")
else:
  for k,v in ct_dict.items():
    if v<=T:
      ans_list.append(k)

print(min(ans_list))
Problem p02573 (python)

Fixed submission:
import collections

n, m = map(int, input().split())
if m == 0:
    print(1)
    exit()
if m == 1:
    print(2)
    exit()
boss = list(range(n))

def look_boss(target):
    num = target
    while num != boss[num]:
        num = boss[num]
    boss[target] = num
    return num

for _ in range(m):
    a, b = map(int, input().split())
    boss_a = look_boss(a-1)
    boss_b = look_boss(b-1)
    if boss_a != boss_b:
        boss[boss_b] = boss_a

count = [0]*n
for i in range(n):
    count[look_boss(i)] += 1
print(max(count))

Buggy submission (verdict: Runtime Error):
import collections

n, m = map(int, input().split())
if m == 0:
    print(1)
    exit()
if m == 1:
    print(2)
    exit()
ids = {i: 0 for i in range(1, n+1)}
id = 1
for _ in range(m):
    a, b = map(int, input().split())
    if ids[a] == 0 and ids[b] != 0:
        ids[a] = ids[b]
    elif ids[a] != 0 and ids[b] == 0:
        ids[b] = ids[a]
    elif ids[a] == 0 and ids[b] == 0:
        ids[a] = id
        ids[b] = id
        id += 1
tmp = collections.Counter(ids.values())
tmp.pop(0)
print(max(tmp.values()))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [list(map(int, input().split()))]
for _ in range(m-1):
    a, b = map(int, input().split())
    for i in ab:
        if a not in i and b in i:
            i.append(a)
            break
        elif b not in i and a in i:
            i.append(b)
            break
        elif a in i and b in i:
            break
    else:
        ab.append([a, b])
ab_m = []
for i in ab:
    ab_m.append(len(i))

print(max(ab_m))
Problem p02576 (python)

Fixed submission:
N, X, T = map(int, input().split())
a = (N // X) * T
if N % X != 0:
    a += T
print(a)

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = {}
for i in range(M):
    h, w = map(int, input().split())
    t[(h-1, w-1)] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
print(t)
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if (h, w) not in t:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)
Problem p02642 (python)

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

m_a = max(A)+1
B = [0]*(m_a)

for i in A:
  B[i]+=1
  if B[i] == 1:
    for j in range(i*2, m_a, i):
      B[j]+=100
print(B.count(1))

Buggy submission (verdict: Runtime Error):
import numpy as np

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

sosu = []
count = 0

def loop(target, A):
  global count
  B = []
  flg = True
  for i in range(len(A)):
    if A[i] % target != 0:
      B.append(A[i])
    if target % A[i] == 0:
      flg = False
  if flg:
    count+=1
  if len(B) == 1:
    count+=1
    return
  if len(B) == 0:
    return
  target = B.pop(0)
  loop(target, B)

target = A.pop(0)
loop(target, A)
print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

sosu = []
count = 0

def loop(target, A):
  global count
  B = []
  flg = True
  for i in range(len(A)):
    if A[i] % target != 0:
      B.append(A[i])
    if target == A[i]:
      flg = False
  if flg:
    count+=1
  if len(B) == 1:
    count+=1
    return
  if len(B) == 0:
    return
  target = B.pop(0)
  loop(target, B)

target = A.pop(0)
loop(target, A)
print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

sosu = []
count = 0

def loop(target, A):
  global count
  B = []
  flg = True
  for i in range(len(A)):
    if A[i] % target != 0:
      B.append(A[i])
    if target == A[i]:
      flg = False
  if flg:
    count+=1
  if len(B) == 1:
    count+=1
    return
  if len(B) == 0:
    return
  target = B.pop(0)
  loop(target, B)

target = A.pop(0)
loop(target, A)
print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

sosu = []
count = 0

def loop(target, A):
  global count
  B = []
  flg = True
  for i in range(len(A)):
    if A[i] % target != 0:
      B.append(A[i])
    if target == A[i]:
      flg = False
  if flg:
    count+=1
  if len(B) == 1:
    count+=1
    return
  target = B.pop(0)
  loop(target, B)

target = A.pop(0)
loop(target, A)
print(count)
Problem p02663 (python)

Fixed submission:
h1, m1, h2, m2, k = map(int, input().split())

h1*=60
h1+=m1
h2*=60
h2+=m2
if h1 > h2:
  h2+=60*24

begin = h2 - k

print(begin-h1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
last = A[-1]
count = last
root = 1
for i in range(N):
  if root <= A[i]:
    print(-1)
    break
  if i+1 == N and root-A[i] > A[i+1]:
    root = last + A[i]
  elif root-A[i] > (last + A[i+1]):
    root = (last + A[i+1]) + A[i]
  count+=root
  root = (root-A[i])*2
else:
  if count == 0 or root < last:
    count = -1
  print(count)
Problem p02675 (python)

Fixed submission:
N = int(input())

a = N%10

if a == 3:
  print('bon')
elif a == 0 or a == 1 or a == 6 or a == 8:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
from math import gcd
 
n=int(input())
mod = 10**9+7
 
d = dict()
zeros=0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  if all((a,b)):
    g = gcd(a,b)
  elif a:
    g = a
  else:
    g = b
  
  p = a//g,b//g
  d[p] = d.get(p,0)+1
 
ans = 1
done = set()
for (a,b),v in d.items():
  if (-b,a) in done or (b,-a) in done:
    continue
  done.add((a,b))
  w=d.get((-b,a),0)+d.get((b,-a),0)
  ans *= (pow(2,v,mod)+pow(2,w,mod)-1)
  ans %= mod
print((ans+zeros-1+mod)%mod)
Problem p02678 (python)

Fixed submission:
import numpy as np
import itertools
from collections import deque

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

class Room:
  def __init__(self, num):
    self.num = num
    self.roots = []
    self.kyori = -1
    self.near = 0
    
  def add_root(self, to):
    self.roots.append(to)
  def set_kyori(self, num, kyori):
    self.kyori = kyori
    self.near = num

r_list = sorted(np.unique(np.array(list(itertools.chain.from_iterable(root)))))
rooms = {i:Room(i) for i in r_list}

for r in root:
  a, b = rooms[r[0]], rooms[r[1]]
  a.add_root(b)
  b.add_root(a)

kyori = 0
near = 0
rooms[1].set_kyori(near, kyori)
rooms[1].near = near
q = deque()
q.append(rooms[1])
while len(q) > 0:
  node = q.popleft()
  kyori+=1
  for r in node.roots:
    if r.kyori != -1:
      continue
    r.set_kyori(node.num, kyori)
    q.append(r)
  
rooms[1].set_kyori(0, 0)
for r in rooms.values():
  if r.kyori == -1:
    print('No')
    break
else:
  print('Yes')
  for r in list(rooms.values())[1:]:
    print(r.near)

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools

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

class Room:
  def __init__(self, num):
    self.num = num
    self.roots = []
    self.kyori = -1
    self.near = 0
    
  def add_root(self, to):
    self.roots.append(to)
  def set_kyori(self, num, kyori):
    if self.kyori == -1 or self.kyori > kyori:
      self.kyori = kyori
      self.near = num
      for r in self.roots:
        if r.num == num:
          continue
        r.set_kyori(self.num, self.kyori+1)

r_list = sorted(np.unique(np.array(list(itertools.chain.from_iterable(root)))))
rooms = {i:Room(i) for i in r_list}

for r in root:
  a, b = rooms[r[0]], rooms[r[1]]
  a.add_root(b)
  b.add_root(a)

rooms[1].set_kyori(0, 0)
for r in rooms.values():
  if r.kyori == -1:
    print('No')
    break
else:
  print('Yes')
  for r in list(rooms.values())[1:]:
    print(r.near)
Problem p02844 (python)

Fixed submission:
N = input()
S = list(input())
count = 0
num_count = [False]*10
for i in range(len(S)-2):
    s_i = int(S[i])
    if num_count[s_i]:
        continue
    num_count[s_i] = True
    num_count_2 = [False]*10
    for j in range(i+1, len(S)-1):
        s_j = int(S[j])
        if num_count_2[s_j]:
            continue
        num_count_2[s_j] = True
        num_count_3 = [False] * 10
        for k in range(j+1, len(S)):
            s_k = int(S[k])
            if num_count_3[s_k]:
                continue
            num_count_3[s_k] = True
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = input()
S = input()
ans = set()
num_count = [0]*10
i = 0
while i < len(S):
    s_num = int(S[i])
    if num_count[s_num] <= 3:
        num_count[s_num] += 1
        i += 1
    else:
        S.pop(i)
for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        for k in range(j+1, len(S)):
            s = S[i]+S[j]+S[k]
            if s not in ans:
                ans.add(s)
print(len(ans))
Problem p03752 (python)

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

ans = 10**12
for i in range(1, 2**n, 2):
    if k != sum([i >> j & 1 for j in range(n)]):
        continue
    pre = a[0]
    cost = 0
    for j in range(1, n):
        if i >> j & 1:
            tmp = max(pre - a[j] + 1, 0)
            pre = a[j] + tmp
            cost += tmp
        else:
            pre = max(pre, a[j])
    ans = min(ans, cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 10**9
for i in range(1, 2**n, 2):
    if not i & 1 or k != sum([i >> j & 1 for j in range(n)]):
        continue
    pre = a[0]
    cost = 0
    for j in range(1, n):
        if i >> j & 1:
            tmp = max(pre - a[j] + 1, 0)
            pre = a[j] + tmp
            cost += tmp
    ans = min(ans, cost)
print(ans+'\n')
Problem p02642 (python)

Fixed submission:
# エラトステネスの篩を使う！O(nloglogn)
N = int(input())
A = list(map(int,input().split()))

listA = [0] * (10**6+10)
ans = 0
for i in A:
    if listA[i] != 0:
            listA[i] = 2
            continue
    for j in range(i,10**6+10,i):
        listA[j] += 1

for i in A:
    if listA[i] == 1:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# エラトステネスの篩を使う！O(nloglogn)
N = int(input())
A = list(map(int,input().split()))

listA = [0] * 10**6
ans = 0
for i in A:
    for j in range(i,10**6,i):
        if listA[j] == 2:
            continue
        else:
            listA[j] += 1

for i in A:
    if listA[i] == 1:
        ans += 1

print(ans)
Problem p02642 (python)

Fixed submission:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit,i8


def sieve(N,A,dp):
    for i in range(N):
        now = A[i]
        M = A[-1] // now
        for j in range(2,M+1):
            dp[now*j-1] = False
    return dp


def cnt(N,A,dp):
    skip = 0
    res = 0
    for i in range(N):
        now = A[i]
        if skip == now:
            continue
        if i != N - 1:
            if now == A[i+1]:
                skip = now
                continue
        if dp[now-1]:
            res += 1
    return res


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

    A = sorted(A)
    A = np.array(A)

    dp = np.array([True for i in range(A[-1])])
    # print(dp)
    dp = sieve(N,A,dp)
    # print(dp)

    res = cnt(N,A,dp)

    print(res)



main()

Buggy submission (verdict: Runtime Error):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8[:](i8,i8,i8[:]))
def sieve(N,A,dp):
    for i in range(N):
        now = A[i]
        M = A[-1] // now
        for j in range(2,M+1):
            dp[now*j-1] = False
    return dp


@njit(i8(i8,i8,i8[:]))
def cnt(N,A,dp):
    skip = 0
    res = 0
    for i in range(N):
        now = A[i]
        if skip == now:
            continue
        if i != N - 1:
            if now == A[i+1]:
                skip = now
                continue
        if dp[now-1]:
            res += 1
    return res


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

    A = sorted(A)
    A = np.array(A)

    dp = np.array([True for i in range(A[-1])])
    # print(dp)
    dp = sieve(N,A,dp)
    # print(dp)

    res = cnt(N,A,dp)

    print(res)



main()
Problem p02774 (python)

Fixed submission:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def cnt(x,A,An,Ap,N,Nz):
    res = 0
    if x >= 0:
        res += N * Nz
    res += np.searchsorted(A,x//Ap,side='right').sum()
    res += N * len(An) - np.searchsorted(A,-(-x//An),side='left').sum()
    res -= np.count_nonzero(A*A<=x)
    return res//2


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

    A = np.array(A)
    A.sort()

    An = A[A<0]
    Az = A[A==0]
    Ap = A[A>0]

    Nz = np.count_nonzero(A==0)

    INF = 10 ** 18

    l = - INF - 1
    r = INF

    while r-l > 1:
        m = (l+r)//2
        if cnt(m,A,An,Ap,N,Nz) >= K:
            r = m
        else:
            l = m

    print(r)





main()

Buggy submission (verdict: Runtime Error):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def cnt(x,A,An,Ap,N,Nz):
    res = 0
    if x >= 0:
        res += N * Nz
    res += np.searchsorted(A,x//Ap,side='right').sum()
    res += N * len(An) - np.searchsorted(A,-(-x//An),side='left').sum()
    res -= np.count_nonzero(A*A<=x)
    return res//2


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

    print(len(A))

    A = np.array(A)
    A.sort()

    An = A[A<0]
    Az = A[A==0]
    Ap = A[A>0]

    Nz = np.count_nonzero(A==0)

    INF = 10 ** 18

    l = - INF - 1
    r = INF

    while r-l > 1:
        m = (l+r)//2
        if cnt(m,A,An,Ap,N,Nz) >= K:
            r = m
        else:
            l = m

    print(r)





main()

Buggy submission (verdict: Runtime Error):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def cnt(x,A,An,Ap,N,Nz):
    res = 0
    if x >= 0:
        res += N * Nz
    res += np.searchsorted(A,x//Ap,side='right').sum()
    res += N * len(An) - np.searchsorted(A,-(-x//An),side='left').sum()
    res -= np.count_nonzero(A*A<=x)
    return res//2


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

    print(len(A))

    A = np.array(A)
    A.sort()

    An = A[A<0]
    Az = A[A==0]
    Ap = A[A>0]

    Nz = np.count_nonzero(A==0)

    INF = 10 ** 18

    l = - INF - 1
    r = INF + 1

    while r-l > 1:
        m = (l+r)//2
        if cnt(m,A,An,Ap,N,Nz) >= K:
            r = m
        else:
            l = m

    print(r)





main()