#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;


int main() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vll V(N + 1);
    rep(i,N + 1) {cin >> V[i];}
    ll k = INF;
    rep(i,N) {
        k = min(k,abs(V[i + 1] - V[i]));
    }
    cout << k << endl;
    vector<vll> W(k,vll(N + 1));
    rep(i,N + 1) {
        ll a = V[i]/k;
        rep(j,V[i]%k) {
            W[j][i] = a + 1;
        }
        rep2(j,V[i]%k,k) {
            W[j][i] = a;
        }
    }
    rep(i,k) {
        rep(j,N + 1) {
            cout << W[i][j];
            if (j == N) {cout << endl;}
            else {cout << " ";}
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
string num;
int rn[200005];
int k;
int n;
int dp[200005][20];
ll dfs(int x,ll now,bool zero,bool flag)
{
    int cnt=0;
    for(int i=0;i<16;i++)
    {
        if(now&(1<<i))cnt++;
    }
    if(x>=n)return cnt==k;
    if(cnt>k)return 0;
    if(!flag&&zero&&dp[x][cnt]!=-1)return dp[x][cnt];
    ll ans=0;
    int lim=flag?rn[x]:15;
    for(int i=0;i<=lim;i++)
    {
        int tmp;
        if(!zero&&i==0)tmp=now;
        else tmp=now|(1<<i);
        ans+=dfs(x+1,tmp,zero||(i!=0),flag&&(i==lim));
        ans%=mod;
    }
    if(!flag&&zero)dp[x][cnt]=ans;
    return ans;
}
int main()
{
    cin>>num>>k;
    n=num.size();
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
    {
        if(num[i]>='0'&&num[i]<='9')rn[i]=num[i]-'0';
        else rn[i]=num[i]-'A'+10;
    }
    printf("%lld\n",dfs(0,0,0,1));
    return 0;
}
