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

Fixed submission:
s = input()
i = 0
while True:
    if s == "":
        print("YES")
        exit(0)
    if i == 0:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        else:
            break
    elif i == 1:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:2] == "er":
            s = s[2:]
            i = 3
        else:
            break
    elif i == 2:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        elif s[:1] == "r":
            s = s[1:]
            i = 0
        else:
            break
    elif i == 3:
        if s[:5] == "dream":
            s = s[5:]
            i = 1
        elif s[:3] == "ase":
            s = s[3:]
            i = 2
        elif s[:5] == "erase":
            s = s[5:]
            i = 2
        else:
            break
print("NO")

Buggy submission (verdict: Runtime Error):
S = input()
def trans(s,i):
    if s == "":
        return "YES"
    if i == 0:
        t = s[:5]
        if t == "dream":
            return trans(s[5:],1)
        elif t == "erase":
            return trans(s[5:],2)
        else:
            return "NO"
    elif i == 1:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:2] == "er":
            return trans(s[2:],3)
        else:
            return "NO"
    elif i == 2:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:5] == "erase":
            return trans(s[5:],2)
        elif s[:1] == "r":
            return trans(s[1:],0)
        else:
            return "NO"
    elif i == 3:
        if s[:5] == "dream":
            return trans(s[5:],1)
        elif s[:3] == "ase":
            return trans(s[3:],2)
        elif s[:5] == "erase":
            return trans(s[5:],2)
        else:
            return "NO"
    
print(trans(S,0))
Problem p02602 (python)

Fixed submission:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    

for i in range(n-k):
    if a[i]>=a[i+k]:
        print("No")
    else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
ans=[a[0]]
ap=a[0]
for i in range(n-1):
    ap*=a[i+1]
    if i>=k-1:
        ans.append(ap/ans[i-k+1])
    else:
        ans.append(ap)
    

for i in range(n-k):
    if ans[i+k-1]>=ans[i+k]:
        print("No")
    else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
ans=[a[0]]
ap=a[0]
for i in range(n-1):
    ap*=a[i+1]
    if i>=k-1:
        ans.append(ap/ans[i-k+1])
    else:
        ans.append(ap)
    
com=ans[k-1]

for i in range(n-k):
    if ans[i+k-1]>=ans[i+k]:
        print("No")
    else:
        print("Yes")
    com=ans[i+k]/ans[i]
Problem p02631 (python)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
aa=[]
ans=0
for i in a:
    ans^=i
anss=int(ans)
for i in range(n):
    anss^=a[i]
    aa.append(anss)
    anss=int(ans)
print(" ".join(map(str,aa)))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
    ans=0
    for j in a:
        if j!=a[i]:
            ans^=j
    aa.append(a)
print("".join(aa))
Problem p02647 (python)

Fixed submission:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    a=b
print(" ".join(map(str,a)))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
    a=b
    if e==n:
        break
print(" ".join(map(str,a)))
Problem p02713 (python)

Fixed submission:
k=int(input())
ans=0
import math
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        t=math.gcd(a,b)
        for c in range(1,k+1):
            ans+=math.gcd(t,c)
                
print(ans)

Buggy submission (verdict: Runtime Error):
k=int(input())
ans=0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            lis=sorted([a,b,c])
            elif lis in sumlis.values(): 
                ans+=sumlis[lis]
            else:
                x=gcdlist(lis)
                sumlis[x]=sumlis
                ans+=x
                
print(ans)
Problem p02761 (python)

Fixed submission:
ok=True
okay=True
a,b=map(int,input().split())
val=[]
for i in range(b):
    c,d=map(int,input().split())
    val.append([c,d])
    if c==1 and d==0:
        okay=False
val=sorted(val)
for i in range(b-1):
    if val[i][0]==val[i+1][0] and val[i][1]!=val[i+1][1]:
        ok=False
        print(-1)
        break
if ok:
    e=[0 for i in range(a)]
    strr=""
    for i in val:
        e[i[0]-1]=i[1]
    if e[0]==0:
        if e==[0]:
            print(0)
        else:
            if okay:
                for i in range(1,a):
                    strr+=str(e[i])
                strr="1"+strr
                print(strr)
            else:
                print(-1)
    else:
        for i in range(a):
            strr+=str(e[i])
        print(int(strr))

Buggy submission (verdict: Runtime Error):
ok=True
a,b=map(int,input().split())
val=[]
for i in range(b):
    c,d=map(int,input().split())
    val.append([c,d])
val=sorted(val)
for i in range(b-1):
    if val[i][0]==val[i+1][0] and val[i][1]!=val[i+1][1]:
        ok=False
        print(-1)
        break
if ok:
    e=[0 for i in range(a)]
    strr=""
    for i in val:
        e[i[0]-1]=i[1]
    if e[0]==0:
        if e==[0]:
            print(0)
        for i in range(1,a):
            strr+=str(e[i])
        if set(strr)=={'0'}:
            print(-1)
        else:
            print(int(strr))
    else:
        for i in range(a):
            strr+=str(e[i])
        print(strr)
Problem p02801 (python)

Fixed submission:
a="abcdefghijklmnopqrstuvwxyz"
b=input()
c=0
while True:
    if b==a[c]:
        print(a[c+1])
        break
    c+=1

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
d=0
e=[int(x) for x in input().split()]
g=0
for i in range(a-1):
    d+=int(e[i])
for i in range(b):
    if (d+i)/a>=c:
        print(i)
        g=1
        break
if g==0:
    print(-1)
Problem p02802 (python)

Fixed submission:
a,b=map(int,input().split())
wa={i:0 for i in range(1,a+1)}
ac={i:0 for i in range(1,a+1)}
g=0
pe=0
if b==0:
    print("0 0")
    g=1
for i in range(b):
    c,d=input().split()
    
    if d=="WA" and ac[int(c)]==0:
        wa[int(c)]+=1
        
    if d=="AC" and ac[int(c)]==0:
        pe+=wa[int(c)]
        ac[int(c)]=1
    
        
f=0
h=0
if g==0:
    
    print(str(sum(ac.values()))+" "+str(pe))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
wa={i:0 for i in range(1,a+1)}
ac=wa
for i in range(b):
    c,d=input().split()
    if d=="WA" and ac[int(c)]==0:
        wa[int(c)]+=1
    else:
        ac[int(c)]=1
print(sum(wa.values())+" "+sum(ac.values()))
Problem p02999 (python)

Fixed submission:
c=input().split( )
a=c[0]
b=c[1]
if a<b:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
a,b=int(input().split())
if a<b:
    print(0)
else:
    print(10)
Problem p03000 (python)

Fixed submission:
a,b=input().split()
d=0
n=1
l=input().split( )
for p in range(int(a)):
  d+=int(l[p])
  if d<=int(b):
    n+=1
print(n)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
d=0
n=1
l=input().split( )
while True:
  d+=int(l[n])
  if d<=int(b):
    n+=1
  else:
    break
print(n)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
d=0
n=0
l=input().split( )
while True:
  if d>int(b):
    break
  if d==int(b):
    n+=1
    break
  else:
    w=l[n]
    d+=int(w)
    n+=1

print(n)
Problem p03001 (python)

Fixed submission:
W,H,x,y=input().split( )
answer=int(W)*int(H)/2
q=0
if int(x)*2==int(W) and int(y)*2==int(H):
    q=1
else:
    q=0

print(answer,q)

Buggy submission (verdict: Runtime Error):
W,H,x,y=input().split( )
answer=W*H/2
q=0
if x*2==W and y*2==H:
    q=1
else:
    q=0

print(answer,q)
Problem p03448 (python)

Fixed submission:
a=[]
for i in range(3):
    a.append(int(input()))
x=int(input())
ans=0

for i in range(a[0]+1):
    for j in range(a[1]+1):
        for k in range(a[2]+1):
            if i*500+j*100+k*50==x:
                ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(3):
    a.append(int(input()))
x=int(input())
ans+=1

for i in range(a[0]):
    for j in range(a[1]):
        for k in range(a[2]):
            if i*500+j*100+k*50==x:
                ans+=1
print(ans)
Problem p03474 (python)

Fixed submission:
a,b=map(int,input().split())
s=input()
if len(s)==a+b+1 and "-" in s and s.index("-")==a and s.count("-")==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=input()
if len(s)==a+b+1 and "-" in s and s.index("-")==a s.count("-")==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=input()
if len(s)==a+b+1 and s.index("-")==a:
    print("Yes")
else:
    print("No")
Problem p03544 (python)

Fixed submission:
n=int(input())
if n==1:
    print(1)
else:
    l1=2
    l2=1
    for i in range(n-1):
        l3=l1+l2
        l1=l2
        l2=l3
    print(l2)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n==1:
    print(1)
else:
    l1=2
    l2=1
    for i in range(n-1):
        l3=l1+l2
        l1=l2
        l2=l3
print(l2)
Problem p03759 (python)

Fixed submission:
a=sorted([int(i) for i in input().split()])
if a[1]-a[0]==a[2]-a[1]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=sorted[int(i) for i in input().split()]
if a[1]-a[0]==a[2]-a[1]:
    print("YES")
else:
    print("NO")
Problem p03944 (python)

Fixed submission:
w,h,n=map(int,input().split())
w1=0
w2=w
h1=0
h2=h
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        w1=max(a,w1)
    elif c==2:
        w2=min(a,w2)
    elif c==3:
        h1=max(b,h1)
    elif c==4:
        h2=min(b,h2)
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1)))

Buggy submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
w1=0
w2=w
h1=0
h2=h
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        w1=a
    elif c==2:
        w2=a
    elif c==3:
        h1=b
    elif c==4:
        h2=b
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1))
Problem p02658 (python)

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

ans = 1
l = 0;
flag = 0

for i in range(N):
    if A[i]== 0:
        print(0)
        exit(0)

    l+=(len(str(A[i])) -1)
    if l>18:
        flag=1
        continue
    
    ans*=A[i]
    if ans > 1000000000000000000:
        flag = 1

if flag == 0:
    print(ans)
else :
    print(-1)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[map(int,input().split())]
sorted(A)
if A[0] == 0:
  print(0)
  exit(0)

ans = 1
for i in range(N):
  ans*=A[i]
  if(ans>1000000000000000000):
    print(-1)
    exit(0)
print(ans)
Problem p02741 (python)

Fixed submission:
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())-1
print(A[K])

Buggy submission (verdict: Runtime Error):
A= list(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
K = int(input())
print(A[K-1])
Problem p02772 (python)

Fixed submission:
n = int(input())
list = [int(x) for x in input().split(" ")]
result = 'APPROVED'
for i in range(len(list)):
    if list[i]%2 == 0:
        if list[i]%3 != 0 and list[i]%5 != 0:
            result = 'DENIED'
            break
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
list = [int(x) for x in input().split(" ")]
result = 'APPROVED'
for i in range(len(list)):
    if list[i]%2 == 0:
        if list[i]%3!=0 AND list[i]%5!=0:
            result = 'DENIED'
            break
print(result)
Problem p03504 (python)

Fixed submission:
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(31):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

Buggy submission (verdict: Runtime Error):
N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [0]*int(1e5+1)
for i in range(N):
    imos[s[i]]+=1
    imos[t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+1)):
    imos[i]=imos[i-1]+imos[i]
    ans = max(ans,imos[i])
print(ans)
Problem p03547 (python)

Fixed submission:
A,B = input().split()
if A>B:
  print(">")
elif A==B:
  print("=")
else:
  print("<")

Buggy submission (verdict: Runtime Error):
A,B = map(input().split())
if A>B:
  print(">")
elif A==B:
  print("=")
else:
  print("<")
Problem p03557 (python)

Fixed submission:
import bisect

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

ans = 0
for i in range(N):
    b = B[i]
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    ans+=(a*(len(C)-c))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):
    b = B[i]
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    ans+=(a*(len(C)-c))
print(ans)
Problem p03564 (python)

Fixed submission:
N = int(input())
K = int(input())

now = 1
for i in range(N):
    if now <= K:
        now *= 2
    else:
        now+=K
print(now)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

now = 1
for i in range(N):
	if now >= K:
        now *= 2
    else:
		now+=K
print(now)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

now = 1
for i in range(N):
	if(now >= K):
		now *= 2
    else:
		now+=K
print(now)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

now = 1
for i in range(N):
	if(now>=K):
		now*=2
    else:
		now+=K
print(now)
Problem p03597 (python)

Fixed submission:
N = int(input())
A = int(input())
 
print(N**2-A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(inpiut())

print(N**2-A)
Problem p02616 (python)

Fixed submission:
from math import log10 as log2

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

p = []
m = []
for a in A :
  if a > 0 :
    p.append(a)
  elif a < 0 :
    m.append(-a)
    
p.sort(reverse=True)
m.sort(reverse=True)
pl = [0]
ml = [0]

for i in range(len(p)) :
  pl.append(log2(p[i]))
for i in range(len(m)) :
  ml.append(log2(m[i]))
for i in range(1, len(pl)) :
  pl[i] += pl[i - 1]
for i in range(1, len(ml)) :
  ml[i] += ml[i - 1]

Mi = -1
Mv = 0
for i in range(0, len(ml), 2) :
  j = K - i
  if len(pl) <= j or j < 0 : continue
  if ml[i] + pl[j] > Mv :
    Mi, Mv = i, ml[i] + pl[j]

if Mi != -1 :
  ret = 1
  for i in range(K - Mi) :
    ret *= p[i]
    ret %= mod
  for i in range(Mi) :
    ret *= m[i]
    ret %= mod
else :
  x = [abs(a) for a in A]
  x.sort()
  ret = 1
  for i in range(K) :
    ret *= x[i]
    ret %= mod
  ret = -ret % mod
  
print(ret)

Buggy submission (verdict: Runtime Error):
from math import log2

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

p = []
m = []
for a in A :
  if a > 0 :
    p.append(a)
  else :
    m.append(-a)
    
p.sort(reverse=True)
m.sort(reverse=True)
pl = [0]
ml = [0]

for i in range(len(p)) :
  pl.append(log2(p[i]))
for i in range(len(m)) :
  ml.append(log2(m[i]))
for i in range(1, len(pl)) :
  pl[i] += pl[i - 1]
for i in range(1, len(ml)) :
  ml[i] += ml[i - 1]

Mi = -1
Mv = 0
for i in range(0, len(ml), 2) :
  j = K - i
  if len(pl) <= j or j < 0 : continue
  if ml[i] + pl[j] > Mv :
    Mi, Mv = i, ml[i] + pl[j]

if Mi != -1 :
  ret = 1
  for i in range(K - Mi) :
    ret *= p[i]
    ret %= mod
  for i in range(Mi) :
    ret *= m[i]
    ret %= mod
else :
  x = [abs(a) for a in A]
  x.sort()
  ret = 1
  for i in range(K) :
    ret *= x[i]
    ret %= mod
  ret = -ret % mod
  
print(ret)
Problem p02642 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

x = [0] * (10 ** 6 + 10)
y = [0] * (10 ** 6 + 10)
for a in A :
  x[a] = 1
  y[a] += 1
  
for i in range(10 ** 6 + 1) :
  if x[i] == 0 : continue
  j = i * 2
  while j <= 10 ** 6 :
    x[j] = 0
    j += i

ret = 0
for i in range(10 ** 6 + 1) :
  if x[i] == 1 and y[i] == 1 :
    ret += 1
    
print(ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

x = [0] * (10 ** 6 + 1)
for a in A :
  x[a] += 1
  if x[a] == 2 :
    x[a] = 100000000
  
for i in range(10 ** 6 + 1) :
  if not x[i] : continue
  j = i * 2
  while j <= 10 ** 6 + 1 :
    x[j] = False
    j += i

print(x.count(1))
Problem p02764 (python)

Fixed submission:
N, K = map(int, input().split())
xyc = [[int(i) for i in input().split()] for _ in range(N)]

def check(n) :
  for i in range(N) :
    xi, yi, ci = xyc[i]
    ri = n / ci
    for j in range(i + 1, N) :
      xj, yj, cj = xyc[j]
      xj -= xi
      yj -= yi
      rj = n / cj
      a = (xj ** 2 + yj ** 2 + ri ** 2 - rj ** 2) / 2
      root = max(0, (xj ** 2 + yj ** 2) * (ri ** 2) - a ** 2) ** 0.5
      for sgn in [1, -1] :
        cnt = 0
        X = (a * xj + sgn * yj * root) / (xj ** 2 + yj ** 2) + xi
        Y = (a * yj - sgn * xj * root) / (xj ** 2 + yj ** 2) + yi
        for x, y, c in xyc :
          if (x - X) ** 2 + (y - Y) ** 2 <= (n / c) ** 2 + eps :
            cnt += 1
        if cnt >= K :
          return True
  
  for X, Y, _ in xyc :
    cnt = 0
    for x, y, c in xyc :
      if (x - X) ** 2 + (y - Y) ** 2 <= (n / c) ** 2 + eps :
        cnt += 1
    if cnt >= K :
      return True
      
  return False

eps = 1e-8
ng, ok = 0, 10 ** 6
while ok - ng > eps :
  n = (ng + ok) / 2
  if check(n) :
    ok = n
  else :
    ng = n
 
print(ok)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
xyc = [[int(i) for i in input().split()] for _ in range(N)]

def check(n) :
  global K
  for i in range(N) :
    xi, yi, ci = xyc[i]
    ri = n / ci
    for j in range(i + 1, N) :
      xj, yj, cj = xyc[j]
      xj -= xi
      yj -= yi
      rj = n / cj
      a = (xj ** 2 + yj ** 2 + ri ** 2 - rj ** 2) / 2
      root = (xj ** 2 + yj ** 2) * (ri ** 2) - a ** 2
      if root + eps < 0 : continue
      for sgn in [1, -1] :
        cnt = 0
        X = (a * xj + sgn * yj * (root ** 0.5)) / (xj ** 2 + yj ** 2) + xi
        Y = (a * yj - sgn * xj * (root ** 0.5)) / (xj ** 2 + yj ** 2) + yi
        for x, y, c in xyc :
          if (x - X) ** 2 + (y - Y) ** 2 <= (n / c) ** 2 + eps :
            cnt += 1
        if cnt >= K :
          return True
  
  for X, Y, _ in xyc :
    cnt = 0
    for x, y, c in xyc :
      if (x - X) ** 2 + (y - Y) ** 2 + eps <= (n / c) ** 2 :
        cnt += 1
    if cnt >= K :
      return True
      
  return False

eps = 1e-7
ng, ok = -1, 10 ** 6
while ok - ng > eps :
  n = (ng + ok) / 2
  if check(n) :
    ok = n
  else :
    ng = n
 
print(ok)
Problem p02774 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

p = []
m = []
zero = 0
for i in range(N) :
  if A[i] > 0 :
    p.append(A[i])
  elif A[i] < 0 :
    m.append(-A[i])
  else :
    zero += 1

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0 
  if mid < 0 :
    j = 0
    for i in range(len(m) - 1, -1, -1) :
      while j < len(p) and m[i] * p[j] < -mid :
        j += 1
      s += len(p) - j
      
  else :
    j = len(p) - 1
    for i in range(len(p)) :
      while j >= 0 and p[i] * p[j] > mid :
        j -= 1
      s += max(0, j - i)
      
    j = len(m) - 1
    for i in range(len(m)) :
      while j >= 0 and m[i] * m[j] > mid :
        j -= 1
      s += max(0, j - i)
      
    s += (len(p) + len(m)) * zero + len(p) * len(m) + zero * (zero - 1) // 2

  if s < K :
    ng = mid
  else :
    ok = mid
    
print(ok)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from bisect import bisect_left

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

p = []
m = []
zero = 0
for i in range(N) :
  if A[i] > 0 :
    p.append(A[i])
  elif A[i] < 0 :
    m.append(-A[i])
  else :
    zero += 1

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0 
  if mid < 0 :
    for i in range(len(m)) :
      x = (-mid+m[i]-1) // (m[i])
      s += len(p) - bisect_left(p, x)
    
  else :
    for i in range(len(p)) :
      x = mid // p[i]
      if x < p[i] : break
      s += max(0, bisect_left(p, x + 1) - 1 - i)
    for i in range(len(m)) :
      x = mid // m[i]
      if x < p[i] : break
      s += max(0, bisect_left(m, x + 1) - 1 - i)
    s += (len(p) + len(m)) * zero
    s += len(p) * len(m)
    s += zero * (zero - 1) // 2
  
  if s < K :
    ng = mid
  else :
    ok = mid
    
print(ok)
Problem p02821 (python)

Fixed submission:
from bisect import bisect_left

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()

def calc(m) :
  c = 0
  for i in range(N) :
    c += N - bisect_left(A, m - A[i])
  return c

ng, ok = 0, A[-1] * 2 + 1
while ok - ng > 1 :
  m = (ok + ng) // 2

  if calc(m) <= M :
    ok = m
  else :
    ng = m
  
S = [A[0]]
for i in range(1, N) :
  S.append(S[-1] + A[i])
S.append(0)
S.append(0)

all = sum(A)
ret = 0
for i in range(N) :
  ret += all - S[bisect_left(A, ng - A[i])-1]
  ret += A[i] * (N - bisect_left(A, ng - A[i]))
ret -= (calc(ng) - M) * (ng)
print(ret)

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

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()
mem = dict()

ng, ok = 0, A[-1] * 2 + 1
while ok - ng > 1 :
  m = (ok + ng) // 2
  c = 0
  for i in range(N) :
    c += N - bisect_left(A, m - A[i])
  mem[m] = c
  if c <= M :
    ok = m
  else :
    ng = m
  
S = [A[0]]
for i in range(1, N) :
  S.append(S[-1] + A[i])
S.append(0)

all = sum(A)
ret = 0
for i in range(N) :
  ret += all - S[bisect_left(A, m - A[i])-1]
  ret += A[i] * (N - bisect_left(A, m - A[i]))
ret += (M - mem[ok]) * (ok - 1)
print(ret)