#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Latin Square generator
# by Chatchavan Wacharamanotham
# 05.09.10 Created

import copy
import sys

def main():
  # input
  if len(sys.argv) > 1:
    conditionCount = int(sys.argv[1])
  else:
    conditionCount = int(raw_input("Number of conditions: "))
  
  assert conditionCount > 2, "Number of conditions must be more than 2."
  
  # first line
  firstLine = [0, 1]
  useBack = True
  choices = range(2, conditionCount)
  for i in range(2, conditionCount):
    if useBack:
      number = choices.pop()
    else:
      number = choices.pop(0)
    firstLine.append(number)
    useBack = not useBack
    
  # Latin square
  square = [firstLine]
  for i in range (1, conditionCount):
    line = [(element + i) % conditionCount for element in firstLine]
    square.append(line)
  
  # add reversed lines Latin square for odd-numbered condition
  if (conditionCount % 2 != 0):
   reversedSquare = []
   for line in square:
     reversedLine = copy.copy(line)
     reversedLine.reverse()
     reversedSquare.append(reversedLine)
   square.extend(reversedSquare)
   
  # output
  for line in square:
    print " ".join([str(i) for i in line])
  
if __name__ == "__main__":
  main()