P3896 [Hunan Training Camp] Clever Rabbit

Description

The clever rabbit defines three functions: - $g(x)$ denotes the number formed by arranging the digits of the decimal representation of $x$ in descending order. - $l(x)$ denotes the number formed by arranging the digits of the decimal representation of $x$ in ascending order. - $f(x)=g(x)-l(x)$. If a number $x$ equals $f(x)$, the rabbits call it a lucky number. Now the rabbits want to compute the sum of squares of all lucky numbers among all $n$-digit numbers. Output the result modulo $p$. Note that numbers may contain leading $0$s.

Input Format

One line with two integers $n,p$.

Output Format

One line with one integer, the required result.

Explanation/Hint

#### Constraints - For $20\%$ of the testdata, it is guaranteed that $1 \leq n \leq 10$. - For $100\%$ of the testdata, it is guaranteed that $1 \leq n \leq 30$, $1 \leq p \leq 2 \times 10^9$. Translated by ChatGPT 5