#include <bits/stdc++.h>
using namespace std;
long long max_ham(vector<vector<long long>> &w, long long N) {
  vector<long long> p(N);
  long long i, ans = 0;
  for (i = 0; i < N; i++) {
    p[i] = i;
  }
  do {
    long long now = 0;
    for (i = 1; i < N; i++) {
      now += w[p[i - 1]][p[i]];
    }
    ans = max(ans, now);
  } while (next_permutation(p.begin(), p.end()));
  return ans;
}
signed main() {
  long long N, i, j;
  long long a[] = {1, 2, 4, 7, 12, 20, 29, 38, 52, 73};
  scanf("%lld", &N);
  vector<vector<long long>> w(N, vector<long long>(N, 0));
  w[0][1] = 1;
  w[1][0] = 1;
  for (i = 2; i < N; i++) {
    long long M = max_ham(w, i);
    for (j = 0; j < i; j++) {
      w[i][j] = a[j] * (M + 1);
      w[j][i] = a[j] * (M + 1);
    }
  }
  printf("%lld\n", max_ham(w, N));
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      printf("%lld ", w[i][j]);
    }
    printf("\n");
  }
  return 0;
}
