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 java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sandip Jana
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n = in.readInt();
            ArrayList<TaskD.Point3d> points = new ArrayList<TaskD.Point3d>();
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    int weight = in.readInt();
                    points.add(new TaskD.Point3d(i, j, weight));
                }
            }

            Collections.sort(points, new Comparator<TaskD.Point3d>() {

                public int compare(TaskD.Point3d o1, TaskD.Point3d o2) {
                    if (o1.w == o2.w) {
                        if (o1.u != o2.u)
                            return Integer.compare(o1.u, o2.u);
                        else
                            return Integer.compare(o1.v, o2.v);
                    }
                    return Integer.compare(o1.w, o2.w);
                }
            });

            HashMap<Integer, TaskD.Node> hash = new HashMap<>();
            TaskD.DSU dsu = new TaskD.DSU(2 * n + 1);
            int count = n;
            for (TaskD.Point3d p : points) {
                int u = p.u;
                int v = p.v;
                int w = p.w;

                if (u == v) {
                    TaskD.Node node = new TaskD.Node(u, w);
                    hash.put(u, node);
                    continue;
                }

                if (!dsu.connected(u, v)) {

                    int p1 = dsu.root(u);
                    int p2 = dsu.root(v);

                    if (hash.get(p1).w == w) {
                        dsu.union(p1, v);
                        hash.get(p2).supervisor = p1;
                        continue;
                    }

                    if (hash.get(p2).w == w) {
                        dsu.union(p2, v);
                        hash.get(p2).supervisor = count;
                        continue;
                    }


                    TaskD.Node node = new TaskD.Node(++count, w);
                    hash.get(p1).supervisor = count;
                    hash.get(p2).supervisor = count;
                    dsu.union(count, u);
                    dsu.union(count, v);

                    hash.put(count, node);

                }
            }

            out.println(count);
            int head = 0, maxw = 0;
            for (int i = 1; i <= count; i++) {
                out.print(hash.get(i).w + " ");
                if (i == count)
                    out.print("\n");

                if (hash.get(i).w > maxw) {
                    maxw = hash.get(i).w;
                    head = i;
                }

                //System.out.println(i+" Hi");
                //if( hash.get(i).supervisor == 0 )
                //    throw new IllegalStateException();
            }


            out.println(head);

            for (int i = 1; i <= count; i++) {
                if (i == head) continue;

                out.println(i + " " + hash.get(i).supervisor);
            }


        }

        static class Node {
            int u;
            int w;
            int supervisor;

            public Node(int u, int w) {
                this.u = u;
                this.w = w;
            }

        }

        static class Point3d {
            int u;
            int w;
            int v;

            public Point3d(int u, int v, int w) {
                this.u = u;
                this.v = v;
                this.w = w;
            }

        }

        static class DSU {
            int n;
            int[] parent;

            DSU(int n) {
                this.n = n;
                parent = new int[n + 1];
                Arrays.fill(parent, -1);
            }

            boolean connected(int u, int v) {
                return root(u) == root(v);
            }

            int root(int x) {
                return (parent[x] < 0) ? x : (parent[x] = root(parent[x]));
            }

            int union(int u, int v) {
                u = root(u);
                v = root(v);
                if (u != v) {
//                if( -parent[u] < -parent[v] ) {
//                    int temp = u; u = v ; v = temp;
//                }
                    parent[u] += parent[v];
                    parent[v] = u;
                }
                return u;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}