def max_operations(): import sys input = sys.stdin.read().split() n = int(input[0]) a = list(map(int, input[1:n+1])) count = 0 i = 0 while i < n-2: if a[i] < a[i+1] and a[i+1] > a[i+2]: # Perform the operation new_val = min(a[i], a[i+2]) - 1 a[i+1] = new_val count += 1 # After operation, check if i can still be a peak or if i-1 became a peak # We might need to check previous indices if i > 0 and a[i-1] < a[i] and a[i] > a[i+1]: i = max(i-1, 0) continue else: i = max(i-1, 0) continue i += 1 print(count) max_operations()