def ranking(R):
 l = sorted(list(enumerate(R)), cmp=(lambda a, b: cmp(a[1], b[1])))
 l = sorted(list(enumerate(l)), cmp=(lambda a, b: cmp(a[1], b[1])))
 return array([kv[0] for kv in l])

def ranking ( R ) : l = sorted ( list ( enumerate ( R ) ) , cmp = ( lambda a , b : cmp ( a [ 1 ] , b [ 1 ] ) ) ) l = sorted ( list ( enumerate ( l ) ) , cmp = ( lambda a , b : cmp ( a [ 1 ] , b [ 1 ] ) ) ) return array ( [ kv [ 0 ] for kv in l ] )
produces a linear ranking of the values in r .