Given a number N. We have to find maximum sum of all permutations of numbers from 1 to N. The maximum sum will be sum of absolute difference of adjacent elements in array.
Example 1:
Input: N = 2
Output: 1
Explaination: Permutations of 2 are: 
{1, 2} = 1, {2, 1} = 1.
Example 2:
Input: N = 3
Output: 3
Explaintation: Permutations of size 3 are: 
{1, 2, 3} = 1 + 1, {1, 3, 2} = 2 + 1 
{2, 1, 3} = 1 + 2, {2, 3, 1} = 1 + 2 
{3, 1, 2} = 2 + 1, {3, 2, 1} = 1 + 1 
Your Task:
You do not need to read input or print anything. Your task is to complete the function maxSum() which takes N as input parameter and returns the maximum possible difference sum from all permutations of N numbers.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 1000

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def maxSum(self, N):
        # code here

Solutions:
class Solution:

	def maxSum(self, N):
		if N == 1:
			return 1
		return N * (N - 1) // 2 + N // 2 - 1


class Solution:

	def maxSum(self, n):
		return n * (n + 1) // 2 + n // 2 - (n + 1)


class Solution:

	def maxSum(self, N):
		sum1 = 0
		n = N
		if N == 1:
			return 1
		sum1 = n * (n - 1) / 2 + n / 2 - 1
		return int(sum1)


class Solution:

	def maxSum(self, n):
		if n == 1:
			return 1
		else:
			return n * (n - 1) // 2 - 1 + n // 2


class Solution:

	def maxSum(self, N):
		return N * (N - 1) // 2 + max(0, (N - 2) // 2)


class Solution:

	def maxSum(self, N):
		if N == 1:
			return N
		else:
			return int(N * (N - 1) / 2 - 1 + N / 2)


from itertools import permutations

class Solution:

	def maxSum(self, N):
		if N == 1:
			return 1
		return int(N * (N - 1) / 2 + N / 2 - 1)


class Solution:

	def maxSum(self, N):
		if N == 1:
			return 1
		if N == 2:
			return 1
		if N == 3:
			return 3
		return int((N - 1) * N * 0.5 - 1 + N * 0.5)


class Solution:

	def maxSum(self, N):
		arr = [i for i in range(1, N + 1)]
		i = 0
		j = N - 1
		flag = True
		s = 0
		while i < j:
			s += abs(arr[i] - arr[j])
			if not flag:
				j -= 1
			else:
				i += 1
			flag = not flag
		s += abs(arr[i] - arr[0])
		return s - 1


class Solution:

	def maxSum(self, N):
		if N == 1:
			return 1
		return N * (N - 1) // 2 + N // 2 - 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.maxSum(N))


class Solution:

	def maxSum(self, n):
		ans = n // 2 * (n // 2) + ((n // 2) ** 2 - 1)
		if n % 2 == 0:
			return int(ans)
		else:
			return int(ans) + n - 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.maxSum(N))


class Solution:

	def maxSum(self, n):
		a = []
		for i in range(1, n + 1):
			a.append(i)
		i = 0
		j = n - 1
		sm = 0
		nt = True
		while i < j:
			sm += abs(a[i] - a[j])
			if not nt:
				j -= 1
			else:
				i += 1
			nt = not nt
		sm += abs(a[i] - a[0])
		return sm - 1


class Solution:

	def maxSum(self, n):
		ans = n - 1 + n - 2
		n -= 3
		while n > 0:
			ans += 2 * n
			n -= 2
		return ans


class Solution:

	def maxSum(self, N):
		l = N - 1
		return N * (N - 1) // 2 - 1 + N // 2


class Solution:

	def maxSum(self, N):
		if N % 2 == 1:
			mid = (N + 1) // 2
			mi = (mid - 2) * (mid - 1)
			mi += 2 * mid - 1
			ad = (N * (N + 1) // 2 - mid * (mid + 1) // 2) * 2
			return ad - mi
		else:
			mid = N // 2
			mi = (mid - 1) * mid
			mi += mid
			ad = (N * (N + 1) // 2 - mid * (mid + 1) // 2) * 2
			ad -= mid + 1
			return ad - mi


class Solution:

	def maxSum(self, N):
		if N == 1:
			return N
		array = [i for i in range(N)]
		perm = []
		while array:
			smallest = array.pop(0)
			perm.append(smallest)
			if array:
				biggest = array.pop(-1)
				perm.append(biggest)
		ans = 0
		min_diff = float('inf')
		for i in range(N):
			diff = abs(perm[i % N] - perm[(i + 1) % N])
			min_diff = min(diff, min_diff)
			ans += diff
		ans -= min_diff
		return ans


import math

class Solution:

	def maxSum(self, n):
		if n == 1:
			return 1
		lst = list(range(1, n + 1))
		temp = []
		ans = 0
		(i, j) = (0, n - 1)
		while i <= j:
			if i == j:
				temp.append(lst[i])
			else:
				temp.append(lst[i])
				temp.append(lst[j])
			i += 1
			j -= 1
		val = temp.pop()
		temp = [val] + temp
		for i in range(n - 1):
			ans += abs(temp[i + 1] - temp[i])
		return ans


import math

class Solution:

	def maxSum(self, n):
		if n == 1:
			return 1
		return math.floor(n * n / 2 - 1)


class Solution:

	def maxSum(self, N):
		t1 = (N - 1) * N // 2 - 1
		return abs(t1 + N // 2)


class Solution:

	def maxSum(self, n):
		if n == 1:
			return 1
		if n & 1 == 0:
			half = n // 2 - 1
			ans = 2 * (half * (half + 1)) + n - 1
		else:
			half = (n - 1) // 2
			ans = half * half * 2 + n - 2
		return ans


class Solution:

	def maxSum(self, N):
		if N == 1:
			return 1
		t = (N - 1) * N // 2
		return int(t + N / 2 - 1)