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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Math.min;

/**
 * @author Don Li
 */
public class Mittens {
    
    static int INF = (int) 1e4;
    
    void solve() {
        int n = in.nextInt(), m = in.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) c[i] = in.nextInt() - 1;
        
        int[] cnt = new int[m];
        for (int i = 0; i < n; i++) cnt[c[i]]++;
        
        Dinic dinic = new Dinic(4 * m + 2);
        for (int i = 0; i < m; i++) {
            dinic.addEdge(4 * i, 4 * i + 1, cnt[i]);
            dinic.addEdge(4 * i + 2, 4 * i + 3, cnt[i]);
            for (int j = 0; j < m; j++) {
                if (i != j) {
                    dinic.addEdge(4 * i + 1, 4 * j + 2, INF);
                }
            }
        }
        int s = 4 * m, t = 4 * m + 1;
        for (int i = 0; i < m; i++) dinic.addEdge(s, 4 * i, INF);
        for (int i = 0; i < m; i++) dinic.addEdge(4 * i + 3, t, INF);
        
        int ans = dinic.maxFlow(s, t);
        out.println(ans);
        
        for (int i = 0; i < m; i++) {
            int u = 4 * i + 1;
            for (Edge e : dinic.G[u]) {
                int v = e.to, w = dinic.G[v].get(e.rev).cap;
                if ((v - 2) % 4 == 0) {
                    for (int j = 0; j < w; j++) {
                        out.printf("%d %d%n", i + 1, (v - 2) / 4 + 1);
                    }
                    cnt[i] -= w;
                }
            }
            for (int j = 0; j < cnt[i]; j++) {
                out.printf("%d %d%n", i + 1, i + 1);
            }
        }
    }
    
    static class Dinic {
        
        int V;
        List<Edge>[] G;
        
        int[] level; // level for vertices
        int[] iter;  // index of the current edge, previous checked edges can be safely bypassed
        
        // init the graph represented as adjacent list
        public Dinic(int V) {
            this.V = V;
            G = new List[V];
            for (int i = 0; i < V; i++) G[i] = new ArrayList<>();
            level = new int[V];
            iter = new int[V];
        }
        
        // add edge as well as corresponding reverse edge to the graph
        public void addEdge(int u, int v, int cap) {
            G[u].add(new Edge(v, cap, G[v].size()));
            G[v].add(new Edge(u, 0, G[u].size() - 1));
        }
        
        /**
         * find max flow by repeatedly adding augmenting path.
         *
         * @param s source
         * @param t sink
         * @return max flow
         */
        public int maxFlow(int s, int t) {
            int flow = 0;
            while (true) {
                bfs(s); // reconstruct the levels for vertices
                if (level[t] < 0) return flow; // terminate when there's no augmenting path from s to t
                Arrays.fill(iter, 0); // reset search index for outgoing edges for each vertex
                int f;
                while ((f = dfs(s, t, INF)) > 0) { // find augmenting path using the current level & search index
                    flow += f;
                }
            }
        }
        
        // do BFS to calc the level for vertices start from s
        private void bfs(int s) {
            Arrays.fill(level, -1);
            Queue<Integer> qu = new LinkedList<>();
            qu.offer(s);
            level[s] = 0;
            while (!qu.isEmpty()) {
                int u = qu.poll();
                for (Edge e : G[u]) {
                    int v = e.to;
                    if (e.cap > 0 && level[v] < 0) {
                        level[v] = level[u] + 1;
                        qu.offer(v);
                    }
                }
            }
        }
        
        // do DFS to find any augmenting path, also use level info to speed up.
        private int dfs(int u, int t, int f) {
            if (u == t) return f;
            while (iter[u] < G[u].size()) {
                Edge e = G[u].get(iter[u]);
                int v = e.to;
                if (e.cap > 0 && level[u] < level[v]) {
                    int d = dfs(v, t, min(f, e.cap));
                    if (d > 0) {
                        e.cap -= d;
                        G[v].get(e.rev).cap += d;
                        return d;
                    }
                }
                iter[u]++;
            }
            return 0;
        }
    }
    
    static class Edge {
        int to;  // next vertex
        int cap; // residual flow
        int rev; // index of the reverse edge
        
        public Edge(int to, int cap, int rev) {
            this.to = to;
            this.cap = cap;
            this.rev = rev;
        }
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Mittens().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}