#include #include #include using namespace std; using ll = long long; #include using mint = atcoder::modint; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,p; cin>>n>>p; mint::set_mod(p); vector> comb(n+1,vector(n+1,0)); comb[0][0] = 1; for(int i = 1;i<=n;i++){ comb[i][i] = comb[i][0] = 1; for(int j = 1;j cal(n+1,0); cal[1] = 1; for(int i = 2;i<=n;i++) cal[i] = mint(i).pow(i-2); for(int i = 1;i<=n;i++){ mint tmp = comb[n][i]; int res = n - i + 1; tmp *= cal[i]; if(res==1){ ans += tmp; continue; } tmp *= mint(n).pow(res-2) * i; ans += tmp; } cout<