n = int(input()) m = list(map(int,input().split())) c = 0 for i in range(0,n-2): if m[i]!=m[i+2]: if m[i]m[i+2] or m[i]>m[i+1]