Problems > All the Rectangles

All the Rectangles

Difficulty: 1200 2000 ms 128 MB

math combinatorics

How many axis-aligned rectangles (of any size) does an N×M grid contain?

Input: one line with two integers N and M.

Output: C(N+1, 2) · C(M+1, 2).

Constraints:

  • 1 ≤ N, M ≤ 105

Sample Tests

Input 1
2 2
Output 1
9
Input 2
1 1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.