def main(): num = int(input()) values = list(map(int, input().split())) ans = 0 for i in range(num - 2): tmp_list = [values[i], values[i+1], values[i+2]] sorted_list = sorted(tmp_list) if len(set(tmp_list)) != 3: continue #if max(tmp_list) != tmp_list[2]: # ans += 1 ans += 1 print(ans) if __name__ == '__main__': main()