#B4299. Hamiltonian Cycle in a Flower Grid

    ID: 11955 Type: Default 1000ms 256MiB

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:

  1. The distance between any two adjacent pots is equal.
  2. Each move in her watering route is a straight line (you can only move horizontally or vertically, no diagonal moves).
  3. Except for the top-left pot, every other pot is visited exactly once.
  4. 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