N = int(input()) H = list(map(int, input().split())) stk = [(10 ** 18, 1)] def query(h, cl): while stk: pre_h, pre_cl = stk[-1] if h <= pre_h: if pre_cl != cl: stk.append((h, cl)) break else: stk.pop() ans = len(stk) // 2 print(ans) for i, h in enumerate(H): query(h, i % 2)