#!/usr/bin/env python def read(): raw_input() return map(int, raw_input().split()) def work(vList): cnt = 0 for i in range(len(vList) - 2): if vList[i] == vList[i + 1] or vList[i] == vList[i + 2] or \ vList[i + 1] == vList[i + 2]: continue if not (sorted(vList[i : i + 3])[1] == vList[i ] or \ sorted(vList[i : i + 3])[1] == vList[i + 2]): continue cnt += 1 print cnt if __name__ == "__main__": work(read())