#include <bits/stdc++.h>

using namespace std;

#define DIM 507

long long n, it, boss[DIM*DIM], sell[DIM*DIM], a[DIM][DIM];

vector<long long> vec;

void F(vector<long long> vec, long long MX, long long par)
{
    //cout<<vec.size()<<' '<<MX<<' '<<par<<endl;
    //cout<<"//////"<<endl;
    if(vec.size()==1) return;
    vector<long long> vis;
    vis.resize(n+7);
    for(int i=0; i<vec.size(); i++)
    {
        long long v=vec[i];
        if(vis[v]==1) continue;
        vis[v]=1;
        long long mx=-1;
        for(int i=1; i<=n; i++)
        {
            if(a[v][i]>=MX) continue;
            mx=max(mx, a[v][i]);
        }
        vector<long long> nvec;
        for(int i=1; i<=n; i++)
        {
            if(a[v][i]<=mx) {nvec.push_back(i); vis[i]=1;}
        }
        if(nvec.size()==1)
        {
            boss[nvec[0]]=par;
            sell[nvec[0]]=mx;
            continue;
        }
        it++;
        boss[it]=par;
        sell[it]=mx;
        F(nvec, mx, it);
        nvec.clear();
    }
    vis.clear();
    return;
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        vec.push_back(i);
        for(int j=1; j<=n; j++) cin>>a[i][j];
    }
    it=n;
    F(vec, 10000, -1);
    cout<<it<<endl;
    for(int i=1; i<=it; i++) cout<<sell[i]<<' ';
    cout<<endl<<n+1<<endl;
    for(int i=1; i<=it; i++)
    {
        if(i==n+1) continue;
        cout<<i<<' '<<boss[i]<<endl;
    }
    return 0;
}
