#include <bits/stdc++.h>
using namespace std;
void printmat(vector<vector<long long> >& dp, long long r, long long c) {
  for (long long i = 1; i <= r; i++) {
    for (long long j = 0; j <= c; j++) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n + 1);
  vector<vector<long long> > dp(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i <= n; i++) {
    dp[i].resize(k + 1, 0);
  }
  long long tways = 0;
  for (long long i = 0; i <= n; i++) {
    dp[i][0] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= k; j++) {
      tways = 0;
      long long nj = 0;
      for (long long x = 0; x <= a[i]; x++) {
        nj = j - x;
        if (nj < 0) break;
        tways = (tways + dp[i - 1][nj]) % 1000000007;
      }
      dp[i][j] = tways;
    }
  }
  cout << dp[n][k] << endl;
  printmat(dp, n, k);
  return 0;
}
