get elements from stack until element greater or equal to A [ i ] found
while ( s2 . Count != 0 && ( s2 . Peek ( ) . first ) >= A [ i ] ) { cnt += s2 . Peek ( ) . second ; s2 . Pop ( ) ; } s2 . Push ( new pair ( A [ i ] , cnt ) ) ; right [ i ] = cnt ; } int result = 0 ;