#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 11 09:45:00 2020

@author: pirl
"""


def solution(heights):
    answer = [0]
    
    for i in range(1,len(heights)):#인덱스1부터돌기
        f=0
        for j in range(i-1,-1,-1):#
            if heights[j]>heights[i]:
                print(heights[j],heights[i])
                answer.append(j+1)
                f=1
                break
        if f==0:
            answer.append(0)
    return answer

print(solution([6,9,5,7,4]))
print(solution([3,9,9,3,5,7,2]))
print(solution([1,5,3,6,7,6,5]))
#[6,9,5,7,4]	[0,0,2,2,4]
#[3,9,9,3,5,7,2]	[0,0,0,3,3,3,6]
#[1,5,3,6,7,6,5]	[0,0,2,0,0,5,6]
