Given an integer N, find the absolute difference between sum of the squares of first N natural numbers and square of sum of first N natural numbers.
Example 1:
Input: N = 2
Output: 4 
Explanation: abs|(1^{2 }+ 2^{2}) - (1 + 2)^{2}| = 4.
Example 2:
Input: N = 3
Output: 22
Explanation: abs|(1^{2 }+ 2^{2} + 3^{2}) - (1 + 2 + 3)^{2}| = 22.
Your Task:  
You dont need to read input or print anything. Complete the function squaresDiff() which takes N as input parameter and returns the absolute difference.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def squaresDiff (self, N):
        # code here 

Solutions:
class Solution:

	def squaresDiff(self, N):
		s = 0
		s1 = 0
		for i in range(1, N + 1):
			s += i ** 2
			s1 += i
		return abs(s - s1 ** 2)


class Solution:

	def squaresDiff(self, N):
		a = int(N * (N + 1) * (2 * N + 1) / 6)
		b = int(N * (N + 1) / 2)
		c = a - b ** 2
		d = abs(c)
		return d


class Solution:

	def squaresDiff(self, N):
		a = N * (N + 1) // 2
		x = a * a
		l = []
		for i in range(1, N + 1):
			l.append(i * i)
		y = sum(l)
		return abs(x - y)


class Solution:

	def squaresDiff(self, n):
		return abs(int(n * (n + 1) * (2 * n + 1) / 6 - n * (n + 1) / 2 * (n * (n + 1) / 2)))


class Solution:

	def squaresDiff(self, N):
		a = 0
		for i in range(1, N + 1):
			a = a + i * i
		b = N * (N + 1) // 2
		c = b * b
		return abs(a - c)


class Solution:

	def squaresDiff(self, n):
		s1 = (n * (n + 1) // 2) ** 2
		s2 = n * (n + 1) * (2 * n + 1) // 6
		return abs(s2 - s1)


class Solution:

	def squaresDiff(self, N):
		l = 0
		r = 0
		for i in range(1, N + 1):
			l += i ** 2
			r += i
		return abs(l - r ** 2)


class Solution:

	def squaresDiff(self, N):
		t = int(N * (N + 1) * (2 * N + 1) / 6)
		m = int(N * (N + 1) / 2)
		n = t - m ** 2
		return abs(n)


class Solution:

	def squaresDiff(self, n):
		x = n * (n + 1) * (2 * n + 1) // 6
		y = n * (n + 1) // 2
		return abs(x - y ** 2)


class Solution:

	def squaresDiff(self, N):
		k = 0
		j = 0
		for i in range(N):
			k += (i + 1) ** 2
			j += i + 1
		if k > j ** 2:
			return k - j ** 2
		else:
			return j ** 2 - k


class Solution:

	def squaresDiff(self, N):
		c = 0
		d = 0
		for i in range(1, N + 1, 1):
			c += i ** 2
			d += i
		return abs(c - d ** 2)


class Solution:

	def squaresDiff(self, n):
		s = 0
		l = 0
		for i in range(1, n + 1):
			l += i
			s += i * i
		return abs(s - l * l)


class Solution:

	def squaresDiff(self, n):
		s = (1 - n) * (3 * n + 2) * n * (n + 1) // 12
		q = abs(s)
		return q


class Solution:

	def squaresDiff(self, N):
		ans1 = 0
		ans2 = 0
		for i in range(1, N + 1):
			ans1 = ans1 + i ** 2
			ans2 = ans2 + i
		return abs(ans1 - ans2 ** 2)


class Solution:

	def squaresDiff(self, N):
		square_num = int(N * (N + 1) * (2 * N + 1) / 6)
		num1 = int(N * (N + 1) / 2)
		num1 = num1 ** 2
		return abs(square_num - num1)


class Solution:

	def squaresDiff(self, N):
		square_num = 0
		num1 = 0
		for i in range(1, N + 1):
			square_num = square_num + i ** 2
			num1 = num1 + i
		num1 = num1 ** 2
		return abs(square_num - num1)


from math import *

class Solution:

	def squaresDiff(self, N):
		a = int(N * (N + 1) * (2 * N + 1) / 6)
		b = int(N * (N + 1) / 2) ** 2
		return abs(a - b)


class Solution:

	def squaresDiff(self, n):
		sum = 0
		sum1 = 0
		for v in range(n + 1):
			sq = v ** 2
			sum += sq
		for y in range(n + 1):
			sum1 += y
			pr = sum1 ** 2
		a = abs(sum - pr)
		return a


class Solution:

	def squaresDiff(self, N):
		(v1, v2) = (0, 0)
		for x in range(1, N + 1):
			v1 += x ** 2
			v2 += x
		return abs(v1 - v2 ** 2)


class Solution:

	def squaresDiff(self, N):
		b = N * (N + 1) // 2
		a = N * (1 + N) * (2 * N + 1) // 6
		return abs(a - b * b)


class Solution:

	def squaresDiff(self, N):
		s = N * (N + 1) * (2 * N + 1) // 6
		t = (N * (N + 1) // 2) ** 2
		return abs(s - t)


class Solution:

	def squaresDiff(self, N):
		a1 = N * (N + 1) * (2 * N + 1) // 6
		a2 = (N * (N + 1) // 2) ** 2
		return abs(a1 - a2)


class Solution:

	def squaresDiff(self, N):
		a1 = 0
		a2 = 0
		for i in range(1, N + 1):
			ans = i * i
			a1 += ans
			a2 += i
		return abs(a1 - a2 * a2)


class Solution:

	def squaresDiff(self, N):
		sum = 0
		for i in range(1, N + 1):
			sum += i
		res = sum ** 2
		j = N * (N + 1) * (2 * N + 1) // 6
		ans = abs(j - res)
		return ans


class Solution:

	def squaresDiff(self, N):
		k = 0
		k1 = 0
		while N >= 1:
			k = k + N ** 2
			k1 = k1 + N
			N = N - 1
		d = k - k1 ** 2
		if d > 0:
			return d
		else:
			d = -d
			return d


class Solution:

	def squaresDiff(self, N):
		squr_of_sum = (N * (N + 1) / 2) ** 2
		sum_of_squrs = N * (N + 1) * (2 * N + 1) / 6
		return abs(int(sum_of_squrs) - int(squr_of_sum))


class Solution:

	def squaresDiff(self, N):
		s = 0
		sum = 0
		for i in range(1, N + 1):
			s += i
		for j in range(1, N + 1):
			sum += j ** 2
		x = s ** 2
		if x > sum:
			return x - sum
		else:
			return sum - x


class Solution:

	def squaresDiff(self, n):
		return int(abs(n * (n + 1) * (n - 1) * (3 * n + 2) / 12))


class Solution:

	def squaresDiff(self, N):
		sq_sum = 0
		sum = 0
		for i in range(N + 1):
			sq_sum += i * i
			sum += i
		sum *= sum
		return abs(sq_sum - sum)


class Solution:

	def squaresDiff(self, N):
		sq = N * (N + 1) * (2 * N + 1) // 6
		sumn = N * N * (N + 1) * (N + 1) // 4
		return abs(sq - sumn)


class Solution:

	def squaresDiff(self, N):
		ssq = 0
		s = 0
		for i in range(1, N + 1):
			ssq = ssq + pow(i, 2)
			s = s + i
		a = abs(ssq - s * s)
		return a


class Solution:

	def squaresDiff(self, N):
		return abs(sum([i ** 2 for i in range(N + 1)]) - sum(range(N + 1)) ** 2)


class Solution:

	def squaresDiff(self, N):
		squares = int(N * (N + 1) * (2 * N + 1) / 6)
		sum = int(N * (N + 1) / 2)
		return sum ** 2 - squares


class Solution:

	def squaresDiff(self, N):
		return N * (N + 1) * (3 * N ** 2 - N - 2) // 12


class Solution:

	def squaresDiff(self, N):
		return abs(N * (2 * N + 1) * (N + 1) // 6 - (N * (N + 1) // 2) ** 2)


class Solution:

	def squaresDiff(self, n):
		k = n * (n + 1) // 2
		k = k * k
		n = n * (n + 1) * (2 * n + 1) // 6
		return abs(k - n)


class Solution:

	def squaresDiff(self, N):
		if N in range(10 ** 3 + 1):
			numbers = [i for i in range(1, N + 1)]
			squared_numbers = [i * i for i in range(1, N + 1)]
			diff = abs(sum(squared_numbers) - pow(sum(numbers), 2))
			return diff


class Solution:

	def squaresDiff(self, N):
		n = N
		l = n * (n + 1) * (2 * n + 1) // 6
		k = n * (n + 1) // 2
		k = k ** 2
		m = abs(l - k)
		return m


class Solution:

	def squaresDiff(self, N: int) -> int:
		x = y = 0
		for i in range(1, N + 1):
			x += i ** 2
			y += i
		return abs(x - y ** 2)


class Solution:

	def squaresDiff(self, N):
		return (3 * pow(N, 4) + 2 * pow(N, 3) - 3 * pow(N, 2) - 2 * N) // 12


class Solution:

	def squaresDiff(self, n):
		sum = 0
		sum1 = 0
		for i in range(1, n + 1):
			sum += i ** 2
		for j in range(1, n + 1):
			sum1 += j
			sum2 = sum1 ** 2
		result = sum - sum2
		return abs(result)


class Solution:

	def squaresDiff(self, n):
		x = 1
		sum_of_sqr = n * (n + 1) * (2 * n + 1) // 6
		sqr_of_sum = n * (n + 1) // 2
		x = sqr_of_sum * sqr_of_sum
		return abs(sum_of_sqr - x)


class Solution:

	def squaresDiff(self, N):
		sum_of_squares = 0
		square_of_sum = 0
		for i in range(1, N + 1):
			sum_of_squares += i * i
			square_of_sum += i
		square_of_sum = square_of_sum ** 2
		return square_of_sum - sum_of_squares


class Solution:

	def squaresDiff(self, N):
		x = N * (N + 1) * (2 * N + 1) // 6 - (N * (N + 1) // 2) ** 2
		if '-' in str(x):
			return -x


class Solution:

	def squaresDiff(self, n):
		from math import pow
		r = 0
		s = 0
		for i in range(1, n + 1):
			r = r + int(pow(i, 2))
			s = s + i
		k = int(abs(r - int(pow(s, 2))))
		return k


class Solution:

	def squaresDiff(self, N):
		self.num = N
		n1 = 0
		n2 = 0
		for i in range(1, self.num + 1):
			n1 = n1 + i ** 2
			n2 = n2 + i
		n3 = n2 ** 2
		result = abs(n1 - n3)
		return result


class Solution:

	def squaresDiff(self, N):
		r1 = (N * (N + 1) // 2) ** 2
		r2 = 0
		for i in range(1, N + 1):
			r2 += i * i
		return abs(r1 - r2)


class Solution:

	def squaresDiff(self, N):
		n1 = int(N * (N + 1) * (2 * N + 1) / 6)
		n2 = int(N * (N + 1) / 2)
		n3 = n1 - n2 ** 2
		n4 = abs(n3)
		return n4


class Solution:

	def squaresDiff(self, N):
		l = int(N * (N + 1) * (2 * N + 1) / 6)
		m = int(N * (N + 1) / 2)
		return abs(l - m ** 2)


class Solution:

	def squaresDiff(self, N):
		sum1 = N * (N + 1) * (2 * N + 1) / 6
		x = N * (N + 1) / 2
		sum2 = x * x
		return int(abs(sum1 - sum2))


class Solution:

	def squaresDiff(self, N):
		sq = N * (N + 1) * (2 * N + 1) // 6
		p = N * (N + 1) // 2
		return abs(sq - pow(p, 2))


class Solution:

	def squaresDiff(self, N):
		sumsq = 0
		sqsum = 0
		for i in range(1, N + 1):
			sumsq += i ** 2
			sqsum += i
		return abs(sumsq - sqsum ** 2)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.squaresDiff(N))


class Solution:

	def squaresDiff(self, N):
		l = []
		Sum = 0
		for i in range(1, N + 1):
			l.append(pow(i, 2))
		for i in range(1, N + 1):
			Sum += i
		return abs(sum(l) - Sum * Sum)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.squaresDiff(N))


class Solution:

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


class Solution:

	def squaresDiff(self, N):
		s = 0
		m = 0
		for i in range(1, N + 1):
			s = s + i
			m = m + i * i
		return abs(m - s * s)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.squaresDiff(N))