Problem: The Dogeforces company has k employees. Each employee, except for lower-level employees, has at least 2 subordinates. Lower-level employees have no subordinates. Each employee, except for the head of the company, has exactly one direct supervisor. The head of the company is a direct or indirect supervisor of all employees. It is known that in Dogeforces, each supervisor receives a salary strictly more than all his subordinates.

The full structure of the company is a secret, but you know the number of lower-level employees and for each pair of lower-level employees, the salary of their common supervisor is known (if there are several such supervisors, then the supervisor with the minimum salary). You have to restore the structure of the company.

Input

The first line contains a single integer n (2 ≤ n ≤ 500) — the number of lower-level employees.

This is followed by n lines, where i-th line contains n integers a_{i,1}, a_{i,2}, ..., a_{i,n} (1 ≤ a_{i,j} ≤ 5000) — salary of the common supervisor of employees with numbers i and j. It is guaranteed that a_{i,j} = a_{j,i}. Note that a_{i,i} is equal to the salary of the i-th employee.

Output

In the first line, print a single integer k — the number of employees in the company.

In the second line, print k integers c_1, c_2, ..., c_k, where c_i is the salary of the employee with the number i.

In the third line, print a single integer r — the number of the employee who is the head of the company.

In the following k-1 lines, print two integers v and u (1 ≤ v, u ≤ k) — the number of the employee and his direct supervisor.

Note that the lower-level employees have numbers from 1 to n, and for the rest of the employees, you have to assign numbers from n+1 to k. If there are several correct company structures, you can print any of them.

Example

Input


3
2 5 7
5 1 7
7 7 4


Output


5
2 1 4 7 5 
4
1 5
2 5
5 4
3 4

Note

One of the possible structures in the first example: <image>

Solution (in CPP):

Solution:
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
#include<complex>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
#define DEBUG true




using namespace std;

#define $(x) {if (DEBUG) {cout << __LINE__ << ": "; cout << x << endl;}}
#define _(x) {cout << #x << " = " << x << " ";}
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
const int inf = (int)1e9 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const ll MOD = 998244353;
const ll MOD2 = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const ll mod = LLONG_MAX;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;


#define ent '\n'
bool sortbyfirst(const tuple<int, int, int,int>& a,  
               const tuple<int, int, int,int >& b) 
{ 
    return get<0>(a) > get<0>(b)||(get<0>(a)==get<0>(b) && get<1>(a)>get<1>(b)); 
} 
bool sortbigfirstll(pair<ll,ll>& a,  pair<ll,ll>& b) 
{ 
    return (a.first<b.first)||((a.first==b.first)&&(a.second<b.second)); 
} 
bool sortbigsecondll(pair<ll,ll>& a,  pair<ll,ll>& b) 
{ 
    return (a.second<b.second); 
} 
bool sortbigfirst(pair<int,int>& a,  pair<int,int>& b) 
{ 
    return (a.first>b.first)||((a.first==b.first)&&(a.second<b.second)); 
} 
bool sortbigsecond(pair<int,int>& a,  pair<int,int>& b) 
{ 
    return (a.second>b.second); 
} 
ll llmin(ll a,ll b){
    return (a<b) ? a:b;
}
ll llmax(ll a,ll b){
    return (a<b) ? b:a;
}
ll lgcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return lgcd(b % a, a);  
 }
 ll power(ll x, ll y) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x%mod ;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%mod ; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%mod; 
    } 
    return res; 
} 
 ll modInverse(ll n) 
{ 
    return power(n, mod-2); 
} 

ll fac[500005];
void inifac(int val){
    fac[0]=1;
    int i;
    for(i=1;i<=val;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}
ll nCr(ll n, ll r) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return (fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod) % mod; 
} 
  
bool sortyo(const tuple<int, int,int>& a,  
               const tuple<int, int,int>& b) 
{ 
    return get<0>(a) < get<0>(b)||(get<0>(a) == get<0>(b)&&get<1>(a) < get<1>(b)); 
}
bool difsort(const pii& a,  
               const pii& b) 
{ 
    return a.first-a.second>b.first-b.second; 
}


/*// Driver code 
int main() 
{ 
	insert(1); 
	insert(4); 
	insert(7); 
	cout << "Median for the set {1,4,7} = "
		<< median() << endl; 
	insert(8); 
	insert(9); 
	cout << "Median for the set {1,4,7,8,9} = "
		<< median() << endl; 
	delet(1); 
	delet(8); 
	cout << "Median for the set {4,7,9} = "
		<< median() << endl; 
	return 0; 
}*/
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
        return 0;
 
    while (a > 1) {
        // q is quotient
        ll q = a / m;
        ll t = m;
 
        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;
 
        // Update y and x
        y = x - q * y;
        x = t;
    }
 
    // Make x positive
    if (x < 0)
        x += m0;
 
    return x;
}
const int maxN=500;
int c[maxN][maxN];
int n;
int curhead;
vector<pii> ans2;
vector<int> ans;
int search(vector<int>& t){
    if(t.size()==1){
        return t[0];
    }
    vector<bool> vis(n,false);
    int maxv=0;
    for(auto i:t){
        for(auto j:t){
            maxv=max(maxv,c[i][j]);
        }
    }
    vector<vector<int>> recur;
    for(auto i:t){
        if(vis[i]) continue;
        vector<int> temp2;
        for(auto j:t){
            if(c[i][j]!=maxv){
                temp2.pb(j);
                vis[j]=true;
            }
        }
        if(temp2.size()!=0){
            recur.pb(temp2);
        }
    }
    ans.pb(maxv);
    int temp=curhead;
    curhead++;
    for(auto x:recur){
        /*for(auto i:x){
            _(i)
        }*/
        //_(temp)
        ans2.pb({search(x),temp});
    }
    return temp;
}
int main(){
    cin>>n;
    curhead=n;
    vector<int> x;
    rep(i,0,n){
        rep(j,0,n){
            cin>>c[i][j];
            if(i==j){
                ans.pb(c[i][j]);
            }
        }
    }
    rep(i,0,n){
        x.pb(i);
    }
    search(x);
    //ans
    cout<<ans.size()<<"\n";
    rep(i,0,ans.size()){
        cout<<ans[i]<<" ";
    }
    cout<<"\n";
    cout<<n+1<<"\n";
    rep(i,0,ans2.size()){
        cout<<ans2[i].first+1<<" "<<ans2[i].second+1<<"\n";
    }
    return 0;
}