#include <bits/stdc++.h>
#define ll long long
#define str string
#define FOR(i,k,l) for(int i=l;i<=k;i++)
#define FOD(i,k,l) for(int i=l;i>=k;i--)
using namespace std;
str k;
ll n,m,a[1000],g[1000],g1[1000];
const int BASE = 1000;
typedef vector <ll> big;
big INT(str s) {
big a;
if (s.size() == 0)
{
a.push_back(0);
return a;
}
while (s.size()%3!=0) s='0'+s;
for (int i=0; i<(ll)s.size();i+=log10(BASE))
{
ll r = 0;
FOR(j,log10(BASE)-1,0)
r=r*10+(s[i+j]-'0');
a.insert(a.begin(),r);
}
return a;
}
ll SS (big a,big b)
{
ll c=a.size()-1;
ll d=b.size()-1;
if(c<d) return 1;
else if(c==d)
{
FOD(i,0,c)
{
if(a[i]<b[i]) return 1;
else if(a[i]>b[i]) return 0;
}
}
return 1;
}
big Cong (big a, big b) {
big c;
ll v=a.size();
ll u=b.size();
ll Max = max(v, u)-1;
ll nho = 0;
FOR(i,Max,0)
{
ll x = nho;
if (i<v) x += a[i];
if (i<u) x += b[i];
ll r = x % BASE;
c.push_back(r);
nho = x / BASE;
}
if (nho > 0) c.push_back(nho);
ll z=c.size()-1;
FOD(i,1,z)
{
if(c[i]==0) c.pop_back();
else break;
}
return c;
}
big Tru (big a, big b) {
big c;
ll v=a.size();
ll u=b.size();
ll Max = max(v, u)-1;
ll nho = 0;
FOR(i,Max,0)
{
ll x=0;
if (i<v) x += a[i];
if (i<u) x -= b[i];
x-=nho;
nho=0;
while (x<0) {x+=BASE;nho++;}
c.push_back(x);
}
ll z=c.size()-1;
FOD(i,1,z)
{
if(c[i]==0) c.pop_back();
else break;
}
return c;
}
big Nhan1 (big a,ll b)
{
ll d=a.size()-1;
big c;
ll nho=0;
FOR(i,d,0)
{
ll x=a[i]*b+nho;
nho=x/BASE;
x=x%BASE;
c.push_back(x);
}
if(nho>0) c.push_back(nho);
else
{
ll z=c.size()-1;
FOD(i,1,z)
{
if(c[i]==0) c.pop_back();
else break;
}
}
return c;
}
big Nhan2 (big a, big b) {
ll e=a.size()-1;
ll f=b.size()-1;
big c(e+f+2);
FOR(i,f,0)
{
big d=Nhan1(a,b[i]);
ll q=d.size()-1;
FOR(j,q,0)
c[i+j]+=d[j];
ll nho = 0;
ll zz=c.size()-1;
FOR(j,zz,i)
{
ll x = nho + c[j];
c[j] = x % BASE;
nho = x / BASE;
}
if (nho > 0) c.push_back(nho);
}
while (!c.empty() && c.back() == 0) c.pop_back();
return c;
}
void xuat(big a)
{
ll l = a.size()-1;
cout<<a[l];
FOD(i,0,l-1) cout << setfill('0') << setw(3) << a[i];
cout<<"\n";
}
int main()
{
//freopen("inp","r",stdin);
//freopen("out","w",stdout);
cin>>n>>m;
cin>>k;
big v=INT(k);
FOR(i,m,1)
cin>>a[i];
big f[1000];
f[0].push_back(1);
FOR(i,m-1,1)
f[i]=Nhan1(f[i-1],n-m+i);
FOR(i,m,1)
{
ll s=1;
while(SS(v,f[m-i])==0)
{
v=Tru(v,f[m-i]);
while(g[s]==1) s++;
s++;
}
while(g[s]==1) s++;
g[s]=1;
cout<<s<<" ";
}
big x;
FOR(i,m,1)
{
ll s=0;
FOR(j,a[i]-1,1)
{
if(g1[j]==0) s++;
}
big xx=Nhan1(f[m-i],s);
x=Cong(x,xx);
g1[a[i]]=1;
}
big o={1};
cout<<"\n";
xuat(Cong(x,o));
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc3RyIHN0cmluZwojZGVmaW5lIEZPUihpLGssbCkgZm9yKGludCBpPWw7aTw9aztpKyspCiNkZWZpbmUgRk9EKGksayxsKSBmb3IoaW50IGk9bDtpPj1rO2ktLSkKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RyIGs7CmxsIG4sbSxhWzEwMDBdLGdbMTAwMF0sZzFbMTAwMF07CmNvbnN0IGludCBCQVNFID0gMTAwMDsKdHlwZWRlZiB2ZWN0b3IgPGxsPiBiaWc7CmJpZyBJTlQoc3RyIHMpIHsKICAgIGJpZyBhOwogICAgaWYgKHMuc2l6ZSgpID09IDApCiAgICB7CiAgICAgICAgYS5wdXNoX2JhY2soMCk7CiAgICAgICAgcmV0dXJuIGE7CiAgICB9CiAgICB3aGlsZSAocy5zaXplKCklMyE9MCkgcz0nMCcrczsKICAgIGZvciAoaW50IGk9MDsgaTwobGwpcy5zaXplKCk7aSs9bG9nMTAoQkFTRSkpCiAgICB7CiAgICAgICAgbGwgciA9IDA7CiAgICAgICAgRk9SKGosbG9nMTAoQkFTRSktMSwwKQogICAgICAgIHI9cioxMCsoc1tpK2pdLScwJyk7CiAgICAgICAgYS5pbnNlcnQoYS5iZWdpbigpLHIpOwogICAgfQogICAgcmV0dXJuIGE7Cn0KCmxsIFNTIChiaWcgYSxiaWcgYikKewogICAgbGwgYz1hLnNpemUoKS0xOwogICAgbGwgZD1iLnNpemUoKS0xOwogICAgaWYoYzxkKSByZXR1cm4gMTsKICAgIGVsc2UgaWYoYz09ZCkKICAgIHsKICAgICAgICBGT0QoaSwwLGMpCiAgICAgICAgewogICAgICAgICAgICBpZihhW2ldPGJbaV0pIHJldHVybiAxOwogICAgICAgICAgICBlbHNlIGlmKGFbaV0+YltpXSkgcmV0dXJuIDA7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDE7Cn0KYmlnIENvbmcgKGJpZyBhLCBiaWcgYikgewogICAgYmlnIGM7CiAgICBsbCB2PWEuc2l6ZSgpOwogICAgbGwgdT1iLnNpemUoKTsKICAgIGxsIE1heCA9IG1heCh2LCB1KS0xOwogICAgbGwgbmhvID0gMDsKICAgIEZPUihpLE1heCwwKQogICAgewogICAgICAgIGxsIHggPSBuaG87CiAgICAgICAgaWYgKGk8dikgeCArPSBhW2ldOwogICAgICAgIGlmIChpPHUpIHggKz0gYltpXTsKICAgICAgICBsbCByID0geCAlIEJBU0U7CiAgICAgICAgYy5wdXNoX2JhY2socik7CiAgICAgICAgbmhvID0geCAvIEJBU0U7CiAgICB9CiAgICBpZiAobmhvID4gMCkgYy5wdXNoX2JhY2sobmhvKTsKICAgIGxsIHo9Yy5zaXplKCktMTsKICAgIEZPRChpLDEseikKICAgIHsKICAgICAgICBpZihjW2ldPT0wKSBjLnBvcF9iYWNrKCk7CiAgICAgICAgZWxzZSBicmVhazsKICAgIH0KICAgIHJldHVybiBjOwp9CmJpZyBUcnUgKGJpZyBhLCBiaWcgYikgewogICAgYmlnIGM7CiAgICBsbCB2PWEuc2l6ZSgpOwogICAgbGwgdT1iLnNpemUoKTsKICAgIGxsIE1heCA9IG1heCh2LCB1KS0xOwogICAgbGwgbmhvID0gMDsKICAgIEZPUihpLE1heCwwKQogICAgewogICAgICAgIGxsIHg9MDsKICAgICAgICBpZiAoaTx2KSB4ICs9IGFbaV07CiAgICAgICAgaWYgKGk8dSkgeCAtPSBiW2ldOwogICAgICAgIHgtPW5obzsKICAgICAgICBuaG89MDsKICAgICAgICB3aGlsZSAoeDwwKSB7eCs9QkFTRTtuaG8rKzt9CiAgICAgICAgYy5wdXNoX2JhY2soeCk7CiAgICB9CiAgICBsbCB6PWMuc2l6ZSgpLTE7CiAgICBGT0QoaSwxLHopCiAgICB7CiAgICAgICAgaWYoY1tpXT09MCkgYy5wb3BfYmFjaygpOwogICAgICAgIGVsc2UgYnJlYWs7CiAgICB9CiAgICByZXR1cm4gYzsKfQpiaWcgTmhhbjEgKGJpZyBhLGxsIGIpCnsKICAgIGxsIGQ9YS5zaXplKCktMTsKICAgIGJpZyBjOwogICAgbGwgbmhvPTA7CiAgICBGT1IoaSxkLDApCiAgICB7CiAgICAgICAgbGwgeD1hW2ldKmIrbmhvOwogICAgICAgIG5obz14L0JBU0U7CiAgICAgICAgeD14JUJBU0U7CiAgICAgICAgYy5wdXNoX2JhY2soeCk7CiAgICB9CiAgICBpZihuaG8+MCkgYy5wdXNoX2JhY2sobmhvKTsKICAgIGVsc2UKICAgIHsKICAgICAgICBsbCB6PWMuc2l6ZSgpLTE7CiAgICAgICAgRk9EKGksMSx6KQogICAgICAgIHsKICAgICAgICAgICAgaWYoY1tpXT09MCkgYy5wb3BfYmFjaygpOwogICAgICAgICAgICBlbHNlIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBjOwp9CmJpZyBOaGFuMiAoYmlnIGEsIGJpZyBiKSB7CiAgICBsbCBlPWEuc2l6ZSgpLTE7CiAgICBsbCBmPWIuc2l6ZSgpLTE7CiAgICBiaWcgYyhlK2YrMik7CiAgICBGT1IoaSxmLDApCiAgICB7CiAgICAgICAgYmlnIGQ9TmhhbjEoYSxiW2ldKTsKICAgICAgICBsbCBxPWQuc2l6ZSgpLTE7CiAgICAgICAgRk9SKGoscSwwKQogICAgICAgICAgICBjW2kral0rPWRbal07CiAgICAgICAgbGwgbmhvID0gMDsKICAgICAgICBsbCB6ej1jLnNpemUoKS0xOwogICAgICAgIEZPUihqLHp6LGkpCiAgICAgICAgewogICAgICAgICAgICBsbCB4ID0gbmhvICsgY1tqXTsKICAgICAgICAgICAgY1tqXSA9IHggJSBCQVNFOwogICAgICAgICAgICBuaG8gPSB4IC8gQkFTRTsKICAgICAgICB9CiAgICAgICAgaWYgKG5obyA+IDApIGMucHVzaF9iYWNrKG5obyk7CiAgICB9CiAgICB3aGlsZSAoIWMuZW1wdHkoKSAmJiBjLmJhY2soKSA9PSAwKSBjLnBvcF9iYWNrKCk7CiAgICByZXR1cm4gYzsKfQp2b2lkIHh1YXQoYmlnIGEpCnsKICAgIGxsIGwgPSBhLnNpemUoKS0xOwogICAgY291dDw8YVtsXTsKICAgIEZPRChpLDAsbC0xKSBjb3V0IDw8IHNldGZpbGwoJzAnKSA8PCBzZXR3KDMpIDw8IGFbaV07CiAgICBjb3V0PDwiXG4iOwp9CmludCBtYWluKCkKewogICAgLy9mcmVvcGVuKCJpbnAiLCJyIixzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dCIsInciLHN0ZG91dCk7CiAgICBjaW4+Pm4+Pm07CiAgICBjaW4+Pms7CiAgICBiaWcgdj1JTlQoayk7CiAgICBGT1IoaSxtLDEpCiAgICBjaW4+PmFbaV07CiAgICBiaWcgZlsxMDAwXTsKICAgIGZbMF0ucHVzaF9iYWNrKDEpOwogICAgRk9SKGksbS0xLDEpCiAgICBmW2ldPU5oYW4xKGZbaS0xXSxuLW0raSk7CiAgICBGT1IoaSxtLDEpCiAgICB7CiAgICAgICAgbGwgcz0xOwogICAgICAgIHdoaWxlKFNTKHYsZlttLWldKT09MCkKICAgICAgICB7CiAgICAgICAgICAgIHY9VHJ1KHYsZlttLWldKTsKICAgICAgICAgICAgd2hpbGUoZ1tzXT09MSkgcysrOwogICAgICAgICAgICBzKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlKGdbc109PTEpIHMrKzsKICAgICAgICBnW3NdPTE7CiAgICAgICAgY291dDw8czw8IiAiOwogICAgfQogICAgYmlnIHg7CiAgICBGT1IoaSxtLDEpCiAgICB7CiAgICAgICAgbGwgcz0wOwogICAgICAgIEZPUihqLGFbaV0tMSwxKQogICAgICAgIHsKICAgICAgICAgICAgaWYoZzFbal09PTApIHMrKzsKICAgICAgICB9CiAgICAgICAgYmlnIHh4PU5oYW4xKGZbbS1pXSxzKTsKICAgICAgICB4PUNvbmcoeCx4eCk7CiAgICAgICAgZzFbYVtpXV09MTsKICAgIH0KICAgIGJpZyBvPXsxfTsKICAgIGNvdXQ8PCJcbiI7CiAgICB4dWF0KENvbmcoeCxvKSk7CiAgICByZXR1cm4gMDsKfQo=