#P3896. [湖南集训] Clever Rabbit

[湖南集训] Clever Rabbit

Description

The clever rabbit defines three functions:

  • g(x)g(x) denotes the number formed by arranging the digits of the decimal representation of xx in descending order.
  • l(x)l(x) denotes the number formed by arranging the digits of the decimal representation of xx in ascending order.
  • f(x)=g(x)l(x)f(x)=g(x)-l(x).

If a number xx equals f(x)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 nn-digit numbers. Output the result modulo pp. Note that numbers may contain leading 00s.

Input Format

One line with two integers n,pn,p.

Output Format

One line with one integer, the required result.

4 10000

8276

Hint

Constraints

  • For 20%20\% of the testdata, it is guaranteed that 1n101 \leq n \leq 10.
  • For 100%100\% of the testdata, it is guaranteed that 1n301 \leq n \leq 30, 1p2×1091 \leq p \leq 2 \times 10^9.

Translated by ChatGPT 5