Black and White Painting
Time limit1sMemory limit128 MB
Count the 8x8 blocks inside an n by m checkerboard whose bottom-right square is white, given the color of the painting's bottom-right corner.
- Level
Easy3 of 10
- Topics
- Math, Combinatorics, Implementation, Brute force
- Solved
- No attempts yet
Statement
You are visiting an art museum full of modern paintings. One painting consists solely of black and white squares arranged in rows and columns like a chessboard, so that no two squares that share an edge have the same colour.
Because you are bored, you start to wonder how many chessboards are embedded within this painting. Here an embedded chessboard is any block of consecutive rows and consecutive columns of the painting, and its bottom-right corner square must always be white.
Input
The input contains several test cases. Each test case is a single line with three integers , and (): is the number of rows of the painting and is the number of columns. The value is or , where means the bottom-right corner square of the painting is black and means that corner square is white.
The last test case is followed by a line containing three zeros, which is not part of the input and must not be processed.
Output
For each test case, print on its own line the number of chessboards embedded within the given painting — that is, the number of blocks of consecutive rows and consecutive columns whose bottom-right corner square is white.