#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > Generate_odd(int n) {
  vector<vector<int> > answer(n);
  for (int i = 0; i < n; i++) answer[i].resize(n);
  for (int i = 0; i < n; i++) answer[i][i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int k = (i - j + n) % n;
      if (k != j) answer[j][k] = i + 1;
    }
  }
  return answer;
}
vector<vector<int> > Merge_odd(vector<vector<int> > &odd) {
  int n = odd.size() * 2;
  vector<vector<int> > answer(n);
  for (int i = 0; i < n; i++) answer[i].resize(n);
  for (int i = 0; i < n / 2; i++)
    for (int j = 0; j < n / 2; j++) {
      answer[i][j] = odd[i][j];
      answer[i + n / 2][j + n / 2] = odd[i][j];
    }
  for (int i = 0; i < n / 2; i++) {
    vector<bool> can_be(n / 2 + 1);
    for (int j = 0; j < can_be.size(); j++) can_be[j] = true;
    for (int j = 0; j < n / 2; j++) can_be[odd[i][j]] = false;
    for (int j = 0; j < can_be.size(); j++)
      if (can_be[j]) {
        answer[i][i + n / 2] = j;
        answer[i + n / 2][i] = j;
        break;
      }
  }
  for (int i = n / 2 + 1; i < n; i++)
    for (int j = 0; j < n / 2; j++) {
      int k = (i + j) % (n / 2) + n / 2;
      answer[j][k] = i;
      answer[k][j] = i;
    }
  return answer;
}
vector<vector<int> > Merge_even(vector<vector<int> > &even) {
  int n = even.size() * 2;
  vector<vector<int> > answer(n);
  for (int i = 0; i < n; i++) answer[i].resize(n);
  for (int i = 0; i < n / 2; i++)
    for (int j = 0; j < n / 2; j++) {
      answer[i][j] = even[i][j];
      answer[i + n / 2][j + n / 2] = even[i][j];
    }
  for (int i = n / 2; i < n; i++)
    for (int j = 0; j < n / 2; j++) {
      int k = (i + j) % (n / 2) + n / 2;
      answer[j][k] = i;
      answer[k][j] = i;
    }
  return answer;
}
vector<vector<int> > Solve(int n) {
  int power_of_2 = 0, odd_part;
  while (n % 2 == 0) {
    power_of_2++;
    n /= 2;
  }
  odd_part = n;
  vector<vector<int> > odd = Generate_odd(odd_part);
  vector<vector<int> > even = Merge_odd(odd);
  power_of_2--;
  for (int i = 0; i < power_of_2; i++) even = Merge_even(even);
  return even;
}
int main() {
  int n;
  cin >> n;
  vector<vector<int> > answer = Solve(n);
  for (int i = 0; i < answer.size(); i++) {
    for (int j = 0; j < answer[i].size(); j++) cout << answer[i][j] << ' ';
    cout << '\n';
  }
}
