N = int(input()) ans = [[None] * N for i in range(N)] for i in range(N): for j in range(N): ans[(j+i)%N][i] = j+1 a = ans for i in range(N): for j in range(N): if a[j][i] == i+1: a[i],a[j] = a[j],a[i] break for i in ans: print (*i)