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 JAVA):

Solution:
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.stream.IntStream;

public class MainJava {
    boolean TEST = false;

    class Data implements Comparable<Data> {
        int a;
        int b;
        int val;

        Data(int a, int b, int val) {
            this.a = a;
            this.b = b;
            this.val = val;
        }

        @Override
        public int compareTo(Data o) {
            if (val == o.val) {
                if (a == o.a) {
                    return Integer.compare(b, o.b);
                }
                return Integer.compare(a, o.a);
            }
            return Integer.compare(val, o.val);
        }
    }

    class DSU {
        int[] p, d;

        DSU(int n) {
            p = new int[n];
            d = new int[n];
            for (int i = 0; i < n; i++) {
                d[i] = 1;
                p[i] = i;
            }
        }

        int get(int v) {
            if (p[v] == v) return v;
            return p[v] = get(p[v]);
        }

        void uni(int a, int b) {
            a = get(a);
            b = get(b);
            if (a == b) return;
            if (d[a] < d[b]) {
                int c = a;
                a = b;
                b = c;
            }
            d[a] += d[b];
            p[b] = a;
        }
    }


    void solve() throws IOException {
        int n = readInt();
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) {
            a[i] = readIntArray(n);
        }

        PriorityQueue<Data> pq = new PriorityQueue<>();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                pq.add(new Data(i, j, a[i][j]));
            }
        }
        int[] grand = new int[n];
        for (int i = 0; i < n; i++) {
            grand[i] = i;
        }

        ArrayList<Data> edges = new ArrayList<>();
        int counter = n;
        DSU dsu = new DSU(n);
        int[] values = new int[2 * n];
        for (int i = 0; i < n; i++) values[i] = a[i][i];
        while (!pq.isEmpty()) {
            Data cur = pq.poll();
            int from = cur.a;
            int to = cur.b;
            int value = cur.val;

            int parFrom = dsu.get(from);
            int parTo = dsu.get(to);

            if (values[grand[parFrom]] == value && values[grand[parTo]] == value) {
                if (grand[parFrom] != grand[parTo]) {
                    while (true) {}
                }
            } else if (values[grand[parFrom]] == value) {
                int par = grand[parFrom];
                edges.add(new Data(grand[parTo], par, 0));
                grand[parTo] = par;
            } else if (values[grand[parTo]] == value) {
                int par = grand[parTo];
                edges.add(new Data(grand[parFrom], par, 0));
                grand[parFrom] = par;
            } else {
                int par = counter++;
                values[par] = value;
                edges.add(new Data(grand[parFrom], par, 0));
                edges.add(new Data(grand[parTo], par, 0));
                grand[parFrom] = par;
                grand[parTo] = par;
            }
            dsu.uni(parFrom, parTo);
        }


        out.print(counter + "\n");
        for (int i = 0; i < counter; i++) {
            out.print(values[i] + " ");
        }
        out.print('\n');
        out.print(counter + "\n");
        for (Data data : edges) {
            int from = data.a;
            int to = data.b;
            if (values[from] > values[to]) {
                int tmp = from;
                from = to;
                to = tmp;
            }
            out.print((from + 1) + " " + (to + 1) + "\n");
        }

    }

    int count(int[] a, int l, int r) {
        l = lowerBound(a, l);
        r = upperBound(a, r);
        return r - l;
    }

    int lowerBound(int[] a, int value) {
        int l = 0;
        int r = a.length - 1;
        int m;
        int ans = r + 1;
        while (l <= r) {
            m = (l + r) >> 1;
            if (a[m] >= value) {
                ans = m;
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        return ans;
    }

    int upperBound(int[] a, int value) {
        int l = 0;
        int r = a.length - 1;
        int m;
        int ans = r + 1;
        while (l <= r) {
            m = (l + r) >> 1;
            if (a[m] > value) {
                ans = m;
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        return ans;
    }

    void solveMain() throws IOException {
        init();
        int t = 1;
        if (TEST) {
            t = readInt();
        }
        while (t-- > 0) {
            solve();
        }
        out.flush();
    }


    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;


    void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
    }


    String readLine() throws IOException {
        return in.readLine();
    }

    String delimiter = " ";

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int[] readIntArray(int b) {
        int[] a = new int[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }


    long[] readLongArray(int b) {
        long[] a = new long[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readLong();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }


    void sortArrayInteger(int[] a) {
        Integer[] arr = new Integer[a.length];
        for (int i = 0; i < a.length; i++) {
            arr[i] = a[i];
        }
        Arrays.sort(arr);
        for (int i = 0; i < a.length; i++) {
            a[i] = arr[i];
        }
    }


    public static void main(String[] args) {
        new MainJava().run();
    }

    void run() {
        try {
            long timeStart = System.currentTimeMillis();

            init();
            solveMain();

            out.close();

            long timeEnd = System.currentTimeMillis();
            System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

}