/*

Code for problem A by cookiedoth
Generated 10 Apr 2021 at 03.05 PM


█▒▒▒▒▒▒▒▒▒
10%
███▒▒▒▒▒▒▒
30%
█████▒▒▒▒▒
50%
███████▒▒▒
70%
██████████
100%

~_^
=_=
¯\_(ツ)_/¯

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#include <random>
#include <utility>
#include <tuple>
#include <chrono>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define length(a) (int)a.size()

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int mx = 110;
const int INF = 1e9 + 228;
int n, a[mx];
string s;

signed main() {
	fast_io();
	cin >> n;
	cin >> s;
	for (int i = 0; i <= n; ++i) {
		cin >> a[i];
	}
	int k = INF;
	for (int i = 0; i < n; ++i) {
		k = min(k, abs(a[i + 1] - a[i]));
	}
	cout << k << '\n';
	for (int i = 0; i < k; ++i) {
		for (int j = 0; j <= n; ++j) {
			int val = a[j] / k;
			if (i < (a[j] % k)) {
				val++;
			}
			cout << val << ' ';
		}
		cout << '\n';
	}
}

#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n), w(m);
  REP(i, n) cin >> h[i];
  REP(i, m) cin >> w[i];
  sort(ALL(h));

  vector<ll> left(n+1, 0), right(n+1, 0);
  for(ll i = 2; i < n; i += 2){
    //左側がi個残ったときの累積和
    left[i] = left[i-2] + h[i-1] - h[i-2];
    //右側がi個残ったときの累積和
    right[i] = right[i-2] + h[n-i+1] - h[n-i];
  }
  ll ans = INF;
  REP(i, m){
    //w[i]の身長の先生が入る場所を探す
    ll x = lower_bound(ALL(h), w[i]) - h.begin();
    //0->一番左 1->左から2番目 ... x=左に残る数
    //xが偶数->先生が左側 x番目の子とペアを組む
    if(x%2 == 0){
      chmin(ans, left[x] + right[n-1-x] + h[x]-w[i]);
    //ｘが奇数->先生が右側 x-1番目のことペアを組む
    }else{
      chmin(ans, left[x-1] + right[n-x] + w[i]-h[x-1]);
    }
  }
  cout << ans << endl;
  return 0;
}