n = int(input()) ls = list(map(int, input().split())) counter = 0 for i in range(1, n - 1): if ls[i - 1] <= ls[i] <= ls[i + 1]: continue elif ls[i + 1] <= ls[i] <= ls[i - 1]: continue elif ls[i - 1] == ls[i] or ls[i] == ls[i + 1] or ls[i - 1] == ls[i + 1]: continue else: print(ls[i - 1], ls[i], ls[i + 1]) counter += 1 print(counter)