get elements from stack until element greater or equal to A [ i ] found
while ( ! s2 . empty ( ) && ( s2 . top ( ) . first ) >= A [ i ] ) { cnt += s2 . top ( ) . second ; s2 . pop ( ) ; } s2 . push ( { A [ i ] , cnt } ) ; right [ i ] = cnt ; } int result = 0 ;