# Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5 + 100, M = 5e5 + 5, INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int fa[N], val[N], cnt, Edge[N];
vector<pair<int, PII>> ve;
int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int x; cin >> x;
if (i == j) val[++cnt] = x, fa[cnt] = cnt;
else if (i < j) {
ve.push_back({x, {i, j}});
}
}
}
sort(ve.begin(), ve.end());
for (auto it : ve) {
int value = it.first, x = it.second.first, y = it.second.second;
int fx = find(x), fy = find(y);
if (fx != fy) {
if (value == val[fx]) fa[fy] = fx, Edge[fy] = fx;
else if (value == val[fy]) fa[fx] = fy, Edge[fx] = fy;
else {
fa[fx] = fa[fy] = Edge[fx] = Edge[fy] = ++cnt;
val[cnt] = value; fa[cnt] = cnt;
}
}
}
cout << cnt << endl;
for (int i = 1; i <= cnt; i++) cout << val[i] << " ";
cout << endl;
cout << cnt << endl;
for (int i = 1; i <= cnt-1; i++) cout << i << " " << Edge[i] << endl;
}

signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
solve();
}


12-25 180