#include<bits/stdc++.h> #define LL long long #define IL inline #define re register usingnamespace std; constint N = 30 + 5, A = 15; int n, p, m, o; int t, cnt; int a[A], b[N], c[N], d[N]; int B[A]; //桶 int ans = 0; IL voidcheck() { t = 0; for (re int i = 0; i <= 9; ++i) for (re int j = 1; j <= B[i]; ++j) c[++t] = i, d[n - t + 1] = i; for (re int i = 1; i <= cnt; ++i) d[i] = d[i] - c[i]; for (re int i = 1; i <= cnt; ++i) if (d[i] != b[i]) return ; for (re int i = 1; i <= cnt; ++i) b[n + 1 - i] = -b[i]; for (re int i = n; i >= 1; --i) if (b[i] < 0) b[i] += 10, --b[i - 1]; else break; t = 0; for (re int i = 1; i <= n; ++i) t = ((LL)t * 10 + b[i]) % p; ans = (((LL)t * t % p) + ans) % p; } IL voidwork()//生成b' { for (re int i = 0; i <= 9; ++i) B[i] = 0; cnt = 0; for (re int i = 9; i >= 0; --i) for (re int j = 1; j <= a[i]; ++j) b[++cnt] = i; if (o) b[cnt + 1] = 0, ++B[9]; for (re int i = cnt, f = 1; i >= 1; --i) { if (i != 1) ++B[9 - b[i]]; else ++B[10 - b[i]]; if (b[i] == 0 && f) ++B[9]; elseif (f) ++B[b[i] - 1], f = 0; else ++B[b[i]]; } } IL voiddfs(int x, int r) { if (x == 9) { a[x] = r; work(); check(); return ; } for (re int i = 0; i <= r; ++i) { a[x] = i; dfs(x + 1, r - i); } } intmain() { scanf("%d%d", &n, &p); o = n & 1; m = n >> 1; dfs(0, m); printf("%d\n", ans % p); return0; }