from scipy.stats import hypergeom

b = 50
k = 55
x = 3
lh0 = 0.0
ne = b + k - x - 1
while True:
    lh = hypergeom.pmf(x, ne+1, b, k)
    if lh < lh0:
        break
    else:
        lh0 = lh
        ne += 1
        
print("ne =",ne)