stack to store elements and the count of the numbers they popped First part of pair will be the value of inserted element . Second part will be the count of the number of elements pushed before with a greater value
stack < pair < int , int > > q ;