Problem: You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.

A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different.

What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself.

Input

The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9).

Output

In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any.

Examples

Input


12
3 1 4 1 5 9 2 6 5 3 5 8


Output


12
3 4
1 2 3 5
3 1 5 4
5 6 8 9


Input


5
1 1 1 1 1


Output


1
1 1
1

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class SolutionC extends Thread {
    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;
        }
    }

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        solve();
        out.close();
    }

    static class Pair implements Comparable<Pair> {
        int number;
        int amount;


        public Pair(int number, int amount) {
            this.number = number;
            this.amount = amount;
        }

        @Override
        public int compareTo(Pair o) {
            return this.amount - o.amount;
        }
    }

    private static void solve() {
        int n = scanner.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> distr = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            distr.merge(a[i], 1, Integer::sum);
        }

        List<Pair> pairs = new ArrayList<>();
        for (Map.Entry<Integer, Integer> entry: distr.entrySet()) {
            pairs.add(new Pair(entry.getKey(), entry.getValue()));
        }
        Collections.sort(pairs);

        int[] prefixSum = new int[pairs.size() + 1];
        for (int i = 0; i < pairs.size(); i++) {
            prefixSum[i+1] = prefixSum[i] + pairs.get(i).amount;
        }

        int maxArea = 0;
        int bestWidth = 0;
        int bestHeight = 0;

        for (int height = 1; height <= Math.sqrt(n); height++) {
            int amountElementsUsable = 0;
            int low = -1;
            int high = pairs.size();
            while(high - low > 1) {
                int mid = (low + high) / 2;
                if (pairs.get(mid).amount < height) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            amountElementsUsable = prefixSum[high] + (pairs.size() - high) * height;

            int width = amountElementsUsable / height;
            if (width < height) {
                continue;
            }
            int area = width * height;
            if (area > maxArea) {
                maxArea = area;
                bestWidth = width;
                bestHeight = height;
            }
        }

        int pointerPairs = pairs.size() - 1;
        int currentRow = 0;
        int currentCol = 0;
        int startCol = 1;
        int[][] rect = new int[bestHeight][bestWidth];
        int amountCellsSet = 0;

        pairs.get(pointerPairs).amount = Math.min(bestHeight, pairs.get(pointerPairs).amount);

        while (amountCellsSet < bestHeight * bestWidth) {
            rect[currentRow][currentCol] = pairs.get(pointerPairs).number;
            pairs.get(pointerPairs).amount--;
            if (pairs.get(pointerPairs).amount == 0) {
                pointerPairs--;
                if (pointerPairs > 0) {
                    pairs.get(pointerPairs).amount = Math.min(pairs.get(pointerPairs).amount, bestHeight);
                }
            }
            amountCellsSet++;
            currentRow++;
            currentCol = (currentCol + 1) % bestWidth;

            if (currentRow == bestHeight) {
                currentRow = 0;
                currentCol = startCol++;
            }
        }

        out.println(bestWidth * bestHeight);
        out.println(bestHeight + " " + bestWidth);
        for (int h = 0; h < bestHeight; h++) {
            StringBuilder s = new StringBuilder();
            for (int w = 0; w < bestWidth; w++) {
                s.append(rect[h][w])
                 .append(" ");
            }
            out.println(s);
        }
    }

    //REMINDERS:
    //- CHECK FOR INTEGER-OVERFLOW BEFORE SUBMITTING

    //- CAN U BRUTEFORCE OVER SOMETHING, TO MAKE IT EASIER TO CALCULATE THE SOLUTION
}