#include <bits/stdc++.h>
using namespace std;
 
void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
 
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
 
#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int main() {
	int n;
	string s;
	cin >> n >> s;

	vector<int> a(n);
	int k = 1e9;
	for(int i = 0; i <= n; i++) {
		cin >> a[i];
		if(i - 1 >= 0)
			k = min(k, abs(a[i] - a[i - 1]));
	}

	cout << k << '\n';
	for(int i = 0; i < k; i++) {
		for(int j = 0; j <= n; j++) {
			cout << (a[j] + i) / k << ' ';
		}
		cout << '\n';
	}

}

#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vi a(n + 1);
    rep(i, 0, n + 1) cin >> a[i];
    int ans = INT_MAX;
    rep(i, 0, n) ans = min(ans, abs(a[i] - a[i + 1]));
    vector<vi> b(n + 1, vi(ans, 0));
    int k = 0;
    rep(i, 0, n + 1) {
        rep(j, 0, ans) b[i][j] = a[i] / ans;
        int dif = a[i] - (a[i] / ans) * ans;
        if(i % 2 == 0) {
            rep(j, 0, dif) {
                b[i][k]++;
                k = (k + 1) % ans;
            }
        }else {
            rep(j, 0, dif) {
                k = (k + ans - 1) % ans;
                b[i][k]++;
            }
        }
    }

    cout << ans << '\n';
    rep(j, 0, ans) {
        rep(i, 0, n + 1) {
            cout << b[i][j] << ' ';
        }
        cout << '\n';
    }
}