n = int(input()) a = list(map(int, input().split())) # Process the array to remove consecutive duplicates b = [] prev = None for num in a: if num != prev: b.append(num) prev = num m = len(b) if m < 3: print(0) else: up = 1 down = 1 for i in range(1, m): if b[i] > b[i-1]: new_up = down + 1 new_down = down else: new_down = up + 1 new_up = up up, down = new_up, new_down max_len = max(up, down) print(max_len if max_len >= 3 else 0)