Problem:
Score : 900 points

Problem Statement

Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.

The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided.

A Hamiltonian path is a path that starts at one of the towns and visits each of the other towns exactly once.
The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path.

There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse.

Find one such set of the lengths of the roads, under the following conditions:

The length of each road must be a positive integer.

The maximum total length of a Hamiltonian path must be at most 10^{11}.

Constraints

N is a integer between 2 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print a set of the lengths of the roads that meets the objective, in the following format:

w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
: : :
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}

where w_{i, j} is the length of the road connecting Town i and Town j, which must satisfy the following conditions:

w_{i, i} = 0

w_{i, j} = w_{j, i} \ (i \neq j)

1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)

If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted.

Sample Input 1

3

Sample Output 1

0 6 15
6 0 21
15 21 0

There are three Hamiltonian paths. The total lengths of these paths are as follows:

1 → 2 → 3: The total length is 6 + 21 = 27.

1 → 3 → 2: The total length is 15 + 21 = 36.

2 → 1 → 3: The total length is 6 + 15 = 21.

They are distinct, so the objective is met.

Sample Input 2

4

Sample Output 2

0 111 157 193
111 0 224 239
157 224 0 258
193 239 258 0

There are 12 Hamiltonian paths, with distinct total lengths.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#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;
	}
}