```cpp
#include<bits/stdc++.h>
using namespace std;
#define N 10000100
#define int long long
int n,m,mod,fac[N],prime[N],poww[N],ans=-1,tt,endans=1;
void exgcd(int a,int b,int &x,int &y){
if(!b){
x=1;y=0;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
int qpow(int x,int y,int mod){
int res=1;
while(y){
if(y&1)res=res*x%mod;
x=x*x%mod;
y>>=1;
}
return res;
}
int get_fac(int u,int p,int poww){
if(u<=p)return fac[u];
return fac[u%poww]*qpow(fac[poww],u/poww%(poww/p*(p-1)),poww)%poww*get_fac(u/p,p,poww)%poww;
}
int C(int n,int m,int p,int poww){
fac[0]=1;
for(signed i=1;i<=poww;++i){
if(i%p==0)fac[i]=fac[i-1];
else fac[i]=fac[i-1]*i%poww;
}
int res1=get_fac(n,p,poww),res2=get_fac(m,p,poww)*get_fac(n-m,p,poww)%poww;
int l=0ll,x=n;
while(x){
l+=x/p;
x/=p;
}
x=m;
while(x){
l-=x/p;
x/=p;
}
x=n-m;
while(x){
l-=x/p;
x/=p;
}
for(signed i=1;i<=l;++i){
res1=res1*p%poww;
if(!res1)return 0;
}
return res1*qpow(res2,poww/p*(p-1)-1,poww)%poww;
}
int CRT(int x,int y,int M,int mm){
int k1=-1,k2=-1;
exgcd(M,mm,k1,k2);
return ((k1+M*mm)*(y-x+M*mm)%(M*mm)*M+x)%(M*mm);
}
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>mod;
int lm=sqrt(mod)+1,x=mod;
for(signed i=2;i<=lm;++i){
if(x%i==0){
prime[++tt]=i,poww[tt]=1;
while(x%i==0){
poww[tt]*=i;
x/=i;
}
}
}
if(x>1){
prime[++tt]=poww[tt]=x;
}
int a,b;
cin>>a>>b;
int pass=0;
for(int i=1;i<=b;++i){
int c;
cin>>c;
n=a-pass;m=c;
if(n<0){
puts("Impossible");
return 0;
}
pass+=c;
ans=C(n,m,prime[1],poww[1]);
int M=poww[1];
for(signed i=2;i<=tt;++i){
ans=CRT(ans,C(n,m,prime[i],poww[i]),M,poww[i]);
M*=poww[i];
}
endans=ans*endans%mod;
}
if(endans==0){
puts("Impossible");
return 0;
}
printf("%lld\n",endans);
return 0;
}
```
by 哈撒各一 @ 2020-09-25 19:22:10
ddd
by 哈撒各一 @ 2020-09-25 20:21:22