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:
// Author : RegalBeast

import java.io.*;
import java.util.*;

public class Main {
  static final FastReader FR = new FastReader();
  static final PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));

  public static void main(String[] args) {
    StringBuilder solution = new StringBuilder();
    int baseEmployees = FR.nextInt();
    // List<Integer> subordinates = new ArrayList<Integer>(baseEmployees);
    Set<Integer> subordinates = new HashSet<Integer>();
    List<List<Integer>> sharedSupervisorSalary = new ArrayList<List<Integer>>(baseEmployees);
    Map<Integer, Map<Integer, Set<Integer>>> sharedPairs = new HashMap<Integer, Map<Integer, Set<Integer>>>();

    for (int e1 = 0; e1 < baseEmployees; e1 += 1) {
      subordinates.add(e1+1);
      sharedSupervisorSalary.add(new ArrayList<Integer>(baseEmployees));
      for (int e2 = 0; e2 < baseEmployees; e2 += 1) {
        int sharedSalary = FR.nextInt();
        sharedSupervisorSalary.get(e1).add(sharedSalary);
        if (!sharedPairs.containsKey(sharedSalary)) {
          sharedPairs.put(sharedSalary, new HashMap<Integer, Set<Integer>>());
        }
        if (!sharedPairs.get(sharedSalary).containsKey(e1+1)) {
          sharedPairs.get(sharedSalary).put(e1+1, new HashSet<Integer>());
        }
        sharedPairs.get(sharedSalary).get(e1+1).add(e2+1);
      }
    }
    NextFree.setValue(baseEmployees+1);

    Map<Integer, Integer> salaries = new HashMap<Integer, Integer>();
    Map<Integer, Integer> supervisors = new HashMap<Integer, Integer>();
    
    Node boss = new Node(subordinates, sharedSupervisorSalary, sharedPairs, -1, salaries, supervisors);
    boss.buildStructure();

    solution.append(salaries.size() + "\n");
    for (int e = 0; e < salaries.size(); e += 1) {
      solution.append(salaries.get(e+1) + " ");
    }
    solution.append("\n");

    solution.append((baseEmployees+1) + "\n");
    for (var entry : supervisors.entrySet()) {
      int employeeIdx = entry.getKey();
      int supervisorIdx = entry.getValue();
      if (supervisorIdx == -1) {
        continue;
      }
      solution.append(employeeIdx + " " + supervisorIdx + "\n");
    }

		PW.print(solution.toString());
    PW.close();
  }

  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e)  {
        e.printStackTrace();
      }
      return str;
    }
  }
}

class Node {
  private int supervisorIdx;
  private int index;
  private Set<Integer> subordinates;
  private List<List<Integer>> sharedSupervisorSalary;
  private Map<Integer, Map<Integer, Set<Integer>>> sharedPairs;
  private Map<Integer, Integer> salaries;
  private Map<Integer, Integer> supervisors;
  private Node subordinate1, subordinate2;

  public Node(Set<Integer> subordinates, List<List<Integer>> sharedSupervisorSalary, Map<Integer, Map<Integer, Set<Integer>>> sharedPairs, int supervisorIdx, Map<Integer, Integer> salaries, Map<Integer, Integer> supervisors) {
    this.supervisorIdx = supervisorIdx;
    this.index = subordinates.size() == 1 ? subordinates.iterator().next() : NextFree.getIdx();
    this.subordinates = subordinates;
    this.sharedSupervisorSalary = sharedSupervisorSalary;
    this.sharedPairs = sharedPairs;
    this.salaries = salaries;
    this.supervisors = supervisors;
    subordinate1 = null;
    subordinate2 = null;
  }

  public void buildStructure() {
    if (subordinates.size() == 1) {
      supervisors.put(index, supervisorIdx);
      salaries.put(index, sharedSupervisorSalary.get(index-1).get(index-1));
      return;
    }

    int salary = findSalary();
    int passIdx = index;
    if (supervisorIdx > 0 && salary == salaries.get(supervisorIdx)) {
      passIdx = supervisorIdx;
      NextFree.decrement();
    }
    if (passIdx == index) {
      supervisors.put(index, supervisorIdx);
      salaries.put(index, salary);
    }


    Set<Integer> leftSubordinates = new HashSet<Integer>();
    Set<Integer> rightSubordinates = new HashSet<Integer>();
    Set<Integer> settled = new HashSet<Integer>();
    
    int firstSub = -1;
    for (var sub : sharedPairs.get(salary).keySet()) {
      if (subordinates.contains(sub)) {
        firstSub = sub;
        break;
      }
    }
    // System.out.println("Index: " + index + " Salary: " + salary);
    // System.out.println("Set: " + subordinates + "\n");

    // int firstSub = sharedPairs.get(salary).keySet().iterator().next();
    leftSubordinates.add(firstSub);
    settled.add(firstSub);
    for (var other : sharedPairs.get(salary).get(firstSub)) {
      if (!subordinates.contains(other)) {
        continue;
      }
      rightSubordinates.add(other);
      settled.add(other);
    }
    for (var sub : subordinates) {
      if (!settled.contains(sub)) {
        leftSubordinates.add(sub);
        settled.add(sub);
      }
    }
    // for (var sub : sharedPairs.get(salary).keySet()) {
      // if (!subordinates.contains(sub)) {
        // continue;
      // }
      // if (settled.contains(sub)) {
        // continue;
      // }
      // leftSubordinates.add(sub);
      // settled.add(sub);
    // }

    subordinate1 = new Node(leftSubordinates, sharedSupervisorSalary, sharedPairs, passIdx, salaries, supervisors);
    subordinate1.buildStructure();
    subordinate2 = new Node(rightSubordinates, sharedSupervisorSalary, sharedPairs, passIdx, salaries, supervisors);
    subordinate2.buildStructure();
  }

  private int findSalary() {
    int salary = 0;
    int commonSub = subordinates.iterator().next();
    for (var other : subordinates) {
      salary = Math.max(salary, sharedSupervisorSalary.get(commonSub-1).get(other-1));
    }
    return salary;
  }
}

class NextFree {
  private static int useThis = 0;
  public static void setValue(int value) {
    useThis = value;
  }
  public static int getIdx() {
    return useThis++;
  }
  public static void decrement() {
    useThis -= 1;
  }
}