get elements from stack until element greater than A [ i ] found
while ( s1 . Count != 0 && ( s1 . Peek ( ) . first ) > A [ i ] ) { cnt += s1 . Peek ( ) . second ; s1 . Pop ( ) ; } s1 . Push ( new pair ( A [ i ] , cnt ) ) ; left [ i ] = cnt ; }