#B4299. Hamiltonian Cycle in a Flower Grid
Hamiltonian Cycle in a Flower Grid
Hamiltonian Cycle in a Flower Grid
Little Blue arranged multiple flower pots in an \( M \times N \) matrix. Every day, she starts at the top-left pot and waters each flower. The following conditions must be satisfied:
- The distance between any two adjacent pots is equal.
- Each move in her watering route is a straight line (you can only move horizontally or vertically, no diagonal moves).
- Except for the top-left pot, every other pot is visited exactly once.
- After watering all the flowers, she returns to the top-left pot.
Given values \( M \) and \( N \), determine the total number of routes that satisfy these conditions. If there is no valid route, output \( 0 \).
For example, when \( M=3 \) and \( N=4 \), there are \( 4 \) valid routes.
inputFormat
The input consists of a single line containing two integers \( M \) and \( N \) separated by a space.
outputFormat
Output a single integer representing the number of valid routes.
sample
2 2
2