Store the sum of frequency of elements greater than the current element
p = [ ] NEW_LINE q = [ ] NEW_LINE m = [ ] NEW_LINE for key , value in mp . items ( ) : NEW_LINE INDENT m . append ( [ key , value ] ) NEW_LINE DEDENT m = m [ : : - 1 ] NEW_LINE for p in m : NEW_LINE INDENT temp = p [ 1 ] NEW_LINE mp [ p [ 0 ] ] = x NEW_LINE x += temp NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( mp [ arr [ i ] ] , end = " ▁ " ) NEW_LINE DEDENT