from collections import deque n = int(input()) A = list(map(int, input().split())) queue = deque() # 初始化队列,找到所有初始的峰的位置 for j in range(1, n - 1): if A[j-1] < A[j] and A[j] > A[j+1]: queue.append(j) count = 0 while queue: j = queue.popleft() # 检查当前j是否有效并满足峰的条件 if j < 1 or j >= len(A) - 1: continue if not (A[j-1] < A[j] and A[j] > A[j+1]): continue # 执行操作 min_val = min(A[j-1], A[j+1]) A[j] = min_val - 1 count += 1 # 检查相邻的位置是否形成新的峰 for neighbor in [j-1, j+1]: if 1 <= neighbor <= len(A) - 2: if A[neighbor-1] < A[neighbor] and A[neighbor] > A[neighbor+1]: queue.append(neighbor) print(count)