A sequence of integers ($a_1, a_2, \ldots, a_k$) is said to be UpDown, if these inequalities hold true:
- $a_1 \le a_2$
- $a_2 \ge a_3$
- $a_3 \le a_4$
and so on.
That is, every even-indexed element should be at least as large as its adjacent elements. And every odd-indexed element should be at most as large as its adjacent elements. Formally, $a_{2i} \ge a_{2i+1}$ and $a_{2i+1} \le a_{2i+2}$, for all valid positions.
A subsegment is a consecutive portion of a sequence. That is, a subsegment of ($b_1, b_2, \ldots, b_k$)  will be of the form ($b_i, b_{i+1}, \ldots, b_j$), for some $i$ and $j$.
You are given a sequence ($s_1, s_2, \ldots, s_n$). You can insert at most one integer anywhere in this sequence. It could be any integer. After inserting an integer (or choosing not to), suppose you have the new sequence ($t_1, t_2, \ldots, t_m$). Note that $m$ will either be $n$+1 or $n$. You want to maximize the length of the longest subsegment of ($t_1, t_2, \ldots, t_m$) which is UpDown, and output the length of that.

-----Input-----
- The first line contains a single integer, $T$, which is the number of testcases. The description of each testcase follows.
- The first line of every testcase contains a single integer, $n$, which is the number of integers in the original sequence.
- The second line contains $n$ integers: $s_1, s_2, \ldots, s_n$, which forms the original sequence.

-----Output-----
For each testcase output a single line containing one integer, which should be the length of the longest UpDown subsegment that you can get after inserting at most one integer.

-----Constraints-----
- $1 \le T \le 2$
- $1 \le n \le 10^6$
- $1 \le s_i \le 10^9$

-----Subtasks-----
Subtask #1 (20 points): $1 \le n \le 100$
Subtask #2 (10 points): $1 \le n \le 10000$
Subtask #3 (70 points): Original constraints

-----Sample Input-----
2
7
100 1 10 3 20 25 24
5
3 3 2 4 1

-----Sample Output-----
7
6

-----Explanation-----
Testcase 1: The original sequence is (100, 1, 10, 3, 20, 25, 24). Suppose you insert the element 5 between the elements 20 and 25, you will get the new sequence (100, 1, 10, 3, 20, 5, 25, 24). The longest UpDown subsegment of this sequence is (1, 10, 3, 20, 5, 25, 24), whose length is 7. You can check that you cannot do any better, and hence the answer is 7.
Testcase 2: The original sequence is (3, 3, 2, 4, 1). Suppose you insert the element 4 at the end, you will get the new sequence (3, 3, 2, 4, 1, 4). This entire sequence is UpDown, and so the longest UpDown subsegment of this sequence is (3, 3, 2, 4, 1, 4), whose length is 6. You can check that you cannot do any better, and hence the answer is 6.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	list_sub = []
	idx = 0
	counter = 0
	for i in range(n - 1):
		if counter % 2 == 0 and array[i] <= array[i + 1]:
			counter += 1
		elif counter % 2 == 1 and array[i] >= array[i + 1]:
			counter += 1
		else:
			list_sub.append((idx, i))
			if counter % 2 == 1:
				idx = i
				counter = 1
			else:
				idx = i + 1
				counter = 0
	list_sub.append((idx, n - 1))
	massimo = 0
	if len(list_sub) == 1:
		massimo = list_sub[0][1] - list_sub[0][0] + 2
	for i in range(len(list_sub) - 1):
		if list_sub[i][1] == list_sub[i + 1][0]:
			massimo = max(massimo, list_sub[i][1] - list_sub[i][0] + 2 + list_sub[i + 1][1] - list_sub[i + 1][0])
		else:
			massimo = max(massimo, list_sub[i][1] - list_sub[i][0] + 3 + list_sub[i + 1][1] - list_sub[i + 1][0])
	print(massimo)


t = int(input())
for j in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	up = [1] * (n + 1)
	dn = [1] * (n + 1)
	(up[-1], dn[-1]) = (0, 0)
	for i in reversed(range(n - 1)):
		if x[i] <= x[i + 1]:
			dn[i] += up[i + 1]
		if x[i] >= x[i + 1]:
			up[i] += dn[i + 1]
	ans = 0
	for i in range(n):
		t = dn[i]
		if t % 2:
			t += dn[i + t]
		else:
			t += up[i + t]
		ans = max(ans, t + 1)
	print(ans)


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	n = inp()
	x = ip()
	up = [1] * (n + 1)
	dn = [1] * (n + 1)
	(up[-1], dn[-1]) = (0, 0)
	for i in reversed(list(range(n - 1))):
		if x[i] <= x[i + 1]:
			dn[i] += up[i + 1]
		if x[i] >= x[i + 1]:
			up[i] += dn[i + 1]
	ans = 0
	for i in range(n):
		t = dn[i]
		if t % 2:
			t += dn[i + t]
		else:
			t += up[i + t]
		ans = max(ans, t + 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[1] * 2 for _ in range(n)]
	for i in range(n - 2, -1, -1):
		if a[i] <= a[i + 1]:
			dp[i][0] = 1 + dp[i + 1][1]
		if a[i] >= a[i + 1]:
			dp[i][1] = 1 + dp[i + 1][0]
	m = 0
	for i in range(n):
		l = dp[i][0]
		if l % 2 == 0:
			m = max(m, l + dp[i + l - 1][0])
		else:
			m = max(m, l + dp[i + l - 1][1])
	print(m)


def main():
	from sys import stdin, stdout
	rl = stdin.readline
	for _ in range(int(rl())):
		n = int(rl())
		a = [int(x) for x in rl().split()]
		dp = [[1] * 2 for _ in range(n)]
		for i in range(n - 2, -1, -1):
			if a[i] <= a[i + 1]:
				dp[i][0] = 1 + dp[i + 1][1]
			if a[i] >= a[i + 1]:
				dp[i][1] = 1 + dp[i + 1][0]
		m = 0
		for i in range(n):
			l = dp[i][0]
			if l % 2 == 0:
				m = max(m, l + dp[i + l - 1][0])
			else:
				m = max(m, l + dp[i + l - 1][1])
		stdout.write(str(m) + '\n')
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	s = 0
	i = 1
	down = True
	prev_s = -1
	prev_v = -1
	prev_i = -1
	while i < len(l):
		down = not down
		if l[i] == l[i - 1]:
			if l[i] != prev_v:
				prev_v = l[i]
				prev_i = i - 1
		elif down == True and l[i] < l[i - 1] or (down == False and l[i] > l[i - 1]):
			prev_v = -1
			prev_i = -1
			pass
		else:
			down = not down
			if prev_s != -1:
				ans = max(ans, i - prev_s + 1)
			else:
				ans = max(ans, i - prev_s)
			prev_s = s
			if l[i - 1] == prev_v:
				if l[i] < prev_v:
					if (i - prev_i) % 2 == 0:
						s = prev_i
					else:
						s = prev_i + 1
				elif (i - prev_i) % 2 == 0:
					s = prev_i + 1
				else:
					s = prev_i
			elif l[i] < l[i - 1]:
				s = i
			else:
				s = i - 1
		i += 1
	if prev_s != -1:
		ans = max(ans, i - prev_s + 1)
	ans = max(ans, i - s + 1)
	print(ans)


for g in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	up = [[0 for i in range(n)] for j in range(2)]
	up[0][n - 1] = 1
	up[1][n - 1] = 1
	for i in range(n - 2, -1, -1):
		if a[i] < a[i + 1]:
			up[0][i] = up[1][i + 1] + 1
			up[1][i] = 1
		elif a[i] > a[i + 1]:
			up[1][i] = up[0][i + 1] + 1
			up[0][i] = 1
		else:
			up[0][i] = up[1][i + 1] + 1
			up[1][i] = up[0][i + 1] + 1
	max1 = 0
	for i in range(n):
		op = up[0][i]
		if i + op >= n:
			max1 = max(max1, op + 1)
		elif op % 2 == 0:
			max1 = max(max1, up[0][i] + 1 + up[1][i + op])
		elif op % 2 == 1:
			max1 = max(max1, up[0][i] + 1 + up[0][i + op])
		max1 = max(max1, up[1][i] + 1)
	print(max1)


t = int(input())
for _ in range(t):
	finalans = 0
	n = int(input())
	seq = list(map(int, input().split()))
	(ans, r, count, i) = (1, 0, 0, 1)
	while i < n:
		tem = i + r
		if seq[i] >= seq[i - 1] and tem % 2 == 1 or (seq[i] <= seq[i - 1] and tem % 2 == 0):
			ans += 1
			if i == n - 1 and count < 1:
				ans += 1
		elif seq[i] >= seq[i - 1] and tem % 2 == 0:
			if count < 1:
				ref = i - 1
				ans += 2
				r += 1
				count = 1
			else:
				finalans = max(ans, finalans)
				ans = i - ref
				r = ref % 2
				i -= 1
				count = 0
		elif seq[i] <= seq[i - 1] and tem % 2 == 1:
			if count < 1:
				ref = i
				ans += 2
				r += 1
				count = 1
			else:
				finalans = max(ans, finalans)
				ans = i - ref
				r = ref % 2
				i -= 1
				count = 0
		i += 1
	finalans = max(finalans, ans)
	print(finalans)


def check(b):
	ch = True
	for m in range(len(b) - 1):
		if m % 2 == 0:
			if b[m] > b[m + 1]:
				ch = False
		elif b[m] < b[m + 1]:
			ch = False
	return ch

def big(n, a):
	maxi = 1
	c = []
	for j in range(len(a)):
		for l in range(j + 1, len(a)):
			if check(a[j:l + 1]) == True:
				if len(a[j:l + 1]) > maxi:
					maxi = len(a[j:l + 1])
					c = a[j:l + 1]
	return (maxi, c)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	final_max = 0
	e = a[:]
	e.insert(0, a[0] + 1)
	if len(big(n, e)[1]) > final_max:
		final_max = len(big(n, e)[1])
	e = a[:]
	e.insert(0, a[0] + 1)
	if len(big(n, e)[1]) > final_max:
		final_max = len(big(n, e)[1])
	e = a[:]
	e.insert(len(a), a[len(a) - 1] - 1)
	if len(big(n, e)[1]) > final_max:
		final_max = len(big(n, e)[1])
	e = a[:]
	e.insert(len(a), a[len(a) - 1] + 1)
	if len(big(n, e)[1]) > final_max:
		final_max = len(big(n, e)[1])
	for l in range(1, len(a)):
		d = a[:]
		(bef, aft) = (a[l - 1], a[l])
		if bef > aft:
			d.insert(l, bef + 1)
		else:
			d.insert(l, bef - 1)
		(maxi, c) = big(l, d)
		if len(c) > final_max:
			final_max = len(c)
	print(final_max)


for i in range(int(input())):
	n = int(input())
	dp = [[1 for k in range(n)] for k in range(2)]
	nums = [int(i) for i in input().split()]
	answer = 0
	for k in range(n - 2, -1, -1):
		if nums[k + 1] >= nums[k]:
			dp[0][k] = 1 + dp[1][k + 1]
			if dp[0][k] > answer:
				answer = dp[0][k]
		if nums[k + 1] <= nums[k]:
			dp[1][k] = 1 + dp[0][k + 1]
	answer += 1
	for k in range(n - 1):
		if k + dp[0][k] >= n:
			continue
		possible = 0
		if dp[0][k] % 2 == 0:
			possible = dp[0][k] + dp[1][k + dp[0][k]] + 1
		else:
			possible = dp[0][k] + dp[0][k + dp[0][k]] + 1
		if possible > answer:
			answer = possible
	print(answer)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[[None, None], [None, None]] for _ in range(n)]
	dp[n - 1] = [[1, 2], [1, 2]]
	i = n - 2
	while i > -1:
		if a[i + 1] > a[i]:
			dp[i][1][0] = 1 + dp[i + 1][0][0]
			dp[i][1][1] = 1 + dp[i + 1][0][1]
			dp[i][0][1] = 2 + dp[i + 1][0][0]
			dp[i][0][0] = 1
		elif a[i + 1] < a[i]:
			dp[i][0][1] = 1 + dp[i + 1][1][1]
			dp[i][0][0] = 1 + dp[i + 1][1][0]
			dp[i][1][1] = 2 + dp[i + 1][1][0]
			dp[i][1][0] = 1
		else:
			dp[i][1][0] = 1 + dp[i + 1][0][0]
			dp[i][1][1] = 1 + dp[i + 1][0][1]
			dp[i][0][1] = 1 + dp[i + 1][1][1]
			dp[i][0][0] = 1 + dp[i + 1][1][0]
		i -= 1
	print(max([dp[p][1][1] for p in range(n)]))


from sys import stdin
for __ in range(int(stdin.readline())):
	(n, nums) = (int(stdin.readline()), list(map(int, stdin.readline().split())))
	longest = [1] * n
	opp_longest = [1] * n
	best = 1
	for i in range(n - 2, -1, -1):
		if nums[i] <= nums[i + 1]:
			if nums[i] == nums[i + 1]:
				opp_longest[i] += longest[i + 1]
			longest[i] += opp_longest[i + 1]
			if i + longest[i] < n:
				if longest[i] % 2:
					best = max(best, longest[i] + longest[i + longest[i]])
				else:
					best = max(best, longest[i] + opp_longest[i + longest[i]])
		else:
			opp_longest[i] += longest[i + 1]
		best = max(opp_longest[i], longest[i], best)
	print(max(best, opp_longest[0]) + 1)