classSolution:defGetNumberOfK(self,arr: List[int],x:int) ->int:defbisect(arr,x,fn): l, r =0,len(arr)while l < r: m = (l + r) //2iffn(arr[m], x): l = m +1else: r = mreturn l l =bisect(arr, x, lambdax1, x2: x1 < x2) r =bisect(arr, x, lambdax1, x2: x1 <= x2)return r - l