#include <string>
#include <vector>
#include <stack>
using namespace std;
vector<int> solution(vector<int> heights) {
vector<int> answer(heights.size());
stack <int> test;
stack <int> tmp;
int leng = heights.size();
int k =0;
for(int i=0; i < leng; i++){
test.push(heights[i]);
}
for(int i=leng; i >0; i--){
k = i;
int now_n = test.top();
test.pop();
while(!test.empty()){
int next_n = test.top();
test.pop();
tmp.push(next_n);
k--;
if(next_n > now_n){
answer[i-1] = k;
break;
}
}
while(!tmp.empty()){
test.push(tmp.top());
tmp.pop();
}
}
if(!test.empty()){
for(int i=0; i < test.size(); i++){
answer[i] = 0;
}
}
return answer;
}