Given a mxn matrix, count the number of squares in the matrix. 
Example 1:
Input:
m = 2, n = 2
Output:
5
Explanation:
There are a total of 5 squares in a 2*2
matrix. Four 1*1 squares and one 2*2 square.
Example 2:
Input:
m = 4, n = 3
Output:
20
Explanation:
There are a total of 20 squares in a 4*3
matrix. 
Your Task:
You don't need to read input or print anything. Your task is to complete the function squaresInMatrix() which takes 2 Integers m and n as input and returns the number of total squares in a m*n matrix.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= m,n <= 10^{4}

Difficulty: EASY
Tags: Matrices

Data structures

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

Starter code:
#User function Template for python3



class Solution:

    def squaresInMatrix(self, m, n):

        # code here 

Solutions:
class Solution:

	def squaresInMatrix(self, m, n):
		sum = 0
		for i in range(min(m, n)):
			sum += (m - i) * (n - i)
		return sum


class Solution:

	def squaresInMatrix(self, m, n):
		sz = min(m, n)
		of = max(m, n)
		diff = of - sz
		qs = sz * (sz + 1) * (sz * 2 + 1) / 6
		dfs = sz / 2 * (2 * diff + (sz - 1) * diff)
		return int(qs + dfs)


class Solution:

	def squaresInMatrix(self, m, n):
		ans = 0
		while m > 0 and n > 0:
			p = m * n
			m -= 1
			n -= 1
			ans += p
		return ans


class Solution:

	def squaresInMatrix(self, m, n):
		if n < m:
			(m, n) = (n, m)
		return m * (m + 1) * (2 * m + 1) // 6 + (n - m) * m * (m + 1) // 2


class Solution:

	def squaresInMatrix(self, m, n):
		count = 0
		while m > 0 and n > 0:
			product = m * n
			m -= 1
			n -= 1
			count += product
		return count


class Solution:

	def squaresInMatrix(self, m, n):
		sum = 0
		while m != 0 and n != 0:
			prod = m * n
			sum += prod
			n -= 1
			m -= 1
		return sum


class Solution:

	def squaresInMatrix(self, m, n):
		c = 0
		for i in range(0, min(m, n) + 1):
			c += (m - i) * (n - i)
		return c


class Solution:

	def squaresInMatrix(self, m, n):
		(n1, n2) = (max(m, n), min(m, n))
		return n2 * (n2 + 1) * (3 * n1 - n2 + 1) // 6


class Solution:

	def squaresInMatrix(self, m, n):
		summa = 0
		while m > 0 and n > 0:
			summa += m * n
			m -= 1
			n -= 1
		return summa


class Solution:

	def squaresInMatrix(self, m, n):
		x = min(m, n)
		return int(x * (x + 1) * (2 * x + 1) / 6 + abs(m - n) * (x * (x + 1) / 2))


class Solution:

	def squaresInMatrix(self, m, n):
		s = 0
		k = min(m, n)
		for i in range(k):
			s += (m - i) * (n - i)
		return s


from math import floor

class Solution:

	def squaresInMatrix(self, m, n):
		if m < n:
			(m, n) = (n, m)
		return n * (n + 1) * (3 * m - n + 1) // 6

	def squaresInMatrix2(self, m, n):
		sq = 0
		x = min(m, n)
		for i in range(x):
			sq += (m - i) * (n - i)
		return sq


class Solution:

	def squaresInMatrix(self, m, n):
		squares = 0
		val = min(m, n)
		for z in range(val):
			squares += (m - z) * (n - z)
		return squares


class Solution:

	def squaresInMatrix(self, m, n):
		sq = 0
		x = min(m, n)
		for i in range(x):
			sq += (m - i) * (n - i)
		return sq


class Solution:

	def squaresInMatrix(self, m, n):
		if n < m:
			temp = m
			m = n
			n = temp
		return int(m * (m + 1) * (3 * n - m + 1) / 6)


class Solution:

	def squaresInMatrix(self, m, n):
		t = min(m, n)
		count = 0
		i = 1
		for i in range(t):
			count += (n - i) * (m - i)
		return count


class Solution:

	def squaresInMatrix(self, m, n):
		sum_squares = 0
		if n <= m:
			for i in range(0, n):
				sum_squares += (m - i) * (n - i)
		elif m < n:
			for i in range(0, m):
				sum_squares += (m - i) * (n - i)
		return sum_squares


class Solution:

	def squaresInMatrix(self, m, n):
		if m == n:
			return m * (m + 1) * (2 * m + 1) // 6
		else:
			a = min(m, n)
			b = m + n - a
			return a * (a + 1) * (2 * a + 1) // 6 + (b - a) * a * (a + 1) // 2


class Solution:

	def squaresInMatrix(self, m, n):
		s = 0
		for i in range(min(m, n)):
			s += (m - i) * (n - i)
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(m, n) = map(int, input().split())
		ob = Solution()
		print(ob.squaresInMatrix(m, n))


class Solution:

	def squaresInMatrix(self, m, n):
		if m > n:
			(m, n) = (n, m)
		return int(m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(m, n) = map(int, input().split())
		ob = Solution()
		print(ob.squaresInMatrix(m, n))


class Solution:

	def squaresInMatrix(self, m, n):
		mv = min(m, n)
		diff = abs(m - n)
		x = mv * (mv + 1) * (2 * mv + 1) // 6
		y = diff * (mv * (mv + 1)) // 2
		return x + y
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(m, n) = map(int, input().split())
		ob = Solution()
		print(ob.squaresInMatrix(m, n))


class Solution:

	def squaresInMatrix(self, m, n):
		cnt = 0
		while m >= 1 and n >= 1:
			cnt += m * n
			m -= 1
			n -= 1
		return cnt
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(m, n) = map(int, input().split())
		ob = Solution()
		print(ob.squaresInMatrix(m, n))


class Solution:

	def squaresInMatrix(self, m, n):
		sum_square = 0
		while m * n > 0:
			sum_square += m * n
			m -= 1
			n -= 1
		return sum_square


class Solution:

	def squaresInMatrix(self, m, n):
		k = min(m, n)
		z = m * n
		count = 0
		for i in range(k):
			count += (m - i) * (n - i)
		return count


class Solution:

	def squaresInMatrix(self, m, n):
		c = 0
		while m != 0 and n != 0:
			a = m * n
			m -= 1
			n -= 1
			c = c + a
		return c


class Solution:

	def squaresInMatrix(self, m, n):
		i = 0
		j = 0
		sum = 0
		while i <= m and j <= n:
			sum += m * n
			m -= 1
			n -= 1
		return sum


class Solution:

	def squaresInMatrix(self, m, n):
		if m == n:
			p = n * (n + 1) * (2 * n + 1)
			return int(p / 6)
		elif m < n:
			p = m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2
			return int(p)
		else:
			p = n * (n + 1) * (2 * n + 1) / 6 + (m - n) * n * (n + 1) / 2
			return int(p)


class Solution:

	def squaresInMatrix(self, m, n):
		if m < n:
			l = m
			s = n
		else:
			l = n
			s = m
		a = l * (l + 1) * (3 * s - l + 1) / 6
		return int(a)


class Solution:

	def squaresInMatrix(self, m, n):
		Sum = 0
		while m > 0 and n > 0:
			sq = m * n
			Sum += sq
			m -= 1
			n -= 1
		return Sum


class Solution:

	def squaresInMatrix(self, m, n):
		a = min(m, n)
		b = a - 1
		return int(a * m * n + b * (b + 1) * (2 * b + 1) / 6 - (m + n) * (b * (b + 1) / 2))


class Solution:

	def squaresInMatrix(self, m, n):
		M = min(m, n)
		N = max(m, n)
		return int(M * (M + 1) * (2 * M + 1) / 6 + (N - M) * M * 0.5 * (M + 1))


class Solution:

	def squaresInMatrix(self, m, n):
		total_squares = 0
		for i in range(0, n):
			x = (m - i) * (n - i)
			if x < 0:
				break
			total_squares += x
		return total_squares