import sys from collections import deque def main(): n = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) if n < 3: print(0) return peak = [False] * (n - 2) # 0-based indices for peaks for i in range(n - 2): if A[i] < A[i+1] and A[i+1] > A[i+2]: peak[i] = True q = deque() for i in range(n - 2): if peak[i]: q.append(i) count = 0 while q: i = q.popleft() if not peak[i]: continue # Perform the operation min_val = min(A[i], A[i+2]) A[i+1] = min_val - 1 count += 1 # Mark current peak as non-peak peak[i] = False # Check neighboring positions for new peaks for dj in [-1, 0, 1]: j = i + dj if 0 <= j < n - 2: current_peak = (A[j] < A[j+1] and A[j+1] > A[j+2]) if current_peak != peak[j]: peak[j] = current_peak if current_peak: q.append(j) print(count) if __name__ == "__main__": main()