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:
/**
1、规则：总共k（k>n）个employees，n个lower-level employees，每个lower-level employees都有一个直接父亲，
         每个employees至少有2个下属，根节点是所有employees的间接主管。
         每个employees都有工资，每个employees的工资必须严格大于它子树中所有employees的值
         给定n*n的a数组，a(i,i)表示第i个lower-level employee的工资
                         a(i,j)[i!=j]表示第i个lower-level employee和第j个lower-level employee的最近公共”祖先“的工资
         求还原出来的树
2、解决：最近公共祖先+严格大于---->从底向上建树

**/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MP make_pair
#define UM unordered_map
#define pii pair<int,int>
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
#define lc root<<1
#define rc root<<1|1
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
#define pi 3.1415926535898
#define DEC (pi/180)
const int M=2e3+3;
ll ksm(ll x,ll y){
    ll t=1;
    while(y){
        if(y&1)
            t=t*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return t;
}
int fa[M],f[M],val[M];
vector< pair <int, pair <int, int> > >g;
int Find(int x){
    return x==f[x]?f[x]:f[x]=Find(f[x]);
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int x;
            scanf("%d",&x);
            if(i==j){
                val[i]=x;f[i]=i;
            }
            else if(i<j){
                g.pb(MP(x,MP(i,j)));
            }
        }
    }
    int tot=n;
    sort(g.begin(),g.end());
    for(auto it:g){
        int x = it.first, u = it.second.first, v = it.second.second;
        int fu = Find(u), fv = Find(v);
        if(fu!=fv){
            if(val[fu] == x){
                fa[fv]=f[fv]=fu;
            }
            else if(val[fv] == x){
                fa[fu]=f[fu]=fv;
            }
            else{
                tot++;
                val[tot]=x;
                f[tot]=tot;
                f[fu]=f[fv]=fa[fu]=fa[fv]=tot;
            }
        }
    }
    printf("%d\n",tot);
    for(int i=1;i<=tot;i++)
        printf("%d%c",val[i],(i==tot?'\n':' '));
    printf("%d\n",tot);
    for(int i=1;i<tot;i++)
        printf("%d %d\n",i,fa[i]);
    return 0;
}