B
    \ Çcý	  ã               @   sZ   d Z ddd„Zddd„Zddd„Zdd	d
„ZyddlT W n ek
rL   Y nX eZeZdS )zBisection algorithms.é    Nc             C   sd   |dk rt dƒ‚|dkr t| ƒ}x2||k rR|| d }|| | k rH|}q"|d }q"W |  ||¡ dS )zï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.
    r   zlo must be non-negativeNé   é   )Ú
ValueErrorÚlenÚinsert)ÚaÚxÚloÚhiÚmid© r   úlib/python3.7/bisect.pyÚinsort_right   s    	
 r   c             C   sX   |dk rt dƒ‚|dkr t| ƒ}x2||k rR|| d }|| | k rH|}q"|d }q"W |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(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.
    r   zlo must be non-negativeNr   r   )r   r   )r   r   r	   r
   r   r   r   r   Úbisect_right   s    
 r   c             C   sd   |dk rt dƒ‚|dkr t| ƒ}x2||k rR|| d }| | |k rL|d }q"|}q"W |  ||¡ dS )zí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.
    r   zlo must be non-negativeNr   r   )r   r   r   )r   r   r	   r
   r   r   r   r   Úinsort_left+   s    	
 
r   c             C   sX   |dk rt dƒ‚|dkr t| ƒ}x2||k rR|| d }| | |k rL|d }q"|}q"W |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(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.
    r   zlo must be non-negativeNr   r   )r   r   )r   r   r	   r
   r   r   r   r   Úbisect_left?   s    
 
r   )Ú*)r   N)r   N)r   N)r   N)	Ú__doc__r   r   r   r   Z_bisectÚImportErrorZbisectZinsortr   r   r   r   Ú<module>   s   



