3331 - Bob and Solitary Kings

Created by Alfredo Fundora Rolo
Added by alfredo12345 (2015-06-15)
Limits
Total Time: 5000 MS | Test Time: 1000 MS |Memory: 256 MB | Output: 64 MB | Size: 16 KB
Enabled languages
Available in

Description

A chess game can end in a draw when all non-King pieces are captured, leaving the White and Black Kings as the only remaining pieces on the chess board; they must be in non-attacking positions. Kings are said to be in attacking positions if they are on adjacent cells in the horizontal, vertical, or diagonal directions. Two cells are adjacent if they share a common side or corner.

Two chess endgame positions with Kings as the only remaining pieces are considered to be equal when the position of the White King is exactly the same in both games and the position of the Black King is exactly the same in both games. Otherwise, we say that the two endgame positions are different.

Bob is a smart boy who loves chess; he has the task to count how many different endgame positions have Kings as the only remaining pieces on the board and in non-attacking positions? To make the question more interesting, he should assume that the game is played on a non-standard chess board with dimensions N x M. Can you help Bob with the task?
Un juego de ajedrez puede terminar en un empate cuando se capturan todas las piezas excepto los Reyes, dejando a los Reyes Blanco y Negro como las únicas piezas que quedan en el tablero; los mismos deben estar en posiciones que no se ataquen. Se dice que dos Reyes están en posiciones atacadas si están en casillas adyacentes en las direcciones horizontales, verticales o diagonales. Dos casillas son adyacentes si comparten un lado común o una esquina.

Dos posiciones de finales de ajedrez con los Reyes como las únicas piezas que quedan se consideran iguales cuando la posición del Rey Blanco es exactamente igual en ambos juegos y la posición del Rey Negro es exactamente igual en ambos casos. De lo contrario, se dice que las dos posiciones de finales son diferentes.

Bob es un chico inteligente que ama el ajedrez; él tiene la tarea de contar el número de diferentes posiciones de finales que tienen los Reyes como las únicas piezas en el tablero y en posiciones que no se ataquen. Para hacer la pregunta más interesante, supongamos que el juego se juega en un tablero de ajedrez no estándar de dimensiones N x M. ¿Puede usted ayudar a Bob?
A chess game can end in a draw when all non-King pieces are captured, leaving the White and Black Kings as the only remaining pieces on the chess board; they must be in non-attacking positions. Kings are said to be in attacking positions if they are on adjacent cells in the horizontal, vertical, or diagonal directions. Two cells are adjacent if they share a common side or corner.

Two chess endgame positions with Kings as the only remaining pieces are considered to be equal when the position of the White King is exactly the same in both games and the position of the Black King is exactly the same in both games. Otherwise, we say that the two endgame positions are different.

Bob is a smart boy who loves chess; he has the task to count how many different endgame positions have Kings as the only remaining pieces on the board and in non-attacking positions? To make the question more interesting, he should assume that the game is played on a non-standard chess board with dimensions N x M. Can you help Bob with the task?

Input specification

Input consists of several test cases, no more than 1000. Each case consists of a line with integers N and M (1 <= N, M <= 10^4) separated by a single blank space. Last line of input is followed by a line containing two zeros, which should not be processed.
La entrada consiste de múltiples casos de prueba, no más de 1000. Cada caso consiste en una línea con los números enteros N y M (1 <= N, M <= 10^4) separados por un espacio en blanco. Al último caso de prueba le sigue una línea con dos ceros que no debe ser procesada.
Input consists of several test cases, no more than 1000. Each case consists of a line with integers N and M (1 <= N, M <= 10^4) separated by a single blank space. Last line of input is followed by a line containing two zeros, which should not be processed.

Output specification

For each case output a line with the possible number of endgame positions which have only kings on the board and in non-attacking positions.
Por cada caso usted debe imprimir una línea con la cantidad posible de posiciones de finales que tiene los Reyes como las únicas piezas en el tablero y en posiciones que no se ataquen.
Input consists of several test cases, no more than 1000. Each case consists of a line with integers N and M (1 <= N, M <= 10^4) separated by a single blank space. Last line of input is followed by a line containing two zeros, which should not be processed.

Sample input

2 3
4 4
0 0

Sample output

8
156

Hint(s)