#NEWLINE# def insort_right( a , x , lo = 0 , hi = None ) : #NEWLINE# #INDENT# 'Insert item x in list a, and keep it sorted assuming a is sorted.\n\n    If x is already in a, insert it to the right of the rightmost x.\n\n    Optional args lo (default 0) and hi (default len(a)) bound the\n    slice of a to be searched.\n    ' #NEWLINE# if ( lo < 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'lo must be non-negative' ) #NEWLINE# #UNINDENT# if ( lo is None ) : #NEWLINE# #INDENT# hi = len ( a ) #NEWLINE# #UNINDENT# while ( lo < hi ) : #NEWLINE# #INDENT# mid = ( ( lo + hi ) // 2 ) #NEWLINE# if ( x < a [ mid ] ) : #NEWLINE# #INDENT# hi = mid #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lo = ( mid + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# a . insert ( lo , x )