qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# coding: utf-8
import time
import re
import math

def main():
    global N,A,memo
    N=int(input())
    A=[int(input()) for  a in range(N)] 
    if sum(A)%10==0:
        nm0=[]
        for a in A:
            if not a%10==0:
                nm0.append(a)
        if len(nm0)==0:
            print(0)
        else:
            print(sum(A)-math.min(nm0))

    else:
        print(sum(A))

main()

Fixed code:
# coding: utf-8
import time
import re
import math

def main():
    global N,A,memo
    N=int(input())
    A=[int(input()) for  a in range(N)] 
    if sum(A)%10==0:
        nm0=[]
        for a in A:
            if not a%10==0:
                nm0.append(a)
        if len(nm0)==0:
            print(0)
        else:
            print(sum(A)-min(nm0))

    else:
        print(sum(A))

main()
Buggy code:
N=int(input())
s=[int(input()) for i in range(N)]
s.sort()
Su=0
for i in range (N):
    Su+=s[i]
if Su%10==0:
    m=s[0]
    while m%10==0 and i<N:
        if s[i]%10!=0:
            m=s[i]
        else:
            i+=1
    if i==N and m%10==0:
        print (0)
    else:
        Su-=m
        print (Su)


Fixed code:
N=int(input())
s=[int(input()) for i in range(N)]
s.sort()
Su=0
for i in range (N):
    Su+=s[i]
if Su%10==0:
    m=s[0]
    i=0
    while m%10==0 and i<N:
        if s[i]%10!=0:
            m=s[i]
        else:
            i+=1
    if i==N and m%10==0:
        print (0)
    else:
        Su-=m
        print (Su)
else:
    print (Su)
Buggy code:
import sys

n = int(input())
s = [int(input()) for i in range(n)]
s.sort()

ans = sum(s)

for i in s:
	if(ans%10==0 and i%10 != 0):
		ans -= i
		print(ans)
	else:
		print(ans)
		sys.exit()

print(0)

Fixed code:
import sys

n = int(input())
s = [int(input()) for i in range(n)]
s.sort()

ans = sum(s)

for i in s:
	if(ans%10==0):
		if(i%10!=0):
			print(ans-i)
			sys.exit()
	else:
		print(ans)
		sys.exit()

print(0)
Buggy code:
n = int(input())
a = list(int(input()) for i in range(n))
a.sort()
b = sum(a)

c = b

for i in range(n) :
  if c % 10 == 0 :
    c = b - a[i]
  else :
    break

print (c)


Fixed code:
n = int(input())
a = list(int(input()) for i in range(n))
a.sort()
b = sum(a)

c = b

for j in range(100) :
  for i in range(n) :
    if c % 10 == 0 :
      c = b - a[i]
      if c == 0 :
        break
    else :
      break
  b = b - a[i]
  n = n - 1

print (c)
Buggy code:
N, A, B = map(int, input().split())
monsters = [int(input()) for _ in range(N)]
monsters.sort(reverse=True)

def can_terminate(x):
  count = 0
  for monster in monsters:
    count += max(0, (monster-B*x)//(A-B))
  return count <= x

l, r = 0, 10**9+1
while(r-l > 1):
  mid = (r+l)//2
  if can_terminate(mid):
    l = mid
  else:
    r = mid
print(l)
  
  

Fixed code:
import math
N, A, B = map(int, input().split())
monsters = [int(input()) for _ in range(N)]
monsters.sort(reverse=True)

def can_terminate(x):
  count = 0
  for monster in monsters:
    count += max(0, math.ceil((monster-B*x)/(A-B)))
  return count <= x

l, r = 0, 10**9+1
while r-l > 1:
  mid = (r+l)//2
  if can_terminate(mid):
    r = mid
  else:
    l = mid
print(r)
Buggy code:
import math
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l,r=0,10**9
while l+1!=r:
    m,c=(l+r)//2,0
    for i in range(n):
        c+=math.ceil(max(0,(h[i]-b*m)/a))
    if c>m:
        l=m
    else:
        r=m
print(r)

Fixed code:
import math
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l,r=0,10**9
while r-l>1:
    m=(l+r)//2
    count=0
    for i in h:
        count+=max(math.ceil((i-b*m)/(a-b)),0)
    if count<=m:
        r=m
    else:
        l=m
print(r)
Buggy code:
import sys
from heapq import heapify, heappop, heappush
from collections import defaultdict

def main():
    finput=lambda :sys.stdin.readline().strip()
    n,a,b=map(int,finput().split())
    h=[int(finput()) for _ in range(n)]
    gs=lambda a,b:a//b+(a%b>0)
    def enough(t):
        s=sum([max(x-t*b,0)//(a-b)+(max(x-t*b,0)%b>0) for x in h])
        if s<=t:
            return True
        else:
            return False
    #def biser(t,l):
    #    if l==0:
    #        return t
    #    t=t+l//2
    #    if enough(t):
    #        return biser(t-l//2,l//2)
    #    else:
    #        return biser(t+1,l-l//2)
    l=max(h)//b+1
    t=0
    while l>0:
        t=t+l//2
        if enough(t):
            t=t-l//2
            l=l//2
        else:
            t+=1
            l=l-l//2
    print(t)

if __name__=='__main__':
    main()



Fixed code:
import sys
from heapq import heapify, heappop, heappush
from collections import defaultdict
finput=lambda :sys.stdin.readline().strip()

def main():
    n,a,b=map(int,finput().split())
    h=[int(finput()) for _ in range(n)]
    gs=lambda a,b:a//b+(a%b>0)
    def enough(t):
        s=sum([gs(max(x-t*b,0),a-b) for x in h])
        if s<=t:
            return True
        else:
            return False
    l=max(h)//b+1
    t=0
    while l>0:
        t=t+l//2
        if enough(t):
            t=t-l//2
            l=l//2
        else:
            t+=1
            l=l-l//2
    print(t)

if __name__=='__main__':
    main()
Buggy code:
n,a,b = map(int,input().split())
s = 0
H = []
for _ in range(n):
    h = int(input())
    H.append(h)
from copy import deepcopy

from math import ceil
def count(x):
    Hc = deepcopy(H)
    cnt = 0
    for i in range(n):
        Hc[i] -= b*x
        if Hc[i]>0:
            cnt += (Hc[i]//(a-b)) + 1
    return cnt <= x

l,r = 0, max(H)//b + 1
while l < r:
    mid = (l+r)//2
    if count(mid):
        r = mid
    else:
        l = mid+1
print(r)

Fixed code:
n,a,b = map(int,input().split())
s = 0
H = []
for _ in range(n):
    h = int(input())
    H.append(h)
from copy import deepcopy

from math import ceil
def count(x):
    Hc = deepcopy(H)
    cnt = 0
    for i in range(n):
        Hc[i] -= b*x
        if Hc[i]>0:
            cnt += (Hc[i]-1)//(a-b) + 1
    return cnt <= x

l,r = 0, max(H)//b + 1
while l < r:
    mid = (l+r)//2
    if count(mid):
        r = mid
    else:
        l = mid+1
print(r)
Buggy code:
from math import ceil
def solve():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    top = max(H)+1
    total = sum(H)
    bottom = 1
    mid = (top+bottom)//2
    while bottom+1<top:
        cnt = 0
        for i in range(N):
            cnt += max(ceil((H[i]-B*mid)/(A-B)),0)
        if cnt>mid:
            bottom = mid+1
        else:
            top = mid+1
        mid = (top+bottom)//2
    ans = mid
    return ans
print(solve())

Fixed code:
from math import ceil
def solve():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    top = max(H)
    total = sum(H)
    bottom = 0
    mid = (top+bottom)//2
    while bottom+1<top:
        cnt = 0
        for i in range(N):
            cnt += max(ceil((H[i]-B*mid)/(A-B)),0)
        if cnt>mid:
            bottom = mid
        else:
            top = mid
        mid = (top+bottom)//2
    ans = top
    return ans
print(solve())
Buggy code:
import numpy as np

n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = np.array(h)

hi = 10**10
low = -1

def calc(x):
    f = ((h-b*x)//(a-b)).sum()
    return f

while hi-low > 1:
    ave = (hi+low)//2
    if calc(ave) > ave:
        low = ave
    else:
        hi = ave
    
print(hi)

Fixed code:
import numpy as np

n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = np.array(h)

hi = 10**10
low = -1

def calc(x):
    y = h-x*b
    y[y<0] = 0
    f = np.ceil(y/(a-b)).sum()
    return f

while hi-low > 1:
    ave = (hi+low)//2
    if calc(ave) <= ave:
        hi = ave
    else:
        low = ave
    
print(hi)
Buggy code:
import sys, math
input = sys.stdin.readline

def main():
    n,a,b = map(int,input().split())
    h = [int(input()) for _ in range(n)]
    ok = max(h)
    ng = 0
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        cnt = 0
        for i in range(n):
            cnt += max(0, math.ceil((h[i]-mid*b)/a))
        if cnt <= mid:
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == "__main__":
    main()

Fixed code:
import sys, math
input = sys.stdin.readline

def main():
    n,a,b = map(int,input().split())
    h = [int(input()) for _ in range(n)]
    ok = max(h)
    ng = 0
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        cnt = 0
        for i in range(n):
            cnt += max(0, math.ceil((h[i]-mid*b)/(a-b)))
        if cnt <= mid:
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == "__main__":
    main()
Buggy code:
import math


def check(k, A, B, H):
    return sum([max([0, math.ceil((h - B * k) // (A - B))]) for h in H]) <= k


def main():
    N, A, B = list(map(int, input().split(' ')))
    H = [int(input()) for _ in range(N)]
    ng, ok = 0, 10**9
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid, A, B, H):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()

Fixed code:
import math


def check(k, A, B, H):
    return sum([max([0, math.ceil((h - B * k) / (A - B))]) for h in H]) <= k


def main():
    N, A, B = list(map(int, input().split(' ')))
    H = [int(input()) for _ in range(N)]
    ng, ok = 0, 10**9
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid, A, B, H):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()
Buggy code:
import numpy as np

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

H = []

for i in range(N):
    H.append(int(input()))

H = np.array(H)

def binary_search(x):
    H_tmp = H - B * x
    count = (H_tmp[H_tmp > 0] // (A-B) + 1).sum()
    return x >= count

left = 0
right = 10**30

while(right - left > 1):
    mid = (left + right) // 2
    ret = binary_search(mid)
    if ret:
        right = mid
    else:
        left = mid

print(mid)

Fixed code:
import numpy as np

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

H = []

for i in range(N):
    H.append(int(input()))

H = np.array(H)

def binary_search(x):
    H_tmp = H - B * x
    H_tmp = H_tmp[H_tmp > 0]
    count = ((H_tmp + A - B - 1) // (A - B)).sum()
    return x >= count

left = 0
right = 10**10

while(right - left > 1):
    mid = (left + right) // 2
    ret = binary_search(mid)
    if ret:
        right = mid
    else:
        left = mid

print(right)
Buggy code:
def f(x,hp):
  hp=[hh-(b*x) for hh in hp]
  c=0
  for p in hp:
    if p<=0:continue
    c+=(p+(a-b)-1)/(a-b)
  return c<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
ng=0
ok=10**9
while ok-ng>1:
  mid=(ok+ng)//2
  if f(mid,h):
    ok=mid
  else:
    ng=mid
print(ok)

Fixed code:
from math import ceil
def f(x,hp):
  hp=[hh-(b*x) for hh in hp]
  c=0
  for p in hp:
    if p<=0:continue
    c+=ceil(p/(a-b))
  return c<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
ng=0
ok=10**9
while ok-ng>1:
  mid=(ok+ng)//2
  if f(mid,h):
    ok=mid
  else:
    ng=mid
print(ok)
Buggy code:
import math
n,a,b = map(int,input().split())
H = list(int(input()) for _ in range(n))
l,r = 0, 10**9
d = a-b
while r-l>1:
    mid = (r+l)//2
    tmp = 0
    for h in H:
        if h <= mid*b:
            continue
        tmp += math.ceil((h-mid*b)/d)
    if tmp < mid:
        r = mid
    else:
        l = mid
print(l)

Fixed code:
import math
n,a,b = map(int,input().split())
H = list(int(input()) for _ in range(n))
l,r = 0, 10**9
d = a-b
while r-l>1:
    mid = (r+l)//2
    tmp = 0
    for h in H:
        if h <= mid*b:
            continue
        tmp += math.ceil((h-mid*b)/d)
    if tmp <= mid:
        r = mid
    else:
        l = mid
print(r)
Buggy code:
import sys

def solve():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    H.sort()
    TotalH = sum(H)
    low = 0; high = 10 ** 20
    while high - low > 1:
        mid = (low + high) // 2
        explosion = B * mid
        direct = 0
        for h in H:
            direct += (h - explosion) // (A - B)
            if (h - explosion) // (A - B) > 0: direct += 1
        if direct <= mid: high = mid
        else: low = mid
    print(high)

    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import sys

def solve():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    low = 0; high = 10 ** 20
    while high - low > 1:
        mid = (low + high) // 2
        explosion = B * mid
        direct = 0
        for h in H:
            if h - explosion > 0:
                direct += (h - explosion) // (A - B)
                if (h - explosion) % (A - B) > 0: direct += 1
        if direct <= mid: high = mid
        else: low = mid
    print(high)

    return 0

if __name__ == "__main__":
    solve()
Buggy code:
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def enough(x):
  cnt=0
  for i in range(n):
    if h[i]-x*b<=0:
      continue:
    cnt+=ceil((h[i]-x*b)/(a-b))
  if cnt<=x:
    return True
  else:
    return False
l=0
r=10**9
while r-l>0:
  mid=(r+l)//2
  if enough(mid):
    r=mid
  else:
    l=mid+1
print(r)

Fixed code:
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def enough(x):
  cnt=0
  for i in range(n):
    if h[i]-x*b<=0:
      continue
    cnt+=ceil((h[i]-x*b)/(a-b))
  if cnt<=x:
    return True
  else:
    return False
l=0
r=10**9
while r-l>0:
  mid=(r+l)//2
  if enough(mid):
    r=mid
  else:
    l=mid+1
print(r)
Buggy code:
u = 10**18
d = 0
N,A,B = map(int,input().split())
s = A - B
H = []
import math
for i in range(N):
    h = int(input())
    H.append(h)
for i in range(50):
    x = (u+d)//2
    a = 0
    for j in range(N):
        h = H[j]
        h -= B
        if h > 0:
            a += math.ceil(h//A)
    if a > x:
        d = x
    else:
        u = x
print(u)

Fixed code:
u = 10**9
d = 0
N,A,B = map(int,input().split())
s = A - B
H = []
import math
for i in range(N):
    h = int(input())
    H.append(h)
for i in range(30):
    x = (u+d)//2
    a = 0
    for j in range(N):
        h = H[j]
        h -= B*x
        if h > 0:
            a += math.ceil(h/s)
    if a > x:
        d = x
    else:
        u = x
print(u)
Buggy code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, a, b = LI()
H = IR(n)
ok = 10 ** 9
ng = 0
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for h in H:
        remain = h - b * mid
        if remain > 0:
            ret += remain // (a - b) + remain % (a - b)
    if ret <= mid:
        ok = mid
    else:
        ng = mid


print(ok)



Fixed code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, a, b = LI()
H = IR(n)
ok = 10 ** 9
ng = 0
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for h in H:
        remain = h - b * mid
        if remain > 0:
            ret += remain // (a - b) + bool(remain % (a - b))
    if ret <= mid:
        ok = mid
    else:
        ng = mid


print(ok)
Buggy code:
import math

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]


def ok(n):
    d = n * B
    t = 0
    for h in H:
        if h <= d:
            continue
        t += (h - d) / (A - B)
    return t <= n


lo, hi = 0, 10 ** 9

while lo < hi:
    mi = (lo + hi) // 2
    if ok(mi):
        hi = mi
    else:
        lo = mi + 1

print(hi)


Fixed code:
import math

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]


def ok(n):
    d = n * B
    t = 0
    for h in H:
        if h <= d:
            continue
        t += math.ceil((h - d) / (A - B))
        # t += (h - d) // (A - B)
    return t <= n


lo, hi = 0, 10 ** 9

while lo < hi:
    mi = (lo + hi) // 2
    if ok(mi):
        hi = mi
    else:
        lo = mi + 1

print(hi)
Buggy code:
n,a,b=map(int,input().split())

h=[]
for i in range(n):
    a=int(input())
    h.append(a)
left=0
right=max(h)+1

def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=(((h[i]-b*t)//(a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False

while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)

Fixed code:
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    q=int(input())
    h.append(q)
left=0
right=max(h)+1
def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=((h[i]-b*t)//((a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False
while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)
Buggy code:
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    #print(l1)
    for i in l1: 
        c+=ceil((i)/a)
    c+=ceil((b*x)/a)
    return c<=x
lo=0 
ans=-1 
hi=10**19 
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)

Fixed code:
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    for i in l1: 
         if i<=0:
             continue 
         c+=ceil((i)/(a-b))
    return c<=x
lo=0 
ans=-1 
hi=10**9+4 
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)
Buggy code:
def calc(n):
    damage = (b * n)
    d = [max(dd - damage, 0) for dd in h]
    a_num = 0
    for i in range(len(d)):
        a_num += max(0, 1 + (d[i]-1) // (a - b))
    if a_num <= n:
        return True
    return False

n, a, b = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))
ans = 0
h.sort()

left = 0
right = (h[-1] + 1) // (b)

while (right - left) > 1:
    middle = (left + right) // 2
    if calc(middle):
        right = middle
    else:
        left = middle
print(middle)

Fixed code:
def calc(n):
    damage = (b * n)
    d = [max(dd - damage, 0) for dd in h]
    a_num = 0
    for i in range(len(d)):
        a_num += max(0, 1 + (d[i]-1) // (a - b))
    if a_num <= n:
        return True
    return False

n, a, b = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))
ans = 0
h.sort()

left = 0
right = 10000000000

while (right - left) > 1:
    middle = (left + right) // 2
    if calc(middle):
        right = middle
    else:
        left = middle
print(right)
Buggy code:
import numpy as np
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
H = np.array(h)

def test(n):
    x = H - B*n
    x[x<0] = 0
    return x.sum() <= n*(A-B)

left = 0
right = 10**9

while right - left > 1:
    mid = (left - right)//2
    if test(mid):
        right = mid
    else:
        left = mid
ans = right
print(ans)

Fixed code:
import numpy as np
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
H = np.array(h)

def test(n):
    x = H - n*B
    x[x<0] = 0
    return np.ceil(x/(A-B)).sum() <= n

left = 0
right = 10**9

while right - left > 1:
    mid = (left + right)//2
    if test(mid):
        right = mid
    else:
        left = mid
ans = right
print(ans)
Buggy code:
import math
def bsearch_int(init_ng, init_ok, cond):
    ng = init_ng
    ok = init_ok
    while(abs(ok - ng) > 1):
        mid = math.floor(abs(ok + ng)/2)
        if cond(mid):
            ok = mid
        else:
            ng = mid + 1
    return ok if ok != init_ok else -1

def condition(cnt, N, A, B, hs):
    basedmg = B*cnt
    diff = A - B
    diffcnt = 0
    for h in hs:
        if h < basedmg:
            break
        else:
            diffcnt += math.ceil((h-basedmg)/diff)
    if diffcnt > cnt:
        return False
    else:
        return True

import functools
def resolve():
    N, A, B = list(map(int, input().split(" ")))
    hs = [int(input()) for i in range(N)]
    hs.sort(reverse=True)
    print(bsearch_int(0, math.ceil(hs[0]/B), functools.partial(condition, N=N, A=A, B=B, hs=hs)))


if __name__ == '__main__':
    resolve()

Fixed code:
import math
def bsearch_int(init_ng, init_ok, cond):
    ng = init_ng
    ok = init_ok
    while(abs(ok - ng) > 1):
        mid = math.floor(abs(ok + ng)/2)
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

def condition(cnt, N, A, B, hs):
    basedmg = B*cnt
    diff = A - B
    diffcnt = 0
    for h in hs:
        if h < basedmg:
            break
        else:
            diffcnt += math.ceil((h-basedmg)/diff)
    if diffcnt > cnt:
        return False
    else:
        return True

import functools
def resolve():
    N, A, B = list(map(int, input().split(" ")))
    hs = [int(input()) for i in range(N)]
    hs.sort(reverse=True)
    print(bsearch_int(0, math.ceil(hs[0]/B), functools.partial(condition, N=N, A=A, B=B, hs=hs)))


if __name__ == '__main__':
    resolve()
Buggy code:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=1
r=1+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    #ans=r
print(ans)



Fixed code:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=0
r=3+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    ans=r
print(ans)