#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
template<class T>
T rnd(T l,T r){	//[l,r)
	using D = uniform_int_distribution<T>;
	static random_device rd;
	static mt19937 gen(rd());
	return D(l,r-1)(gen);
}
template<class T>
T rnd(T n){	//[0,n)
	return rnd(0,n);
}

void test(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	V<ll> fib(70);
	fib[0] = 1, fib[1] = 2;
	for(int i=2;i<70;i++) fib[i] = fib[i-1] + fib[i-2] + 1;

	int N = 10;

//	V<int> r(N*(N-1)/2); rep(i,r.size()) r[i] = i;
//	random_shuffle(all(r));

	VV<ll> a(N,V<ll>(N));
	V<ll> magic = {1,45,1332,22344,181944,667800,1292400,1693440,1814400};
	{
		auto getst = [&](){
			V<ll> st;
			V<int> o(N); rep(j,N) o[j] = j;
			do{
				ll sm = 0;
				rep(i,N-1){
					int x = o[i], y = o[i+1];
					if(x > y) swap(x,y);
					sm += a[x][y];
				}
				st.pb(sm);
			}while(next_permutation(all(o)));
			sort(all(st));
			st.erase(unique(all(st)),st.end());
			return st;
		};
		rep(i,N-2){
			V<ll> st = getst();

			ll X = (*st.rbegin() - *st.begin()) + 1;
			ll c = X;
			show(st.size());
			V<ll> use;
			rep(j,N-1-i) use.pb(fib[j]*c);

			for(int j=i+1;j<N;j++){
				a[i][j] = use[N-1-j];
//				a[i][j] = use[j-(i+1)];
				cout << a[i][j] << " ";
			}
			cout << endl;
		}
	}
	while(true){
		ll fix;
		cin >> fix;
		a[7][8] = fix;

		V<int> o(N); rep(i,N) o[i] = i;
		set<ll> st;
		do{
			if(o.front() > o.back()) continue;
			auto f = [&](int i,int j){
				if(i>j) swap(i,j);
				return a[i][j];
			};
			ll sm = 0;
			rep(i,N-1){
				sm += f(o[i],o[i+1]);
			}
			st.insert(sm);
		}while(next_permutation(all(o)));
		int num = 1; rep1(i,N) num *= i; num /= 2;

		show(*st.rbegin());
		if((int)st.size() == num){
			cout << "OK!" << endl;
			rep(i,N){
				cout << "{";
				rep(j,N){
					cout << max(a[i][j],a[j][i])+1;
					if(j == N-1) cout <<"},"<<endl;
					else cout<<",";
				}
			}
			return;
		}else{
			cout << "NG" << endl;
		}
	}
}

int main(){
	VV<ll> a = {
		{1,89,55,34,21,13,8,5,3,2},
		{89,1,7669,4687,2841,1705,995,569,285,143},
		{55,7669,1,407221,246801,148081,86381,49361,24681,12341},
		{34,4687,407221,1,13204801,7922881,4621681,2640961,1320481,660241},
		{21,2841,246801,13204801,1,257499097,150207807,85833033,42916517,21458259},
		{13,1705,148081,7922881,257499097,1,2928568987,1673467993,836733997,418366999},
		{8,995,86381,4621681,150207807,2928568987,1,19193325393,9596662697,4798331349},
		{5,569,49361,2640961,85833033,1673467993,19193325393,1,55000000001,30937585342},
		{3,285,24681,1320481,42916517,836733997,9596662697,55000000001,1,1},
		{2,143,12341,660241,21458259,418366999,4798331349,30937585342,1,1}
	};
	// for(int N=2;N<=10;N++){
	// 	V<int> o(N); rep(i,N) o[i] = i;
	// 	set<ll> st;
	// 	do{
	// 		if(o.front() > o.back()) continue;
	// 		auto f = [&](int i,int j){
	// 			if(i>j) swap(i,j);
	// 			return a[i][j];
	// 		};
	// 		ll sm = 0;
	// 		rep(i,N-1){
	// 			sm += f(o[i],o[i+1]);
	// 		}
	// 		st.insert(sm);
	// 	}while(next_permutation(all(o)));
	// 	int num = 1; rep1(i,N) num *= i; num /= 2;

	// 	show(*st.rbegin());
	// 	if((int)st.size() == num){
	// 		cout << "OK!" << endl;
	// 	}
	// }
	int N;
	cin >> N;
	rep(i,N){
		a[i][i] = 0;
		rep(j,N) cout << a[i][j] << " ";
		cout << endl;
	}
}

Measured memory_bytes: 256