White Squares

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types

Mahmut was a hardworking student, an intelligent person, and a well-behaved child. But all of these lost their purpose with a question from his teacher. Mahmut started counting and never stopped after his teacher asked "What will be the number of rectangles which include more white squares than black ones on a \(\mathbf{N}\times\mathbf{M}\) chessboard?" to the class. His friends knew that the only way to save Mahmut was to find the correct answer.

Mahmut's closest friend Şehmuz has reached you for your help to find the answer to this problem. Find the answer and save Mahmut from this painful situation.

The upper left square of the chessboard is white.

For 2 rectangles to be different either their top left corner or bottom right corner must be different than each other.


Input consists of the width \(\mathbf{N}\) and the height \(\mathbf{M}\) of the chessboard.

  • \(1\leq\mathbf{N,M}\leq 10^5\)


The number of rectangles that have more white squares.



3 3




The board is 3x3 and the square in the upper left is white. Therefore, there are 5 1x1 white squares and 4 1x1 black squares in total.

We can choose 5 white squares which are 1x1 rectangles.

Additionally, we can choose 4 of the 1x3 and 3x1 rectangles in total:

  • First row of the chessboard
  • Third row of chessboard
  • First column of the chessboard
  • Third column of the chessboard

Besides, we can choose the board itself (3x3). In total, we choose 5 + 4 + 1 = 10 rectangles.