Problem: A Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with integers from 1 to m, and the children are numbered from 1 to n. Then the i-th child has both mittens of color ci.

The Party had Santa Claus ('Father Frost' in Russian), his granddaughter Snow Girl, the children danced around the richly decorated Christmas tree. In fact, everything was so bright and diverse that the children wanted to wear mittens of distinct colors. The children decided to swap the mittens so that each of them got one left and one right mitten in the end, and these two mittens were of distinct colors. All mittens are of the same size and fit all the children.

The children started exchanging the mittens haphazardly, but they couldn't reach the situation when each child has a pair of mittens of distinct colors. Vasily Petrov, the dad of one of the children, noted that in the general case the children's idea may turn out impossible. Besides, he is a mathematician and he came up with such scheme of distributing mittens that the number of children that have distinct-colored mittens was maximum. You task is to repeat his discovery. Note that the left and right mittens are different: each child must end up with one left and one right mitten.

Input

The first line contains two integers n and m — the number of the children and the number of possible mitten colors (1 ≤ n ≤ 5000, 1 ≤ m ≤ 100). The second line contains n integers c1, c2, ... cn, where ci is the color of the mittens of the i-th child (1 ≤ ci ≤ m).

Output

In the first line, print the maximum number of children who can end up with a distinct-colored pair of mittens. In the next n lines print the way the mittens can be distributed in this case. On the i-th of these lines print two space-separated integers: the color of the left and the color of the right mitten the i-th child will get. If there are multiple solutions, you can print any of them.

Examples

Input

6 3
1 3 2 2 1 1


Output

6
2 1
1 2
2 1
1 3
1 2
3 1


Input

4 2
1 2 1 1


Output

2
1 2
1 1
2 1
1 1

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.StringTokenizer;

public class CodeC
{
    static class Scanner
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch(Exception e)
            {
                throw(new RuntimeException());
            }
        }

        public String next()
        {
            while(!st.hasMoreTokens())
            {
                String l = nextLine();
                if(l == null)
                    return null;
                st = new StringTokenizer(l);
            }
            return st.nextToken();
        }

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

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

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

        public int[] nextIntArray(int n)
        {
            int[] res = new int[n];
            for(int i = 0; i < res.length; i++)
                res[i] = nextInt();
            return res;
        }

        public long[] nextLongArray(int n)
        {
            long[] res = new long[n];
            for(int i = 0; i < res.length; i++)
                res[i] = nextLong();
            return res;
        }

        public double[] nextDoubleArray(int n)
        {
            double[] res = new double[n];
            for(int i = 0; i < res.length; i++)
                res[i] = nextDouble();
            return res;
        }

        public void sortIntArray(int[] array)
        {
            Integer[] vals = new Integer[array.length];
            for(int i = 0; i < array.length; i++)
                vals[i] = array[i];
            Arrays.sort(vals);
            for(int i = 0; i < array.length; i++)
                array[i] = vals[i];
        }

        public void sortLongArray(long[] array)
        {
            Long[] vals = new Long[array.length];
            for(int i = 0; i < array.length; i++)
                vals[i] = array[i];
            Arrays.sort(vals);
            for(int i = 0; i < array.length; i++)
                array[i] = vals[i];
        }

        public void sortDoubleArray(double[] array)
        {
            Double[] vals = new Double[array.length];
            for(int i = 0; i < array.length; i++)
                vals[i] = array[i];
            Arrays.sort(vals);
            for(int i = 0; i < array.length; i++)
                array[i] = vals[i];
        }

        public String[] nextStringArray(int n)
        {
            String[] vals = new String[n];
            for(int i = 0; i < n; i++)
                vals[i] = next();
            return vals;
        }

        public Integer nextInteger()
        {
            String s = next();
            if(s == null)
                return null;
            return Integer.parseInt(s);
        }

        public int[][] nextIntMatrix(int n, int m)
        {
            int[][] ans = new int[n][];
            for(int i = 0; i < n; i++)
                ans[i] = nextIntArray(m);
            return ans;
        }

        public char[][] nextGrid(int r)
        {
            char[][] grid = new char[r][];
            for(int i = 0; i < r; i++)
                grid[i] = next().toCharArray();
            return grid;
        }

        public static <T> T fill(T arreglo, int val)
        {
            if(arreglo instanceof Object[])
            {
                Object[] a = (Object[]) arreglo;
                for(Object x : a)
                    fill(x, val);
            }
            else if(arreglo instanceof int[])
                Arrays.fill((int[]) arreglo, val);
            else if(arreglo instanceof double[])
                Arrays.fill((double[]) arreglo, val);
            else if(arreglo instanceof long[])
                Arrays.fill((long[]) arreglo, val);
            return arreglo;
        }

        <T> T[] nextObjectArray(Class<T> clazz, int size)
        {
            @SuppressWarnings("unchecked")
            T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);
            for(int c = 0; c < 3; c++)
            {
                Constructor<T> constructor;
                try
                {
                    if(c == 0)
                        constructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE);
                    else if(c == 1)
                        constructor = clazz.getDeclaredConstructor(Scanner.class);
                    else
                        constructor = clazz.getDeclaredConstructor();
                }
                catch(Exception e)
                {
                    continue;
                }
                try
                {
                    for(int i = 0; i < result.length; i++)
                    {
                        if(c == 0)
                            result[i] = constructor.newInstance(this, i);
                        else if(c == 1)
                            result[i] = constructor.newInstance(this);
                        else
                            result[i] = constructor.newInstance();
                    }
                }
                catch(Exception e)
                {
                    throw new RuntimeException(e);
                }
                return result;
            }
            throw new RuntimeException("Constructor not found");
        }

        public void printLine(int... vals)
        {
            if(vals.length == 0)
                System.out.println();
            else
            {
                System.out.print(vals[0]);
                for(int i = 1; i < vals.length; i++)
                    System.out.print(" ".concat(String.valueOf(vals[i])));
                System.out.println();
            }
        }

        public void printLine(long... vals)
        {
            if(vals.length == 0)
                System.out.println();
            else
            {
                System.out.print(vals[0]);
                for(int i = 1; i < vals.length; i++)
                    System.out.print(" ".concat(String.valueOf(vals[i])));
                System.out.println();
            }
        }

        public void printLine(double... vals)
        {
            if(vals.length == 0)
                System.out.println();
            else
            {
                System.out.print(vals[0]);
                for(int i = 1; i < vals.length; i++)
                    System.out.print(" ".concat(String.valueOf(vals[i])));
                System.out.println();
            }
        }

        public void printLine(int prec, double... vals)
        {
            if(vals.length == 0)
                System.out.println();
            else
            {
                System.out.printf("%." + prec + "f", vals[0]);
                for(int i = 1; i < vals.length; i++)
                    System.out.printf(" %." + prec + "f", vals[i]);
                System.out.println();
            }
        }

        public Collection<Integer> wrap(int[] as)
        {
            ArrayList<Integer> ans = new ArrayList<Integer>();
            for(int i : as)
                ans.add(i);
            return ans;
        }

        public int[] unwrap(Collection<Integer> collection)
        {
            int[] vals = new int[collection.size()];
            int index = 0;
            for(int i : collection)
                vals[index++] = i;
            return vals;
        }
    }

    static class Edge
    {
        int from, to, index;
        long cap, flow;

        Edge(int fromi, int toi, long capi, long flowi, int indexi)
        {
            from = fromi;
            to = toi;
            cap = capi;
            flow = flowi;
            index = indexi;
        }
    }

    static class Dinic
    {
        int N;
        ArrayList<Edge>[] G;
        Edge[] dad;
        int[] Q;

        @SuppressWarnings("unchecked")
        Dinic(int N1)
        {
            N = N1;
            G = new ArrayList[N];
            for(int i = 0; i < N; i++)
                G[i] = new ArrayList<Edge>();
            dad = new Edge[N];
            Q = new int[N];
        }

        void AddEdge(int from, int to, int cap)
        {
            G[from].add(new Edge(from, to, cap, 0, G[to].size()));
            if(from == to)
                G[from].get(G[from].size() - 1).index++;
            G[to].add(new Edge(to, from, 0, 0, G[from].size() - 1));
        }

        Edge especial = new Edge(0, 0, 0, 0, 0);

        long BlockingFlow(int s, int t)
        {
            Arrays.fill(dad, null);
            dad[s] = especial;

            int head = 0, tail = 0;
            Q[tail++] = s;
            while(head < tail)
            {
                int x = Q[head++];
                for(Edge e : G[x])
                {
                    if(dad[e.to] == null && e.cap - e.flow > 0)
                    {
                        dad[e.to] = e;
                        Q[tail++] = e.to;
                    }
                }
            }
            if(dad[t] == null)
                return 0;

            long totflow = 0;
            for(Edge e1 : G[t])
            {
                Edge start = G[e1.to].get(e1.index);
                long amt = Long.MAX_VALUE / 4;
                for(Edge e = start; amt != 0 && e != dad[s]; e = dad[e.from])
                {
                    if(e == null)
                    {
                        amt = 0;
                        break;
                    }
                    amt = Math.min(amt, e.cap - e.flow);
                }
                if(amt == 0)
                    continue;
                for(Edge e = start; amt != 0 && e != dad[s]; e = dad[e.from])
                {
                    e.flow += amt;
                    G[e.to].get(e.index).flow -= amt;
                }
                totflow += amt;
            }
            return totflow;
        }

        long GetMaxFlow(int s, int t)
        {
            long totflow = 0;
            long flow = 0;
            while((flow = BlockingFlow(s, t)) != 0)
                totflow += flow;
            return totflow;
        }
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] leftCount = new int[m];
        int[] rightCount = new int[m];
        int[] leftLabel = new int[m];
        int[] rightLabel = new int[m];
        for(int i : sc.nextIntArray(n))
        {
            leftCount[i - 1]++;
            rightCount[i - 1]++;
        }
        int current = 0;
        int source = current++;
        int sink = current++;
        for(int i = 0; i < m; i++)
        {
            leftLabel[i] = current++;
            rightLabel[i] = current++;
        }
        Dinic dinic = new Dinic(current);
        for(int i = 0; i < m; i++)
        {
            if(leftCount[i] != 0)
                dinic.AddEdge(source, leftLabel[i], leftCount[i]);
            if(rightCount[i] != 0)
                dinic.AddEdge(rightLabel[i], sink, rightCount[i]);
            for(int j = 0; leftCount[i] != 0 && j < m; j++)
            {
                if(i == j)
                    continue;
                if(rightCount[j] != 0)
                    dinic.AddEdge(leftLabel[i], rightLabel[j], n);
            }
        }
        int ans = (int) dinic.GetMaxFlow(source, sink);
        int[][] flows = new int[current][current];
        for(int i = 0; i < current; i++)
        {
            for(Edge e : dinic.G[i])
                flows[i][e.to] = (int) e.flow;
        }
        ArrayList<String> answerStrings = new ArrayList<String>();
        for(int i = 0; i < m; i++)
        {
            for(int j = 0; j < m; j++)
            {
                int count = flows[leftLabel[i]][rightLabel[j]];
                for(int k = 0; k < count; k++)
                {
                    answerStrings.add((i + 1) + " " + (j + 1));
                    leftCount[i]--;
                    rightCount[j]--;
                }
            }
        }
        for(int i = 0; i < m; i++)
        {
            for(int j = 0; j < m; j++)
            {
                int count = Math.min(leftCount[i], rightCount[j]);
                for(int k = 0; k < count; k++)
                {
                    answerStrings.add((i + 1) + " " + (j + 1));
                    leftCount[i]--;
                    rightCount[j]--;
                }
            }
        }
        System.out.println(ans);
        for(String s : answerStrings)
            System.out.println(s);
    }
}