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 static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;

public class A
{
    static int n;
    static int[][] arr;
    static char[] s;
    static List<Node> A;
    static Map<Integer, Integer> root;
    public static void main(String[] args) throws IOException
    {
        f = new Flash();
        out = new PrintWriter(System.out);
        
        int T = 1; //ni();
        for(int tc = 1; tc <= T; tc++){
            n = ni(); arr = new int[n+1][n+1];
            A = new ArrayList<>();
            for(int i = 1; i <= n; i++) {
            	for(int j = 1; j <= n; j++) {
            		arr[i][j] = ni();
            		if(j <= i) continue;
            		A.add(new Node(i, j, arr[i][j]));
            	}
            }
            
            fn();
        }
        
        out.flush(); out.close();
    }
    
    //DSU approach with little modification
    static void fn()
    {
    	List<Integer> salary = new ArrayList<>();
    	salary.add(0);
    	for(int i = 1; i <= n; i++) salary.add(arr[i][i]);
    	List<int[]> ans = new ArrayList<>();
    	
    	root = new HashMap<>();
    	for(int i = 1; i <= n; i++) root.put(i, i);
        Collections.sort(A);
        for(Node N : A) {
        	int r1 = find(N.i);
        	int r2 = find(N.j);
        	if(r1 == r2) continue;
        	int s1 = salary.get(r1), s2 = salary.get(r2);
        	if(N.salary == max(s1, s2)) {
        		if(N.salary == s1) {
        			root.put(r2, r1);
        			ans.add(new int[] {r2, r1});
        		}else {
        			root.put(r1, r2);
        			ans.add(new int[] {r1, r2});
        		}
        	}
        	
        	else {
        		int newNode = ++n;
        		root.put(newNode, newNode);
        		root.put(r1, newNode);
        		root.put(r2, newNode);
        		salary.add(N.salary);
        		ans.add(new int[] {r1, newNode});
        		ans.add(new int[] {r2, newNode});
        	}
        }
        
        StringBuilder sb = new StringBuilder();
    	for(int i = 1; i <= n; i++) {
    		int value = salary.get(i);
    		sb.append(value).append(" ");
    	}
    	
        sop(n);
        sop(sb);
        sop(n);
        for(int[] uv : ans) {
        	sop(uv[0] + " " + uv[1]);
        }
    }
    
    static int find(int u) {
    	if(root.get(u) == u) return u;
    	root.put(u, find(root.get(u)));
    	return root.get(u);
    }
    
    static class Node implements Comparable<Node>{
    	int salary, i, j;
    	Node(int i, int j, int s){
    		this.i = i;
    		this.j = j;
    		salary = s;
    	}
    	
    	public int compareTo(Node N2) {
    		return Integer.compare(this.salary, N2.salary);
    	}
    }
    
    static Flash f;
    static PrintWriter out;
    static final long mod = (long)1e9+7;
    static final long inf = Long.MAX_VALUE;
    static final int _inf = Integer.MAX_VALUE;
    static final int maxN = (int)5e5+5;
    static long[] fact, inv;
    
    static void sort(int[] a){
        List<Integer> A = new ArrayList<>();
        for(int i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }
    
    static void sort(long[] a){
        List<Long> A = new ArrayList<>();
        for(long i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }
    
    static void print(int[] a){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
        sop(sb);
    }
    
    static void print(long[] a){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
        sop(sb);
    }
    
    static int swap(int itself, int dummy){return itself;}
    static long swap(long itself, long dummy){return itself;}
    static void sop(Object o){out.println(o);}
    static int ni(){return f.ni();}
    static long nl(){return f.nl();}
    static double nd(){return f.nd();}
    static String next(){return f.next();}
    static String ns(){return f.ns();}
    static char[] nc(){return f.nc();}
    static int[] arr(int len){return f.arr(len);}
    static int gcd(int a, int b){if(b == 0) return a; return gcd(b, a%b);}
    static long gcd(long a, long b){if(b == 0) return a; return gcd(b, a%b);}
    static int lcm(int a, int b){return (a*b)/gcd(a, b);}
    static long lcm(long a, long b){return (a*b)/gcd(a, b);}
    
    static class Flash
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        
        String next(){
            while(!st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            
            return st.nextToken();
        }
        
        String ns(){
            String s = new String();
            try{
                s = br.readLine().trim();
            }catch(IOException e){
                e.printStackTrace();
            }
            
            return s;
        }
        
        int[] arr(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = ni();
            return a;
        }
        
        char[] nc(){return ns().toCharArray();}
        int ni(){return Integer.parseInt(next());}
        long nl(){return Long.parseLong(next());}
        double nd(){return Double.parseDouble(next());}
    }
}