For the length of strictly larger numbers on the right of A [ i ]
for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT count = 1 ; NEW_LINE while ( len ( r ) != 0 and r [ - 1 ] [ 0 ] >= arr [ i ] ) : NEW_LINE INDENT count += r [ - 1 ] [ 1 ] NEW_LINE r . pop ( ) ; NEW_LINE DEDENT r . append ( [ arr [ i ] , count ] ) ; NEW_LINE DEDENT