P1287 Boxes and Balls

Description

There are $r$ distinct boxes and $n$ distinct balls. Put these $n$ balls into the $r$ boxes, with no box left empty. Find how many different placements there are. Two placements are different if and only if there exists a ball that is placed into different boxes in the two placements.

Input Format

The input contains one line with two integers, representing $n$ and $r$.

Output Format

Output one line with a single integer representing the answer.

Explanation/Hint

#### Sample Explanation 1 There are two boxes (IDs $1, 2$) and three balls (IDs $1, 2, 3$), for a total of six arrangements, as follows: | Box ID | Arrangement 1 | Arrangement 2 | Arrangement 3 | Arrangement 4 | Arrangement 5 | Arrangement 6 | | :----: | :------------: | :------------: | :------------: | :------------: | :------------: | :------------: | | Box $1$ | Ball $1$ | Ball $2$ | Ball $3$ | Balls $2, 3$ | Balls $1, 3$ | Balls $1, 2$ | | Box $2$ | Balls $2, 3$ | Balls $1, 3$ | Balls $1, 2$ | Ball $1$ | Ball $2$ | Ball $3$ | #### Constraints For $100\%$ of the testdata, it is guaranteed that $0 \leq r \leq n \leq 10$, and the answer is less than $2^{31}$. Translated by ChatGPT 5