Language: C++


using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

#define int ll
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define in(x, a, b) a <= x && x < b
const int inf = 1000000001;
const ll INF = 2e18;
//const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p <<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


ll n, MOD;
const int MAXN = 3010;
vl ways(MAXN);
vll ways2(MAXN, vl(MAXN));

vll secondStirling(MAXN, vl(MAXN));
vl fact(MAXN);
vl rfact(MAXN);

ll mod_pow(ll x, ll p, ll M = MOD) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%M;
		x = x*x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll M = MOD) {
	return mod_pow(a, M - 2, M);
}

void set_fact(int n, ll M = MOD) {
	fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
	for (ll i = 2; i <= n; i++) {
		fact[i] = i * fact[i - 1] % M;
		rfact[i] = mod_inverse(fact[i], M);
	}
}

ll nCr(ll n, ll r, ll M = MOD) {
	ll ret = fact[n];
	ret = (ret*rfact[r]) % M;
	ret = (ret*rfact[n - r]) % M;
	return ret;
}



void setSecondStirling(int n, ll M = MOD) {
	secondStirling[0][0] = 1;
	rep1(i, n) {
		rep(j, i + 1) {
			if (j == i) {
				secondStirling[i][j] = 1;
			}
			else if (j == 0) {
				secondStirling[i][j] = 0;
			}
			else {
				secondStirling[i][j] = (secondStirling[i - 1][j - 1] + (ll)j*secondStirling[i - 1][j] % M) % M;
			}
		}
	}
}

signed main() {
	cin >> n >> MOD;
	assert(n < 20);
	setSecondStirling(n);
	set_fact(n);
	rep(i, n + 1) {
		rep(j, i + 1) {
			ll temp = 0;
			//*
			rep(k, i + 1) {
				temp += nCr(i, k)*secondStirling[k][j] % MOD;
				temp %= MOD;
			}
			cout << i << " " << j << " " << temp << "   ";
			//*/
			temp *= mod_pow(2, (n - i)*j);
			temp %= MOD;
			temp *= mod_pow(2, mod_pow(2, n - i));
			temp %= MOD;
			ways2[i][j] = temp;
		}
		cout << endl;
	}
	rep(i, n + 1) {
		//DEBUG(i);
		rep(j, i + 1) {
			ways[i] += ways2[i][j];
			ways[i] %= MOD;
		}
		//DEBUG(ways[i]);
	}
	ll ans = 0;
	ll fugou = 1;
	rep(i, n + 1) {
		ans += fugou*nCr(n, i) % MOD *ways[i] % MOD;
		ans %= MOD;
		fugou *= -1;
	}
	while (ans < 0) {
		ans += MOD;
	}
	cout << ans << endl;
}

Compiler output:
a.cc:10:12: error: 'vector' does not name a type
   10 | #define vl vector<ll>
      |            ^~~~~~
a.cc:36:1: note: in expansion of macro 'vl'
   36 | vl ways(MAXN);
      | ^~
a.cc:12:13: error: 'vector' does not name a type
   12 | #define vll vector< vector<ll> >
      |             ^~~~~~
a.cc:37:1: note: in expansion of macro 'vll'
   37 | vll ways2(MAXN, vl(MAXN));
      | ^~~
a.cc:12:13: error: 'vector' does not name a type
   12 | #define vll vector< vector<ll> >
      |             ^~~~~~
a.cc:39:1: note: in expansion of macro 'vll'
   39 | vll secondStirling(MAXN, vl(MAXN));
      | ^~~
a.cc:10:12: error: 'vector' does not name a type
   10 | #define vl vector<ll>
      |            ^~~~~~
a.cc:40:1: note: in expansion of macro 'vl'
   40 | vl fact(MAXN);
      | ^~
a.cc:10:12: error: 'vector' does not name a type
   10 | #define vl vector<ll>
      |            ^~~~~~
a.cc:41:1: note: in expansion of macro 'vl'
   41 | vl rfact(MAXN);
      | ^~
a.cc: In function 'void set_fact(ll, ll)':
a.cc:59:9: error: 'fact' was not declared in this scope
   59 |         fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
      |         ^~~~
a.cc:59:29: error: 'rfact' was not declared in this scope
   59 |         fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
      |                             ^~~~~
a.cc: In function 'll nCr(ll, ll, ll)':
a.cc:67:18: error: 'fact' was not declared in this scope
   67 |         ll ret = fact[n];
      |                  ^~~~
a.cc:68:20: error: 'rfact' was not declared in this scope
   68 |         ret = (ret*rfact[r]) % M;
      |                    ^~~~~
a.cc: In function 'void setSecondStirling(ll, ll)':
a.cc:76:9: error: 'secondStirling' was not declared in this scope; did you mean 'setSecondStirling'?
   76 |         secondStirling[0][0] = 1;
      |         ^~~~~~~~~~~~~~
      |         setSecondStirling
a.cc: In function 'int main()':
a.cc:93:9: error: 'cin' was not declared in this scope
   93 |         cin >> n >> MOD;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:94:9: error: 'assert' was not declared in this scope
   94 |         assert(n < 20);
      |         ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | 
a.cc:102:51: error: 'secondStirling' was not declared in this scope; did you mean 'setSecondStirling'?
  102 |                                 temp += nCr(i, k)*secondStirling[k][j] % MOD;
      |                                                   ^~~~~~~~~~~~~~
      |                                                   setSecondStirling
a.cc:105:25: error: 'cout' was not declared in this scope
  105 |                         cout << i << " " << j << " " << temp << "   ";
      |                         ^~~~
a.cc:105:25: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:111:25: error: 'ways2' was not declared in this scope
  111 |                         ways2[i][j] = temp;
      |                         ^~~~~
a.cc:113:17: error: 'cout' was not declared in this scope
  113 |                 cout << endl;
      |                 ^~~~
a.cc:113:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:113:25: error: 'endl' was not declared in this scope
  113 |                 cout << endl;
      |                         ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | 
a.cc:118:25: error: 'ways' was not declared in this scope
  118 |                         ways[i] += ways2[i][j];
      |                         ^~~~
a.cc:118:36: error: 'ways2' was not declared in this scope
  118 |                         ways[i] += ways2[i][j];
      |                                    ^~~~~
a.cc:126:47: error: 'ways' was not declared in this scope
  126 |                 ans += fugou*nCr(n, i) % MOD *ways[i] % MOD;
      |                                               ^~~~
a.cc:133:9: error: 'cout' was not declared in this scope
  133 |         cout << ans << endl;
      |         ^~~~
a.cc:133:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:133:24: error: 'endl' was not declared in this scope
  133 |         cout << ans << endl;
      |                        ^~~~
a.cc:133:24: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'