def main(): n = int(input()) if n < 3: print(0) return a = list(map(int, input().split())) l = [1]*n if a[0] == a[1]: run = [1] cur = 1 else: run = [] cur = 2 for i in range(2, n): if a[i-2] < a[i-1] < a[i] or a[i-2] > a[i-1] > a[i]: cur += 1 else: run.append(cur) cur = 1 run.append(cur) max_run = 0 for i, v in enumerate(run): if i+1 < len(run) and v + run[i+1] > max_run: max_run = v + run[i+1] print((max_run-1)//2) if __name__ == "__main__": main()