Editorial
Consider the size of a rectangle drawn on the grid. Let's examine how many ways we can choose the value of . The grid contains rows of squares, and therefore there are horizontal lines in the grid. Let's number them from to . We choose two lines and . Drawing a segment between them forms the vertical side a of the rectangle. The number of ways to choose two numbers and from the set is equal to . For example, for there are options to choose the vertical side of the rectangle:
Similarly, the grid has vertical lines. The number of ways to select the horizontal side of a rectangle is .
Therefore the number of different rectangles on the grid is equal to
Example
For a rectangle there are:
rectangles of size ;
rectangles of size ;
horizontal rectangles ;
vertical rectangles ;
rectangles ;
rectangle ;
The total result is rectangles.
Algorithm realization
Since , the number of rectangles can be as large as . This result is beyond the bounds of a -bit integer. Therefore, let's implement the solution in Python.
n, m = map(int,input().split()) a = (n + 1) * n // 2 b = (m + 1) * m // 2 res = a * b print(res)