
    (g_                     j    d Z d	dddZd	dddZd	dddZd	dddZ	 ddl eZeZy# e$ r Y w xY w)
zBisection algorithms.    Nkeyc                v    |t        | |||      }nt        |  ||      |||      }| j                  ||       y)a7  Insert item x in list a, and keep it sorted assuming a is sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.

    A custom key function can be supplied to customize the sort order.
    Nr   )bisect_rightinsertaxlohir   s        /usr/lib/python3.12/bisect.pyinsort_rightr      s<     {!QB'!SVR5HHRO    c                    |dk  rt        d      |t        |       }|%||k  r||z   dz  }|| |   k  r|}n|dz   }||k  r|S ||k  r$||z   dz  }| || |         k  r|}n|dz   }||k  r$|S )a  Return the index where to insert item x in list a, assuming a is sorted.

    The return value i is such that all e in a[:i] have e <= x, and all e in
    a[i:] have e > x.  So if x already appears in the list, a.insert(i, x) will
    insert just after the rightmost x already there.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.

    A custom key function can be supplied to customize the sort order.
    r   lo must be non-negative      
ValueErrorlenr	   r
   r   r   r   mids         r   r   r      s     
Av233	zV {2g7q.C1S6z1W 2g I 2g7q.C3qv;1W 2g Ir   c                v    |t        | |||      }nt        |  ||      |||      }| j                  ||       y)a5  Insert item x in list a, and keep it sorted assuming a is sorted.

    If x is already in a, insert it to the left of the leftmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.

    A custom key function can be supplied to customize the sort order.
    Nr   )bisect_leftr   r   s        r   insort_leftr   9   s<     {Ar2&CFB4HHROr   c                    |dk  rt        d      |t        |       }|%||k  r||z   dz  }| |   |k  r|dz   }n|}||k  r|S ||k  r$||z   dz  } || |         |k  r|dz   }n|}||k  r$|S )a  Return the index where to insert item x in list a, assuming a is sorted.

    The return value i is such that all e in a[:i] have e < x, and all e in
    a[i:] have e >= x.  So if x already appears in the list, a.insert(i, x) will
    insert just before the leftmost x already there.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.

    A custom key function can be supplied to customize the sort order.
    r   r   r   r   r   r   s         r   r   r   J   s     
Av233	zV {2g7q.Cvz1W 2g I 2g7q.C1S6{Q1W 2g Ir   )*)r   N)	__doc__r   r   r   r   _bisectImportErrorbisectinsort r   r   <module>r$      sb    T "!T !HD "!D !J	
 
	  		s   * 22