Walking Home Separately
Time limit1sMemory limit1024 MB
Count the ways two people can walk from (1,1) to (N,M) using only right and down moves, without sharing any cell except the start and the end.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
Tosuni and Tojuni had a big fight and now want to walk home separately.

Tosuni and Tojuni move on a two-dimensional grid of rows and columns, and they can only move right or down.
Let be the position reached from by moving down cells and right cells.
The couple starts at and moves one cell at a time at the same moment until they reach their home at .
During this walk, they want to avoid meeting in the same cell, except at the starting point and at the destination (home).

Find the number of ways the couple can walk home.
Input
The first line contains integers and separated by a space. ()
Output
Print the number of ways the couple can walk home, modulo . ( is a prime number.)