SNOOKER  Snooker
Consider a rectangular snooker table with pockets only at the 4 corners of the rectangle as shown in the image below. Consider all integer points on the boundary of the table. At each point, except the four corners (four pockets), you are allowed to hit the ball at an angle of 45 degrees from the side of the table from which you are hitting the ball.
From any point on the boundary you can hit the ball in two directions and they are considered to be two different ways. For instance in the image shown below, from the point S the ball can be hit in two ways as shown.
Given the dimensions of the board your task is to find the number of ways in which the ball can be hit so that it eventually reaches one of the four holes.
Consider the ball to be of negligible size, like a point. Also assume that the ball does not lose energy due to collisions or friction  it keeps moving until it drops into a hole.
Input
The input has multiple test cases. Each test case consists of two space separated integers M and N, 2 ≤ M,N ≤ 10^5, representing the dimensions of the table. M=N=0 indicates the end of tests. There are at most 300 testcases.
Output
For each test case output the number of ways as described, in a separate line.
Example
Input: 2 2 2 4 3 5 0 0 Output: 0 4 24
hide comments
maxboom321:
20180614 12:45:42
http://sigmaa.maa.org/mcst/PosterActivitySessions/documents/BilliardsPoster.pdf


Ajey Golsangi:
20130617 07:24:10
Tedious to code this one. 

sudipto das:
20110206 15:21:39
this is a simple application of schoollevel geometry................ 
Added by:  Swarnaprakash 
Date:  20090116 
Time limit:  1.970s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Kurukshetra 09 OPC 