Language: C++

#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=20;
const ll S=1<<16;
const ll mod=1e9+7;
ll n,m,a[N],f[N][S],size[S],fac[S+5],inv[S+5],id[S],ans;
ll C(ll n,ll m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	n=read(),m=read();
	for(ll i=1;i<=m;i++)a[i]=read();
	for(ll i=1;i<1<<n;i++)size[i]=size[i>>1]+(i&1);
	for(ll i=0;i<n;i++)id[1<<i]=i;
	fac[0]=1;for(ll i=1;i<=S;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(ll i=2;i<=S;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(ll i=1;i<=S;i++)inv[i]=inv[i-1]*inv[i]%mod;
	f[m+1][0]=1;
	for(ll i=m+1;i>=2;i--)for(ll sta=0;sta<1<<n;sta++)if(f[i][sta]){
		f[i-1][sta]=(f[i-1][sta]+f[i][sta])%mod;
		ll fsta=((1<<n)-1)^sta;
		for(;fsta;){
			ll x=id[fsta&(-fsta)];
			if((1<<n)-a[i-1]+1>=(sta|(1<<x)))f[i-1][sta|(1<<x)]=(f[i-1][sta|(1<<x)]+f[i][sta]*C((1<<n)-a[i-1]-sta,(1<<x)-1)%mod*fac[1<<x]%mod)%mod;
			fsta-=fsta&(-fsta);
		}
	}
	ans=fac[1<<n];for(ll sta=1;sta<1<<n;sta++)ans=(ans+(size[sta]&1?mod-1:1)*f[1][sta]%mod*fac[(1<<n)-1-sta]%mod*(1<<n)%mod)%mod;
	return cout<<ans,signed();
}
/*
2 1 3
4 3 2 4 6
3 0
3 3 3 4 7
16 16 5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
*/

Compiler output:
a.cc: In function 'int main()':
a.cc:32:31: error: reference to 'size' is ambiguous
   32 |         for(ll i=1;i<1<<n;i++)size[i]=size[i>>1]+(i&1);
      |                               ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:24:21: note:                 'long long int size [65536]'
   24 | ll n,m,a[N],f[N][S],size[S],fac[S+5],inv[S+5],id[S],ans;
      |                     ^~~~
a.cc:32:39: error: reference to 'size' is ambiguous
   32 |         for(ll i=1;i<1<<n;i++)size[i]=size[i>>1]+(i&1);
      |                                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:24:21: note:                 'long long int size [65536]'
   24 | ll n,m,a[N],f[N][S],size[S],fac[S+5],inv[S+5],id[S],ans;
      |                     ^~~~
a.cc:47:61: error: reference to 'size' is ambiguous
   47 |         ans=fac[1<<n];for(ll sta=1;sta<1<<n;sta++)ans=(ans+(size[sta]&1?mod-1:1)*f[1][sta]%mod*fac[(1<<n)-1-sta]%mod*(1<<n)%mod)%mod;
      |                                                             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:24:21: note:                 'long long int size [65536]'
   24 | ll n,m,a[N],f[N][S],size[S],fac[S+5],inv[S+5],id[S],ans;
      |                     ^~~~