#P3223. Lineup Arrangements with Restrictions

    ID: 16480 Type: Default 1000ms 256MiB

Lineup Arrangements with Restrictions

Lineup Arrangements with Restrictions

There are \(n\) distinct male students, \(m\) distinct female students and 2 distinct teachers that need to stand in a line for a physical examination. The arrangement must satisfy the following conditions:

  • No two female students are adjacent.
  • No two teachers are adjacent.

Compute the total number of valid arrangements. Note that all individuals are distinct.

Hint: First arrange the male students and then insert the female students in the gaps. Afterward, insert the two teachers into the lineup ensuring they are not consecutive.

The final formula (when \(m \leq n+1\)) is given by:

\[ \text{Answer} = n!\cdot \binom{n+1}{m}\cdot m!\cdot \binom{n+m+1}{2}\cdot 2!, \]

If \(m > n+1\), the answer is 0.

inputFormat

The input consists of two integers separated by space or newline:

  1. \(n\): the number of male students
  2. \(m\): the number of female students

outputFormat

Output a single integer: the total number of valid arrangements satisfying the given conditions.

sample

1 1
12