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:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 29;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
#define pb push_back
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define all(x) (x).begin(),(x).end()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mrand(ll B) {
  return (ull)rng() % B;
}

ll cross(pair<ll, ll> p1, pair<ll, ll> p2) {
    return p1.first*p2.second - p2.first*p1.second;
}

bool online(pair<ll, ll> a, pair<ll, ll> b, pair<ll, ll> c) {
    pair<ll, ll> p1{b.first-a.first, b.second-a.second};
    pair<ll, ll> p2{c.first-a.first, c.second-a.second};
    return cross(p1, p2) == 0;
}

void z_func(vector<int> &z, vector<int> &s, int n) {
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
}

const int N = 505;
int n;
int next_id;
int ans[N*N];
int sal[N*N];
int v[N][N];

int solve(set<int> &nodes) {
    // cout << "solve: ";
    // for (auto s : nodes) cout << s << ' ';
    // cout << '\n' << endl;
    if (sz(nodes) == 1) {
        int id = *(nodes.begin());
        sal[id] = v[id][id];
        return id;
    }

    int max_val = -1;
    for (auto node : nodes) {
        for (int i = 1; i <= n; i++) {
            if (i == node || !nodes.count(i)) continue;
            max_val = max(max_val, v[i][node]);
        }
    }

    vector<set<int>> sets;
    //cout << "max_val: " << max_val << endl;
    for (auto node : nodes) {
        //cout << "processing node " << node << endl;
        bool found_set = false;
        for (auto &s : sets) {
            bool can_use_this_set = true;
            for (auto u : s) {
                if (v[u][node] == max_val) {
                    can_use_this_set = false;
                    break;
                }
            }
            if (can_use_this_set) {
                //cout << "A" << endl;
                s.insert(node);
                found_set = true;
                break;
            }
        }
        
        if (!found_set) {
            set<int> tmp; tmp.insert(node);
            sets.pb(tmp);
            //cout << "B" << endl;
        }
    }

    int root = next_id++;
    sal[root] = max_val;
    for (auto s : sets) {
        int ret = solve(s);
        ans[ret] = root;
    }
    return root;
}

void work() {
    cin >> n; next_id = n + 1;
    set<int> s;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> v[i][j];
        }
        s.insert(i);
    }

    int root = solve(s);
    cout << next_id - 1 << '\n';
    for (int i = 1; i < next_id; i++) cout << sal[i] << ' ';
    cout << '\n' << root << '\n';
    for (int i = 1; i < next_id; i++) {
        if (i == root) continue;
        cout << i << ' ' << ans[i] << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //int nt; cin>>nt; while (nt--) work();
    work();
    return 0;
}