def stock_spans(prices):
    stack = []
    output = []
    for price in prices:
        span = 1
        while stack and stack[-1][0] <= price:
            span += stack.pop()[1]
        stack.append((price, span))
        output.append(span)
    return output
