def _searchsorted(array, val, side=u'left'):
 if hasattr(array, u'searchsorted'):
  return array.searchsorted(val, side=side)
 begin = 0
 end = len(array)
 while (begin < end):
  mid = ((begin + end) // 2)
  if (val > array[mid]):
   begin = (mid + 1)
  elif (val < array[mid]):
   end = mid
  elif (side == u'right'):
   begin = (mid + 1)
  else:
   end = mid
 return begin

def _searchsorted ( array , val , side = u'left' ) : if hasattr ( array , u'searchsorted' ) : return array . searchsorted ( val , side = side ) begin = 0 end = len ( array ) while ( begin < end ) : mid = ( ( begin + end ) // 2 ) if ( val > array [ mid ] ) : begin = ( mid + 1 ) elif ( val < array [ mid ] ) : end = mid elif ( side == u'right' ) : begin = ( mid + 1 ) else : end = mid return begin
call np .