#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
int main() {
  long long i, j;
  long long n;
  cin >> n;
  long long fib[50];
  fib[0] = 1;
  fib[1] = 3;
  for (i = 2; i < 49; i++) fib[i] = fib[i - 1] + fib[i - 2];
  long long ans[n][n];
  for (i = 0; i < n; i++) ans[i][i] = 0;
  long long p = 0;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      ans[i][j] = fib[p];
      ans[j][i] = fib[p];
      p++;
    }
  }
  cout << fib[p] << endl;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cout << ans[i][j];
      if (j != n - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}
