设g=n/m
对于每个小组第一,设他的位置是a[i],要从他排名下面选g-1个人加入他的小组,可选的人数为n-a[i]-(m-i)*g,所以把组合数乘起来就可以了。
var
c:array[0..101,0..101] of int64;
a:array[0..101] of int64;
n,m,i,j,g,t:longint;
ans,p:int64;
procedure sort(l,r:longint);
var
i,j:longint;
e,t:int64;
begin
i:=l;j:=r;e:=a[(l+r)>>1];
repeat
while a[i]<e do inc(i);
while e<a[j] do dec(j);
if not (i>j) then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n,m,p);
for i:=0 to n do c[i][0]:=1;
for i:=0 to n do c[i][i]:=1;
for i:=0 to n do
for j:=1 to i-1 do
c[i][j]:=(c[i-1][j]+c[i-1][j-1]) mod p;
g:=n div m;
ans:=1;
for i:=1 to m do read(a[i]);
sort(1,m);
for i:=1 to m do
begin
if n-a[i]-(m-i)*g<g-1 then
begin
writeln(-1);
halt;
end;
ans:=(ans*c[n-a[i]-(m-i)*g][g-1]) mod p;
end;
writeln(ans);
end.