#P8707. Path Counting in a Grid with Forbidden Cells

    ID: 21871 Type: Default 1000ms 256MiB

Path Counting in a Grid with Forbidden Cells

Path Counting in a Grid with Forbidden Cells

You are given a grid with n rows and m columns. The cells of the grid are indexed like a 2D array: the rows are numbered from 1 to \( n \) (top to bottom) and the columns from 1 to \( m \) (left to right). A cell is identified by its row and column number \((i, j)\).

A person starts at cell \((1, 1)\) and wants to reach cell \((n, m)\) by only moving right or down at each step.

However, there is a constraint: if both the row number and the column number of a cell are even (i.e. \(i \% 2 = 0\) and \(j \% 2 = 0\)), then that cell is forbidden and cannot be entered, even if it is the destination.

Your task is to determine the number of possible paths from the starting cell to the destination cell that do not pass through any forbidden cell.

Note: The movement is restricted to only right or down directions.

inputFormat

The input consists of a single line containing two integers n and m (\(1 \leq n, m \leq 1000\)), representing the number of rows and columns of the grid respectively.

outputFormat

Output a single integer: the number of valid paths from cell \((1, 1)\) to cell \((n, m)\) while avoiding the forbidden cells.

sample

2 2
0