get elements from stack until element greater than A [ i ] found
while ( s1 . length != 0 && ( s1 [ s1 . length - 1 ] [ 0 ] ) > A [ i ] ) { cnt += s1 [ s1 . length - 1 ] [ 1 ] ; s1 . pop ( ) ; } s1 . push ( [ A [ i ] , cnt ] ) ; left [ i ] = cnt ; }