Vishesh, who doesn't like maths, has to certify v-shaped tracks. A track is valid if it satisfies the following conditions :
1. There must be a constant difference between the height of pillars (not zero) of a track. For eg., if the heights of first two pillars are 7 and 5, then height of 3rd pillar must be 3. As 7-5=2 & 5-3=2.
2. The height of middle pillar must be always 1.
3. Number of pillars on the left side must be equal to the number of pillars on the right side of middle pillar. And their heights must be also equal. for example: Track with pillar heights [3 2 1 2 3] is a valid track. 
Help him in finding the valid tracks.
 
Example 1:
Input:
N = 3
A[] = {2, 1, 2}
Output:
Yes
Example 2:
Input:
N = 5
A[] = {4, 3, 2, 3, 4}
Output:
No
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function answer() which takes the array A[] and its size N as inputs and returns "Yes" if it is a valid v-shaped track. Otherwise, return "No".
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
3 <= N <= 10^{6}
1 <= H[i] <= 10^{6}

Difficulty: EASY
Tags: Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

def answer( arr, n):
    #code here.



Solutions:
def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	mid = n // 2
	if arr[mid] != 1:
		return 'No'
	else:
		constant1 = abs(arr[1] - arr[0])
		constant2 = abs(arr[-1] - arr[-2])
		if constant1 == constant2 and constant1 != 0 and (constant2 != 0):
			left = 1
			right = n - 2
			while left < right:
				if abs(arr[left] - arr[left + 1]) != constant1 or abs(arr[right] - arr[right - 1]) != constant2:
					return 'No'
				left += 1
				right -= 1
			return 'Yes'
		else:
			return 'No'


def isConstDiff(arr, n):
	diff = arr[0] - arr[1]
	if diff == 0:
		return 0
	for i in range(n - 1):
		if abs(arr[i] - arr[i + 1]) != diff:
			return 0
	return 1

def answer(arr, n):
	if n % 2 != 0 and arr[int(n / 2)] == 1:
		if isConstDiff(arr, n):
			return 'Yes'
	return 'No'


def answer(arr, n):
	if arr[n // 2] == 1:
		i = n // 2 - 1
		j = n // 2 + 1
		while i > -1 and j < n:
			if arr[i] != arr[j]:
				return 'No'
				break
			i -= 1
			j += 1
		if i == -1 and j == n:
			diff = arr[n // 2 - 1] - arr[n // 2]
			if diff == 0:
				return 'No'
			else:
				for i in range(0, n // 2 - 1, 1):
					if arr[i] - arr[i + 1] != diff:
						return 'No'
						break
				return 'Yes'
	return 'No'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	elif arr[n // 2] != 1:
		return 'No'
	else:
		p = abs(arr[1] - arr[0])
		for i in range(1, n - 1):
			t = abs(arr[i] - arr[i + 1])
			if t != p or t == 0:
				return 'No'
			else:
				p = t
		return 'Yes'


def answer(arr, n):
	if (arr[n // 2] != 1 or n % 2 == 0) or (arr[0] == 1 and arr[-1] == 1):
		return 'No'
	else:
		d = abs(arr[n // 2] - arr[n // 2 - 1])
		for i in range(n // 2):
			if abs(arr[i] - arr[i + 1]) != d:
				return 'No'
				break
		for i in range(n // 2, n - 1):
			if abs(arr[i] - arr[i + 1]) != d:
				return 'No'
				break
		return 'Yes'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	i = j = n // 2
	if arr[i] != 1:
		return 'No'
	i -= 1
	j += 1
	cd = arr[i] - arr[i + 1]
	if cd == 0:
		return 'No'
	while i >= 0 and j < n:
		if arr[i] != arr[j] or arr[i] - arr[i + 1] != cd:
			return 'No'
		i -= 1
		j += 1
	return 'Yes'


def answer(arr, n):
	mid = n // 2
	condition_1 = len(set(arr)) > 1
	condition_2 = n % 2 == 1
	condition_3 = arr[mid] == 1
	condition_4 = arr[:mid] == arr[mid + 1:][::-1]
	isValid = condition_1 and condition_2 and condition_3 and condition_4
	equalDiff = len(set([abs(arr[index] - arr[index + 1]) for index in range(n - 1)])) == 1
	return 'Yes' if isValid and equalDiff else 'No'


def answer(arr, n):
	mid = n // 2
	isValid = len(set(arr)) > 1 and n % 2 == 1 and (arr[mid] == 1) and (arr[:mid] == arr[mid + 1:][::-1])
	equalDiff = len(set([abs(arr[index] - arr[index + 1]) for index in range(n - 1)])) == 1
	return 'Yes' if isValid and equalDiff else 'No'


def answer(arr, n):
	mid = n // 2
	diff = abs(arr[0] - arr[1])
	isValid = True
	if n % 2 == 0 or arr[mid] != 1 or len(set(arr)) == 1:
		isValid = False
	elif arr[:mid] == arr[mid + 1:][::-1]:
		isValid = True
	else:
		isValid = False
	equalDiff = len(set([abs(arr[index] - arr[index + 1]) for index in range(n - 1)])) == 1
	return 'Yes' if isValid and equalDiff else 'No'


def answer(arr, n):

	def isConstDiff(a, n):
		diff = a[0] - a[1]
		for i in range(n - 1):
			if abs(a[i] - a[i + 1]) != diff or diff == 0:
				return False
		return True
	mid = n // 2
	if n % 2 == 0 or arr[mid] != 1:
		return 'No'
	if isConstDiff(arr, n):
		return 'Yes'
	return 'No'


def answer(arr, n):
	d = abs(arr[1] - arr[0])
	if n % 2 == 0:
		return 'No'
	if arr[n // 2] != 1:
		return 'No'
	flag = 1
	for i in range(n - 1):
		if abs(arr[i] - arr[i + 1]) != d:
			return 'No'
		if arr[i] != arr[i + 1]:
			flag = 0
	if flag == 1:
		return 'No'
	return 'Yes'


def answer(arr, n):
	dif = abs(arr[0] - arr[1])
	if dif == 0:
		return 'No'
	elif n % 2 == 0:
		return 'No'
	else:
		if arr[n // 2] != 1:
			return 'No'
		elif all((abs(arr[i] - arr[i + 1]) == dif for i in range(1, n - 1))):
			return 'Yes'
		return 'No'


def answer(arr, n):
	f = 0
	c = 0
	d = arr[0] - arr[1]
	for k in range(n - 1):
		if f == 0:
			if arr[k] - arr[k + 1] == d:
				c += 1
			if arr[k + 1] == 1:
				f = 1
		elif arr[k] - arr[k + 1] == -1 * d:
			c += 1
	if arr[n // 2] != 1 or (arr[n % 2] != 1 and c + 1 != n):
		return 'No'
	f = arr[:n // 2]
	s = arr[n // 2 + 1:][::-1]
	co = n // 2
	c = 0
	for j in range(len(f)):
		if len(f) == len(s) and f[j] == s[j] and (f[j] != 1) and (s[j] != 1):
			c += 1
	if co == c:
		return 'Yes'
	else:
		return 'No'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	if arr[n // 2] != 1:
		return 'No'
	j = n - 1
	m = arr[0]
	for i in range(n):
		if arr[i] != arr[j]:
			return 'No'
		j -= 1
	k = abs(arr[1] - arr[0])
	for i in range(n - 1):
		if abs(arr[i] - arr[i + 1]) != k or arr[i] - arr[i + 1] == 0:
			return 'No'
	return 'Yes'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	x = abs(arr[0] - arr[1])
	for i in range(n - 1):
		if x != abs(arr[i] - arr[i + 1]) or arr[i] - arr[i + 1] == 0:
			return 'No'
	mid = int(n / 2)
	if arr[mid] != 1:
		return 'No'
	a = arr[:mid]
	b = arr[mid + 1:]
	if sum(a) != sum(b):
		return 'No'
	return 'Yes'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	else:
		if arr[n // 2] != 1:
			return 'No'
		else:
			x = arr[0] - arr[1]
			for i in range(n // 2):
				if arr[i] - arr[i + 1] != x or arr[i] == arr[i + 1]:
					return 'No'
			for i in range(n // 2):
				if arr[i] != arr[n - i - 1]:
					return 'No'
		return 'Yes'
	return 'Yes'


def answer(arr, n):
	cd = abs(arr[1] - arr[0])
	mid = n // 2
	if arr[mid] == 1 and n % 2 != 0 and (cd != 0):
		for i in range(n - 1):
			if abs(arr[i + 1] - arr[i]) != cd:
				return 'No'
		return 'Yes'
	return 'No'


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	elif arr[n // 2] == 1:
		arr1 = arr[::-1]
		if arr1 == arr:
			d = abs(arr[1] - arr[0])
			for i in range(n // 2, n - 1):
				if abs(arr[i] - arr[i + 1]) != d or abs(arr[i] - arr[i + 1]) == 0:
					return 'No'
			return 'Yes'
		else:
			return 'No'
	else:
		return 'No'


def answer(a, n):
	if n % 2 == 0:
		return 'No'
	if a[n // 2] != 1:
		return 'No'
	d = a[0] - a[1]
	for i in range(n // 2):
		if a[i] != a[n - 1 - i]:
			return 'No'
		if a[i] <= a[i + 1]:
			return 'No'
		if a[i] - a[i + 1] != d:
			return 'No'
	return 'Yes'

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		print(answer(a, n))
		T -= 1
if __name__ == '__main__':
	main()


def answer(arr, n):
	if n % 2 == 0:
		return 'No'
	if arr[n // 2] != 1:
		return 'No'
	first = []
	second = []
	for itr in range(n // 2):
		first.append(arr[itr])
	for itr in range(n // 2 + 1, n):
		second.append(arr[itr])
	second.reverse()
	if first != second:
		return 'No'
	d = abs(arr[1] - arr[0])
	if d == 0:
		return 'No'
	for itr in range(n - 1):
		if abs(arr[itr + 1] - arr[itr]) != d:
			return 'No'
	return 'Yes'

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		print(answer(a, n))
		T -= 1
if __name__ == '__main__':
	main()


def answer(arr, n):

	def isConstDiff(a, n):
		diff = a[0] - a[1]
		for i in range(n - 1):
			if abs(a[i] - a[i + 1]) != diff or diff == 0:
				return False
		return True
	mid = n // 2
	if n % 2 == 0 or arr[mid] != 1:
		return 'No'
	if isConstDiff(arr, n):
		return 'Yes'
	return 'No'

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		print(answer(a, n))
		T -= 1
if __name__ == '__main__':
	main()


def answer(arr, n):
	dif = arr[0] - arr[1]
	if dif == 0 or n % 2 == 0:
		return 'No'
	if arr[n // 2] != 1:
		return 'No'
	for i in range(1, n - 1):
		if abs(arr[i] - arr[i + 1]) != dif:
			return 'No'
	return 'Yes'


def answer(arr, n):
	if n % 2 == 0 or n < 3:
		return 'No'
	mid = (n - 1) // 2
	if arr[mid] != 1:
		return 'No'
	l = 0
	r = n - 1
	flag = False
	dif = abs(arr[0] - arr[1])
	if dif == 0:
		return 'No'
	while l < r:
		if arr[l] != arr[r]:
			return 'No'
		if abs(arr[l] - arr[l + 1]) != dif:
			return 'No'
		l += 1
		r -= 1
	return 'Yes'


def answer(arr, n):
	flag = 1
	if arr[(n - 1) // 2] == 1 and n % 2 != 0:
		d = arr[0] - arr[1]
		if d > 0:
			for i in range(1, n - 1):
				if arr[i] == 1 and i != (n - 1) // 2:
					flag = 0
				elif arr[i] == 1 and i == (n - 1) // 2:
					if arr[i + 1] - arr[i] != d:
						flag = 0
				elif arr[i] != 1 and i < (n - 1) // 2:
					if arr[i - 1] - arr[i] != d:
						flag = 0
				elif arr[i] != 1 and i > (n - 1) // 2:
					if arr[i + 1] - arr[i] != d:
						flag = 0
		else:
			flag = 0
	else:
		flag = 0
	if flag == 1:
		return 'Yes'
	else:
		return 'No'


def answer(arr, n):
	mid = n // 2
	diff = abs(arr[0] - arr[1])
	if arr[mid] != 1 or n % 2 == 0 or diff == 0 or (arr[n - 1] != arr[0]):
		return 'No'
	else:
		for i in range(1, n):
			if abs(arr[i] - arr[i - 1]) != diff:
				return 'No'
	return 'Yes'