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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <cstdlib>
#include <iomanip>
#include <cassert>


using namespace std;
//#define FAST_ALLOCATOR_MEMORY 10000000000
#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
    char *res = allocator_memory + allocator_pos;
    allocator_pos += n;
    assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
    return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

#define int long long
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define X first
#define Y second


const int inf = 1e18 + 7;
const int linf = 1e18 + 1;

template<typename T>
using V = vector<T>;

template<typename T = int>
T nxt() {
    T x;
    cin >> x;
    return x;
}

template<typename T = int>
void read(vector<T> &x) {
    for (T &i : x)
        cin >> i;
}

template<typename T = int>
void print(vector<T> &x) {
    for (T v : x) {
        cout << v << " ";
    }
}

template<typename T = int>
void printset(set<T> &x) {
    for (auto v : x)
        cout << v << " ";
    cout << endl;
}


signed main() {
    FAST;
    int n;
    cin >> n;
    vvi a(n, vi(n));
    for (int i = 0; i < n; ++i) {
        read(a[i]);
    }

    vi ans_prev(n, -1);
    vi ans_pay(n);
    vi prev(n);

    vi has;


    for (int i = 0; i < n; ++i) {
        has.pb(i);
        ans_pay[i] = a[i][i];
        prev[i] = i;
    }

    while(has.size() > 1) {
        int min_ = inf;

        unordered_set<int> ids;

        for (int i = 0; i < has.size(); ++i) {
            int u = has[i];
            for (int j = i + 1; j < has.size(); ++j) {
                int v = has[j];
                int mp = a[prev[u]][prev[v]];
                min_ = min(min_, mp);
            }
        }

        bool f = false;
        for (int i = 0; i < has.size()  && !f; ++i) {
            int u = has[i];
            for (int j = i + 1; j < has.size() && !f; ++j) {
                int v = has[j];
                int mp = a[prev[u]][prev[v]];

                if (mp == min_) {
                    ids.insert(u);
                    ids.insert(v);
                    f = true;
                }
            }
        }

        for (int i = 0; i < has.size(); ++i) {
            int v = has[i];
            if (ids.find(v) != ids.end()) {
                continue;
            }
            bool check = true;
            for (int u : ids) {
                int mp = a[prev[u]][prev[v]];
                if (mp != min_) {
                    check = false;
                }
            }
            if (check) {
                ids.insert(v);
            }
        }

        int next_num = ans_prev.size();

        for (int v : ids) {
            ans_prev[v] = next_num;
        }

        ans_pay.push_back(min_);
        ans_prev.push_back(-1);
        prev.push_back(prev[*ids.begin()]);

        has.push_back(next_num);

        vi new_has;

        for (int v : has) {
            if (ids.find(v) == ids.end()) {
                new_has.pb(v);
            }
        }

        swap(has, new_has);
    }

    int r = has[0];
    assert(ans_pay.size() == r + 1);
    cout << ans_pay.size() << endl;

    for (int v : ans_pay) {
        cout << v << " ";
    }
    cout << endl;
    cout << r + 1 << endl;

    for (int i = 0; i + 1 < ans_prev.size(); ++i) {
        cout << i + 1 << " " << ans_prev[i] + 1 << endl;
    }


    return 0;
}